Skip to content

Commit f1ecbbc

Browse files
committed
fix(oauth): honor default server grant support
1 parent 7d2b265 commit f1ecbbc

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

scripts/check-mcp-oauth-integration.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,10 @@ for (let mask = 0; mask < 1 << advertisedGrantTypes.length; mask++) {
6565
checkedCases++
6666
}
6767

68-
// Repository policy: retain both implemented grants when RFC 8414's optional
69-
// grant_types_supported metadata is omitted.
68+
// RFC 8414 defaults omitted grant_types_supported to authorization_code and
69+
// implicit. Zoo Code implements only authorization_code from that default.
7070
// https://www.rfc-editor.org/rfc/rfc8414.html#section-2
71-
// Normative SHOULD: MCP clients that use refresh tokens should include
72-
// refresh_token in their grant_types client metadata.
73-
// https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization#refresh-tokens
74-
assert.deepEqual(selectMcpOAuthGrantTypes(), [...MCP_OAUTH_GRANT_TYPES])
71+
assert.deepEqual(selectMcpOAuthGrantTypes(), [AUTHORIZATION_CODE_GRANT_TYPE])
7572
assert.deepEqual(
7673
selectMcpOAuthGrantTypes([REFRESH_TOKEN_GRANT_TYPE, AUTHORIZATION_CODE_GRANT_TYPE, REFRESH_TOKEN_GRANT_TYPE]),
7774
[...MCP_OAUTH_GRANT_TYPES],

src/services/mcp/__tests__/McpOAuthClientProvider.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,29 @@ describe("McpOAuthClientProvider", () => {
190190

191191
expect(metadata.client_name).toBe("Roo Code")
192192
expect(metadata.redirect_uris).toEqual(["http://localhost:0/callback"])
193-
expect(metadata.grant_types).toContain("authorization_code")
193+
expect(metadata.grant_types).toEqual(["authorization_code", "refresh_token"])
194194
expect(metadata.response_types).toContain("code")
195195
expect(metadata.token_endpoint_auth_method).toBe("none")
196196
expect(metadata).toMatchObject({ application_type: "native" })
197197
await provider.close()
198198
})
199199

200+
it("should default to authorization code when server grant metadata is omitted", async () => {
201+
mockFetch.mockResolvedValueOnce({
202+
ok: true,
203+
json: () =>
204+
Promise.resolve({
205+
issuer: "https://auth.example.com",
206+
token_endpoint_auth_methods_supported: ["none"],
207+
}),
208+
})
209+
210+
const provider = await McpOAuthClientProvider.create("https://example.com/mcp", createMockSecretStorage())
211+
212+
expect(provider.clientMetadata.grant_types).toEqual(["authorization_code"])
213+
await provider.close()
214+
})
215+
200216
it("should use server name as client_name when provided", async () => {
201217
setupCallbackServerMock()
202218
const provider = await McpOAuthClientProvider.create(

src/services/mcp/oauthMetadata.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ export interface McpOAuthClientMetadata extends OAuthClientMetadata {
1010
application_type: "native"
1111
}
1212

13+
/** Selects the grants Zoo Code implements from authorization-server metadata. */
1314
export function selectMcpOAuthGrantTypes(supportedGrantTypes?: readonly string[]): McpOAuthGrantType[] {
14-
const supported = new Set(supportedGrantTypes ?? MCP_OAUTH_GRANT_TYPES)
15+
const supported = new Set(supportedGrantTypes ?? [AUTHORIZATION_CODE_GRANT_TYPE])
1516
return MCP_OAUTH_GRANT_TYPES.filter((grantType) => supported.has(grantType))
1617
}
1718

19+
/** Builds dynamic-registration metadata for Zoo Code's native authorization-code client. */
1820
export function buildMcpOAuthClientMetadata(options: {
1921
clientName: string
2022
redirectUrl: string

0 commit comments

Comments
 (0)