mcp-trellis 0.2.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (293) hide show
  1. package/README.md +70 -620
  2. package/dist/adapters/node-request.d.ts +53 -0
  3. package/dist/adapters/node-request.d.ts.map +1 -0
  4. package/dist/adapters/node-request.js +165 -0
  5. package/dist/adapters/node-request.js.map +1 -0
  6. package/dist/adapters/node.d.ts +16 -24
  7. package/dist/adapters/node.d.ts.map +1 -1
  8. package/dist/adapters/node.js +69 -88
  9. package/dist/adapters/node.js.map +1 -1
  10. package/dist/advanced.d.ts +18 -0
  11. package/dist/advanced.d.ts.map +1 -0
  12. package/dist/advanced.js +18 -0
  13. package/dist/advanced.js.map +1 -0
  14. package/dist/app-options.d.ts +132 -0
  15. package/dist/app-options.d.ts.map +1 -0
  16. package/dist/app-options.js +2 -0
  17. package/dist/app-options.js.map +1 -0
  18. package/dist/app.d.ts +2 -66
  19. package/dist/app.d.ts.map +1 -1
  20. package/dist/app.js +150 -57
  21. package/dist/app.js.map +1 -1
  22. package/dist/audit.d.ts +5 -5
  23. package/dist/audit.d.ts.map +1 -1
  24. package/dist/audit.js +19 -8
  25. package/dist/audit.js.map +1 -1
  26. package/dist/auth/bearer.d.ts +4 -1
  27. package/dist/auth/bearer.d.ts.map +1 -1
  28. package/dist/auth/bearer.js +25 -5
  29. package/dist/auth/bearer.js.map +1 -1
  30. package/dist/clients.d.ts.map +1 -1
  31. package/dist/clients.js +3 -6
  32. package/dist/clients.js.map +1 -1
  33. package/dist/deprecated.d.ts +42 -0
  34. package/dist/deprecated.d.ts.map +1 -0
  35. package/dist/deprecated.js +35 -0
  36. package/dist/deprecated.js.map +1 -0
  37. package/dist/http/body.d.ts +69 -0
  38. package/dist/http/body.d.ts.map +1 -0
  39. package/dist/http/body.js +165 -0
  40. package/dist/http/body.js.map +1 -0
  41. package/dist/http/http.d.ts +42 -0
  42. package/dist/http/http.d.ts.map +1 -0
  43. package/dist/http/http.js +100 -0
  44. package/dist/http/http.js.map +1 -0
  45. package/dist/http/origins.d.ts +37 -0
  46. package/dist/http/origins.d.ts.map +1 -0
  47. package/dist/http/origins.js +87 -0
  48. package/dist/http/origins.js.map +1 -0
  49. package/dist/mcp/dispatch.d.ts +7 -0
  50. package/dist/mcp/dispatch.d.ts.map +1 -0
  51. package/dist/mcp/dispatch.js +99 -0
  52. package/dist/mcp/dispatch.js.map +1 -0
  53. package/dist/{jsonrpc.d.ts → mcp/jsonrpc.d.ts} +10 -0
  54. package/dist/mcp/jsonrpc.d.ts.map +1 -0
  55. package/dist/mcp/jsonrpc.js +88 -0
  56. package/dist/mcp/jsonrpc.js.map +1 -0
  57. package/dist/mcp/methods.d.ts +133 -0
  58. package/dist/mcp/methods.d.ts.map +1 -0
  59. package/dist/mcp/methods.js +84 -0
  60. package/dist/mcp/methods.js.map +1 -0
  61. package/dist/mcp/protocol.d.ts +16 -0
  62. package/dist/mcp/protocol.d.ts.map +1 -0
  63. package/dist/mcp/protocol.js +22 -0
  64. package/dist/mcp/protocol.js.map +1 -0
  65. package/dist/mcp/registry.d.ts +58 -0
  66. package/dist/mcp/registry.d.ts.map +1 -0
  67. package/dist/mcp/registry.js +81 -0
  68. package/dist/mcp/registry.js.map +1 -0
  69. package/dist/mcp/rpc-handlers.d.ts +11 -0
  70. package/dist/mcp/rpc-handlers.d.ts.map +1 -0
  71. package/dist/mcp/rpc-handlers.js +133 -0
  72. package/dist/mcp/rpc-handlers.js.map +1 -0
  73. package/dist/{tools.d.ts → mcp/tools.d.ts} +30 -2
  74. package/dist/mcp/tools.d.ts.map +1 -0
  75. package/dist/mcp/tools.js +166 -0
  76. package/dist/mcp/tools.js.map +1 -0
  77. package/dist/{validate.d.ts → mcp/validate.d.ts} +24 -12
  78. package/dist/mcp/validate.d.ts.map +1 -0
  79. package/dist/mcp/validate.js +186 -0
  80. package/dist/mcp/validate.js.map +1 -0
  81. package/dist/oauth/audit.d.ts +20 -0
  82. package/dist/oauth/audit.d.ts.map +1 -0
  83. package/dist/oauth/audit.js +29 -0
  84. package/dist/oauth/audit.js.map +1 -0
  85. package/dist/oauth/cimd/cimd-parse.d.ts +4 -0
  86. package/dist/oauth/cimd/cimd-parse.d.ts.map +1 -0
  87. package/dist/oauth/cimd/cimd-parse.js +70 -0
  88. package/dist/oauth/cimd/cimd-parse.js.map +1 -0
  89. package/dist/oauth/cimd/cimd-ssrf.d.ts +8 -0
  90. package/dist/oauth/cimd/cimd-ssrf.d.ts.map +1 -0
  91. package/dist/oauth/cimd/cimd-ssrf.js +193 -0
  92. package/dist/oauth/cimd/cimd-ssrf.js.map +1 -0
  93. package/dist/oauth/cimd/cimd.d.ts +36 -0
  94. package/dist/oauth/cimd/cimd.d.ts.map +1 -0
  95. package/dist/oauth/cimd/cimd.js +132 -0
  96. package/dist/oauth/cimd/cimd.js.map +1 -0
  97. package/dist/oauth/cimd/types.d.ts +12 -0
  98. package/dist/oauth/cimd/types.d.ts.map +1 -0
  99. package/dist/oauth/cimd/types.js +3 -0
  100. package/dist/oauth/cimd/types.js.map +1 -0
  101. package/dist/oauth/config.d.ts +51 -0
  102. package/dist/oauth/config.d.ts.map +1 -0
  103. package/dist/oauth/config.js +108 -0
  104. package/dist/oauth/config.js.map +1 -0
  105. package/dist/oauth/constants.d.ts +15 -0
  106. package/dist/oauth/constants.d.ts.map +1 -1
  107. package/dist/oauth/constants.js +15 -0
  108. package/dist/oauth/constants.js.map +1 -1
  109. package/dist/oauth/{base64url.d.ts → crypto/base64url.d.ts} +1 -2
  110. package/dist/oauth/crypto/base64url.d.ts.map +1 -0
  111. package/dist/oauth/{base64url.js → crypto/base64url.js} +1 -5
  112. package/dist/oauth/crypto/base64url.js.map +1 -0
  113. package/dist/oauth/crypto/clientauth.d.ts +13 -0
  114. package/dist/oauth/crypto/clientauth.d.ts.map +1 -0
  115. package/dist/oauth/crypto/clientauth.js +195 -0
  116. package/dist/oauth/crypto/clientauth.js.map +1 -0
  117. package/dist/oauth/crypto/codes.d.ts +65 -0
  118. package/dist/oauth/crypto/codes.d.ts.map +1 -0
  119. package/dist/oauth/crypto/codes.js +121 -0
  120. package/dist/oauth/crypto/codes.js.map +1 -0
  121. package/dist/oauth/crypto/hkdf.d.ts +13 -0
  122. package/dist/oauth/crypto/hkdf.d.ts.map +1 -0
  123. package/dist/oauth/crypto/hkdf.js +30 -0
  124. package/dist/oauth/crypto/hkdf.js.map +1 -0
  125. package/dist/oauth/crypto/keycache.d.ts +19 -0
  126. package/dist/oauth/crypto/keycache.d.ts.map +1 -0
  127. package/dist/oauth/crypto/keycache.js +44 -0
  128. package/dist/oauth/crypto/keycache.js.map +1 -0
  129. package/dist/oauth/crypto/pkce.d.ts.map +1 -0
  130. package/dist/oauth/{pkce.js → crypto/pkce.js} +1 -1
  131. package/dist/oauth/crypto/pkce.js.map +1 -0
  132. package/dist/oauth/crypto/sealed.d.ts +26 -0
  133. package/dist/oauth/crypto/sealed.d.ts.map +1 -0
  134. package/dist/oauth/crypto/sealed.js +65 -0
  135. package/dist/oauth/crypto/sealed.js.map +1 -0
  136. package/dist/oauth/crypto/secrethash.d.ts +58 -0
  137. package/dist/oauth/crypto/secrethash.d.ts.map +1 -0
  138. package/dist/oauth/crypto/secrethash.js +82 -0
  139. package/dist/oauth/crypto/secrethash.js.map +1 -0
  140. package/dist/oauth/deprecated.d.ts +52 -0
  141. package/dist/oauth/deprecated.d.ts.map +1 -0
  142. package/dist/oauth/deprecated.js +49 -0
  143. package/dist/oauth/deprecated.js.map +1 -0
  144. package/dist/oauth/endpoints/authorize.d.ts +3 -0
  145. package/dist/oauth/endpoints/authorize.d.ts.map +1 -0
  146. package/dist/oauth/endpoints/authorize.js +209 -0
  147. package/dist/oauth/endpoints/authorize.js.map +1 -0
  148. package/dist/oauth/endpoints/callback.d.ts +20 -0
  149. package/dist/oauth/endpoints/callback.d.ts.map +1 -0
  150. package/dist/oauth/endpoints/callback.js +31 -0
  151. package/dist/oauth/endpoints/callback.js.map +1 -0
  152. package/dist/oauth/endpoints/consent-page.d.ts +5 -0
  153. package/dist/oauth/endpoints/consent-page.d.ts.map +1 -0
  154. package/dist/oauth/endpoints/consent-page.js +63 -0
  155. package/dist/oauth/endpoints/consent-page.js.map +1 -0
  156. package/dist/oauth/endpoints/consent.d.ts +29 -0
  157. package/dist/oauth/endpoints/consent.d.ts.map +1 -0
  158. package/dist/oauth/endpoints/consent.js +98 -0
  159. package/dist/oauth/endpoints/consent.js.map +1 -0
  160. package/dist/oauth/{metadata.d.ts → endpoints/metadata.d.ts} +14 -8
  161. package/dist/oauth/endpoints/metadata.d.ts.map +1 -0
  162. package/dist/oauth/{metadata.js → endpoints/metadata.js} +10 -4
  163. package/dist/oauth/endpoints/metadata.js.map +1 -0
  164. package/dist/oauth/endpoints/register.d.ts +10 -0
  165. package/dist/oauth/endpoints/register.d.ts.map +1 -0
  166. package/dist/oauth/endpoints/register.js +96 -0
  167. package/dist/oauth/endpoints/register.js.map +1 -0
  168. package/dist/oauth/{revoke.d.ts → endpoints/revoke.d.ts} +1 -1
  169. package/dist/oauth/endpoints/revoke.d.ts.map +1 -0
  170. package/dist/oauth/{revoke.js → endpoints/revoke.js} +11 -9
  171. package/dist/oauth/endpoints/revoke.js.map +1 -0
  172. package/dist/oauth/endpoints/token.d.ts +3 -0
  173. package/dist/oauth/endpoints/token.d.ts.map +1 -0
  174. package/dist/oauth/{token.js → endpoints/token.js} +33 -47
  175. package/dist/oauth/endpoints/token.js.map +1 -0
  176. package/dist/oauth/{wellknown.d.ts → endpoints/wellknown.d.ts} +1 -1
  177. package/dist/oauth/endpoints/wellknown.d.ts.map +1 -0
  178. package/dist/oauth/{wellknown.js → endpoints/wellknown.js} +7 -7
  179. package/dist/oauth/endpoints/wellknown.js.map +1 -0
  180. package/dist/oauth/{redirect.d.ts → policy/redirect.d.ts} +6 -1
  181. package/dist/oauth/policy/redirect.d.ts.map +1 -0
  182. package/dist/oauth/policy/redirect.js +39 -0
  183. package/dist/oauth/policy/redirect.js.map +1 -0
  184. package/dist/oauth/policy/reqbody.d.ts +18 -0
  185. package/dist/oauth/policy/reqbody.d.ts.map +1 -0
  186. package/dist/oauth/policy/reqbody.js +68 -0
  187. package/dist/oauth/policy/reqbody.js.map +1 -0
  188. package/dist/oauth/policy/resource.d.ts +37 -0
  189. package/dist/oauth/policy/resource.d.ts.map +1 -0
  190. package/dist/oauth/policy/resource.js +74 -0
  191. package/dist/oauth/policy/resource.js.map +1 -0
  192. package/dist/oauth/policy/scope.d.ts +20 -0
  193. package/dist/oauth/policy/scope.d.ts.map +1 -0
  194. package/dist/oauth/policy/scope.js +35 -0
  195. package/dist/oauth/policy/scope.js.map +1 -0
  196. package/dist/oauth/router.d.ts +12 -12
  197. package/dist/oauth/router.d.ts.map +1 -1
  198. package/dist/oauth/router.js +105 -87
  199. package/dist/oauth/router.js.map +1 -1
  200. package/dist/oauth/types.d.ts +177 -26
  201. package/dist/oauth/types.d.ts.map +1 -1
  202. package/dist/oauth/types.js +1 -27
  203. package/dist/oauth/types.js.map +1 -1
  204. package/dist/server.d.ts +14 -13
  205. package/dist/server.d.ts.map +1 -1
  206. package/dist/server.js +10 -9
  207. package/dist/server.js.map +1 -1
  208. package/dist/util/defined.d.ts +11 -0
  209. package/dist/util/defined.d.ts.map +1 -0
  210. package/dist/util/defined.js +15 -0
  211. package/dist/util/defined.js.map +1 -0
  212. package/dist/util/json.d.ts +3 -0
  213. package/dist/util/json.d.ts.map +1 -0
  214. package/dist/util/json.js +3 -0
  215. package/dist/util/json.js.map +1 -0
  216. package/docs/ROADMAP.md +283 -0
  217. package/docs/compatibility.md +84 -0
  218. package/docs/diagrams/mcp-trellis-architecture.html +305 -0
  219. package/docs/guide.md +441 -0
  220. package/docs/reference.md +210 -0
  221. package/docs/security.md +112 -0
  222. package/docs/troubleshooting.md +19 -0
  223. package/package.json +24 -8
  224. package/dist/adapters/origins.d.ts +0 -19
  225. package/dist/adapters/origins.d.ts.map +0 -1
  226. package/dist/adapters/origins.js +0 -55
  227. package/dist/adapters/origins.js.map +0 -1
  228. package/dist/dispatch.d.ts +0 -7
  229. package/dist/dispatch.d.ts.map +0 -1
  230. package/dist/dispatch.js +0 -79
  231. package/dist/dispatch.js.map +0 -1
  232. package/dist/http.d.ts +0 -17
  233. package/dist/http.d.ts.map +0 -1
  234. package/dist/http.js +0 -38
  235. package/dist/http.js.map +0 -1
  236. package/dist/jsonrpc.d.ts.map +0 -1
  237. package/dist/jsonrpc.js +0 -17
  238. package/dist/jsonrpc.js.map +0 -1
  239. package/dist/methods.d.ts +0 -61
  240. package/dist/methods.d.ts.map +0 -1
  241. package/dist/methods.js +0 -114
  242. package/dist/methods.js.map +0 -1
  243. package/dist/oauth/authorize.d.ts +0 -3
  244. package/dist/oauth/authorize.d.ts.map +0 -1
  245. package/dist/oauth/authorize.js +0 -109
  246. package/dist/oauth/authorize.js.map +0 -1
  247. package/dist/oauth/base64url.d.ts.map +0 -1
  248. package/dist/oauth/base64url.js.map +0 -1
  249. package/dist/oauth/clientauth.d.ts +0 -19
  250. package/dist/oauth/clientauth.d.ts.map +0 -1
  251. package/dist/oauth/clientauth.js +0 -76
  252. package/dist/oauth/clientauth.js.map +0 -1
  253. package/dist/oauth/codes.d.ts +0 -30
  254. package/dist/oauth/codes.d.ts.map +0 -1
  255. package/dist/oauth/codes.js +0 -93
  256. package/dist/oauth/codes.js.map +0 -1
  257. package/dist/oauth/metadata.d.ts.map +0 -1
  258. package/dist/oauth/metadata.js.map +0 -1
  259. package/dist/oauth/pkce.d.ts.map +0 -1
  260. package/dist/oauth/pkce.js.map +0 -1
  261. package/dist/oauth/redirect.d.ts.map +0 -1
  262. package/dist/oauth/redirect.js +0 -26
  263. package/dist/oauth/redirect.js.map +0 -1
  264. package/dist/oauth/resource.d.ts +0 -7
  265. package/dist/oauth/resource.d.ts.map +0 -1
  266. package/dist/oauth/resource.js +0 -44
  267. package/dist/oauth/resource.js.map +0 -1
  268. package/dist/oauth/revoke.d.ts.map +0 -1
  269. package/dist/oauth/revoke.js.map +0 -1
  270. package/dist/oauth/scope.d.ts +0 -11
  271. package/dist/oauth/scope.d.ts.map +0 -1
  272. package/dist/oauth/scope.js +0 -24
  273. package/dist/oauth/scope.js.map +0 -1
  274. package/dist/oauth/token.d.ts +0 -3
  275. package/dist/oauth/token.d.ts.map +0 -1
  276. package/dist/oauth/token.js.map +0 -1
  277. package/dist/oauth/wellknown.d.ts.map +0 -1
  278. package/dist/oauth/wellknown.js.map +0 -1
  279. package/dist/protocol.d.ts +0 -4
  280. package/dist/protocol.d.ts.map +0 -1
  281. package/dist/protocol.js +0 -14
  282. package/dist/protocol.js.map +0 -1
  283. package/dist/registry.d.ts +0 -37
  284. package/dist/registry.d.ts.map +0 -1
  285. package/dist/registry.js +0 -69
  286. package/dist/registry.js.map +0 -1
  287. package/dist/tools.d.ts.map +0 -1
  288. package/dist/tools.js +0 -97
  289. package/dist/tools.js.map +0 -1
  290. package/dist/validate.d.ts.map +0 -1
  291. package/dist/validate.js +0 -130
  292. package/dist/validate.js.map +0 -1
  293. /package/dist/oauth/{pkce.d.ts → crypto/pkce.d.ts} +0 -0
@@ -1,88 +1,103 @@
1
- import { INTERNAL_ERROR, jsonResponse, requireHttpMethod } from "../http.js";
2
- import { newClientId } from "./codes.js";
3
- import { GRANT_TYPES, OAUTH_ERRORS } from "./constants.js";
4
- import { CLAUDE_CALLBACK, isAllowedRedirectUri } from "./redirect.js";
5
- import { DEFAULT_RESOURCE_PATH } from "./resource.js";
6
- import { oauthError, unregisteredClientsAllowed, } from "./types.js";
7
- import { handleAuthorize } from "./authorize.js";
8
- import { handleToken } from "./token.js";
9
- import { handleRevoke } from "./revoke.js";
10
- import { handleWellKnown } from "./wellknown.js";
11
- const POST_ONLY = new Set(["POST"]);
12
- const handleRegister = async (request, options) => {
13
- const methodError = requireHttpMethod(request, POST_ONLY);
14
- if (methodError)
15
- return methodError;
16
- let suppliedRedirectUris = false;
17
- let redirectUris = [];
18
- try {
19
- const body = (await request.json());
20
- const raw = body.redirect_uris;
21
- if (Array.isArray(raw)) {
22
- suppliedRedirectUris = true;
23
- redirectUris = raw
24
- .map((u) => String(u))
25
- .filter((uri) => isAllowedRedirectUri(uri, options.redirect));
26
- }
1
+ import { errorReason, INTERNAL_ERROR } from "../http/http.js";
2
+ import { safeOAuthAudit } from "./audit.js";
3
+ import { assertCodeSecret, assertScopeConfig, oauthError, unregisteredClientsAllowed, } from "./config.js";
4
+ import { DEFAULT_OAUTH_PATH, OAUTH_ERRORS } from "./constants.js";
5
+ import { processCodeStore } from "./crypto/codes.js";
6
+ import { handleAuthorize } from "./endpoints/authorize.js";
7
+ import { handleConsent } from "./endpoints/consent.js";
8
+ import { handleRegister } from "./endpoints/register.js";
9
+ import { handleRevoke } from "./endpoints/revoke.js";
10
+ import { handleToken } from "./endpoints/token.js";
11
+ import { handleWellKnown } from "./endpoints/wellknown.js";
12
+ import { DEFAULT_RESOURCE_PATH, normalizeConfiguredPath } from "./policy/resource.js";
13
+ /**
14
+ * Function-form `codeSecret` is re-validated on every call in
15
+ * `resolveSecrets`, since its value can vary per request; a string or array
16
+ * form is fixed for the life of this router, so fail fast at construction
17
+ * instead of at the first request.
18
+ */
19
+ const assertRouterOptions = (options) => {
20
+ if (!unregisteredClientsAllowed(options) && !options.ports.clientStore) {
21
+ throw new Error("allowUnregisteredClients: false requires ports.clientStore " +
22
+ "so pre-registered clients can be resolved");
27
23
  }
28
- catch {
29
- redirectUris = [];
24
+ if (!options.ports.codeStore && !options.allowInMemoryCodeStore) {
25
+ throw new Error("ports.codeStore is required (shared jti store for auth-code / consent single-use). " +
26
+ "Pass a CodeStore, or set allowInMemoryCodeStore: true for single-process demos/tests only");
30
27
  }
31
- // No redirect_uris in the body: fall back to the Claude callback only if
32
- // this server's own allowlist actually accepts it — never advertise a
33
- // redirect_uri that `/authorize` would go on to reject (e.g. `clients`
34
- // without `"claude"`, where `createMcpApp` sets `allowClaude: false`).
35
- if (!suppliedRedirectUris && isAllowedRedirectUri(CLAUDE_CALLBACK, options.redirect)) {
36
- redirectUris = [CLAUDE_CALLBACK];
28
+ if (typeof options.ports.codeSecret === "string") {
29
+ assertCodeSecret(options.ports.codeSecret);
37
30
  }
38
- if (redirectUris.length === 0) {
39
- return oauthError(OAUTH_ERRORS.invalidRedirectUri, 400, suppliedRedirectUris
40
- ? "no allowed redirect_uris"
41
- : "redirect_uris required — this server has no default redirect_uri");
31
+ if (Array.isArray(options.ports.codeSecret)) {
32
+ if (options.ports.codeSecret.length === 0) {
33
+ throw new Error("codeSecret array must not be empty — at least one key is required");
34
+ }
35
+ options.ports.codeSecret.forEach(assertCodeSecret);
42
36
  }
43
- return jsonResponse({
44
- client_id: newClientId(),
45
- client_id_issued_at: Math.floor(Date.now() / 1000),
46
- token_endpoint_auth_method: "none",
47
- redirect_uris: redirectUris,
48
- grant_types: [GRANT_TYPES.authorizationCode],
49
- response_types: ["code"],
50
- });
37
+ assertScopeConfig(options);
51
38
  };
52
- export const createOAuthRouter = (options) => {
53
- if (!unregisteredClientsAllowed(options) && !options.ports.clientStore) {
54
- throw new Error("allowUnregisteredClients: false requires ports.clientStore " +
55
- "so pre-registered clients can be resolved");
39
+ /**
40
+ * Normalized once, not per request, so "/mcp/" and "/mcp" yield one
41
+ * canonical resource, and the routing table, discovery documents and the
42
+ * consent form action all agree on `oauthPath`.
43
+ */
44
+ const normalizeRouterPaths = (options) => {
45
+ const resourcePath = normalizeConfiguredPath(options.resourcePath ?? DEFAULT_RESOURCE_PATH);
46
+ const oauthPath = normalizeConfiguredPath(options.oauthPath ?? DEFAULT_OAUTH_PATH);
47
+ if (oauthPath === resourcePath) {
48
+ throw new Error(`oauthPath (${oauthPath}) must not equal resourcePath — they would shadow each other`);
56
49
  }
57
- const resourcePath = options.resourcePath ?? DEFAULT_RESOURCE_PATH;
58
- const oauthPath = options.oauthPath ?? "/mcp/oauth";
59
- const prmPaths = new Set([
60
- "/.well-known/oauth-protected-resource",
61
- `/.well-known/oauth-protected-resource${resourcePath}`,
62
- ]);
63
- const asPaths = new Set([
64
- "/.well-known/oauth-authorization-server",
65
- `/.well-known/oauth-authorization-server${resourcePath}`,
66
- ]);
67
- const routes = {
68
- ...(unregisteredClientsAllowed(options)
69
- ? {
70
- [`${oauthPath}/register`]: (request) => handleRegister(request, options),
71
- }
72
- : {}),
73
- [`${oauthPath}/authorize`]: (request) => handleAuthorize(request, options),
74
- [`${oauthPath}/token`]: (request) => handleToken(request, options),
75
- ...(options.ports.revokeToken
76
- ? {
77
- [`${oauthPath}/revoke`]: (request) => handleRevoke(request, options),
78
- }
79
- : {}),
50
+ if (resourcePath.startsWith("/.well-known")) {
51
+ throw new Error(`resourcePath (${resourcePath}) must not start with /.well-known — reserved for OAuth discovery documents`);
52
+ }
53
+ return {
54
+ resourcePath,
55
+ oauthPath,
56
+ prmPaths: new Set([
57
+ "/.well-known/oauth-protected-resource",
58
+ `/.well-known/oauth-protected-resource${resourcePath}`,
59
+ ]),
60
+ asPaths: new Set([
61
+ "/.well-known/oauth-authorization-server",
62
+ `/.well-known/oauth-authorization-server${resourcePath}`,
63
+ ]),
80
64
  };
65
+ };
66
+ const buildRoutes = (options, normalizedOptions, oauthPath) => ({
67
+ ...(unregisteredClientsAllowed(options)
68
+ ? {
69
+ [`${oauthPath}/register`]: (request) => handleRegister(request, normalizedOptions),
70
+ }
71
+ : {}),
72
+ [`${oauthPath}/authorize`]: (request) => handleAuthorize(request, normalizedOptions),
73
+ [`${oauthPath}/consent`]: (request) => handleConsent(request, normalizedOptions),
74
+ [`${oauthPath}/token`]: (request) => handleToken(request, normalizedOptions),
75
+ ...(options.ports.revokeToken
76
+ ? {
77
+ [`${oauthPath}/revoke`]: (request) => handleRevoke(request, normalizedOptions),
78
+ }
79
+ : {}),
80
+ });
81
+ export const createOAuthRouter = (options) => {
82
+ assertRouterOptions(options);
83
+ // Resolved once; `assertRouterOptions` already required
84
+ // `allowInMemoryCodeStore` before the process store can be reached.
85
+ const codeStore = options.ports.codeStore ?? processCodeStore;
86
+ const ports = { ...options.ports, codeStore };
87
+ const { resourcePath, oauthPath, prmPaths, asPaths } = normalizeRouterPaths(options);
88
+ // Handlers read paths from here, never from the caller's raw options.
89
+ const normalizedOptions = {
90
+ ...options,
91
+ resourcePath,
92
+ oauthPath,
93
+ ports,
94
+ };
95
+ const routes = buildRoutes(options, normalizedOptions, oauthPath);
81
96
  return {
82
97
  tryHandle: async (request) => {
83
98
  try {
84
99
  const path = new URL(request.url).pathname;
85
- const known = await handleWellKnown(request, options, {
100
+ const known = await handleWellKnown(request, normalizedOptions, {
86
101
  prmPaths,
87
102
  asPaths,
88
103
  resourcePath,
@@ -93,22 +108,25 @@ export const createOAuthRouter = (options) => {
93
108
  const route = routes[path];
94
109
  return route ? await route(request) : null;
95
110
  }
96
- catch {
97
- // A host port (resolveUser/mintAccessToken/clientStore/...) threw.
98
- // We only ever reach here on a route this router owns, so answer
99
- // with a real error instead of throwing out of `tryHandle`.
111
+ catch (caught) {
112
+ // A host port threw, or a per-request codeSecret failed validation.
113
+ // Only routes this router owns get here: the caller sees a generic
114
+ // server_error, ports.audit gets the real reason.
115
+ await safeOAuthAudit(normalizedOptions, {
116
+ event: "server_error",
117
+ reason: errorReason(caught),
118
+ });
100
119
  return oauthError(OAUTH_ERRORS.serverError, 500, INTERNAL_ERROR);
101
120
  }
102
121
  },
103
122
  };
104
123
  };
105
- export { authorizationServerMetadata, protectedResourceMetadata, mcpWwwAuthenticate, } from "./metadata.js";
106
- export { canonicalResource, resourcesEqual, DEFAULT_RESOURCE_PATH, firstResourceError, } from "./resource.js";
107
- export { isAllowedRedirectUri, CLAUDE_CALLBACK } from "./redirect.js";
108
- export { issueAuthCode, consumeAuthCode, newClientId, } from "./codes.js";
109
- export { verifyPkceS256, sha256Base64Url, randomBase64Url } from "./pkce.js";
110
- export { GRANT_TYPES, OAUTH_ERRORS, DEFAULT_SCOPE, TOKEN_ENDPOINT_AUTH_METHODS, } from "./constants.js";
111
- export { parseScope, formatScope, requestedScopes, firstScopeError, } from "./scope.js";
112
- export { readClientAuth, firstClientAuthError } from "./clientauth.js";
113
- export { unregisteredClientsAllowed } from "./types.js";
124
+ export { isCimdClientId, resolveCimdClient, } from "./cimd/cimd.js";
125
+ export { DEFAULT_SCOPE, GRANT_TYPES, OAUTH_ERRORS, TOKEN_ENDPOINT_AUTH_METHODS, } from "./constants.js";
126
+ export { hashClientSecret, verifyClientSecret } from "./crypto/secrethash.js";
127
+ // Moved to `mcp-trellis/advanced`; deprecated aliases until 3.0.
128
+ export * from "./deprecated.js";
129
+ export { authorizationServerMetadata, mcpWwwAuthenticate, protectedResourceMetadata, } from "./endpoints/metadata.js";
130
+ export { CLAUDE_CALLBACK, isAllowedRedirectUri } from "./policy/redirect.js";
131
+ export { canonicalResource, DEFAULT_RESOURCE_PATH, resourcesEqual, } from "./policy/resource.js";
114
132
  //# sourceMappingURL=router.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/oauth/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,UAAU,EACV,0BAA0B,GAE3B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AASjD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,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c,CAAC,iBAAiB,EAAE;oBACtC,KAAK,EAAE,cAAc;oBACrB,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;iBAC5B,CAAC,CAAC;gBACH,OAAO,UAAU,CAAC,YAAY,CAAC,WAAW,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAGL,cAAc,EACd,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,aAAa,EACb,WAAW,EACX,YAAY,EACZ,2BAA2B,GAE5B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,iEAAiE;AACjE,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,GACf,MAAM,sBAAsB,CAAC"}
@@ -1,6 +1,7 @@
1
- import { type TokenEndpointAuthMethod } from "./constants.js";
2
- import type { CodeStore } from "./codes.js";
3
- import type { RedirectAllowlistOptions } from "./redirect.js";
1
+ import type { CimdCache } from "./cimd/types.js";
2
+ import type { TokenEndpointAuthMethod } from "./constants.js";
3
+ import type { CodeStore } from "./crypto/codes.js";
4
+ import type { RedirectAllowlistOptions } from "./policy/redirect.js";
4
5
  export type OAuthUser = {
5
6
  id: string;
6
7
  };
@@ -15,15 +16,69 @@ export type RegisteredClient = {
15
16
  redirectUris: string[];
16
17
  tokenEndpointAuthMethod: TokenEndpointAuthMethod;
17
18
  };
19
+ export type ConsentRequest = {
20
+ clientId: string;
21
+ registeredClient: RegisteredClient | null;
22
+ redirectUri: string;
23
+ scope: string[];
24
+ resource: string;
25
+ user: OAuthUser;
26
+ /** Embed this in your form's `consent_ticket` field (hidden input or POST body). */
27
+ ticket: string;
28
+ oauthPath: string;
29
+ };
30
+ export type ConsentOptions = {
31
+ /**
32
+ * Render the approval page yourself. Return any `Response` — HTML, or a
33
+ * redirect to your own route. Omit for the built-in hardened interstitial.
34
+ *
35
+ * If your page sets its own `Content-Security-Policy` with `form-action`,
36
+ * include `new URL(input.redirectUri).origin` in it — Chromium enforces
37
+ * `form-action` across the redirect your approval POST triggers, not just
38
+ * the immediate submission target, so `'self'` alone blocks the eventual
39
+ * redirect back to the client's own callback.
40
+ */
41
+ render?: (input: ConsentRequest) => Response | Promise<Response>;
42
+ /**
43
+ * Client ids that skip approval. Only honored when `clientStore` actually
44
+ * resolves the id — a DCR or self-invented id is never trusted.
45
+ */
46
+ preApprovedClientIds?: string[];
47
+ };
48
+ /**
49
+ * The payload sealed into a `client_id` this server itself issued via
50
+ * `/register` (see `sealed.ts`, type `"client"`). Zero storage: the id
51
+ * *is* the registration record, self-verifying against `codeSecret`.
52
+ */
53
+ export type ClientAssertion = {
54
+ redirectUris: string[];
55
+ /**
56
+ * Unix seconds when `/register` sealed this assertion. Informational only
57
+ * — not enforced as an expiry — so it can help an operator judge how old
58
+ * a still-valid DCR client is. Optional on read: an assertion sealed
59
+ * before this field existed still unseals and works.
60
+ */
61
+ iat?: number;
62
+ };
18
63
  export type ClientStore = {
19
64
  /** Resolve a pre-registered client, or null when unknown. */
20
65
  get: (clientId: string) => Promise<RegisteredClient | null>;
21
66
  /**
22
- * Verify a presented client secret. Required for confidential clients.
23
- * Secret storage and comparison stay in your implementation — the library
24
- * never sees or persists credentials.
67
+ * Verify a presented client secret yourself. Secret storage and
68
+ * comparison stay entirely in your implementation — the library never
69
+ * sees or persists credentials. Prefer `secretHash` below when you can:
70
+ * a hand-rolled `stored === presented` here is a timing oracle with no
71
+ * warning from the library.
25
72
  */
26
73
  verifySecret?: (clientId: string, presented: string) => Promise<boolean>;
74
+ /**
75
+ * Preferred over `verifySecret`: return the stored hash (from
76
+ * `hashClientSecret`) for `clientId`, or `null` when unknown, and the
77
+ * library does the comparison with the same constant-time primitive it
78
+ * uses everywhere else. Checked first when both are present. See
79
+ * `secrethash.ts`.
80
+ */
81
+ secretHash?: (clientId: string) => Promise<string | null>;
27
82
  };
28
83
  export type MintedToken = {
29
84
  accessToken: string;
@@ -47,15 +102,47 @@ export type RefreshAccessTokenInput = {
47
102
  * Implementations MUST reject refresh tokens not originally issued for this resource.
48
103
  */
49
104
  resource: string;
105
+ /**
106
+ * RFC 6749 §6 — optional scope reduction requested by the client.
107
+ * When set, the library validates against advertised `scopes` only.
108
+ * Implementations MUST also reject any scope outside what was originally
109
+ * granted to this refresh token (the library cannot see opaque RTs).
110
+ */
111
+ scope?: string;
50
112
  };
51
113
  export type RevokeTokenInput = {
52
114
  token: string;
53
115
  clientId: string;
54
- tokenTypeHint?: "access_token" | "refresh_token";
116
+ tokenTypeHint?: "access_token" | "refresh_token" | undefined;
117
+ };
118
+ /**
119
+ * OAuth-side metrics hook, mirroring `McpPorts.audit` on the MCP side.
120
+ * `reason` is intentionally more specific than what the caller ever sees —
121
+ * `/token` and `/revoke` collapse every client-auth failure to one generic
122
+ * `invalid_client` (closing an enumeration oracle; see `clientauth.ts`),
123
+ * and a rejected `codeSecret` surfaces to the caller only as `server_error`
124
+ * — this port is where an operator gets the real reason back, without
125
+ * handing it to an unauthenticated caller.
126
+ */
127
+ export type OAuthAuditEntry = {
128
+ /** Machine-stable event name, e.g. "client_auth_failed", "server_error". */
129
+ event: string;
130
+ clientId?: string | undefined;
131
+ reason: string;
55
132
  };
56
133
  export type OAuthPorts = {
57
- /** HMAC secret for signing auth codes. */
58
- codeSecret: string | ((req: Request) => string | Promise<string>);
134
+ /**
135
+ * Secret(s) that seal auth codes, consent tickets, and self-issued DCR
136
+ * client assertions (`sealed.ts`), and key `ClientStore.secretHash`.
137
+ *
138
+ * Pass a single string, or for key rotation an array: the **first** entry seals new material and hashes new client
139
+ * secrets; **every** entry is tried when unsealing/verifying, so material
140
+ * sealed under an older key keeps working until you drop it from the
141
+ * array. `ports.audit` sees a `"legacy_code_secret_used"` event whenever
142
+ * anything but the first entry was the one that actually verified,
143
+ * so you know when it's safe to remove.
144
+ */
145
+ codeSecret: string | string[] | ((req: Request) => string | string[] | Promise<string | string[]>);
59
146
  /** Resolve the logged-in user, or null → redirect to login. */
60
147
  resolveUser: (req: Request) => Promise<OAuthUser | null>;
61
148
  /** Where to send unauthenticated authorize requests. */
@@ -63,7 +150,7 @@ export type OAuthPorts = {
63
150
  /** Mint an access token bound to the consenting user and resource audience. */
64
151
  mintAccessToken: (input: MintAccessTokenInput) => Promise<MintedToken>;
65
152
  /** Optional refresh_token grant. Presence advertises the grant. */
66
- refreshAccessToken?: (input: RefreshAccessTokenInput) => Promise<MintedToken | null>;
153
+ refreshAccessToken?: ((input: RefreshAccessTokenInput) => Promise<MintedToken | null>) | undefined;
67
154
  /**
68
155
  * RFC 7009. Presence mounts `/revoke` and advertises `revocation_endpoint`.
69
156
  * Well-formed authenticated revoke is HTTP 200 even if the token is unknown
@@ -71,11 +158,18 @@ export type OAuthPorts = {
71
158
  * `refreshAccessToken` MUST consult the same store; unknown tokens and
72
159
  * tokens not issued to `clientId` MUST no-op (not throw).
73
160
  */
74
- revokeToken?: (input: RevokeTokenInput) => Promise<void>;
75
- /** Shared single-use jti store for multi-instance; in-memory default otherwise. */
76
- codeStore?: CodeStore;
161
+ revokeToken?: ((input: RevokeTokenInput) => Promise<void>) | undefined;
162
+ /** Shared single-use jti store for multi-instance. Required unless `allowInMemoryCodeStore`. */
163
+ codeStore?: CodeStore | undefined;
77
164
  /** Pre-registered clients. Required to serve confidential clients. */
78
- clientStore?: ClientStore;
165
+ clientStore?: ClientStore | undefined;
166
+ /**
167
+ * Opt-in metrics hook. Pass any function to see the real reason behind a
168
+ * collapsed `invalid_client` or a rejected `codeSecret`. Omit it and the
169
+ * library stays silent. Throwing never fails the request — same
170
+ * guarantee as `McpPorts.audit`.
171
+ */
172
+ audit?: ((entry: OAuthAuditEntry) => void | Promise<void>) | undefined;
79
173
  };
80
174
  export type OAuthRouterOptions = {
81
175
  ports: OAuthPorts;
@@ -83,6 +177,13 @@ export type OAuthRouterOptions = {
83
177
  oauthPath?: string;
84
178
  realm?: string;
85
179
  scopes?: string[];
180
+ /**
181
+ * Scopes granted when a client omits `scope` entirely. Required when
182
+ * `scopes` advertises more than one — with only one advertised scope
183
+ * there's no escalation to prevent, so it defaults to that scope.
184
+ * Must be a subset of `scopes`.
185
+ */
186
+ defaultScopes?: string[];
86
187
  redirect?: RedirectAllowlistOptions;
87
188
  /** Advertised in AS metadata. Defaults to `["none"]` (public clients only). */
88
189
  tokenEndpointAuthMethods?: TokenEndpointAuthMethod[];
@@ -98,18 +199,68 @@ export type OAuthRouterOptions = {
98
199
  * `hasDynamicClient`.
99
200
  */
100
201
  allowUnregisteredClients?: boolean;
202
+ /**
203
+ * Require every `client_id` to have gone through `clientStore` or this
204
+ * server's own `/register` (whose issued ids are self-verifying sealed
205
+ * assertions — see `sealed.ts`). Unlike `allowUnregisteredClients: false`,
206
+ * DCR stays mounted; a client just can't invent an id out of thin air.
207
+ *
208
+ * Default **true** since 1.0. Set **false** only when you intentionally
209
+ * accept arbitrary public `client_id`s (pre-CIMD connectors that invent ids).
210
+ */
211
+ requireRegisteredClients?: boolean;
212
+ /**
213
+ * Consent policy. Policy, not a credential — sits alongside `redirect`,
214
+ * not under `ports`. Omit for the built-in hardened interstitial.
215
+ */
216
+ consent?: ConsentOptions;
217
+ /**
218
+ * Max time to wait for `ports.audit` before responding anyway. Default
219
+ * 1000ms — same guarantee as `McpHandlerOptions.auditTimeoutMs`.
220
+ */
221
+ auditTimeoutMs?: number;
222
+ /**
223
+ * Allow the process-local in-memory jti Map when `ports.codeStore` is
224
+ * omitted. Default **false** since 2.0 — multi-instance deploys silently
225
+ * double-redeem auth codes without a shared store. Set true only for
226
+ * single-process demos and tests.
227
+ */
228
+ allowInMemoryCodeStore?: boolean;
229
+ /**
230
+ * Resolve Client ID Metadata Documents (HTTPS URL `client_id`s).
231
+ * Default **false** — opt in with `cimd: true`. Off until connect-pinned
232
+ * fetch exists; see `cimd.ts` ponytail.
233
+ */
234
+ cimd?: boolean;
235
+ /**
236
+ * CIMD document cache (respects Cache-Control max-age, capped at 1 h).
237
+ * **Strongly recommended with `cimd: true`:** without it `/token` and
238
+ * `/revoke` re-fetch the client's document on every call, so a flaky
239
+ * document host fails refresh/revoke (audited as `cimd_resolve_failed`).
240
+ */
241
+ cimdCache?: CimdCache;
242
+ /** Optional DNS lookup for CIMD SSRF checks — see `CimdFetchOptions.lookup`. */
243
+ cimdLookup?: (hostname: string) => Promise<string[]>;
101
244
  };
102
- /** Default true — see `OAuthRouterOptions.allowUnregisteredClients`. */
103
- export declare const unregisteredClientsAllowed: (options: OAuthRouterOptions) => boolean;
104
- /** Scopes this AS advertises and is willing to grant. */
105
- export declare const advertisedScopes: (options: OAuthRouterOptions) => string[];
106
- export declare const resolveSecret: (ports: OAuthPorts, req: Request) => Promise<string>;
107
- export declare const oauthError: (error: string, status: number, description?: string) => Response;
108
- /** Direct JSON error when this AS does not serve unknown `client_id`s. */
109
- export declare const unregisteredClientError: (options: OAuthRouterOptions, reject: {
245
+ /**
246
+ * `OAuthRouterOptions` after `createOAuthRouter` has resolved them: paths
247
+ * normalized and `ports.codeStore` always present, so no endpoint handler
248
+ * can fall back to a store of its own. Internal — not re-exported.
249
+ */
250
+ export type ResolvedOAuthRouterOptions = OAuthRouterOptions & {
251
+ resourcePath: string;
252
+ oauthPath: string;
253
+ ports: OAuthPorts & {
254
+ codeStore: CodeStore;
255
+ };
256
+ };
257
+ /**
258
+ * An OAuth error's code and description without a `Response` built yet —
259
+ * lets a caller choose delivery: `oauthError` for a direct JSON body, or a
260
+ * redirect to the client's own callback (RFC 6749 §4.1.2.1).
261
+ */
262
+ export type OAuthErrorInfo = {
110
263
  code: string;
111
- status: number;
112
- }) => Response | null;
113
- /** `grantedScope` is what the auth code carried; the port may narrow it further. */
114
- export declare const tokenResponse: (minted: MintedToken, grantedScope?: string) => Response;
264
+ description: string;
265
+ };
115
266
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAG9D,MAAM,MAAM,SAAS,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,uBAAuB,EAAE,uBAAuB,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,6DAA6D;IAC7D,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAC5D;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1E,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MA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E,wBAAwB,CAAC,EAAE,uBAAuB,EAAE,CAAC;IACrD;;;;;;;;;;OAUG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC;;;;;;;;OAQG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,gFAAgF;IAChF,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACtD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG,kBAAkB,GAAG;IAC5D,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,UAAU,GAAG;QAAE,SAAS,EAAE,SAAS,CAAA;KAAE,CAAC;CAC9C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -1,28 +1,2 @@
1
- import { DEFAULT_SCOPE } from "./constants.js";
2
- import { jsonResponse } from "../http.js";
3
- /** Default true — see `OAuthRouterOptions.allowUnregisteredClients`. */
4
- export const unregisteredClientsAllowed = (options) => options.allowUnregisteredClients !== false;
5
- /** Scopes this AS advertises and is willing to grant. */
6
- export const advertisedScopes = (options) => options.scopes ?? [DEFAULT_SCOPE];
7
- export const resolveSecret = async (ports, req) => {
8
- if (typeof ports.codeSecret === "string")
9
- return ports.codeSecret;
10
- return ports.codeSecret(req);
11
- };
12
- export const oauthError = (error, status, description) => jsonResponse(description ? { error, error_description: description } : { error }, status, undefined, { cors: false });
13
- const UNREGISTERED_CLIENT_DESCRIPTION = "unknown client_id — this server only serves pre-registered clients";
14
- /** Direct JSON error when this AS does not serve unknown `client_id`s. */
15
- export const unregisteredClientError = (options, reject) => {
16
- if (unregisteredClientsAllowed(options))
17
- return null;
18
- return oauthError(reject.code, reject.status, UNREGISTERED_CLIENT_DESCRIPTION);
19
- };
20
- /** `grantedScope` is what the auth code carried; the port may narrow it further. */
21
- export const tokenResponse = (minted, grantedScope) => jsonResponse({
22
- access_token: minted.accessToken,
23
- token_type: minted.tokenType ?? "bearer",
24
- expires_in: minted.expiresIn,
25
- scope: minted.scope ?? grantedScope ?? DEFAULT_SCOPE,
26
- ...(minted.refreshToken ? { refresh_token: minted.refreshToken } : {}),
27
- }, 200, undefined, { cors: false });
1
+ export {};
28
2
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAgC,MAAM,gBAAgB,CAAC;AAG7E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA6G1C,wEAAwE;AACxE,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,OAA2B,EAClB,EAAE,CAAC,OAAO,CAAC,wBAAwB,KAAK,KAAK,CAAC;AAEzD,yDAAyD;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAA2B,EAAY,EAAE,CACxE,OAAO,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC;AAEpC,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,KAAiB,EACjB,GAAY,EACK,EAAE;IACnB,IAAI,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,UAAU,CAAC;IAClE,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAa,EACb,MAAc,EACd,WAAoB,EACV,EAAE,CACZ,YAAY,CACV,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EACnE,MAAM,EACN,SAAS,EACT,EAAE,IAAI,EAAE,KAAK,EAAE,CAChB,CAAC;AAEJ,MAAM,+BAA+B,GACnC,oEAAoE,CAAC;AAEvE,0EAA0E;AAC1E,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,OAA2B,EAC3B,MAAwC,EACvB,EAAE;IACnB,IAAI,0BAA0B,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IACrD,OAAO,UAAU,CACf,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,MAAM,EACb,+BAA+B,CAChC,CAAC;AACJ,CAAC,CAAC;AAEF,oFAAoF;AACpF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,MAAmB,EACnB,YAAqB,EACX,EAAE,CACZ,YAAY,CACV;IACE,YAAY,EAAE,MAAM,CAAC,WAAW;IAChC,UAAU,EAAE,MAAM,CAAC,SAAS,IAAI,QAAQ;IACxC,UAAU,EAAE,MAAM,CAAC,SAAS;IAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,YAAY,IAAI,aAAa;IACpD,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;CACvE,EACD,GAAG,EACH,SAAS,EACT,EAAE,IAAI,EAAE,KAAK,EAAE,CAChB,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":""}
package/dist/server.d.ts CHANGED
@@ -1,15 +1,16 @@
1
- export { createMcpApp, type McpApp, type McpAppOptions, type McpAppAuth, type VerifiedToken, } from "./app.js";
2
- /** Auth-port types used by `McpAppAuth` — annotate extracted stores/callbacks. */
3
- export type { ClientStore, RegisteredClient, MintAccessTokenInput, RefreshAccessTokenInput, RevokeTokenInput, MintedToken, OAuthUser, } from "./oauth/types.js";
4
- export type { CodeStore } from "./oauth/codes.js";
5
- export { CLIENT_PROFILES, DEFAULT_CLIENTS, authMethodsFor, redirectUrisFor, preRegisteredClients, hasDynamicClient, type ClientName, type ClientProfile, } from "./clients.js";
6
- export { createMcpHandler, type McpHandler, type McpHandlerOptions, type McpPorts, type Principal, type AuditEntry, type ServerInfo, } from "./dispatch.js";
1
+ export { createMcpApp, type McpApp, type McpAppAuth, type McpAppOptions, type UnifiedAuditEntry, type VerifiedToken, } from "./app.js";
7
2
  export { consoleAudit } from "./audit.js";
8
- export { createToolRegistry, type ToolDef, type ToolHandler, type ToolResult, type ToolRegistry, type ToolListEntry, type RegistryOptions, } from "./registry.js";
9
- export { defineTool, apiTool, type StandardSchemaV1, type DefineToolOptions, type ApiToolOptions, type ApiRequest, } from "./tools.js";
10
- export { rpcResult, rpcError, JSONRPC_PARSE_ERROR, JSONRPC_INVALID_REQUEST, JSONRPC_METHOD_NOT_FOUND, JSONRPC_INVALID_PARAMS, JSONRPC_INTERNAL_ERROR, JSONRPC_UNAUTHORIZED, type JsonRpcId, type JsonRpcRequest, type JsonRpcResponse, } from "./jsonrpc.js";
11
- export { pickProtocolVersion, PROTOCOL_VERSIONS, DEFAULT_PROTOCOL_VERSION, } from "./protocol.js";
12
- export { parseBearer, timingSafeEqual, matchesAny, wwwAuthenticateHeader, rejectQueryToken, type WwwAuthenticateOptions, } from "./auth/bearer.js";
13
- export { validateAgainstSchema, JSON_SCHEMA_TYPES, SUPPORTED_SCHEMA_KEYWORDS, IGNORED_SCHEMA_KEYWORDS, unsupportedKeywords, type JsonSchema, } from "./validate.js";
14
- export { jsonResponse, emptyResponse, optionsResponse, corsHeaders, methodNotAllowed, } from "./http.js";
3
+ export { parseBearer, rejectQueryToken, type WwwAuthenticateOptions, wwwAuthenticateHeader, } from "./auth/bearer.js";
4
+ export { authMethodsFor, CLIENT_PROFILES, type ClientName, type ClientProfile, DEFAULT_CLIENTS, hasDynamicClient, preRegisteredClients, redirectUrisFor, } from "./clients.js";
5
+ export * from "./deprecated.js";
6
+ export { type JsonResponseInput, type JsonResponseOptions, jsonResponse, } from "./http/http.js";
7
+ export { type AuditEntry, createMcpHandler, type McpHandler, type McpHandlerOptions, type McpPorts, type Principal, type ServerInfo, } from "./mcp/dispatch.js";
8
+ export { JSONRPC_INTERNAL_ERROR, JSONRPC_INVALID_PARAMS, JSONRPC_INVALID_REQUEST, JSONRPC_METHOD_NOT_FOUND, JSONRPC_PARSE_ERROR, JSONRPC_UNAUTHORIZED, type JsonRpcId, type JsonRpcRequest, type JsonRpcResponse, rpcError, rpcResult, } from "./mcp/jsonrpc.js";
9
+ export { DEFAULT_PROTOCOL_VERSION, PROTOCOL_VERSIONS } from "./mcp/protocol.js";
10
+ export { createToolRegistry, type RegistryOptions, type ToolDef, type ToolHandler, type ToolListEntry, type ToolRegistry, type ToolResult, } from "./mcp/registry.js";
11
+ export { type ApiRequest, type ApiToolOptions, apiTool, type DefineToolOptions, defineTool, type StandardSchemaV1, } from "./mcp/tools.js";
12
+ export type { JsonSchema } from "./mcp/validate.js";
13
+ export type { CodeStore } from "./oauth/crypto/codes.js";
14
+ /** Auth-port types used by `McpAppAuth` — annotate extracted stores/callbacks. */
15
+ export type { ClientStore, ConsentOptions, ConsentRequest, MintAccessTokenInput, MintedToken, OAuthUser, RefreshAccessTokenInput, RegisteredClient, RevokeTokenInput, } from "./oauth/types.js";
15
16
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,UAAU,CAAC;A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;AAE1B,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,KAAK,UAAU,GAChB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,eAAe,EACf,WAAW,EACX,gBAAgB,GACjB,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,aAAa,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,KAAK,sBAAsB,EAC3B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,cAAc,EACd,eAAe,EACf,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,GAChB,MAAM,cAAc,CAAC;AAEtB,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,UAAU,EACf,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,UAAU,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,QAAQ,EACR,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,wBAAwB,EAAE,iB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