MCP OAuth Protect hosted MCP endpoints with resource metadata, DCR/CIMD, PKCE, and audience checks. agentic reference agentic/oauth agentic/oauth.md

MCP OAuth

Protect hosted MCP endpoints with resource metadata, DCR/CIMD, PKCE, and audience checks.

Hosted MCP identity

GraphJin serves MCP at:

text
/api/v1/mcp

When OAuth is enabled, GraphJin can advertise protected-resource metadata and authorization-server metadata for clients that understand the MCP OAuth flow.

YAML
mcp:
  oauth:
    enabled: true
    mode: builtin
    scopes: ["mcp"]

Verified by TestMCPOAuthProtectedResourceMetadata serv/mcp_oauth_test.go:17
Verified by TestMCPOAuthAuthorizationServerMetadataIncludesDCRCIMD serv/mcp_oauth_test.go:45

Audience checks

Tokens must match the expected MCP resource/audience. Wrong-audience requests are rejected with a challenge rather than silently accepted.

Verified by TestNewMCPAuthHandlerRejectsWrongAudienceWithChallenge serv/mcp_oauth_test.go:106

Client expectations

Hosted MCP clients discover the protected resource metadata before authorization. A working setup should expose:

SurfacePurpose
Protected resource metadataTells the client which MCP resource it is requesting access to.
Authorization server metadataPublishes issuer, token endpoint, PKCE support, and DCR/CIMD support.
Audience/resource validationPrevents a token minted for one MCP server from being replayed against another.
YAML
mcp:
  oauth:
    enabled: true
    mode: builtin
    issuer: https://graphjin.example.com
    audience: https://graphjin.example.com/api/v1/mcp

Validate hosted MCP with the same care as the GraphQL endpoint: TLS, resource audience, allowed origins, token lifetime, and whether raw GraphQL or mutation tools are advertised for the current caller.

Verified by TestValidateMCPOAuthConfig serv/mcp_oauth_test.go:239
Docs