Commit 2e0b5c7
committed
feat(mcp): wire up oauth2 token verification for streamable-http transport
the mcp sdk (v1.26.0+) has built-in oauth 2.1 support via AuthSettings
and TokenVerifier, but the agent-memory-server never wired it up for the
streamable-http transport. without it, unauthenticated requests to /mcp
return 406 instead of 401 + WWW-Authenticate header, which prevents mcp
clients (like claude) from discovering the oauth flow.
changes:
- add JWTTokenVerifier that implements the sdk's TokenVerifier protocol
by wrapping the existing verify_jwt() function
- conditionally pass AuthSettings + token_verifier to FastMCP when
AUTH_MODE=oauth2 and OAUTH2_RESOURCE_HOST are set
- add /.well-known/oauth-authorization-server endpoint (RFC 9728) to
the REST API for protected resource metadata discovery
- add OAUTH2_RESOURCE_HOST config setting for the server's public hostname
when enabled, the mcp transport now:
- returns 401 with WWW-Authenticate: Bearer resource_metadata="..." header
- serves /.well-known/oauth-protected-resource automatically (sdk built-in)
- validates jwt tokens on all mcp requests via jwks
when AUTH_MODE != oauth2 or OAUTH2_RESOURCE_HOST is unset, behavior is
unchanged — no auth kwargs are passed to FastMCP.
tested with ory hydra as the oidc provider and claude as the mcp client.1 parent cc3a832 commit 2e0b5c7
3 files changed
Lines changed: 53 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
| 430 | + | |
430 | 431 | | |
431 | 432 | | |
432 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
133 | 144 | | |
134 | 145 | | |
135 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
258 | 298 | | |
259 | 299 | | |
260 | 300 | | |
261 | 301 | | |
262 | 302 | | |
263 | 303 | | |
| 304 | + | |
264 | 305 | | |
265 | 306 | | |
266 | 307 | | |
| |||
0 commit comments