1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Serves an RFC 9728 protected-resource metadata document beside an MCP
//! endpoint, so a client that receives a `401` can find out where to get a
//! token.
//!
//! This is the smallest deployment that makes the OAuth discovery step work:
//! one well-known route merged into the app, and the MCP router mounted beside
//! it. Run it and ask for the document:
//!
//! ```text
//! cargo run --example protected_resource_server --features http
//! curl -i http://127.0.0.1:3000/.well-known/oauth-protected-resource/mcp
//! ```
//!
//! The `resource` field in the response is the audience a token must carry, so
//! it has to match the resource identifier the client asks for. That is why
//! the document is served at `/.well-known/oauth-protected-resource/mcp`
//! rather than at the origin root: two resources on one host each get their
//! own document without the two colliding.
//!
//! # No merge, and no second router
//!
//! `ServerConfig::with_resource_metadata` mounts the document on the MCP router
//! and points the `401` challenge at the same URL from the same value. There
//! is nothing to merge and nothing to keep in step.
//!
//! The document is reached before a client has a token, so the route
//! deliberately skips the authenticator — the escape route cannot require the
//! credential it explains how to obtain. It still passes the same `Host` and
//! rate-limit checks as every other route on the server.
//!
//! `serve_protected_resource` remains for serving the document from a different
//! origin or port than the MCP endpoint; this example does not need it.
use ServerConfig;
use ;