Blame
|
1 | --- |
||||||
| 2 | category: reference |
|||||||
| 3 | tags: [task, phase-1, mcp, auth, infra] |
|||||||
| 4 | last_updated: 2026-03-13 |
|||||||
| 5 | confidence: high |
|||||||
| 6 | --- |
|||||||
| 7 | ||||||||
| 8 | # P1-9: Fix MCP OAuth Discovery Routing |
|||||||
| 9 | ||||||||
|
10 | **Status: COMPLETE** (2026-03-13) |
||||||
| 11 | ||||||||
|
12 | ## Problem |
||||||
| 13 | ||||||||
| 14 | Claude.ai cannot connect to the dev.wikibot.io MCP server via OAuth because the `/.well-known/oauth-authorization-server` discovery endpoint is routed to the Otterwiki Lambda (`$default` catch-all) instead of the MCP Lambda. It returns an HTML wiki page instead of the OAuth JSON metadata document. |
|||||||
| 15 | ||||||||
|
16 | Additionally, `MCP_BASE_URL` was set to `https://dev.wikibot.io/mcp`, causing FastMCP to compute a doubled path (`/mcp/mcp`) for the protected resource URL. |
||||||
|
17 | |||||||
| 18 | ## Root Cause |
|||||||
| 19 | ||||||||
|
20 | 1. API Gateway only routed `/mcp` and `/mcp/{proxy+}` to the MCP Lambda. All `/.well-known/*` paths fell through to Otterwiki's `$default` route. |
||||||
| 21 | 2. `MCP_BASE_URL` included the `/mcp` subpath, but FastMCP uses this as the base for constructing OAuth metadata URLs, resulting in doubled paths. |
|||||||
|
22 | |||||||
|
23 | ## Fix |
||||||
|
24 | |||||||
|
25 | Two infra changes, zero code changes: |
||||||
|
26 | |||||||
|
27 | 1. **`infra/__main__.py`** — Added API Gateway route `ANY /.well-known/{proxy+}` → MCP Lambda integration |
||||||
| 28 | 2. **`infra/Pulumi.dev.yaml`** — Changed `mcp_base_url` from `https://dev.wikibot.io/mcp` to `https://dev.wikibot.io` |
|||||||
|
29 | |||||||
|
30 | Commit: `e46ef4a` on `main`. Deployed via `pulumi up`. |
||||||
|
31 | |||||||
|
32 | ## Verification |
||||||
|
33 | |||||||
|
34 | | Endpoint | Expected | Result | |
||||||
| 35 | |----------|----------|--------| |
|||||||
| 36 | | `GET /.well-known/oauth-authorization-server` | WorkOS OAuth metadata JSON | PASS | |
|||||||
| 37 | | `GET /.well-known/oauth-protected-resource/mcp` | Protected resource JSON | PASS | |
|||||||
| 38 | | `POST /mcp` (with bearer token) | MCP initialize response | PASS | |
|||||||
| 39 | | `GET /Home` | Otterwiki HTML | PASS (unchanged) | |
|||||||