Skip to content

Commit 73daea0

Browse files
committed
fix: pass OAuth scopes to DCR and extract granted_scopes from token response
Two fixes for OAuth scope handling in MCP server connections: 1. Patch rmcp to include scopes from WWW-Authenticate in the DCR registration request (see modelcontextprotocol/rust-sdk#705) 2. Extract granted_scopes from the token response instead of always saving an empty vec, so stored credentials accurately reflect what the authorization server granted. Signed-off-by: Peter Siska <63866+peschee@users.noreply.github.com>
1 parent 85c7f97 commit 73daea0

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

Cargo.lock

Lines changed: 13 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ tracing-opentelemetry = "0.32"
7272

7373
[patch.crates-io]
7474
v8 = { path = "vendor/v8" }
75+
rmcp = { git = "https://github.com/peschee/rust-sdk.git", branch = "fix-dcr-scopes" }

crates/goose/src/oauth/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use axum::response::Html;
55
use axum::routing::get;
66
use axum::Router;
77
use minijinja::render;
8-
use rmcp::transport::auth::{CredentialStore, OAuthState, StoredCredentials};
8+
use rmcp::transport::auth::{CredentialStore, OAuthState, StoredCredentials, TokenResponse};
99
use rmcp::transport::AuthorizationManager;
1010
use serde::Deserialize;
1111
use std::net::SocketAddr;
@@ -101,11 +101,18 @@ pub async fn oauth_flow(
101101
.into_authorization_manager()
102102
.ok_or_else(|| anyhow::anyhow!("Failed to get authorization manager"))?;
103103

104+
let granted_scopes: Vec<String> = token_response
105+
.as_ref()
106+
.and_then(|tr| tr.scopes())
107+
.map(|scopes| scopes.iter().map(|s| s.to_string()).collect())
108+
.unwrap_or_default();
109+
104110
credential_store
105111
.save(StoredCredentials {
106112
client_id,
107113
token_response,
108-
granted_scopes: vec![],
114+
granted_scopes,
115+
token_received_at: None,
109116
})
110117
.await?;
111118

0 commit comments

Comments
 (0)