feat: allow clients to override client_name (#469)

Many MCP Servers use client_name for a variety of things including:
* Whitelisting
* Logos
* Copy shown directly on the page
* etc

As a result, it's important for MCP Clients to be able to override the client name.
This commit is contained in:
Gabriel Peal 2025-10-03 18:03:31 -07:00 • committed by GitHub
commit 6011f34ddf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View file

@ -623,6 +623,7 @@ impl AuthorizationSession {
mut auth_manager: AuthorizationManager, mut auth_manager: AuthorizationManager,
scopes: &[&str], scopes: &[&str],
redirect_uri: &str, redirect_uri: &str,
client_name: Option<&str>,
) -> Result<Self, AuthError> { ) -> Result<Self, AuthError> {
// set redirect uri // set redirect uri
let config = OAuthClientConfig { let config = OAuthClientConfig {
@ -634,7 +635,7 @@ impl AuthorizationSession {
// try to dynamic register client // try to dynamic register client
let config = match auth_manager let config = match auth_manager
.register_client("MCP Client", redirect_uri) .register_client(client_name.unwrap_or("MCP Client"), redirect_uri)
.await .await
{ {
Ok(config) => config, Ok(config) => config,
@ -793,6 +794,7 @@ impl OAuthState {
&mut self, &mut self,
scopes: &[&str], scopes: &[&str],
redirect_uri: &str, redirect_uri: &str,
client_name: Option<&str>,
) -> Result<(), AuthError> { ) -> Result<(), AuthError> {
if let OAuthState::Unauthorized(mut manager) = std::mem::replace( if let OAuthState::Unauthorized(mut manager) = std::mem::replace(
self, self,
@ -802,7 +804,8 @@ impl OAuthState {
let metadata = manager.discover_metadata().await?; let metadata = manager.discover_metadata().await?;
manager.metadata = Some(metadata); manager.metadata = Some(metadata);
debug!("start session"); debug!("start session");
let session = AuthorizationSession::new(manager, scopes, redirect_uri).await?; let session =
AuthorizationSession::new(manager, scopes, redirect_uri, client_name).await?;
*self = OAuthState::Session(session); *self = OAuthState::Session(session);
Ok(()) Ok(())
} else { } else {

View file

@ -100,7 +100,11 @@ async fn main() -> Result<()> {
.await .await
.context("Failed to initialize oauth state machine")?; .context("Failed to initialize oauth state machine")?;
oauth_state oauth_state
.start_authorization(&["mcp", "profile", "email"], MCP_REDIRECT_URI) .start_authorization(
&["mcp", "profile", "email"],
MCP_REDIRECT_URI,
Some("Test MCP Client"),
)
.await .await
.context("Failed to start authorization")?; .context("Failed to start authorization")?;