From 3adad9767eb19ab651b35e1f76b7f4a358df0225 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Wed, 21 Oct 2026 19:30:36 -0700 Subject: [PATCH] Publish public MCP server discovery Expose /.well-known/mcp-servers using the versioned discovery format, deriving endpoints and OAuth scopes from the active catalogs and configured origin. Keep MCP transport authentication intact and cover discovery in the authentication integration checks. Assisted-by: gpt-6-astra --- dashboard/src/main.rs | 1 + dashboard/src/mcp.rs | 21 +++++++++++++++++++++ tools/dashboard-auth-test.py | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/dashboard/src/main.rs b/dashboard/src/main.rs index a1caea1d51efc463f2d5053d25be525d439728aa..662cb3cf127fbed05d4d520a9d432904cf70d979 100644 --- a/dashboard/src/main.rs +++ b/dashboard/src/main.rs @@ -587,6 +587,7 @@ async fn main() -> std::result::Result<(), Box> { .route("/api/{*path}", any(api)) .route("/auth/{*path}", any(auth::route)) .route("/.well-known/openid-configuration", any(oidc::route)) + .route("/.well-known/mcp-servers", axum::routing::get(mcp::discovery)) .route("/oauth/{*path}", any(mcp::oauth)) .route("/.well-known/{*path}", any(mcp::oauth)) .nest_service("/assets", ServeDir::new(format!("{dist}/assets"))) diff --git a/dashboard/src/mcp.rs b/dashboard/src/mcp.rs index ef3c9a08bebfcbc5eea3bfe1e5d9c85598b7a2fe..c7e08e1d545ec9409dfbeb90de29e72e488e39ef 100644 --- a/dashboard/src/mcp.rs +++ b/dashboard/src/mcp.rs @@ -575,8 +575,29 @@ pub fn router( )) } +pub async fn discovery(State(app): State>) -> axum::Json { + axum::Json(json!({ + "version": "1.0", + "servers": CATALOGS.iter().map(|(id, name, scopes)| json!({ + "name": id, + "description": name, + "url": app.mcp.resource(id), + "transport": "streamable-http", + "authentication": { + "type": "oauth2", + "required": true, + "authorization_url": app.mcp.origin.join("oauth/authorize").unwrap().as_str(), + "scopes": scopes, + }, + "capabilities": ["tools"], + })).collect::>(), + "registry": {"name": "Snow Globe", "version": env!("CARGO_PKG_VERSION")}, + })) +} + pub fn public(path: &str) -> bool { path == "/.well-known/openid-configuration" + || path == "/.well-known/mcp-servers" || path.starts_with("/oauth/") || CATALOGS.iter().any(|(id, _, _)| { path == format!("/mcp/{id}") || path.starts_with(&format!("/mcp/{id}/")) diff --git a/tools/dashboard-auth-test.py b/tools/dashboard-auth-test.py index 2d6a1878897175bbce1f5a9563c12fd7904184b0..1b98153f2ef3b7dcaa24ef9f6ad408d3fc1611a4 100644 --- a/tools/dashboard-auth-test.py +++ b/tools/dashboard-auth-test.py @@ -113,6 +113,27 @@ def main(): cookies = {} start() try: + discovery = '/.well-known/mcp-servers' + public_headers = {'Snowglobe-Proxy-Token': '', 'Host': 'untrusted.example', + 'X-Forwarded-Host': 'untrusted.example', 'X-Forwarded-Proto': 'http'} + catalog = request(discovery, extra=public_headers) + assert catalog['version'] == '1.0' + assert catalog['registry']['name'] == 'Snow Globe' + assert {'observability', 'shale'} <= {entry['name'] for entry in catalog['servers']} + for entry in catalog['servers']: + endpoint = '/mcp/' + entry['name'] + assert entry['description'] and entry['url'] == origin + endpoint + assert entry['transport'] == 'streamable-http' and entry['capabilities'] == ['tools'] + fields = request(endpoint, status=401, extra={'Snowglobe-Proxy-Token': ''}, include_headers=True) + metadata = '/.well-known/oauth-protected-resource' + endpoint + assert fields['www-authenticate'] == 'Bearer resource_metadata="' + origin + metadata + '"' + protected = request(metadata, extra=public_headers) + assert protected['resource'] == entry['url'] + assert entry['authentication'] == {'type': 'oauth2', 'required': True, + 'authorization_url': origin + '/oauth/authorize', 'scopes': protected['scopes_supported']} + assert request(discovery, 'HEAD', extra=public_headers)['content-type'] == 'application/json' + request(discovery, 'POST', {}, status=405, extra=public_headers) + request(discovery + '/private', status=403, extra=public_headers) (data / 'pictures').mkdir(exist_ok=True) (data / 'pictures' / actor).write_bytes(base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Wl6qWQAAAAASUVORK5CYII=')) picture_headers = request('/api/account/pictures/' + actor, include_headers=True) -- 2.54.1