Add lazy-auth-server example (#679)

Adds an example MCP App server demonstrating lazy (on-demand) OAuth:
the server connects and lists tools without authentication, and only
prompts for auth when a protected tool is called, by responding 401
with a WWW-Authenticate header pointing at protected-resource metadata.

- Public `show_auth_button` app calls the protected `get_secret` tool
  via callServerTool; the host runs the OAuth flow on 401 and retries
- Embedded mock authorization server (authorization-code + PKCE,
  short-lived HS256 tokens, refresh + session revocation) so the whole
  flow runs from a single process
- TTL-scoped endpoint paths (/ttl/<seconds>/mcp) let slow or automated
  clients request longer-lived tokens per connection, threaded through
  OAuth via RFC 8707 resource indicators
- `elicit_url` / `elicit_by_error` tools demonstrating URL elicitation
This commit is contained in:
Mel Ludowise 2026-06-01 03:19:53 -07:00 • committed by GitHub
commit fcc4b03bde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

46
package-lock.json generated
View file

@ -591,6 +591,48 @@
"dev": true,
"license": "MIT"
},
"examples/lazy-auth-server": {
"name": "@modelcontextprotocol/server-lazy-auth",
"version": "1.7.2",
"license": "MIT",
"dependencies": {
"@modelcontextprotocol/ext-apps": "^1.0.0",
"@modelcontextprotocol/sdk": "^1.29.0",
"cors": "^2.8.5",
"express": "^5.1.0",
"jose": "^6.0.0"
},
"bin": {
"mcp-server-lazy-auth": "dist/index.js"
},
"devDependencies": {
"@types/cors": "^2.8.19",
"@types/express": "^5.0.0",
"@types/node": "22.10.0",
"concurrently": "^9.2.1",
"cross-env": "^10.1.0",
"typescript": "^5.9.3",
"vite": "^6.0.0",
"vite-plugin-singlefile": "^2.3.0"
}
},
"examples/lazy-auth-server/node_modules/@types/node": {
"version": "22.10.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.0.tgz",
"integrity": "sha512-XC70cRZVElFHfIUB40FgZOBbgJYFKKMa5nb9lxcwYstFG/Mi+/Y0bGS+rs6Dmhmkpq4pnNiLiuZAbc02YCOnmA==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~6.20.0"
}
},
"examples/lazy-auth-server/node_modules/undici-types": {
"version": "6.20.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
"dev": true,
"license": "MIT"
},
"examples/map-server": {
"name": "@modelcontextprotocol/server-map",
"version": "1.7.2",
@ -2678,6 +2720,10 @@
"resolved": "examples/debug-server",
"link": true
},
"node_modules/@modelcontextprotocol/server-lazy-auth": {
"resolved": "examples/lazy-auth-server",
"link": true
},
"node_modules/@modelcontextprotocol/server-map": {
"resolved": "examples/map-server",
"link": true