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

View file

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