Skip to content

Commit 6011f34

Browse files
authored
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.
1 parent c0b777c commit 6011f34

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

crates/rmcp/src/transport/auth.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ impl AuthorizationSession {
623623
mut auth_manager: AuthorizationManager,
624624
scopes: &[&str],
625625
redirect_uri: &str,
626+
client_name: Option<&str>,
626627
) -> Result<Self, AuthError> {
627628
// set redirect uri
628629
let config = OAuthClientConfig {
@@ -634,7 +635,7 @@ impl AuthorizationSession {
634635

635636
// try to dynamic register client
636637
let config = match auth_manager
637-
.register_client("MCP Client", redirect_uri)
638+
.register_client(client_name.unwrap_or("MCP Client"), redirect_uri)
638639
.await
639640
{
640641
Ok(config) => config,
@@ -793,6 +794,7 @@ impl OAuthState {
793794
&mut self,
794795
scopes: &[&str],
795796
redirect_uri: &str,
797+
client_name: Option<&str>,
796798
) -> Result<(), AuthError> {
797799
if let OAuthState::Unauthorized(mut manager) = std::mem::replace(
798800
self,
@@ -802,7 +804,8 @@ impl OAuthState {
802804
let metadata = manager.discover_metadata().await?;
803805
manager.metadata = Some(metadata);
804806
debug!("start session");
805-
let session = AuthorizationSession::new(manager, scopes, redirect_uri).await?;
807+
let session =
808+
AuthorizationSession::new(manager, scopes, redirect_uri, client_name).await?;
806809
*self = OAuthState::Session(session);
807810
Ok(())
808811
} else {

examples/clients/src/auth/oauth_client.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ async fn main() -> Result<()> {
100100
.await
101101
.context("Failed to initialize oauth state machine")?;
102102
oauth_state
103-
.start_authorization(&["mcp", "profile", "email"], MCP_REDIRECT_URI)
103+
.start_authorization(
104+
&["mcp", "profile", "email"],
105+
MCP_REDIRECT_URI,
106+
Some("Test MCP Client"),
107+
)
104108
.await
105109
.context("Failed to start authorization")?;
106110

0 commit comments

Comments
 (0)