Skip to content

Commit add5d62

Browse files
authored
fix(http): serve path-aware OAuth AS metadata for /mcp (#39)
MCP SDK discovery tries /.well-known/oauth-authorization-server/mcp and /mcp/.well-known/openid-configuration when the resource URL has a path. Those 404ed while the root documents were 200.
1 parent ce20545 commit add5d62

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/transports/http.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ describe('http oauth gate', () => {
164164
expect(body.authorization_endpoint).toBe('https://api.vuetifyjs.com/oauth/authorize')
165165
})
166166

167+
it('serves path-aware AS metadata for /mcp', async () => {
168+
const origin = originUrl(server)
169+
const a = await fetch(`${origin}/.well-known/oauth-authorization-server/mcp`)
170+
const b = await fetch(`${origin}/mcp/.well-known/openid-configuration`)
171+
172+
expect(a.status).toBe(200)
173+
expect(b.status).toBe(200)
174+
expect((await a.json()).authorization_endpoint).toBe('https://api.vuetifyjs.com/oauth/authorize')
175+
expect((await b.json()).authorization_endpoint).toBe('https://api.vuetifyjs.com/oauth/authorize')
176+
})
177+
167178
it('advertises RFC9728 resource with /mcp', async () => {
168179
const prev = process.env.MCP_SERVER_URL
169180
delete process.env.MCP_SERVER_URL

src/transports/http.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ function handleOauthRoutes (req: IncomingMessage, res: ServerResponse): boolean
140140
// RFC 8414 — Authorization Server Metadata (proxy to API)
141141
// Some MCP SDK versions fetch this from the resource server directly
142142
if (
143-
req.url === '/.well-known/oauth-authorization-server'
144-
|| req.url === '/.well-known/openid-configuration'
143+
req.url.startsWith('/.well-known/oauth-authorization-server')
144+
|| req.url.startsWith('/.well-known/openid-configuration')
145+
|| req.url.startsWith('/mcp/.well-known/oauth-authorization-server')
146+
|| req.url.startsWith('/mcp/.well-known/openid-configuration')
145147
) {
146148
const apiUrl = getApiUrl()
147149
sendJson(res, {

0 commit comments

Comments
 (0)