@lushly-dev/afd-server 2.3.0 → 2.5.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 (223) hide show
  1. package/README.md +277 -31
  2. package/dist/app-call-registry.d.ts +31 -0
  3. package/dist/app-call-registry.d.ts.map +1 -0
  4. package/dist/app-call-registry.js +56 -0
  5. package/dist/app-call-registry.js.map +1 -0
  6. package/dist/approval-admission.d.ts +93 -0
  7. package/dist/approval-admission.d.ts.map +1 -0
  8. package/dist/approval-admission.js +165 -0
  9. package/dist/approval-admission.js.map +1 -0
  10. package/dist/approval-crypto.d.ts +22 -16
  11. package/dist/approval-crypto.d.ts.map +1 -1
  12. package/dist/approval-crypto.js +41 -66
  13. package/dist/approval-crypto.js.map +1 -1
  14. package/dist/approval-process-state.d.ts +20 -0
  15. package/dist/approval-process-state.d.ts.map +1 -0
  16. package/dist/approval-process-state.js +28 -0
  17. package/dist/approval-process-state.js.map +1 -0
  18. package/dist/approval-relay.d.ts +171 -8
  19. package/dist/approval-relay.d.ts.map +1 -1
  20. package/dist/approval-relay.js +42 -3
  21. package/dist/approval-relay.js.map +1 -1
  22. package/dist/approval-up-front.d.ts +40 -0
  23. package/dist/approval-up-front.d.ts.map +1 -0
  24. package/dist/approval-up-front.js +365 -0
  25. package/dist/approval-up-front.js.map +1 -0
  26. package/dist/approval.d.ts +17 -12
  27. package/dist/approval.d.ts.map +1 -1
  28. package/dist/approval.js +178 -41
  29. package/dist/approval.js.map +1 -1
  30. package/dist/approver.d.ts +84 -0
  31. package/dist/approver.d.ts.map +1 -0
  32. package/dist/approver.js +107 -0
  33. package/dist/approver.js.map +1 -0
  34. package/dist/bootstrap/afd-docs.d.ts.map +1 -1
  35. package/dist/bootstrap/afd-docs.js +4 -0
  36. package/dist/bootstrap/afd-docs.js.map +1 -1
  37. package/dist/bootstrap/afd-help.d.ts +2 -1
  38. package/dist/bootstrap/afd-help.d.ts.map +1 -1
  39. package/dist/bootstrap/afd-help.js +17 -4
  40. package/dist/bootstrap/afd-help.js.map +1 -1
  41. package/dist/bootstrap/described-command.d.ts +2 -1
  42. package/dist/bootstrap/described-command.d.ts.map +1 -1
  43. package/dist/bootstrap/described-command.js.map +1 -1
  44. package/dist/command-timeout.d.ts +17 -0
  45. package/dist/command-timeout.d.ts.map +1 -0
  46. package/dist/command-timeout.js +92 -0
  47. package/dist/command-timeout.js.map +1 -0
  48. package/dist/context-fields.d.ts.map +1 -1
  49. package/dist/context-fields.js +9 -9
  50. package/dist/context-fields.js.map +1 -1
  51. package/dist/credentials.d.ts +17 -0
  52. package/dist/credentials.d.ts.map +1 -0
  53. package/dist/credentials.js +16 -0
  54. package/dist/credentials.js.map +1 -0
  55. package/dist/define-core.d.ts +27 -1
  56. package/dist/define-core.d.ts.map +1 -1
  57. package/dist/define-core.js +8 -1
  58. package/dist/define-core.js.map +1 -1
  59. package/dist/define.d.ts +3 -2
  60. package/dist/define.d.ts.map +1 -1
  61. package/dist/define.js +1 -1
  62. package/dist/define.js.map +1 -1
  63. package/dist/direct-registry.d.ts +27 -3
  64. package/dist/direct-registry.d.ts.map +1 -1
  65. package/dist/direct-registry.js +41 -6
  66. package/dist/direct-registry.js.map +1 -1
  67. package/dist/direct-tool-surface.d.ts +1 -1
  68. package/dist/direct-tool-surface.d.ts.map +1 -1
  69. package/dist/direct-tool-surface.js +14 -4
  70. package/dist/direct-tool-surface.js.map +1 -1
  71. package/dist/direct.d.ts +3 -1
  72. package/dist/direct.d.ts.map +1 -1
  73. package/dist/direct.js +2 -1
  74. package/dist/direct.js.map +1 -1
  75. package/dist/elicitation-state.d.ts +5 -1
  76. package/dist/elicitation-state.d.ts.map +1 -1
  77. package/dist/elicitation-state.js +4 -1
  78. package/dist/elicitation-state.js.map +1 -1
  79. package/dist/execution.d.ts +17 -0
  80. package/dist/execution.d.ts.map +1 -1
  81. package/dist/execution.js +78 -7
  82. package/dist/execution.js.map +1 -1
  83. package/dist/http-handler.d.ts +26 -2
  84. package/dist/http-handler.d.ts.map +1 -1
  85. package/dist/http-handler.js +154 -19
  86. package/dist/http-handler.js.map +1 -1
  87. package/dist/http-security.d.ts +14 -1
  88. package/dist/http-security.d.ts.map +1 -1
  89. package/dist/http-security.js +79 -17
  90. package/dist/http-security.js.map +1 -1
  91. package/dist/http-sessions.d.ts +45 -7
  92. package/dist/http-sessions.d.ts.map +1 -1
  93. package/dist/http-sessions.js +44 -12
  94. package/dist/http-sessions.js.map +1 -1
  95. package/dist/index.d.ts +18 -5
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +18 -3
  98. package/dist/index.js.map +1 -1
  99. package/dist/instance-state.d.ts +46 -0
  100. package/dist/instance-state.d.ts.map +1 -0
  101. package/dist/instance-state.js +91 -0
  102. package/dist/instance-state.js.map +1 -0
  103. package/dist/journal-replay.d.ts.map +1 -1
  104. package/dist/journal-replay.js +41 -3
  105. package/dist/journal-replay.js.map +1 -1
  106. package/dist/journal.d.ts +10 -1
  107. package/dist/journal.d.ts.map +1 -1
  108. package/dist/journal.js +95 -10
  109. package/dist/journal.js.map +1 -1
  110. package/dist/json-rpc.d.ts +3 -2
  111. package/dist/json-rpc.d.ts.map +1 -1
  112. package/dist/json-rpc.js +5 -3
  113. package/dist/json-rpc.js.map +1 -1
  114. package/dist/lazy-tools.d.ts +16 -1
  115. package/dist/lazy-tools.d.ts.map +1 -1
  116. package/dist/lazy-tools.js +13 -2
  117. package/dist/lazy-tools.js.map +1 -1
  118. package/dist/mcp-auth-bearer.d.ts +25 -0
  119. package/dist/mcp-auth-bearer.d.ts.map +1 -0
  120. package/dist/mcp-auth-bearer.js +50 -0
  121. package/dist/mcp-auth-bearer.js.map +1 -0
  122. package/dist/mcp-auth-dispatch.d.ts +38 -0
  123. package/dist/mcp-auth-dispatch.d.ts.map +1 -0
  124. package/dist/mcp-auth-dispatch.js +113 -0
  125. package/dist/mcp-auth-dispatch.js.map +1 -0
  126. package/dist/mcp-auth-jwt.d.ts +179 -0
  127. package/dist/mcp-auth-jwt.d.ts.map +1 -0
  128. package/dist/mcp-auth-jwt.js +365 -0
  129. package/dist/mcp-auth-jwt.js.map +1 -0
  130. package/dist/mcp-auth-resource.d.ts +78 -0
  131. package/dist/mcp-auth-resource.d.ts.map +1 -0
  132. package/dist/mcp-auth-resource.js +197 -0
  133. package/dist/mcp-auth-resource.js.map +1 -0
  134. package/dist/mcp-auth-rules.d.ts +135 -0
  135. package/dist/mcp-auth-rules.d.ts.map +1 -0
  136. package/dist/mcp-auth-rules.js +306 -0
  137. package/dist/mcp-auth-rules.js.map +1 -0
  138. package/dist/mcp-auth-scopes.d.ts +84 -0
  139. package/dist/mcp-auth-scopes.d.ts.map +1 -0
  140. package/dist/mcp-auth-scopes.js +125 -0
  141. package/dist/mcp-auth-scopes.js.map +1 -0
  142. package/dist/mcp-auth-view.d.ts +50 -0
  143. package/dist/mcp-auth-view.d.ts.map +1 -0
  144. package/dist/mcp-auth-view.js +166 -0
  145. package/dist/mcp-auth-view.js.map +1 -0
  146. package/dist/mcp-auth.d.ts +157 -0
  147. package/dist/mcp-auth.d.ts.map +1 -0
  148. package/dist/mcp-auth.js +442 -0
  149. package/dist/mcp-auth.js.map +1 -0
  150. package/dist/mcp-modern.d.ts +15 -1
  151. package/dist/mcp-modern.d.ts.map +1 -1
  152. package/dist/mcp-modern.js +218 -31
  153. package/dist/mcp-modern.js.map +1 -1
  154. package/dist/meta-argument.d.ts +8 -8
  155. package/dist/meta-argument.d.ts.map +1 -1
  156. package/dist/meta-argument.js +17 -10
  157. package/dist/meta-argument.js.map +1 -1
  158. package/dist/meta-tools.js +1 -1
  159. package/dist/meta-tools.js.map +1 -1
  160. package/dist/middleware.d.ts.map +1 -1
  161. package/dist/middleware.js +16 -6
  162. package/dist/middleware.js.map +1 -1
  163. package/dist/output-budget.d.ts +77 -0
  164. package/dist/output-budget.d.ts.map +1 -0
  165. package/dist/output-budget.js +200 -0
  166. package/dist/output-budget.js.map +1 -0
  167. package/dist/request-context.d.ts +7 -1
  168. package/dist/request-context.d.ts.map +1 -1
  169. package/dist/request-context.js +14 -3
  170. package/dist/request-context.js.map +1 -1
  171. package/dist/resources.d.ts +35 -10
  172. package/dist/resources.d.ts.map +1 -1
  173. package/dist/resources.js +59 -18
  174. package/dist/resources.js.map +1 -1
  175. package/dist/scope-view.d.ts +59 -0
  176. package/dist/scope-view.d.ts.map +1 -0
  177. package/dist/scope-view.js +44 -0
  178. package/dist/scope-view.js.map +1 -0
  179. package/dist/server-types.d.ts +191 -26
  180. package/dist/server-types.d.ts.map +1 -1
  181. package/dist/server-types.js.map +1 -1
  182. package/dist/server.d.ts.map +1 -1
  183. package/dist/server.js +165 -18
  184. package/dist/server.js.map +1 -1
  185. package/dist/skills.d.ts.map +1 -1
  186. package/dist/skills.js +99 -3
  187. package/dist/skills.js.map +1 -1
  188. package/dist/strict-json.d.ts +17 -0
  189. package/dist/strict-json.d.ts.map +1 -0
  190. package/dist/strict-json.js +93 -0
  191. package/dist/strict-json.js.map +1 -0
  192. package/dist/task-dispatch.d.ts +34 -0
  193. package/dist/task-dispatch.d.ts.map +1 -0
  194. package/dist/task-dispatch.js +26 -0
  195. package/dist/task-dispatch.js.map +1 -0
  196. package/dist/tasks-runtime.d.ts +113 -0
  197. package/dist/tasks-runtime.d.ts.map +1 -0
  198. package/dist/tasks-runtime.js +687 -0
  199. package/dist/tasks-runtime.js.map +1 -0
  200. package/dist/tasks.d.ts +210 -0
  201. package/dist/tasks.d.ts.map +1 -0
  202. package/dist/tasks.js +289 -0
  203. package/dist/tasks.js.map +1 -0
  204. package/dist/tool-router.d.ts +4 -0
  205. package/dist/tool-router.d.ts.map +1 -1
  206. package/dist/tool-router.js +103 -26
  207. package/dist/tool-router.js.map +1 -1
  208. package/dist/tools.d.ts.map +1 -1
  209. package/dist/tools.js +11 -18
  210. package/dist/tools.js.map +1 -1
  211. package/dist/up-front-steps.d.ts +27 -0
  212. package/dist/up-front-steps.d.ts.map +1 -0
  213. package/dist/up-front-steps.js +110 -0
  214. package/dist/up-front-steps.js.map +1 -0
  215. package/dist/validation.d.ts +24 -3
  216. package/dist/validation.d.ts.map +1 -1
  217. package/dist/validation.js +56 -6
  218. package/dist/validation.js.map +1 -1
  219. package/dist/verified-credentials.d.ts +42 -0
  220. package/dist/verified-credentials.d.ts.map +1 -0
  221. package/dist/verified-credentials.js +84 -0
  222. package/dist/verified-credentials.js.map +1 -0
  223. package/package.json +12 -7
@@ -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;QAAE,OAAO,SAAS,CAAC;IAC3C,MAAM,IA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M,CAAC,EAAE,CAAC,CAAC,CAAC,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,EAAE,WAAoB;YAC7D,OAAO,EAAE,KAAK,EAAE,oBAA6B,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC;QAC/F,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,CA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,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,GAAG,EAAE,MAAM,EACX,WAAW,CAAC,EAAE,MAAM,GAClB,UAAU,CAAC,WAAW,CAAC,CAmDzB;AAID;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,GAAG,EAAE,MAAM,EACX,WAAW,CAAC,EAAE,MAAM,GAClB,UAAU,CAAC,WAAW,CAAC,CAMzB"}
@@ -0,0 +1,306 @@
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
+ import { assertHttpsUrl, audienceAccepts, isScopeToken } from './mcp-auth-resource.js';
8
+ /** Every rule code, in the specification's order. */
9
+ export const AUTH_RULE_CODES = Object.freeze([
10
+ 'no-token',
11
+ 'token-location',
12
+ 'token-malformed',
13
+ 'unknown-issuer',
14
+ 'typ',
15
+ 'alg',
16
+ 'kid',
17
+ 'crit',
18
+ 'key-reference',
19
+ 'key',
20
+ 'signature',
21
+ 'issuer',
22
+ 'audience',
23
+ 'claims',
24
+ 'expired',
25
+ 'not-yet-valid',
26
+ 'lifetime',
27
+ 'scope-malformed',
28
+ 'scopes-too-many',
29
+ 'dpop-unsupported',
30
+ 'binding',
31
+ 'inactive',
32
+ 'unavailable',
33
+ ]);
34
+ /** The largest clock skew a verifier may allow, in seconds. */
35
+ export const MAX_CLOCK_SKEW_S = 300;
36
+ /** The default clock skew, in seconds. */
37
+ export const DEFAULT_CLOCK_SKEW_S = 60;
38
+ /** The default longest token lifetime (`exp - iat`), in seconds. */
39
+ export const DEFAULT_MAX_TOKEN_LIFETIME_S = 3600;
40
+ /** The default scope limit. */
41
+ export const DEFAULT_SCOPE_LIMIT = 64;
42
+ /** The most Unicode code points a `jti`, `sub`, `client_id` or `acr` may hold. */
43
+ export const MAX_CLAIM_CHARS = 255;
44
+ function wholeNumber(what, value, min, max = Number.MAX_SAFE_INTEGER) {
45
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < min || value > max) {
46
+ throw new Error(`[AFD] ${what} must be a whole number from ${min} to ${max}`);
47
+ }
48
+ return value;
49
+ }
50
+ /**
51
+ * The claim rules for tokens whose audience is `options.resource`.
52
+ *
53
+ * @throws Error when the resource is not an absolute `https` URL without user information, query
54
+ * or fragment, the skew is over 300 seconds, the lifetime or limit is under 1, or the prefix
55
+ * is not a scope token
56
+ */
57
+ export function createTokenRules(options) {
58
+ assertHttpsUrl('resource', options.resource);
59
+ const prefix = options.scopePrefix;
60
+ if (prefix !== undefined && !isScopeToken(prefix)) {
61
+ throw new Error(`[AFD] scope prefix ${JSON.stringify(prefix)} is not an OAuth scope token`);
62
+ }
63
+ return Object.freeze({
64
+ resource: options.resource,
65
+ clockSkewS: wholeNumber('clockSkewS', options.clockSkewS ?? DEFAULT_CLOCK_SKEW_S, 0, MAX_CLOCK_SKEW_S),
66
+ maxTokenLifetimeS: wholeNumber('maxTokenLifetimeS', options.maxTokenLifetimeS ?? DEFAULT_MAX_TOKEN_LIFETIME_S, 1),
67
+ scopePrefix: prefix,
68
+ scopeLimit: wholeNumber('scopeLimit', options.scopeLimit ?? DEFAULT_SCOPE_LIMIT, 1),
69
+ requireBoundTokens: options.requireBoundTokens === true,
70
+ });
71
+ }
72
+ const pass = (value) => ({ ok: true, value });
73
+ const refuse = (rule) => ({ ok: false, rule });
74
+ function isRecord(value) {
75
+ return !!value && typeof value === 'object' && !Array.isArray(value);
76
+ }
77
+ /**
78
+ * A `scope` claim parsed (`spec/authorization.md`, M3.2; `undefined` when absent): scope tokens
79
+ * separated by single spaces, each kept once at its first place. An empty string or no claim
80
+ * grants no scope. Only scopes starting with `<prefix>:` count against `limit` when a prefix is
81
+ * given. Refused with `scope-malformed` or `scopes-too-many`.
82
+ */
83
+ export function parseScopeClaim(scope, prefix, limit) {
84
+ if (scope === undefined)
85
+ return pass([]);
86
+ if (typeof scope !== 'string')
87
+ return refuse('scope-malformed');
88
+ if (scope === '')
89
+ return pass([]);
90
+ const scopes = [];
91
+ for (const token of scope.split(' ')) {
92
+ if (!isScopeToken(token))
93
+ return refuse('scope-malformed');
94
+ if (!scopes.includes(token))
95
+ scopes.push(token);
96
+ }
97
+ const counted = prefix === undefined
98
+ ? scopes.length
99
+ : scopes.filter((held) => held.startsWith(`${prefix}:`)).length;
100
+ return counted > limit ? refuse('scopes-too-many') : pass(scopes);
101
+ }
102
+ /** Every {@link SigningAlgorithm}. */
103
+ export const SIGNING_ALGORITHMS = Object.freeze([
104
+ 'RS256',
105
+ 'RS384',
106
+ 'RS512',
107
+ 'PS256',
108
+ 'PS384',
109
+ 'PS512',
110
+ 'ES256',
111
+ 'ES384',
112
+ 'EdDSA',
113
+ ]);
114
+ const TYP = new Set(['at+jwt', 'application/at+jwt']);
115
+ const KEY_REFERENCES = ['jku', 'x5u', 'x5c', 'jwk'];
116
+ /**
117
+ * Rule 2 on a decoded JWS header, against the issuer's algorithm list: `typ`, then `alg`, `kid`,
118
+ * `crit` and the key references, the first broken rule refusing. `none` and every `HS*`
119
+ * algorithm are refused whatever the list says.
120
+ */
121
+ export function checkJwsHeader(header, algorithms) {
122
+ if (!isRecord(header))
123
+ return refuse('typ');
124
+ const { typ, alg, kid } = header;
125
+ if (typeof typ !== 'string' || !TYP.has(typ.toLowerCase()))
126
+ return refuse('typ');
127
+ if (typeof alg !== 'string' ||
128
+ alg === 'none' ||
129
+ alg.startsWith('HS') ||
130
+ !algorithms.includes(alg)) {
131
+ return refuse('alg');
132
+ }
133
+ if (typeof kid !== 'string' || kid === '')
134
+ return refuse('kid');
135
+ if (Object.hasOwn(header, 'crit'))
136
+ return refuse('crit');
137
+ if (KEY_REFERENCES.some((member) => Object.hasOwn(header, member))) {
138
+ return refuse('key-reference');
139
+ }
140
+ return pass(undefined);
141
+ }
142
+ /** The `kty`, and `crv` when it matters, each algorithm needs (RFC 7518 3.4, RFC 8037 3.1). */
143
+ function keyFits(alg, kty, crv) {
144
+ switch (alg) {
145
+ case 'RS256':
146
+ case 'RS384':
147
+ case 'RS512':
148
+ case 'PS256':
149
+ case 'PS384':
150
+ case 'PS512':
151
+ return kty === 'RSA';
152
+ case 'ES256':
153
+ return kty === 'EC' && crv === 'P-256';
154
+ case 'ES384':
155
+ return kty === 'EC' && crv === 'P-384';
156
+ case 'ES512':
157
+ return kty === 'EC' && crv === 'P-521';
158
+ case 'EdDSA':
159
+ return kty === 'OKP' && (crv === 'Ed25519' || crv === 'Ed448');
160
+ default:
161
+ return false;
162
+ }
163
+ }
164
+ /**
165
+ * Rule 3 on a header that passed rule 2 and the issuer's key with its `kid` (`undefined` for
166
+ * none): the key's `kid` is the header's; its `kty` is the `alg`'s family; its `alg`, when
167
+ * present, is the header's; its `use`, when present, is `sig`; its `key_ops`, when present,
168
+ * contain `verify`. Refused with `key`.
169
+ */
170
+ export function checkKeyFit(header, key) {
171
+ if (!isRecord(header) || !isRecord(key))
172
+ return refuse('key');
173
+ const { alg, kid } = header;
174
+ if (typeof alg !== 'string' || typeof kid !== 'string' || key.kid !== kid)
175
+ return refuse('key');
176
+ if (!keyFits(alg, key.kty, key.crv))
177
+ return refuse('key');
178
+ if (Object.hasOwn(key, 'alg') && key.alg !== alg)
179
+ return refuse('key');
180
+ if (Object.hasOwn(key, 'use') && key.use !== 'sig')
181
+ return refuse('key');
182
+ if (Object.hasOwn(key, 'key_ops')) {
183
+ const ops = key.key_ops;
184
+ if (!Array.isArray(ops) || !ops.includes('verify'))
185
+ return refuse('key');
186
+ }
187
+ return pass(undefined);
188
+ }
189
+ const CONTROL = /\p{Cc}/u;
190
+ /** A string claim of rule 7: non-empty, at most 255 code points, no control character. */
191
+ function claimText(value) {
192
+ return (typeof value === 'string' &&
193
+ value !== '' &&
194
+ [...value].length <= MAX_CLAIM_CHARS &&
195
+ !CONTROL.test(value));
196
+ }
197
+ const isTime = (value) => typeof value === 'number' && Number.isFinite(value);
198
+ /** Redacted debug output (M4): every field but `issuer` and `expiresAt` prints `[redacted]`. */
199
+ function inspectRedacted() {
200
+ const fields = this;
201
+ const shown = Object.keys(fields).map((key) => key === 'issuer' || key === 'expiresAt'
202
+ ? `${key}: ${JSON.stringify(fields[key])}`
203
+ : `${key}: '[redacted]'`);
204
+ return `Credentials { ${shown.join(', ')} }`;
205
+ }
206
+ /**
207
+ * `fields` as credentials whose Node.js debug form (`util.inspect`, `console.log`) redacts every
208
+ * field but `issuer` and `expiresAt` (M4). JSON keeps every field.
209
+ */
210
+ export function withRedactedInspect(fields) {
211
+ Object.defineProperty(fields, Symbol.for('nodejs.util.inspect.custom'), {
212
+ value: inspectRedacted,
213
+ enumerable: false,
214
+ });
215
+ return fields;
216
+ }
217
+ /**
218
+ * Rules 5 to 10 on a token's claims after its signature (or on an introspection response), at
219
+ * `now` (whole seconds since the epoch), for `issuer` (its exact configured string) under
220
+ * `rules`. `certificate` is the SHA-256 thumbprint (unpadded base64url) of the request's TLS
221
+ * client certificate, `undefined` for none.
222
+ *
223
+ * Rule 10 also refuses a `cnf` that is not an object, and one holding a confirmation method
224
+ * other than `x5t#S256` (`jkt` is `dpop-unsupported`, anything else `binding`).
225
+ */
226
+ export function checkClaims(claims, issuer, rules, now, certificate) {
227
+ // 5. Issuer.
228
+ if (claims.iss !== issuer)
229
+ return refuse('issuer');
230
+ // 6. Audience: never optional.
231
+ if (!audienceAccepts(claims.aud, rules.resource))
232
+ return refuse('audience');
233
+ // 7. Required claims.
234
+ const { exp, iat, nbf, auth_time: authTime, acr, jti, sub, client_id: clientId } = claims;
235
+ if (!isTime(exp) || !isTime(iat))
236
+ return refuse('claims');
237
+ if (!claimText(jti) || !claimText(sub) || !claimText(clientId))
238
+ return refuse('claims');
239
+ if (Object.hasOwn(claims, 'nbf') && !isTime(nbf))
240
+ return refuse('claims');
241
+ if (Object.hasOwn(claims, 'auth_time') && !isTime(authTime))
242
+ return refuse('claims');
243
+ if (Object.hasOwn(claims, 'acr') && !claimText(acr))
244
+ return refuse('claims');
245
+ // 8. Time.
246
+ const skew = rules.clockSkewS;
247
+ if (now >= exp + skew)
248
+ return refuse('expired');
249
+ if (iat > now + skew || (isTime(nbf) && nbf > now + skew))
250
+ return refuse('not-yet-valid');
251
+ // A token that expires before it was issued has no lifetime at all.
252
+ if (exp < iat || exp - iat > rules.maxTokenLifetimeS)
253
+ return refuse('lifetime');
254
+ // 9. Scopes.
255
+ const scopes = parseScopeClaim(claims.scope, rules.scopePrefix, rules.scopeLimit);
256
+ if (!scopes.ok)
257
+ return scopes;
258
+ // 10. Binding.
259
+ let thumbprint;
260
+ if (Object.hasOwn(claims, 'cnf')) {
261
+ const cnf = claims.cnf;
262
+ if (!isRecord(cnf))
263
+ return refuse('binding');
264
+ if (Object.hasOwn(cnf, 'jkt'))
265
+ return refuse('dpop-unsupported');
266
+ if (Object.keys(cnf).some((method) => method !== 'x5t#S256'))
267
+ return refuse('binding');
268
+ if (Object.hasOwn(cnf, 'x5t#S256')) {
269
+ const bound = cnf['x5t#S256'];
270
+ if (typeof bound !== 'string' || certificate === undefined || bound !== certificate) {
271
+ return refuse('binding');
272
+ }
273
+ thumbprint = bound;
274
+ }
275
+ }
276
+ if (thumbprint === undefined && rules.requireBoundTokens)
277
+ return refuse('binding');
278
+ return pass(withRedactedInspect({
279
+ issuer,
280
+ subject: sub,
281
+ clientId,
282
+ scopes: scopes.value,
283
+ resource: rules.resource,
284
+ expiresAt: Math.floor(exp),
285
+ issuedAt: Math.floor(iat),
286
+ ...(isTime(authTime) ? { authTime: Math.floor(authTime) } : {}),
287
+ ...(typeof acr === 'string' ? { acr } : {}),
288
+ ...(thumbprint !== undefined ? { cnf: { 'x5t#S256': thumbprint } } : {}),
289
+ }));
290
+ }
291
+ const INTROSPECTION_REQUIRED = ['exp', 'iat', 'iss', 'aud', 'sub', 'client_id'];
292
+ /**
293
+ * An RFC 7662 introspection response for the one issuer configured for introspection
294
+ * (`spec/authorization.md`, M3, "Introspection"): `active` must be `true` (else `inactive`), and
295
+ * `exp`, `iat`, `iss`, `aud`, `sub` and `client_id` must be present (else `claims`); rules 5 to
296
+ * 10 ({@link checkClaims}) then apply to it, `jti` among rule 7's claims.
297
+ */
298
+ export function checkIntrospection(response, issuer, rules, now, certificate) {
299
+ if (!isRecord(response) || response.active !== true)
300
+ return refuse('inactive');
301
+ if (INTROSPECTION_REQUIRED.some((field) => !Object.hasOwn(response, field))) {
302
+ return refuse('claims');
303
+ }
304
+ return checkClaims(response, issuer, rules, now, certificate);
305
+ }
306
+ //# sourceMappingURL=mcp-auth-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth-rules.js","sourceRoot":"","sources":["../src/mcp-auth-rules.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AA4BvF,qDAAqD;AACrD,MAAM,CAAC,MAAM,eAAe,GAA4B,MAAM,CAAC,MAAM,CAAC;IACrE,UAAU;IACV,gBAAgB;IAChB,iBAAiB;IACjB,gBAAgB;IAChB,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,eAAe;IACf,KAAK;IACL,WAAW;IACX,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,SAAS;IACT,eAAe;IACf,UAAU;IACV,iBAAiB;IACjB,iBAAiB;IACjB,kBAAkB;IAClB,SAAS;IACT,UAAU;IACV,aAAa;CACb,CAAC,CAAC;AA6BH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AACpC,0CAA0C;AAC1C,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,oEAAoE;AACpE,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AACjD,+BAA+B;AAC/B,MAAM,CAAC,MAAM,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AC/D,CAAC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @fileoverview Scope decisions (`spec/authorization.md`, M6): the static rule, a host's
3
+ * `ScopeResolver`, the decision on a whole request, and the challenge of a host whose callers
4
+ * authenticate by a scheme of its own. Pure: no request, server or transport.
5
+ */
6
+ import type { Credentials } from './mcp-auth-rules.js';
7
+ /**
8
+ * A scope decision for one call: `'allowed'` when the credentials hold every scope it needs,
9
+ * `{ missing }` naming the scopes it lacks (in the decider's order), or `'defer'` to let the
10
+ * registry answer it (for when naming a scope would reveal something).
11
+ */
12
+ export type ScopeDecision = 'allowed' | 'defer' | {
13
+ missing: readonly string[];
14
+ };
15
+ /**
16
+ * A host's per-call scope rule (`spec/authorization.md`, M6, "A resolver"). It decides every call
17
+ * instead of the static rule (a command's `scopes`); the server's `requiredScopes` still apply.
18
+ *
19
+ * `resolve` is asked twice for a call that runs a command: before dispatch, on the arguments as
20
+ * sent (not validated, no defaults, pipeline references unresolved), for the 403 and again after
21
+ * routing; and at execution, on the validated input, for every command the registry runs with
22
+ * credentials. Decide on the values, not on whether they were sent, so both agree. For a
23
+ * meta-tool that names no command (`afd-discover`, `afd-detail`, or `afd-call`, `afd-batch` and
24
+ * `afd-pipe` without a command for every step), `command` is the tool's own name and `input` its
25
+ * arguments as sent, which may name any command, hidden ones included: decide such a tool without
26
+ * asking whether a command its input names exists. It is never asked about a name that does not
27
+ * exist for the caller (unknown, not exposed to MCP, or not `known`).
28
+ *
29
+ * `visible` and `known` must be pure functions of the command and the credentials. With
30
+ * `filterToolsByScope`, the listings show a command only when both hold, and a command `known`
31
+ * rejects does not exist for the caller on any route (M6, "Hidden commands"). `known` defaults
32
+ * to `visible`.
33
+ */
34
+ export interface ScopeResolver {
35
+ resolve(command: string, input: unknown, credentials: Credentials): ScopeDecision;
36
+ visible(command: string, credentials: Credentials): boolean;
37
+ known?(command: string, credentials: Credentials): boolean;
38
+ }
39
+ /**
40
+ * The static rule (M6): a call needs `required` (the server's `requiredScopes`), then the
41
+ * command's `scopes`, without repeats. `'allowed'` when `held` holds each one exactly
42
+ * (case-sensitive, no hierarchy), else `{ missing }` with those not held, in that order. It never
43
+ * defers.
44
+ */
45
+ export declare function staticDecision(required: readonly string[], scopes: readonly string[], held: readonly string[]): ScopeDecision;
46
+ /**
47
+ * What a whole request gets from the decisions on its steps: `'proceed'` when none is missing
48
+ * (a `'defer'` step is answered by the registry), else `{ forbidden }` naming every missing scope
49
+ * of every step, each once, in step order.
50
+ */
51
+ export type RequestDecision = 'proceed' | {
52
+ forbidden: readonly string[];
53
+ };
54
+ /** A host-facing warning sink for a resolver's mistakes; never given the call's input. */
55
+ export type ScopeWarning = (message: string) => void;
56
+ /**
57
+ * The decision on a request whose steps were decided `decisions` (M6). Any `{ missing }` refuses
58
+ * the request, even one that names no scope or a name that is not a scope token: such a name is
59
+ * the resolver's mistake, reported to `warn` without the call's input and left out of the list.
60
+ */
61
+ export declare function requestDecision(decisions: readonly ScopeDecision[], warn?: ScopeWarning): RequestDecision;
62
+ /** The required scopes' decision, then a call's own. */
63
+ export declare function mergeDecisions(required: ScopeDecision, decision: ScopeDecision): ScopeDecision;
64
+ /** Whether `decision` is one a resolver may return; anything else refuses, failing closed. */
65
+ export declare function checkedDecision(decision: unknown): ScopeDecision;
66
+ /**
67
+ * The `WWW-Authenticate` challenge of a host's 403 when its callers authenticate by a scheme of
68
+ * its own rather than `Bearer` (`spec/authorization.md`, M6, "A host's own layer"):
69
+ * `<scheme> <name>="<value>", ..., error="insufficient_scope", scope="<missing>"`, the host's
70
+ * parameters first, in the order given, `scope` left out rather than sent empty, and nothing
71
+ * pointing to protected-resource metadata.
72
+ */
73
+ export declare class ScopeChallenge {
74
+ #private;
75
+ /**
76
+ * @throws Error when `scheme` is not an HTTP token, or is `Bearer` in any case (M5's own
77
+ * challenge); or a parameter's name is not an HTTP token, is `error` or `scope` in any case,
78
+ * or is given twice, or its value holds anything but visible ASCII and spaces, or `"` or `\`
79
+ */
80
+ constructor(scheme: string, params?: Readonly<Record<string, string>>);
81
+ /** The challenge's value for the `missing` scopes, in order; only scope tokens are named. */
82
+ headerValue(missing: readonly string[]): string;
83
+ }
84
+ //# sourceMappingURL=mcp-auth-scopes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth-scopes.d.ts","sourceRoot":"","sources":["../src/mcp-auth-scopes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,OAAO,GAAG;IAAE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAEjF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,aAAa;IAC7B,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,GAAG,aAAa,CAAC;IAClF,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC;IAC5D,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC;CAC3D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC7B,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,IAAI,EAAE,SAAS,MAAM,EAAE,GACrB,aAAa,CAMf;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG;IAAE,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAE3E,0FAA0F;AAC1F,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAIrD;;;;GAIG;AACH,wBAAgB,eAAe,CAC9B,SAAS,EAAE,SAAS,aAAa,EAAE,EACnC,IAAI,GAAE,YAA6B,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