Skip to content

adds features to implement MCP server responsibilities in agentgateway - #212

Merged
howardjohn merged 3 commits into
agentgateway:mainfrom
rinormaloku:mcp-client-responsibilities
Aug 8, 2025
Merged

howardjohn merged 3 commits into
agentgateway:mainfrom
rinormaloku:mcp-client-responsibilities

Conversation

@rinormaloku

@rinormaloku rinormaloku commented Jul 25, 2025 •

Copy link
Copy Markdown
Collaborator

This PR adds the options to configure MCP Server responsibilities in the agentgateway.

  • Returning 401 and WWW-Authentication header when the requests are unauthenticated
  • Custom authorization server with jwks location
  • Adds more metadata to the resource metadata endpoint.

Additionally, it adds a test authorization server to try out the flows

See the example under examples/mcp-authentication/README.md for quickly testing out the changes.

Copilot AI review requested due to automatic review settings July 25, 2025 09:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds features to implement MCP client responsibilities in agentgateway by enhancing the UI's handling of optional array properties and adding MCP authentication capabilities with OAuth support.

  • Adds null-safe array iteration throughout the UI to prevent runtime errors when backend arrays are undefined
  • Implements OAuth 2.0 protected resource metadata support for MCP authentication flows
  • Adds comprehensive MCP authentication example with authorization server and configuration files

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ui/src/lib/backend-hooks.ts Added null-safe array iteration for backends
ui/src/lib/api.ts Added null-safe forEach calls for backend arrays
ui/src/components/setup-wizard/PolicyStep.tsx Improved code formatting for JWKS URL detection
ui/src/components/route/route-components.tsx Enhanced string literal consistency and formatting
ui/src/components/policy/form-renderers.tsx Improved text formatting for A2A policy descriptions
ui/src/components/policy-config.tsx Enhanced filtering logic formatting
ui/src/components/forms/jwt-config-form.tsx Improved conditional formatting for JWKS configuration
ui/src/components/backend-config.tsx Enhanced button formatting
ui/src/app/policies/page.tsx Improved conditional logic formatting
ui/src/app/playground/page.tsx Enhanced error handling, string formatting, and import organization
ui/src/app/backends/page.tsx Added null-safe forEach for backend iteration
examples/mcp-authentication/config.yaml Added comprehensive MCP authentication configuration
examples/mcp-authentication/config-remote-endpoints.yaml Added remote endpoint authentication configuration
examples/mcp-authentication/auth_server.py Added complete OAuth 2.0 authorization server implementation
examples/mcp-authentication/README.md Added documentation for MCP authentication setup
examples/http/config.yaml Minor formatting change to response body
crates/agentgateway/src/types/local.rs Added OAuth protected resource filter support
crates/agentgateway/src/types/agent.rs Added custom IDP support and OAuth resource filter
crates/agentgateway/src/proxy/httpproxy.rs Integrated OAuth protected resource filter processing
crates/agentgateway/src/mcp/sse.rs Enhanced MCP authentication with proper response handling
crates/agentgateway/src/http/oauth_protected_resource.rs Added OAuth 2.0 resource metadata implementation
crates/agentgateway/src/http/mod.rs Added OAuth protected resource module
crates/agentgateway/src/http/jwt.rs Added required JWT validation method

Comment thread ui/src/lib/backend-hooks.ts Resolved
Comment thread crates/agentgateway/src/mcp/sse.rs Resolved
Comment thread crates/agentgateway/src/mcp/sse.rs Resolved
@rinormaloku
rinormaloku marked this pull request as draft July 25, 2025 09:49
@rinormaloku
rinormaloku marked this pull request as ready for review July 25, 2025 16:50
@rinormaloku
rinormaloku force-pushed the mcp-client-responsibilities branch from 3ccfde7 to ee1fc83 Compare July 25, 2025 19:03
@howardjohn howardjohn self-assigned this Jul 25, 2025
@rinormaloku
rinormaloku force-pushed the mcp-client-responsibilities branch 2 times, most recently from f1d02b4 to a21b891 Compare July 26, 2025 07:31
@rinormaloku

Copy link
Copy Markdown
Collaborator Author

addressed the conflict and the test failures

@rinormaloku rinormaloku changed the title adds features to implement MCP client responsibilities in agentgateway adds features to implement MCP server responsibilities in agentgateway Jul 28, 2025
Comment thread crates/agentgateway/src/mcp/sse.rs Outdated
}

async fn protected_resource_metadata(&self, req: Request, auth: McpAuthentication) -> Response {
let new_uri = Self::get_redirect_url(&req, "/.well-known/oauth-protected-resource");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like /.well-known/oauth-protected-resource is not a suffix (line 311), but a prefix in URL Path. So it ends up with errors like this http://localhost:3003/.well-known/oauth-protected-resource/mcp -> http://localhost:3003/.well-known/oauth-protected-resource/mcp/mcp in MCP Inspector.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this

@amivanoff

Copy link
Copy Markdown

I hacked a quick prototype for MCP protected resource metadata with AgentGateway's DirectResponse and Cors, but this approach looks more promising.
This PR also works in our setup with hard-coded configs and tweaks. But it's not clear whether you still want to separate oauthProtectedResource and mcpAuthentication or not :)
I can help with this issue or some testing (we use Keycloak).

@rinormaloku

Copy link
Copy Markdown
Collaborator Author

@amivanoff I initially started with a separate field, but I was unsure and decided to merge it and gather feedback during PR review. I discovered that I need some changes before we merge this PR I'll try to get back to this before the end of the week.

Tests would be greatly appreciated!

@amivanoff

amivanoff commented Jul 31, 2025 •

Copy link
Copy Markdown

I merged this PR with the latest main and cleared a bit examples (README.md and config.yaml), code and JSON schema to make them consistent and the overall policy a little more configurable and ready for further testing.

In JSON schema and Yaml:

  • All property names are now camelCase (like authorizationServers, not authorization_servers, but in actual RFC 9728 JSON it stays as needed like authorization_servers).
  • Properties mcp.name and target.filters have been removed from the example as they were previously removed earlier from the Schema.

Not touched:

  • UI
  • most of the logic

All resides in a branch in my fork.

I could contribute it here if needed and if allowed in permissions.

@rinormaloku
rinormaloku force-pushed the mcp-client-responsibilities branch 2 times, most recently from 5bd5b29 to 444eac7 Compare July 31, 2025 19:26
@rinormaloku

Copy link
Copy Markdown
Collaborator Author

@amivanoff we are discussing how the API for this should look, but it can end up being very similar to what you have on your branch.

As soon as we agree on the API, we should have the code merged fairly quickly.

@amivanoff

Copy link
Copy Markdown

@rinormaloku regarding the API, it would be great to have ability to customize config or to use reasonable defaults as a fallback of some sort.

For example, admin could provide custom authorization_servers array, or just rely on authorization_servers = [issuer] as in your current variant. It could be helpful while all parts of MCP-related stack still are not working together out of the box.

For example in our current setup issuer is not one of authorization_servers due to some workarounds related to keycloak/keycloak#40923.

@rinormaloku
rinormaloku force-pushed the mcp-client-responsibilities branch from 444eac7 to f729cc7 Compare August 5, 2025 16:05
@rinormaloku
rinormaloku marked this pull request as draft August 6, 2025 00:34
@rinormaloku
rinormaloku force-pushed the mcp-client-responsibilities branch from ffae45c to d280189 Compare August 8, 2025 11:10
- Updated `heck` dependency to version 0.5.0 in `Cargo.lock` and `Cargo.toml`.
- Refactored `ResourceMetadata` to use a flexible structure with additional properties.
- Simplified JSON construction for resource metadata in the MCP server.
- Removed deprecated fields from the schema and updated documentation accordingly.
@rinormaloku
rinormaloku marked this pull request as ready for review August 8, 2025 12:37
- Renamed `run-validate-deps` to `run-validation-deps` for consistency.
- Updated corresponding commands in the `examples/mcp-authentication/README.md` to reflect the new target names.
@rinormaloku

Copy link
Copy Markdown
Collaborator Author

Got around to cleaning this up. It is ready for review!

Comment on lines +292 to +294
.header("access-control-allow-origin", "*")
.header("access-control-allow-methods", "GET, OPTIONS")
.header("access-control-allow-headers", "content-type")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little suspicious. Shouldn't the CORS filter handle this? I believe these apply even with the MCP path

.header("access-control-allow-methods", "GET, OPTIONS")
.header("access-control-allow-headers", "content-type")
.body(axum::body::Body::from(Bytes::from(
serde_json::to_string(&json_body).unwrap_or_default(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should probably make to_string() failing return a INTERNAL_SERVER_ERROR vs the .body() call which cannot actually fail (only fails from invalid headers, and the headers are static)

let mut upstream = client.simple_call(ureq).await?;

// Add CORS headers to the response
let headers = upstream.headers_mut();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment on CORS

// of fields we compute.
for (key, value) in &self.extra {
let snake = key.to_snake_case();
if snake == "resource" || snake == "authorization_servers" {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we add 2 other ones too. But it doesn't matter since we override them?

@howardjohn
howardjohn merged commit 898688d into agentgateway:main Aug 8, 2025
surinderunitone pushed a commit to UnitOneAI/agentgateway that referenced this pull request Feb 1, 2026
agentgateway#212)

* adds support for resource server metadata endpoint and other MCP server responsibilities

* Update dependencies and enhance resource metadata handling

- Updated `heck` dependency to version 0.5.0 in `Cargo.lock` and `Cargo.toml`.
- Refactored `ResourceMetadata` to use a flexible structure with additional properties.
- Simplified JSON construction for resource metadata in the MCP server.
- Removed deprecated fields from the schema and updated documentation accordingly.

* Refactor Makefile targets for validation dependencies

- Renamed `run-validate-deps` to `run-validation-deps` for consistency.
- Updated corresponding commands in the `examples/mcp-authentication/README.md` to reflect the new target names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants