@lushly-dev/afd-server 2.2.1 → 2.4.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 (220) hide show
  1. package/README.md +468 -6
  2. package/dist/approval-crypto.d.ts +26 -4
  3. package/dist/approval-crypto.d.ts.map +1 -1
  4. package/dist/approval-crypto.js +90 -7
  5. package/dist/approval-crypto.js.map +1 -1
  6. package/dist/approval-relay.d.ts +5 -5
  7. package/dist/approval-relay.d.ts.map +1 -1
  8. package/dist/approval.d.ts +6 -1
  9. package/dist/approval.d.ts.map +1 -1
  10. package/dist/approval.js +43 -32
  11. package/dist/approval.js.map +1 -1
  12. package/dist/bootstrap/afd-context.d.ts +2 -27
  13. package/dist/bootstrap/afd-context.d.ts.map +1 -1
  14. package/dist/bootstrap/afd-context.js +6 -36
  15. package/dist/bootstrap/afd-context.js.map +1 -1
  16. package/dist/bootstrap/afd-help.d.ts +24 -2
  17. package/dist/bootstrap/afd-help.d.ts.map +1 -1
  18. package/dist/bootstrap/afd-help.js +17 -2
  19. package/dist/bootstrap/afd-help.js.map +1 -1
  20. package/dist/bootstrap/described-command.d.ts +1 -0
  21. package/dist/bootstrap/described-command.d.ts.map +1 -1
  22. package/dist/bootstrap/described-command.js.map +1 -1
  23. package/dist/bootstrap/registry.d.ts +13 -0
  24. package/dist/bootstrap/registry.d.ts.map +1 -1
  25. package/dist/bootstrap/registry.js +30 -1
  26. package/dist/bootstrap/registry.js.map +1 -1
  27. package/dist/command-allow.d.ts +31 -0
  28. package/dist/command-allow.d.ts.map +1 -0
  29. package/dist/command-allow.js +55 -0
  30. package/dist/command-allow.js.map +1 -0
  31. package/dist/command-names.d.ts +17 -0
  32. package/dist/command-names.d.ts.map +1 -1
  33. package/dist/command-names.js +55 -0
  34. package/dist/command-names.js.map +1 -1
  35. package/dist/command-routing.d.ts +10 -3
  36. package/dist/command-routing.d.ts.map +1 -1
  37. package/dist/command-routing.js +18 -7
  38. package/dist/command-routing.js.map +1 -1
  39. package/dist/confirmation-gate.d.ts +32 -0
  40. package/dist/confirmation-gate.d.ts.map +1 -0
  41. package/dist/confirmation-gate.js +140 -0
  42. package/dist/confirmation-gate.js.map +1 -0
  43. package/dist/confirmations.d.ts +15 -23
  44. package/dist/confirmations.d.ts.map +1 -1
  45. package/dist/confirmations.js +8 -127
  46. package/dist/confirmations.js.map +1 -1
  47. package/dist/context-fields-describe.d.ts +18 -0
  48. package/dist/context-fields-describe.d.ts.map +1 -0
  49. package/dist/context-fields-describe.js +17 -0
  50. package/dist/context-fields-describe.js.map +1 -0
  51. package/dist/context-fields.d.ts +50 -0
  52. package/dist/context-fields.d.ts.map +1 -0
  53. package/dist/context-fields.js +146 -0
  54. package/dist/context-fields.js.map +1 -0
  55. package/dist/context-scope.d.ts +29 -2
  56. package/dist/context-scope.d.ts.map +1 -1
  57. package/dist/context-scope.js +37 -1
  58. package/dist/context-scope.js.map +1 -1
  59. package/dist/credentials.d.ts +17 -0
  60. package/dist/credentials.d.ts.map +1 -0
  61. package/dist/credentials.js +16 -0
  62. package/dist/credentials.js.map +1 -0
  63. package/dist/define-core.d.ts +213 -0
  64. package/dist/define-core.d.ts.map +1 -0
  65. package/dist/define-core.js +161 -0
  66. package/dist/define-core.js.map +1 -0
  67. package/dist/define.d.ts +13 -8
  68. package/dist/define.d.ts.map +1 -1
  69. package/dist/define.js +13 -8
  70. package/dist/define.js.map +1 -1
  71. package/dist/direct-registry.d.ts +154 -7
  72. package/dist/direct-registry.d.ts.map +1 -1
  73. package/dist/direct-registry.js +111 -13
  74. package/dist/direct-registry.js.map +1 -1
  75. package/dist/direct-tool-surface.d.ts +66 -0
  76. package/dist/direct-tool-surface.d.ts.map +1 -0
  77. package/dist/direct-tool-surface.js +162 -0
  78. package/dist/direct-tool-surface.js.map +1 -0
  79. package/dist/direct.d.ts +68 -0
  80. package/dist/direct.d.ts.map +1 -0
  81. package/dist/direct.js +66 -0
  82. package/dist/direct.js.map +1 -0
  83. package/dist/execution.d.ts +11 -1
  84. package/dist/execution.d.ts.map +1 -1
  85. package/dist/execution.js +18 -4
  86. package/dist/execution.js.map +1 -1
  87. package/dist/frontmatter.d.ts +16 -0
  88. package/dist/frontmatter.d.ts.map +1 -0
  89. package/dist/frontmatter.js +111 -0
  90. package/dist/frontmatter.js.map +1 -0
  91. package/dist/http-handler.d.ts +11 -2
  92. package/dist/http-handler.d.ts.map +1 -1
  93. package/dist/http-handler.js +46 -15
  94. package/dist/http-handler.js.map +1 -1
  95. package/dist/http-security.d.ts.map +1 -1
  96. package/dist/http-security.js.map +1 -1
  97. package/dist/http-sessions.d.ts +12 -4
  98. package/dist/http-sessions.d.ts.map +1 -1
  99. package/dist/http-sessions.js +4 -4
  100. package/dist/http-sessions.js.map +1 -1
  101. package/dist/http-sse.js.map +1 -1
  102. package/dist/index.d.ts +16 -4
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +20 -4
  105. package/dist/index.js.map +1 -1
  106. package/dist/issue-message.d.ts +20 -0
  107. package/dist/issue-message.d.ts.map +1 -0
  108. package/dist/issue-message.js +55 -0
  109. package/dist/issue-message.js.map +1 -0
  110. package/dist/journal-replay.d.ts +7 -0
  111. package/dist/journal-replay.d.ts.map +1 -1
  112. package/dist/journal-replay.js +18 -1
  113. package/dist/journal-replay.js.map +1 -1
  114. package/dist/journal.d.ts +9 -1
  115. package/dist/journal.d.ts.map +1 -1
  116. package/dist/journal.js +44 -1
  117. package/dist/journal.js.map +1 -1
  118. package/dist/json-rpc.d.ts +2 -2
  119. package/dist/json-rpc.d.ts.map +1 -1
  120. package/dist/json-rpc.js.map +1 -1
  121. package/dist/json-schema.d.ts +30 -0
  122. package/dist/json-schema.d.ts.map +1 -0
  123. package/dist/json-schema.js +25 -0
  124. package/dist/json-schema.js.map +1 -0
  125. package/dist/lazy-tools.d.ts +3 -0
  126. package/dist/lazy-tools.d.ts.map +1 -1
  127. package/dist/lazy-tools.js +2 -0
  128. package/dist/lazy-tools.js.map +1 -1
  129. package/dist/mcp-auth-bearer.d.ts +23 -0
  130. package/dist/mcp-auth-bearer.d.ts.map +1 -0
  131. package/dist/mcp-auth-bearer.js +50 -0
  132. package/dist/mcp-auth-bearer.js.map +1 -0
  133. package/dist/mcp-auth-jwt.d.ts +178 -0
  134. package/dist/mcp-auth-jwt.d.ts.map +1 -0
  135. package/dist/mcp-auth-jwt.js +365 -0
  136. package/dist/mcp-auth-jwt.js.map +1 -0
  137. package/dist/mcp-auth-resource.d.ts +74 -0
  138. package/dist/mcp-auth-resource.d.ts.map +1 -0
  139. package/dist/mcp-auth-resource.js +196 -0
  140. package/dist/mcp-auth-resource.js.map +1 -0
  141. package/dist/mcp-auth-rules.d.ts +135 -0
  142. package/dist/mcp-auth-rules.d.ts.map +1 -0
  143. package/dist/mcp-auth-rules.js +306 -0
  144. package/dist/mcp-auth-rules.js.map +1 -0
  145. package/dist/mcp-auth.d.ts +81 -0
  146. package/dist/mcp-auth.d.ts.map +1 -0
  147. package/dist/mcp-auth.js +256 -0
  148. package/dist/mcp-auth.js.map +1 -0
  149. package/dist/mcp-modern.d.ts +29 -5
  150. package/dist/mcp-modern.d.ts.map +1 -1
  151. package/dist/mcp-modern.js +99 -19
  152. package/dist/mcp-modern.js.map +1 -1
  153. package/dist/meta-argument.d.ts +42 -0
  154. package/dist/meta-argument.d.ts.map +1 -0
  155. package/dist/meta-argument.js +102 -0
  156. package/dist/meta-argument.js.map +1 -0
  157. package/dist/meta-keys.d.ts +29 -0
  158. package/dist/meta-keys.d.ts.map +1 -0
  159. package/dist/meta-keys.js +90 -0
  160. package/dist/meta-keys.js.map +1 -0
  161. package/dist/meta-tools.d.ts +8 -1
  162. package/dist/meta-tools.d.ts.map +1 -1
  163. package/dist/meta-tools.js +17 -7
  164. package/dist/meta-tools.js.map +1 -1
  165. package/dist/middleware.d.ts.map +1 -1
  166. package/dist/middleware.js +0 -1
  167. package/dist/middleware.js.map +1 -1
  168. package/dist/patterns.d.ts +46 -0
  169. package/dist/patterns.d.ts.map +1 -0
  170. package/dist/patterns.js +38 -0
  171. package/dist/patterns.js.map +1 -0
  172. package/dist/principal-binding.d.ts +42 -0
  173. package/dist/principal-binding.d.ts.map +1 -0
  174. package/dist/principal-binding.js +70 -0
  175. package/dist/principal-binding.js.map +1 -0
  176. package/dist/request-context.d.ts +7 -1
  177. package/dist/request-context.d.ts.map +1 -1
  178. package/dist/request-context.js +14 -3
  179. package/dist/request-context.js.map +1 -1
  180. package/dist/resources.d.ts +122 -0
  181. package/dist/resources.d.ts.map +1 -0
  182. package/dist/resources.js +256 -0
  183. package/dist/resources.js.map +1 -0
  184. package/dist/schema.d.ts +7 -171
  185. package/dist/schema.d.ts.map +1 -1
  186. package/dist/schema.js +10 -135
  187. package/dist/schema.js.map +1 -1
  188. package/dist/server-types.d.ts +94 -7
  189. package/dist/server-types.d.ts.map +1 -1
  190. package/dist/server-types.js +2 -0
  191. package/dist/server-types.js.map +1 -1
  192. package/dist/server.d.ts +2 -2
  193. package/dist/server.d.ts.map +1 -1
  194. package/dist/server.js +45 -31
  195. package/dist/server.js.map +1 -1
  196. package/dist/skills.d.ts +95 -0
  197. package/dist/skills.d.ts.map +1 -0
  198. package/dist/skills.js +340 -0
  199. package/dist/skills.js.map +1 -0
  200. package/dist/strict-json.d.ts +17 -0
  201. package/dist/strict-json.d.ts.map +1 -0
  202. package/dist/strict-json.js +93 -0
  203. package/dist/strict-json.js.map +1 -0
  204. package/dist/tool-router.d.ts +13 -1
  205. package/dist/tool-router.d.ts.map +1 -1
  206. package/dist/tool-router.js +44 -10
  207. package/dist/tool-router.js.map +1 -1
  208. package/dist/tools.d.ts +10 -5
  209. package/dist/tools.d.ts.map +1 -1
  210. package/dist/tools.js +48 -22
  211. package/dist/tools.js.map +1 -1
  212. package/dist/validation.d.ts +6 -45
  213. package/dist/validation.d.ts.map +1 -1
  214. package/dist/validation.js +25 -58
  215. package/dist/validation.js.map +1 -1
  216. package/dist/verified-credentials.d.ts +34 -0
  217. package/dist/verified-credentials.d.ts.map +1 -0
  218. package/dist/verified-credentials.js +51 -0
  219. package/dist/verified-credentials.js.map +1 -0
  220. package/package.json +18 -6
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth-jwt.js","sourceRoot":"","sources":["../src/mcp-auth-jwt.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAc,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAGN,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,gBAAgB,EAEhB,kBAAkB,GAIlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AA0ErE,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACtE,CAAC;AAED,yEAAyE;AACzE,SAAS,QAAQ,CAAC,QAAiB;IAClC,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,oCAAoC,CAAC;IACtE,MAAM,KAAK,GAAG,IAAI,GAAG,EAA6C,CAAC;IACnE,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,GAAG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,CAAC,CAAC;YACpF,OAAO,OAAO,CAAC,EAAE;gBAChB,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,KAAK,EAAE;gBAC1C,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QACrD,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @fileoverview The protected resource: its URI, the audience rule, the RFC 9728 metadata and the
3
+ * challenges that point to it (`spec/authorization.md`, M3.1, M5 and M7).
4
+ */
5
+ /** The well-known suffix of protected-resource metadata (RFC 9728 3.1). */
6
+ export declare const PROTECTED_RESOURCE_WELL_KNOWN = "/.well-known/oauth-protected-resource";
7
+ /** Whether `scope` is one OAuth scope token (RFC 6749 3.3). */
8
+ export declare function isScopeToken(scope: unknown): scope is string;
9
+ /**
10
+ * Whether an `aud` claim (`undefined` when absent) accepts `resource` (`spec/authorization.md`,
11
+ * M3.1): a string, or an array of exactly one string, naming the resource. A token with several
12
+ * audiences is refused even when one matches, since any of them could replay it here.
13
+ */
14
+ export declare function audienceAccepts(aud: unknown, resource: string): boolean;
15
+ /**
16
+ * Throw unless `url` is an absolute `https` URL in visible ASCII with no user information, query
17
+ * or fragment: the form of the resource, an issuer and an authorization server.
18
+ */
19
+ export declare function assertHttpsUrl(what: string, url: unknown): asserts url is string;
20
+ /** What the protected-resource metadata publishes (`spec/authorization.md`, M7 and "Options"). */
21
+ export interface ProtectedResourceOptions {
22
+ /** The MCP endpoint's absolute `https` URL, with no query or fragment: the token audience. */
23
+ resource: string;
24
+ /** The issuers whose access tokens the server accepts, in this order; at least one. */
25
+ authorizationServers: readonly string[];
26
+ /** The metadata's `scopes_supported`, and the 401's `scope`. Default: none. */
27
+ scopesSupported?: readonly string[];
28
+ /** The metadata's `resource_name`. Default: none. */
29
+ resourceName?: string;
30
+ /** Whether only certificate-bound tokens are accepted. Default: `false`. */
31
+ requireBoundTokens?: boolean;
32
+ }
33
+ /**
34
+ * RFC 9728 protected-resource metadata, the URLs it is served at and the challenges that point
35
+ * to it (`spec/authorization.md`, M5 and M7). Built by {@link createProtectedResource}, which
36
+ * checks its options.
37
+ */
38
+ export interface ProtectedResource {
39
+ /** The resource, as configured. */
40
+ readonly resource: string;
41
+ /** The metadata URLs: the path-inserted one first (every challenge's `resource_metadata`). */
42
+ readonly metadataUrls: readonly string[];
43
+ /** The request paths of {@link metadataUrls}, served without authentication. */
44
+ readonly metadataPaths: readonly string[];
45
+ /** The published scopes. */
46
+ readonly scopesSupported: readonly string[];
47
+ /** Whether only certificate-bound tokens are accepted. */
48
+ readonly requireBoundTokens: boolean;
49
+ /** The metadata document. Nothing else is published. */
50
+ document(): Record<string, unknown>;
51
+ /** The 401's `WWW-Authenticate` value; `error="invalid_token"` when a token was sent. */
52
+ unauthorizedChallenge(tokenSent: boolean): string;
53
+ /** The 401's JSON body. */
54
+ unauthorizedBody(): {
55
+ error: 'UNAUTHORIZED';
56
+ suggestion: string;
57
+ };
58
+ /** The 403's `WWW-Authenticate` value for the `missing` scopes, in order. */
59
+ forbiddenChallenge(missing: readonly string[]): string;
60
+ /** The 403's JSON body for the `missing` scopes. */
61
+ forbiddenBody(missing: readonly string[]): {
62
+ error: 'INSUFFICIENT_SCOPE';
63
+ suggestion: string;
64
+ };
65
+ }
66
+ /**
67
+ * The protected-resource metadata of `options.resource`.
68
+ *
69
+ * @throws Error when the resource or an authorization server is not an absolute `https` URL
70
+ * without user information, query or fragment, no authorization server is named or one is
71
+ * named twice, or a published scope is not a scope token or is published twice
72
+ */
73
+ export declare function createProtectedResource(options: ProtectedResourceOptions): ProtectedResource;
74
+ //# sourceMappingURL=mcp-auth-resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth-resource.d.ts","sourceRoot":"","sources":["../src/mcp-auth-resource.ts"],"names":[],"mappings":"AAAA;;;GA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2BAA2B;IAC3B,gBAAgB,IAAI;QAAE,KAAK,EAAE,cAAc,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAClE,6EAA6E;IAC7E,kBAAkB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IACvD,oDAAoD;IACpD,aAAa,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG;QAAE,KAAK,EAAE,oBAAoB,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/F;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,GAAG,iBAAiB,CAqF5F"}
@@ -0,0 +1,196 @@
1
+ /**
2
+ * @fileoverview The protected resource: its URI, the audience rule, the RFC 9728 metadata and the
3
+ * challenges that point to it (`spec/authorization.md`, M3.1, M5 and M7).
4
+ */
5
+ /** The well-known suffix of protected-resource metadata (RFC 9728 3.1). */
6
+ export const PROTECTED_RESOURCE_WELL_KNOWN = '/.well-known/oauth-protected-resource';
7
+ /** A scope token (RFC 6749 3.3): one or more of `%x21 / %x23-5B / %x5D-7E`. */
8
+ const SCOPE_TOKEN = /^[\x21\x23-\x5B\x5D-\x7E]+$/;
9
+ /** Whether `scope` is one OAuth scope token (RFC 6749 3.3). */
10
+ export function isScopeToken(scope) {
11
+ return typeof scope === 'string' && SCOPE_TOKEN.test(scope);
12
+ }
13
+ const VISIBLE_ASCII = /^[\x21-\x7E]+$/;
14
+ const FORBIDDEN = /[?#"\\<>`{}|^]/;
15
+ const SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/;
16
+ /**
17
+ * `url` split for comparison, or `undefined` when it is not `scheme://host[:port][path]` in
18
+ * visible ASCII with no user information, query or fragment. Nothing is normalized: the parts
19
+ * are as written.
20
+ */
21
+ function splitUrl(url) {
22
+ if (!VISIBLE_ASCII.test(url) || FORBIDDEN.test(url))
23
+ return undefined;
24
+ const separator = url.indexOf('://');
25
+ if (separator < 0)
26
+ return undefined;
27
+ const scheme = url.slice(0, separator);
28
+ if (!SCHEME.test(scheme))
29
+ return undefined;
30
+ const rest = url.slice(separator + 3);
31
+ const slash = rest.indexOf('/');
32
+ const authority = slash < 0 ? rest : rest.slice(0, slash);
33
+ const path = slash < 0 ? '' : rest.slice(slash);
34
+ if (authority === '' || authority.includes('@'))
35
+ return undefined;
36
+ let host;
37
+ let port;
38
+ if (authority.startsWith('[')) {
39
+ const close = authority.indexOf(']');
40
+ if (close < 0)
41
+ return undefined;
42
+ host = authority.slice(0, close + 1);
43
+ const after = authority.slice(close + 1);
44
+ if (after !== '') {
45
+ if (!after.startsWith(':'))
46
+ return undefined;
47
+ port = after.slice(1);
48
+ }
49
+ }
50
+ else {
51
+ const colon = authority.lastIndexOf(':');
52
+ host = colon < 0 ? authority : authority.slice(0, colon);
53
+ port = colon < 0 ? undefined : authority.slice(colon + 1);
54
+ }
55
+ if (host === '' ||
56
+ (host.includes(':') && !host.startsWith('[')) ||
57
+ (port !== undefined && !/^[0-9]*$/.test(port))) {
58
+ return undefined;
59
+ }
60
+ return { scheme, host, port, path, origin: url.slice(0, separator + 3 + authority.length) };
61
+ }
62
+ /**
63
+ * Whether `candidate` names `resource` (`spec/authorization.md`, M3.1): the scheme and the host
64
+ * compare ignoring ASCII case; the port as written (`:443` is not the same as no port), the path
65
+ * (a trailing slash differs), percent-encoding and case compare exactly; a value with user
66
+ * information, a query or a fragment never matches.
67
+ */
68
+ function sameResource(resource, candidate) {
69
+ const expected = splitUrl(resource);
70
+ const actual = splitUrl(candidate);
71
+ if (!expected || !actual)
72
+ return false;
73
+ return (expected.scheme.toLowerCase() === actual.scheme.toLowerCase() &&
74
+ expected.host.toLowerCase() === actual.host.toLowerCase() &&
75
+ expected.port === actual.port &&
76
+ expected.path === actual.path);
77
+ }
78
+ /**
79
+ * Whether an `aud` claim (`undefined` when absent) accepts `resource` (`spec/authorization.md`,
80
+ * M3.1): a string, or an array of exactly one string, naming the resource. A token with several
81
+ * audiences is refused even when one matches, since any of them could replay it here.
82
+ */
83
+ export function audienceAccepts(aud, resource) {
84
+ if (typeof aud === 'string')
85
+ return sameResource(resource, aud);
86
+ if (Array.isArray(aud) && aud.length === 1 && typeof aud[0] === 'string') {
87
+ return sameResource(resource, aud[0]);
88
+ }
89
+ return false;
90
+ }
91
+ /**
92
+ * Throw unless `url` is an absolute `https` URL in visible ASCII with no user information, query
93
+ * or fragment: the form of the resource, an issuer and an authorization server.
94
+ */
95
+ export function assertHttpsUrl(what, url) {
96
+ const parts = typeof url === 'string' ? splitUrl(url) : undefined;
97
+ if (parts?.scheme.toLowerCase() !== 'https') {
98
+ throw new Error(`[AFD] ${what} ${JSON.stringify(url)} is not an absolute https URL without user information, query or fragment`);
99
+ }
100
+ }
101
+ /** The scope tokens of `scopes`, joined by single spaces; anything else is left out. */
102
+ function joinedTokens(scopes) {
103
+ return scopes.filter((scope) => isScopeToken(scope)).join(' ');
104
+ }
105
+ /**
106
+ * The protected-resource metadata of `options.resource`.
107
+ *
108
+ * @throws Error when the resource or an authorization server is not an absolute `https` URL
109
+ * without user information, query or fragment, no authorization server is named or one is
110
+ * named twice, or a published scope is not a scope token or is published twice
111
+ */
112
+ export function createProtectedResource(options) {
113
+ const { resource } = options;
114
+ assertHttpsUrl('resource', resource);
115
+ const servers = [];
116
+ for (const server of options.authorizationServers ?? []) {
117
+ assertHttpsUrl('authorization server', server);
118
+ if (servers.includes(server)) {
119
+ throw new Error(`[AFD] authorization server ${JSON.stringify(server)} is named twice`);
120
+ }
121
+ servers.push(server);
122
+ }
123
+ if (servers.length === 0) {
124
+ throw new Error('[AFD] protected-resource metadata needs at least one authorization server');
125
+ }
126
+ const scopes = [];
127
+ for (const scope of options.scopesSupported ?? []) {
128
+ if (!isScopeToken(scope)) {
129
+ throw new Error(`[AFD] scope ${JSON.stringify(scope)} is not an OAuth scope token`);
130
+ }
131
+ if (scopes.includes(scope)) {
132
+ throw new Error(`[AFD] scope ${JSON.stringify(scope)} is published twice`);
133
+ }
134
+ scopes.push(scope);
135
+ }
136
+ const resourceName = options.resourceName;
137
+ if (resourceName !== undefined && typeof resourceName !== 'string') {
138
+ throw new Error('[AFD] resourceName must be a string');
139
+ }
140
+ const requireBoundTokens = options.requireBoundTokens === true;
141
+ const parts = splitUrl(resource);
142
+ const bare = `${parts.origin}${PROTECTED_RESOURCE_WELL_KNOWN}`;
143
+ const onlyOrigin = parts.path === '' || parts.path === '/';
144
+ const metadataUrls = Object.freeze(onlyOrigin ? [bare] : [`${bare}${parts.path}`, bare]);
145
+ const metadataPaths = Object.freeze(onlyOrigin
146
+ ? [PROTECTED_RESOURCE_WELL_KNOWN]
147
+ : [`${PROTECTED_RESOURCE_WELL_KNOWN}${parts.path}`, PROTECTED_RESOURCE_WELL_KNOWN]);
148
+ const metadata = metadataUrls[0];
149
+ const suggestion = (missing) => {
150
+ const joined = joinedTokens(missing);
151
+ return joined
152
+ ? `Obtain a token for ${resource} that also grants ${joined}, then retry.`
153
+ : `Obtain a token for ${resource} that grants the scopes this call needs, then retry.`;
154
+ };
155
+ return Object.freeze({
156
+ resource,
157
+ metadataUrls,
158
+ metadataPaths,
159
+ scopesSupported: Object.freeze([...scopes]),
160
+ requireBoundTokens,
161
+ document() {
162
+ return {
163
+ resource,
164
+ authorization_servers: [...servers],
165
+ ...(scopes.length ? { scopes_supported: [...scopes] } : {}),
166
+ bearer_methods_supported: ['header'],
167
+ ...(resourceName !== undefined ? { resource_name: resourceName } : {}),
168
+ tls_client_certificate_bound_access_tokens: requireBoundTokens,
169
+ };
170
+ },
171
+ unauthorizedChallenge(tokenSent) {
172
+ let challenge = `Bearer resource_metadata="${metadata}"`;
173
+ if (scopes.length)
174
+ challenge += `, scope="${scopes.join(' ')}"`;
175
+ if (tokenSent)
176
+ challenge += ', error="invalid_token"';
177
+ return challenge;
178
+ },
179
+ unauthorizedBody() {
180
+ return {
181
+ error: 'UNAUTHORIZED',
182
+ suggestion: `Obtain a token for ${resource} from an authorization server named in ${metadata}.`,
183
+ };
184
+ },
185
+ forbiddenChallenge(missing) {
186
+ const joined = joinedTokens(missing);
187
+ return joined
188
+ ? `Bearer error="insufficient_scope", scope="${joined}", resource_metadata="${metadata}"`
189
+ : `Bearer error="insufficient_scope", resource_metadata="${metadata}"`;
190
+ },
191
+ forbiddenBody(missing) {
192
+ return { error: 'INSUFFICIENT_SCOPE', suggestion: suggestion(missing) };
193
+ },
194
+ });
195
+ }
196
+ //# sourceMappingURL=mcp-auth-resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth-resource.js","sourceRoot":"","sources":["../src/mcp-auth-resource.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,6BAA6B,GAAG,uCAAuC,CAAC;AAErF,+EAA+E;AAC/E,MAAM,WAAW,GAAG,6BAA6B,CAAC;AAElD,+DAA+D;AAC/D,MAAM,UAAU,YAAY,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7D,CAAC;AAaD,MAAM,aAAa,GAAG,gBAAgB,CAAC;AACvC,MAAM,SAAS,GAAG,gBAAgB,CAAC;AACnC,MAAM,MAAM,GAAG,2BAA2B,CAAC;AAE3C;;;;GAIG;AACH,SAAS,QAAQ,CAAC,GAAW;IAC5B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IACtE,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,SAAS,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IACpC,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IACvC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC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AAC,EAAE,CAAC;gBAC3D,wBAAwB,EAAE,CAAC,QAAQ,CAAC;gBACpC,GAAG,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtE,0CAA0C,EAAE,kBAAkB;aAC9D,CAAC;QACH,CAAC;QACD,qBAAqB,CAAC,SAAkB;YACvC,IAAI,SAAS,GAAG,6BAA6B,QAAQ,GAAG,CAAC;YACzD,IAAI,MAAM,CAAC,MAAM;gBAAE,SAAS,IAAI,YAAY,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAChE,IAAI,SAAS;gBAAE,SAAS,IAAI,yBAAyB,CAAC;YACtD,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,gBAAgB;YACf,OAAO;gBACN,KAAK,EAAE,cAAuB;gBAC9B,UAAU,EAAE,sBAAsB,QAAQ,0CAA0C,QAAQ,GAAG;aAC/F,CAAC;QACH,CAAC;QACD,kBAAkB,CAAC,OAA0B;YAC5C,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;YACrC,OAAO,MAAM;gBACZ,CAAC,CAAC,6CAA6C,MAAM,yBAAyB,QAAQ,GAAG;gBACzF,CAAC,CAAC,yDAAyD,QAAQ,GAAG,CAAC;QACzE,CAAC;QACD,aAAa,CAAC,OAA0B;YACvC,OAAO,EAAE,KAAK,EAAE,oBAA6B,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAClF,CAAC;KACD,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @fileoverview Token rules that need no key and no network (`spec/authorization.md`, M3 rules 2,
3
+ * 3 and 5 to 10, M3.2 and M4), shared by AFD's JWT verifier and a host's introspection verifier.
4
+ * Each rule is checked here explicitly, in the specification's order: no library default is
5
+ * relied on.
6
+ */
7
+ /** The rule a refused token or request broke (`spec/authorization.md`, M5). Logged, never sent. */
8
+ export type AuthRuleCode = 'no-token' | 'token-location' | 'token-malformed' | 'unknown-issuer' | 'typ' | 'alg' | 'kid' | 'crit' | 'key-reference' | 'key' | 'signature' | 'issuer' | 'audience' | 'claims' | 'expired' | 'not-yet-valid' | 'lifetime' | 'scope-malformed' | 'scopes-too-many' | 'dpop-unsupported' | 'binding' | 'inactive' | 'unavailable';
9
+ /** Every rule code, in the specification's order. */
10
+ export declare const AUTH_RULE_CODES: readonly AuthRuleCode[];
11
+ /**
12
+ * The verified claims of one request's access token (`spec/authorization.md`, M4): what a command
13
+ * sees as `context.credentials` on a call the server verified. Never the token.
14
+ */
15
+ export interface Credentials {
16
+ /** `iss`: the issuer, exactly as configured. */
17
+ readonly issuer: string;
18
+ /** `sub`: the subject. */
19
+ readonly subject: string;
20
+ /** `client_id`: the OAuth client the token was issued to. */
21
+ readonly clientId: string;
22
+ /** `scope`, parsed (M3.2): each scope once, in token order. */
23
+ readonly scopes: readonly string[];
24
+ /** The server's configured resource, as configured (not the token's spelling of `aud`). */
25
+ readonly resource: string;
26
+ /** `exp`, in whole seconds since the epoch, rounded down. */
27
+ readonly expiresAt: number;
28
+ /** `iat`, in whole seconds since the epoch, rounded down. */
29
+ readonly issuedAt: number;
30
+ /** `auth_time`, in whole seconds since the epoch, rounded down, when present. */
31
+ readonly authTime?: number;
32
+ /** `acr`, when present. */
33
+ readonly acr?: string;
34
+ /** The TLS client certificate the token is bound to (RFC 8705 3.1), when it is bound. */
35
+ readonly cnf?: {
36
+ readonly 'x5t#S256': string;
37
+ };
38
+ }
39
+ /** The largest clock skew a verifier may allow, in seconds. */
40
+ export declare const MAX_CLOCK_SKEW_S = 300;
41
+ /** The default clock skew, in seconds. */
42
+ export declare const DEFAULT_CLOCK_SKEW_S = 60;
43
+ /** The default longest token lifetime (`exp - iat`), in seconds. */
44
+ export declare const DEFAULT_MAX_TOKEN_LIFETIME_S = 3600;
45
+ /** The default scope limit. */
46
+ export declare const DEFAULT_SCOPE_LIMIT = 64;
47
+ /** The most Unicode code points a `jti`, `sub`, `client_id` or `acr` may hold. */
48
+ export declare const MAX_CLAIM_CHARS = 255;
49
+ /** What {@link createTokenRules} takes. */
50
+ export interface TokenRulesOptions {
51
+ /** The resource: the only audience accepted, and the credentials' `resource`. */
52
+ resource: string;
53
+ /** The clock skew allowed on `exp`, `iat` and `nbf`, in seconds. Default 60, at most 300. */
54
+ clockSkewS?: number;
55
+ /** The longest `exp - iat` accepted, in seconds. Default 3600, at least 1. */
56
+ maxTokenLifetimeS?: number;
57
+ /** Count only scopes starting with `<prefix>:` against the limit. Default: every scope. */
58
+ scopePrefix?: string;
59
+ /** The most scopes a token may hold (under the prefix, when set). Default 64, at least 1. */
60
+ scopeLimit?: number;
61
+ /** Refuse every token that is not bound to the TLS client certificate. Default `false`. */
62
+ requireBoundTokens?: boolean;
63
+ }
64
+ /** The rules a verified token's claims must pass (M3 rules 6 to 10), checked and frozen. */
65
+ export interface TokenRules {
66
+ readonly resource: string;
67
+ readonly clockSkewS: number;
68
+ readonly maxTokenLifetimeS: number;
69
+ readonly scopePrefix: string | undefined;
70
+ readonly scopeLimit: number;
71
+ readonly requireBoundTokens: boolean;
72
+ }
73
+ /**
74
+ * The claim rules for tokens whose audience is `options.resource`.
75
+ *
76
+ * @throws Error when the resource is not an absolute `https` URL without user information, query
77
+ * or fragment, the skew is over 300 seconds, the lifetime or limit is under 1, or the prefix
78
+ * is not a scope token
79
+ */
80
+ export declare function createTokenRules(options: TokenRulesOptions): TokenRules;
81
+ /** A rule's outcome: a value, or the code of the rule that refused. */
82
+ export type RuleResult<T> = {
83
+ ok: true;
84
+ value: T;
85
+ } | {
86
+ ok: false;
87
+ rule: AuthRuleCode;
88
+ };
89
+ /**
90
+ * A `scope` claim parsed (`spec/authorization.md`, M3.2; `undefined` when absent): scope tokens
91
+ * separated by single spaces, each kept once at its first place. An empty string or no claim
92
+ * grants no scope. Only scopes starting with `<prefix>:` count against `limit` when a prefix is
93
+ * given. Refused with `scope-malformed` or `scopes-too-many`.
94
+ */
95
+ export declare function parseScopeClaim(scope: unknown, prefix: string | undefined, limit: number): RuleResult<string[]>;
96
+ /** The JWS algorithms AFD's verifier can check. `none` and `HS*` are always refused. */
97
+ export type SigningAlgorithm = 'RS256' | 'RS384' | 'RS512' | 'PS256' | 'PS384' | 'PS512' | 'ES256' | 'ES384' | 'EdDSA';
98
+ /** Every {@link SigningAlgorithm}. */
99
+ export declare const SIGNING_ALGORITHMS: readonly SigningAlgorithm[];
100
+ /**
101
+ * Rule 2 on a decoded JWS header, against the issuer's algorithm list: `typ`, then `alg`, `kid`,
102
+ * `crit` and the key references, the first broken rule refusing. `none` and every `HS*`
103
+ * algorithm are refused whatever the list says.
104
+ */
105
+ export declare function checkJwsHeader(header: unknown, algorithms: readonly string[]): RuleResult<void>;
106
+ /**
107
+ * Rule 3 on a header that passed rule 2 and the issuer's key with its `kid` (`undefined` for
108
+ * none): the key's `kid` is the header's; its `kty` is the `alg`'s family; its `alg`, when
109
+ * present, is the header's; its `use`, when present, is `sig`; its `key_ops`, when present,
110
+ * contain `verify`. Refused with `key`.
111
+ */
112
+ export declare function checkKeyFit(header: unknown, key: unknown): RuleResult<void>;
113
+ /**
114
+ * `fields` as credentials whose Node.js debug form (`util.inspect`, `console.log`) redacts every
115
+ * field but `issuer` and `expiresAt` (M4). JSON keeps every field.
116
+ */
117
+ export declare function withRedactedInspect(fields: Credentials): Credentials;
118
+ /**
119
+ * Rules 5 to 10 on a token's claims after its signature (or on an introspection response), at
120
+ * `now` (whole seconds since the epoch), for `issuer` (its exact configured string) under
121
+ * `rules`. `certificate` is the SHA-256 thumbprint (unpadded base64url) of the request's TLS
122
+ * client certificate, `undefined` for none.
123
+ *
124
+ * Rule 10 also refuses a `cnf` that is not an object, and one holding a confirmation method
125
+ * other than `x5t#S256` (`jkt` is `dpop-unsupported`, anything else `binding`).
126
+ */
127
+ export declare function checkClaims(claims: Record<string, unknown>, issuer: string, rules: TokenRules, now: number, certificate?: string): RuleResult<Credentials>;
128
+ /**
129
+ * An RFC 7662 introspection response for the one issuer configured for introspection
130
+ * (`spec/authorization.md`, M3, "Introspection"): `active` must be `true` (else `inactive`), and
131
+ * `exp`, `iat`, `iss`, `aud`, `sub` and `client_id` must be present (else `claims`); rules 5 to
132
+ * 10 ({@link checkClaims}) then apply to it, `jti` among rule 7's claims.
133
+ */
134
+ export declare function checkIntrospection(response: unknown, issuer: string, rules: TokenRules, now: number, certificate?: string): RuleResult<Credentials>;
135
+ //# sourceMappingURL=mcp-auth-rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth-rules.d.ts","sourceRoot":"","sources":["../src/mcp-auth-rules.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,mGAAmG;AACnG,MAAM,MAAM,YAAY,GACrB,UAAU,GACV,gBAAgB,GAChB,iBAAiB,GACjB,gBAAgB,GAChB,KAAK,GACL,KAAK,GACL,KAAK,GACL,MAAM,GACN,eAAe,GACf,KAAK,GACL,WAAW,GACX,QAAQ,GACR,UAAU,GACV,QAAQ,GACR,SAAS,GACT,eAAe,GACf,UAAU,GACV,iBAAiB,GACjB,iBAAiB,GACjB,kBAAkB,GAClB,SAAS,GACT,UAAU,GACV,aAAa,CAAC;AAEjB,qDAAqD;AACrD,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAwBjD,CAAC;AAEH;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,2FAA2F;IAC3F,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,6DAA6D;IAC7D,QAA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