| author | |
| committer | |
| log | 3adad9767eb19ab651b35e1f76b7f4a358df0225 |
| tree | 4b15a94d6db7d52f9542b42f71d8f3786e25b533 |
| parent | 8bc89c9ebdfc6894c2903e5954c9d720fef9e108 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
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-astra3 files changed, 43 insertions(+), 0 deletions(-)
dashboard/src/main.rs+1| ... | @@ -587,6 +587,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> { | ... | @@ -587,6 +587,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> { |
| 587 | .route("/api/{*path}", any(api)) | 587 | .route("/api/{*path}", any(api)) |
| 588 | .route("/auth/{*path}", any(auth::route)) | 588 | .route("/auth/{*path}", any(auth::route)) |
| 589 | .route("/.well-known/openid-configuration", any(oidc::route)) | 589 | .route("/.well-known/openid-configuration", any(oidc::route)) |
| 590 | .route("/.well-known/mcp-servers", axum::routing::get(mcp::discovery)) | ||
| 590 | .route("/oauth/{*path}", any(mcp::oauth)) | 591 | .route("/oauth/{*path}", any(mcp::oauth)) |
| 591 | .route("/.well-known/{*path}", any(mcp::oauth)) | 592 | .route("/.well-known/{*path}", any(mcp::oauth)) |
| 592 | .nest_service("/assets", ServeDir::new(format!("{dist}/assets"))) | 593 | .nest_service("/assets", ServeDir::new(format!("{dist}/assets"))) |
dashboard/src/mcp.rs+21| ... | @@ -575,8 +575,29 @@ pub fn router<H: rmcp::ServerHandler>( | ... | @@ -575,8 +575,29 @@ pub fn router<H: rmcp::ServerHandler>( |
| 575 | )) | 575 | )) |
| 576 | } | 576 | } |
| 577 | 577 | ||
| 578 | pub async fn discovery(State(app): State<Arc<App>>) -> axum::Json<Value> { | ||
| 579 | axum::Json(json!({ | ||
| 580 | "version": "1.0", | ||
| 581 | "servers": CATALOGS.iter().map(|(id, name, scopes)| json!({ | ||
| 582 | "name": id, | ||
| 583 | "description": name, | ||
| 584 | "url": app.mcp.resource(id), | ||
| 585 | "transport": "streamable-http", | ||
| 586 | "authentication": { | ||
| 587 | "type": "oauth2", | ||
| 588 | "required": true, | ||
| 589 | "authorization_url": app.mcp.origin.join("oauth/authorize").unwrap().as_str(), | ||
| 590 | "scopes": scopes, | ||
| 591 | }, | ||
| 592 | "capabilities": ["tools"], | ||
| 593 | })).collect::<Vec<_>>(), | ||
| 594 | "registry": {"name": "Snow Globe", "version": env!("CARGO_PKG_VERSION")}, | ||
| 595 | })) | ||
| 596 | } | ||
| 597 | |||
| 578 | pub fn public(path: &str) -> bool { | 598 | pub fn public(path: &str) -> bool { |
| 579 | path == "/.well-known/openid-configuration" | 599 | path == "/.well-known/openid-configuration" |
| 600 | || path == "/.well-known/mcp-servers" | ||
| 580 | || path.starts_with("/oauth/") | 601 | || path.starts_with("/oauth/") |
| 581 | || CATALOGS.iter().any(|(id, _, _)| { | 602 | || CATALOGS.iter().any(|(id, _, _)| { |
| 582 | path == format!("/mcp/{id}") || path.starts_with(&format!("/mcp/{id}/")) | 603 | path == format!("/mcp/{id}") || path.starts_with(&format!("/mcp/{id}/")) |
tools/dashboard-auth-test.py+21| ... | @@ -113,6 +113,27 @@ def main(): | ... | @@ -113,6 +113,27 @@ def main(): |
| 113 | cookies = {} | 113 | cookies = {} |
| 114 | start() | 114 | start() |
| 115 | try: | 115 | try: |
| 116 | discovery = '/.well-known/mcp-servers' | ||
| 117 | public_headers = {'Snowglobe-Proxy-Token': '', 'Host': 'untrusted.example', | ||
| 118 | 'X-Forwarded-Host': 'untrusted.example', 'X-Forwarded-Proto': 'http'} | ||
| 119 | catalog = request(discovery, extra=public_headers) | ||
| 120 | assert catalog['version'] == '1.0' | ||
| 121 | assert catalog['registry']['name'] == 'Snow Globe' | ||
| 122 | assert {'observability', 'shale'} <= {entry['name'] for entry in catalog['servers']} | ||
| 123 | for entry in catalog['servers']: | ||
| 124 | endpoint = '/mcp/' + entry['name'] | ||
| 125 | assert entry['description'] and entry['url'] == origin + endpoint | ||
| 126 | assert entry['transport'] == 'streamable-http' and entry['capabilities'] == ['tools'] | ||
| 127 | fields = request(endpoint, status=401, extra={'Snowglobe-Proxy-Token': ''}, include_headers=True) | ||
| 128 | metadata = '/.well-known/oauth-protected-resource' + endpoint | ||
| 129 | assert fields['www-authenticate'] == 'Bearer resource_metadata="' + origin + metadata + '"' | ||
| 130 | protected = request(metadata, extra=public_headers) | ||
| 131 | assert protected['resource'] == entry['url'] | ||
| 132 | assert entry['authentication'] == {'type': 'oauth2', 'required': True, | ||
| 133 | 'authorization_url': origin + '/oauth/authorize', 'scopes': protected['scopes_supported']} | ||
| 134 | assert request(discovery, 'HEAD', extra=public_headers)['content-type'] == 'application/json' | ||
| 135 | request(discovery, 'POST', {}, status=405, extra=public_headers) | ||
| 136 | request(discovery + '/private', status=403, extra=public_headers) | ||
| 116 | (data / 'pictures').mkdir(exist_ok=True) | 137 | (data / 'pictures').mkdir(exist_ok=True) |
| 117 | (data / 'pictures' / actor).write_bytes(base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Wl6qWQAAAAASUVORK5CYII=')) | 138 | (data / 'pictures' / actor).write_bytes(base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Wl6qWQAAAAASUVORK5CYII=')) |
| 118 | picture_headers = request('/api/account/pictures/' + actor, include_headers=True) | 139 | picture_headers = request('/api/account/pictures/' + actor, include_headers=True) |