@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,125 @@
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 { isScopeToken } from './mcp-auth-resource.js';
7
+ /**
8
+ * The static rule (M6): a call needs `required` (the server's `requiredScopes`), then the
9
+ * command's `scopes`, without repeats. `'allowed'` when `held` holds each one exactly
10
+ * (case-sensitive, no hierarchy), else `{ missing }` with those not held, in that order. It never
11
+ * defers.
12
+ */
13
+ export function staticDecision(required, scopes, held) {
14
+ const missing = [];
15
+ for (const scope of [...required, ...scopes]) {
16
+ if (!held.includes(scope) && !missing.includes(scope))
17
+ missing.push(scope);
18
+ }
19
+ return missing.length === 0 ? 'allowed' : { missing };
20
+ }
21
+ const defaultWarning = (message) => console.warn(`[afd] ${message}`);
22
+ /**
23
+ * The decision on a request whose steps were decided `decisions` (M6). Any `{ missing }` refuses
24
+ * the request, even one that names no scope or a name that is not a scope token: such a name is
25
+ * the resolver's mistake, reported to `warn` without the call's input and left out of the list.
26
+ */
27
+ export function requestDecision(decisions, warn = defaultWarning) {
28
+ let refused = false;
29
+ const missing = [];
30
+ for (const decision of decisions) {
31
+ if (decision === 'allowed' || decision === 'defer')
32
+ continue;
33
+ refused = true;
34
+ const named = Array.isArray(decision.missing) ? decision.missing : [];
35
+ if (named.length === 0 || named.some((scope) => !isScopeToken(scope))) {
36
+ warn('a scope decision answered missing without valid scope names; the call is refused');
37
+ }
38
+ for (const scope of named) {
39
+ if (isScopeToken(scope) && !missing.includes(scope))
40
+ missing.push(scope);
41
+ }
42
+ }
43
+ return refused ? { forbidden: missing } : 'proceed';
44
+ }
45
+ /** The required scopes' decision, then a call's own. */
46
+ export function mergeDecisions(required, decision) {
47
+ if (typeof required === 'object') {
48
+ if (typeof decision !== 'object')
49
+ return required;
50
+ const missing = [...required.missing];
51
+ for (const scope of decision.missing)
52
+ if (!missing.includes(scope))
53
+ missing.push(scope);
54
+ return { missing };
55
+ }
56
+ return decision;
57
+ }
58
+ /** Whether `decision` is one a resolver may return; anything else refuses, failing closed. */
59
+ export function checkedDecision(decision) {
60
+ if (decision === 'allowed' || decision === 'defer')
61
+ return decision;
62
+ const missing = decision?.missing;
63
+ if (typeof decision === 'object' && Array.isArray(missing))
64
+ return { missing: missing.map(String) };
65
+ return { missing: [] };
66
+ }
67
+ /** An HTTP token (RFC 9110 5.6.2). */
68
+ const HTTP_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
69
+ /** A parameter value that is always one quoted string without escapes. */
70
+ const QUOTED_VALUE = /^[ \x21\x23-\x5B\x5D-\x7E]*$/;
71
+ /**
72
+ * The `WWW-Authenticate` challenge of a host's 403 when its callers authenticate by a scheme of
73
+ * its own rather than `Bearer` (`spec/authorization.md`, M6, "A host's own layer"):
74
+ * `<scheme> <name>="<value>", ..., error="insufficient_scope", scope="<missing>"`, the host's
75
+ * parameters first, in the order given, `scope` left out rather than sent empty, and nothing
76
+ * pointing to protected-resource metadata.
77
+ */
78
+ export class ScopeChallenge {
79
+ #scheme;
80
+ #params;
81
+ /**
82
+ * @throws Error when `scheme` is not an HTTP token, or is `Bearer` in any case (M5's own
83
+ * challenge); or a parameter's name is not an HTTP token, is `error` or `scope` in any case,
84
+ * or is given twice, or its value holds anything but visible ASCII and spaces, or `"` or `\`
85
+ */
86
+ constructor(scheme, params = {}) {
87
+ if (typeof scheme !== 'string' || !HTTP_TOKEN.test(scheme)) {
88
+ throw new Error(`[AFD] the challenge scheme ${JSON.stringify(scheme)} is not an HTTP token`);
89
+ }
90
+ if (scheme.toLowerCase() === 'bearer') {
91
+ throw new Error("[AFD] a Bearer 403 is M5's own challenge; a ScopeChallenge names another scheme");
92
+ }
93
+ const seen = new Set();
94
+ const kept = [];
95
+ for (const [name, value] of Object.entries(params)) {
96
+ const folded = name.toLowerCase();
97
+ if (!HTTP_TOKEN.test(name)) {
98
+ throw new Error(`[AFD] the challenge parameter ${JSON.stringify(name)} is not an HTTP token`);
99
+ }
100
+ if (folded === 'error' || folded === 'scope') {
101
+ throw new Error(`[AFD] the challenge parameter ${JSON.stringify(name)} is set by the scope decision`);
102
+ }
103
+ if (seen.has(folded)) {
104
+ throw new Error(`[AFD] the challenge parameter ${JSON.stringify(name)} is named more than once`);
105
+ }
106
+ if (typeof value !== 'string' || !QUOTED_VALUE.test(value)) {
107
+ throw new Error(`[AFD] the value of the challenge parameter ${JSON.stringify(name)} must be visible ASCII or spaces, without '"' or '\\'`);
108
+ }
109
+ seen.add(folded);
110
+ kept.push([name, value]);
111
+ }
112
+ this.#scheme = scheme;
113
+ this.#params = Object.freeze(kept);
114
+ }
115
+ /** The challenge's value for the `missing` scopes, in order; only scope tokens are named. */
116
+ headerValue(missing) {
117
+ const params = this.#params.map(([name, value]) => `${name}="${value}"`);
118
+ params.push('error="insufficient_scope"');
119
+ const scopes = missing.filter((scope) => isScopeToken(scope)).join(' ');
120
+ if (scopes)
121
+ params.push(`scope="${scopes}"`);
122
+ return `${this.#scheme} ${params.join(', ')}`;
123
+ }
124
+ }
125
+ //# sourceMappingURL=mcp-auth-scopes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth-scopes.js","sourceRoot":"","sources":["../src/mcp-auth-scopes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAmCtD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC7B,QAA2B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CAC/E,CAAC;YACH,CAAC;YACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC5D,MAAM,IAAI,KAAK,CACd,8CAA8C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,uDAAuD,CACzH,CAAC;YACH,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACjB,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1B,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,6FAA6F;IAC7F,WAAW,CAAC,OAA0B;QACrC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC;QACzE,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAC1C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxE,IAAI,MAAM;YAAE,MAAM,CAAC,IAAI,CAAC,UAAU,MAAM,GAAG,CAAC,CAAC;QAC7C,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC/C,CAAC;CACD"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @fileoverview The scope authority of a server with MCP authorization (`spec/authorization.md`,
3
+ * M6): it makes each admitted request's {@link ScopeView}, which commands exist for its caller and
4
+ * which it is shown, decided once as the request arrives, and the scope decision on every call it
5
+ * names, before dispatch, after routing and at execution.
6
+ */
7
+ import { type GroupByFn } from './command-routing.js';
8
+ import type { ProtectedResource } from './mcp-auth-resource.js';
9
+ import type { Credentials } from './mcp-auth-rules.js';
10
+ import { type ScopeResolver, type ScopeWarning } from './mcp-auth-scopes.js';
11
+ import type { ZodCommandDefinition } from './schema.js';
12
+ import type { ScopeView } from './scope-view.js';
13
+ import type { ToolStrategy } from './server-types.js';
14
+ /** One call a request names. */
15
+ export type NamedCall = {
16
+ kind: 'command';
17
+ name: string;
18
+ input: unknown;
19
+ } | {
20
+ kind: 'tool';
21
+ name: string;
22
+ input: unknown;
23
+ }
24
+ /** A grouped call that resolves to no single command: it runs nothing. */
25
+ | {
26
+ kind: 'unresolved';
27
+ };
28
+ /** The scope options of `auth` and what the server knows of its own commands. */
29
+ export interface ScopeAuthorityOptions {
30
+ requiredScopes: readonly string[];
31
+ resolver: ScopeResolver | undefined;
32
+ filterToolsByScope: boolean;
33
+ /** The MCP-exposed commands, built-ins included. */
34
+ commands: readonly ZodCommandDefinition[];
35
+ toolStrategy: ToolStrategy;
36
+ groupByFn: GroupByFn | undefined;
37
+ resource: ProtectedResource;
38
+ warn?: ScopeWarning;
39
+ }
40
+ /** Makes the view of each authorized request. */
41
+ export interface ScopeAuthority {
42
+ view(credentials: Credentials): ScopeView;
43
+ }
44
+ /**
45
+ * The scope authority of one server (`spec/authorization.md`, M6).
46
+ *
47
+ * @throws Error when a command declares a scope that is not a scope token
48
+ */
49
+ export declare function createScopeAuthority(options: ScopeAuthorityOptions): ScopeAuthority;
50
+ //# sourceMappingURL=mcp-auth-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth-view.d.ts","sourceRoot":"","sources":["../src/mcp-auth-view.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAA+B,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AA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/authorization.md`,
3
+ * M6): it makes each admitted request's {@link ScopeView}, which commands exist for its caller and
4
+ * which it is shown, decided once as the request arrives, and the scope decision on every call it
5
+ * names, before dispatch, after routing and at execution.
6
+ */
7
+ import { commandAction, commandGroup } from './command-routing.js';
8
+ import { checkedDecision, mergeDecisions, requestDecision, staticDecision, } from './mcp-auth-scopes.js';
9
+ function isRecord(value) {
10
+ return !!value && typeof value === 'object' && !Array.isArray(value);
11
+ }
12
+ /** The input of a call as sent: an absent or `null` input is `{}`. */
13
+ function inputOrEmpty(value) {
14
+ return value === undefined || value === null ? {} : value;
15
+ }
16
+ /** Every step of `afd-batch` or `afd-pipe`, or `undefined` when one names no command. */
17
+ function stepsOf(list) {
18
+ if (!Array.isArray(list) || list.length === 0)
19
+ return undefined;
20
+ const calls = [];
21
+ for (const item of list) {
22
+ if (!isRecord(item) || typeof item.command !== 'string')
23
+ return undefined;
24
+ calls.push({ kind: 'command', name: item.command, input: inputOrEmpty(item.input) });
25
+ }
26
+ return calls;
27
+ }
28
+ /**
29
+ * The scope authority of one server (`spec/authorization.md`, M6).
30
+ *
31
+ * @throws Error when a command declares a scope that is not a scope token
32
+ */
33
+ export function createScopeAuthority(options) {
34
+ const { requiredScopes, resolver, filterToolsByScope, toolStrategy, groupByFn, resource } = options;
35
+ const warn = options.warn;
36
+ const byName = new Map(options.commands.map((command) => [command.name, command]));
37
+ // Only a resolver on a server that filters its listings hides commands.
38
+ const hider = filterToolsByScope ? resolver : undefined;
39
+ const failure = (missing) => ({
40
+ code: 'INSUFFICIENT_SCOPE',
41
+ message: 'The access token lacks a scope this call needs',
42
+ suggestion: resource.forbiddenBody(missing).suggestion,
43
+ details: { scopes: [...missing] },
44
+ retryable: false,
45
+ });
46
+ function view(credentials) {
47
+ const held = credentials.scopes;
48
+ const required = staticDecision(requiredScopes, [], held);
49
+ const ask = (name, input) => {
50
+ try {
51
+ return checkedDecision(resolver?.resolve(name, input, credentials));
52
+ }
53
+ catch {
54
+ // A resolver that throws refuses the call, failing closed.
55
+ return { missing: [] };
56
+ }
57
+ };
58
+ const asks = (test, name) => {
59
+ try {
60
+ return test?.(name, credentials) === true;
61
+ }
62
+ catch {
63
+ return false;
64
+ }
65
+ };
66
+ // Decided once, as the request arrives, for every command (M6, "Hidden commands").
67
+ const known = new Set();
68
+ const shown = new Set();
69
+ for (const command of byName.values()) {
70
+ const name = command.name;
71
+ const exists = !hider || asks((n, c) => (hider.known ?? hider.visible).call(hider, n, c), name);
72
+ if (exists)
73
+ known.add(name);
74
+ const visible = required === 'allowed' &&
75
+ (resolver
76
+ ? asks((n, c) => resolver.visible(n, c), name) && exists
77
+ : (command.scopes ?? []).every((scope) => held.includes(scope)));
78
+ if (!filterToolsByScope || (visible && exists))
79
+ shown.add(name);
80
+ }
81
+ const isKnown = (name) => byName.has(name) && known.has(name);
82
+ /** One named call: the required scopes, then the call's own decision. */
83
+ const decide = (call) => {
84
+ let decision = 'allowed';
85
+ if (call.kind === 'command') {
86
+ const command = isKnown(call.name) ? byName.get(call.name) : undefined;
87
+ // A name that does not exist for the caller needs the required scopes alone, and the
88
+ // resolver is never asked about it.
89
+ if (command) {
90
+ decision = resolver
91
+ ? ask(call.name, call.input)
92
+ : staticDecision([], command.scopes ?? [], held);
93
+ }
94
+ }
95
+ else if (call.kind === 'tool' && resolver) {
96
+ decision = ask(call.name, call.input);
97
+ }
98
+ return mergeDecisions(required, decision);
99
+ };
100
+ /** The calls a `tools/call` names, resolved as the router resolves them (M6). */
101
+ const named = (tool, args) => {
102
+ const record = isRecord(args) ? args : {};
103
+ const own = [{ kind: 'tool', name: tool, input: args ?? {} }];
104
+ switch (tool) {
105
+ case 'afd-call':
106
+ return typeof record.command === 'string'
107
+ ? [{ kind: 'command', name: record.command, input: inputOrEmpty(record.input) }]
108
+ : own;
109
+ case 'afd-batch':
110
+ return stepsOf(record.commands) ?? own;
111
+ case 'afd-pipe':
112
+ return stepsOf(record.steps) ?? own;
113
+ case 'afd-discover':
114
+ case 'afd-detail':
115
+ return own;
116
+ }
117
+ if (toolStrategy === 'grouped') {
118
+ const members = [...byName.values()].filter((command) => commandGroup(command, groupByFn) === tool && known.has(command.name));
119
+ const action = record.action;
120
+ if (typeof action === 'string' && action !== '') {
121
+ const candidates = members.filter((command) => commandAction(command) === action);
122
+ return candidates.length === 1
123
+ ? [
124
+ {
125
+ kind: 'command',
126
+ name: candidates[0].name,
127
+ input: record.params ?? {},
128
+ },
129
+ ]
130
+ : [{ kind: 'unresolved' }];
131
+ }
132
+ // Without an action the router answers a missing action only for a group with a
133
+ // member it shows; any other tool runs the command it names.
134
+ if (members.some((command) => shown.has(command.name)))
135
+ return [{ kind: 'unresolved' }];
136
+ }
137
+ return [{ kind: 'command', name: tool, input: args ?? {} }];
138
+ };
139
+ return Object.freeze({
140
+ credentials,
141
+ filtered: filterToolsByScope,
142
+ known: (name) => !byName.has(name) || known.has(name),
143
+ shown: (name) => shown.has(name),
144
+ decideCall: (tool, args) => requestDecision(named(tool, args).map(decide), warn),
145
+ decideCommands: (calls) => requestDecision(calls.map((call) => decide({ kind: 'command', name: call.command, input: inputOrEmpty(call.input) })), warn),
146
+ decideRequest: () => requestDecision([required], warn),
147
+ decideExecution: (command, input) => resolver && isKnown(command)
148
+ ? requestDecision([mergeDecisions(required, ask(command, input))], warn)
149
+ : 'proceed',
150
+ decideTask: (command) => {
151
+ if (!byName.has(command))
152
+ return 'proceed';
153
+ if (resolver) {
154
+ const visible = asks((n, c) => resolver.visible(n, c), command);
155
+ const resolverKnown = asks((n, c) => (resolver.known ?? resolver.visible).call(resolver, n, c), command);
156
+ return visible && resolverKnown ? 'proceed' : { forbidden: [] };
157
+ }
158
+ const cmd = byName.get(command);
159
+ return requestDecision([staticDecision([], cmd?.scopes ?? [], held)], warn);
160
+ },
161
+ insufficientScope: failure,
162
+ });
163
+ }
164
+ return { view };
165
+ }
166
+ //# sourceMappingURL=mcp-auth-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth-view.js","sourceR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E,CAAC;AACjB,CAAC"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * @fileoverview MCP authorization on HTTP (`spec/authorization.md`, M1 to M5 and M7): the options
3
+ * of `createMcpHandler({ auth })`, and the layer the HTTP handler runs before every route.
4
+ *
5
+ * For each request the layer serves the protected-resource metadata at its two paths without
6
+ * authentication (M7); otherwise it takes the one bearer token (M2), verifies it (M3), and either
7
+ * answers 401 with M5's exact challenge and body, or removes the `Authorization` header and
8
+ * admits the verified credentials (M4), frozen and branded, for that request alone: the brand is
9
+ * removed when the response closes. A route that runs a command without admitted credentials is
10
+ * refused (M1: fail closed).
11
+ *
12
+ * Scopes (M6): each admitted request gets a scope view, decided once as it arrives, which the
13
+ * routes, the router, the engine and the listings read; the layer decides a `POST` body before
14
+ * dispatch and answers a missing scope with M5's 403. A host whose own layer vouches for its
15
+ * callers admits them with `handler.admit` and runs the same decision with
16
+ * `handler.preDispatchCheck`.
17
+ */
18
+ import type { IncomingMessage, ServerResponse } from 'node:http';
19
+ import { type Actor, type Clock } from '@lushly-dev/afd-core';
20
+ import type { GroupByFn } from './command-routing.js';
21
+ import { type PreDispatch } from './mcp-auth-dispatch.js';
22
+ export type { PreDispatch } from './mcp-auth-dispatch.js';
23
+ import type { TokenVerifier } from './mcp-auth-jwt.js';
24
+ import { type ProtectedResource } from './mcp-auth-resource.js';
25
+ import { type Credentials } from './mcp-auth-rules.js';
26
+ import type { ScopeChallenge, ScopeResolver } from './mcp-auth-scopes.js';
27
+ import type { ZodCommandDefinition } from './schema.js';
28
+ import type { ScopeView } from './scope-view.js';
29
+ import type { ToolStrategy } from './server-types.js';
30
+ /** A refused token, as {@link McpAuthOptions.onRefusal} receives it. Never the token or a claim. */
31
+ export interface AuthRefusal {
32
+ /** The rule code (M5), or a host verifier's own code. */
33
+ rule: string;
34
+ /** The alias of the issuer the token was routed to, once known. */
35
+ issuer?: string;
36
+ }
37
+ /**
38
+ * `createMcpHandler`'s `auth` option (`spec/authorization.md`, "Options"): the server becomes an
39
+ * OAuth 2.1 protected resource on every HTTP route. stdio, `server.execute` and in-process
40
+ * registries are unaffected.
41
+ */
42
+ export interface McpAuthOptions {
43
+ /** The MCP endpoint's absolute `https` URL, with no query or fragment: the token audience. */
44
+ resource: string;
45
+ /** The issuers named in the metadata's `authorization_servers`, in order; at least one. */
46
+ authorizationServers: readonly string[];
47
+ /**
48
+ * Verifies each request's token: AFD's `JwtVerifier` (with `createIntrospectionVerifier` for
49
+ * opaque tokens), or the host's own. When it states its `rules`, their `resource` must be
50
+ * `resource` exactly.
51
+ */
52
+ verifier: TokenVerifier;
53
+ /** The metadata's `scopes_supported`, and the 401's `scope`. Default: none. */
54
+ scopesSupported?: readonly string[];
55
+ /** The metadata's `resource_name`. Default: none. */
56
+ resourceName?: string;
57
+ /**
58
+ * Publish `tls_client_certificate_bound_access_tokens: true`. Default: the verifier's
59
+ * `rules.requireBoundTokens`; it must agree with them.
60
+ */
61
+ requireBoundTokens?: boolean;
62
+ /**
63
+ * Receives each refused token's rule code and issuer alias, never the token or a claim value.
64
+ * Default: a `console.warn` line.
65
+ */
66
+ onRefusal?: (refusal: AuthRefusal) => void;
67
+ /** Scopes every request needs, checked before a call's own (M6). Default: none. */
68
+ requiredScopes?: readonly string[];
69
+ /**
70
+ * Decides every call instead of the static rule (a command's `scopes`); `requiredScopes`
71
+ * still apply. Default: none, the static rule.
72
+ */
73
+ resolver?: ScopeResolver;
74
+ /**
75
+ * List only what the caller may use (M6, "Listing"): `tools/list`, `afd-discover`,
76
+ * `afd-detail`, `afd-help`, `afd-docs`, `afd-schema` and grouped actions, with `tools/list`
77
+ * then `cacheScope: "private"`. With a `resolver`, a command its `known` rejects does not exist
78
+ * for the caller on any route (M6, "Hidden commands"). Default: `false`.
79
+ */
80
+ filterToolsByScope?: boolean;
81
+ }
82
+ /** What the server tells the layer about its own commands, for the scope decisions. */
83
+ export interface AuthLayerContext {
84
+ maxBodyBytes: number;
85
+ clock?: Clock;
86
+ /** The MCP-exposed commands, built-ins included. */
87
+ commands: readonly ZodCommandDefinition[];
88
+ toolStrategy: ToolStrategy;
89
+ groupByFn?: GroupByFn;
90
+ }
91
+ /** What `handler.preDispatchCheck` takes: how a host's 403 is spelled. */
92
+ export interface PreDispatchCheckOptions {
93
+ /** The 403's challenge in the host's own scheme, instead of M5's `Bearer` one. */
94
+ challenge?: ScopeChallenge;
95
+ /**
96
+ * What a caller obtains to gain a scope, in the 403's suggestion ("Obtain `<scopeSource>`
97
+ * that also grants ..."). Default: "a token for `<resource>`".
98
+ */
99
+ scopeSource?: string;
100
+ }
101
+ /**
102
+ * The decision before dispatch for a host's own layer (`spec/authorization.md`, M6): the bearer
103
+ * layer's own implementation, so the two cannot drift.
104
+ */
105
+ export interface PreDispatchCheck {
106
+ /** The largest body the decision reads; read at most this many bytes, plus one, before it. */
107
+ readonly maxBodyBytes: number;
108
+ /**
109
+ * Decide `req`, whose body the host has read (`body`, as bytes or text), after admitting its
110
+ * credentials with `handler.admit`. Pass the request on (with the body, as the handler's
111
+ * third argument) only on `{ proceed: true }`; otherwise answer with the response given: the
112
+ * 403 naming every missing scope, the 400 for a JSON-RPC batch, or the 413 for a body over
113
+ * `maxBodyBytes`. A request without credentials admitted for this handler, a method other
114
+ * than `POST`, and a body that cannot be parsed proceed, to be decided after routing.
115
+ */
116
+ decide(req: IncomingMessage, body: Uint8Array | string): PreDispatch;
117
+ }
118
+ /** The default actor of a verified call (M4), when `createContext` maps none. */
119
+ export declare function credentialsActor(credentials: Credentials): Actor;
120
+ /** The layer one HTTP handler runs before its routes. */
121
+ export interface AuthLayer {
122
+ readonly protectedResource: ProtectedResource;
123
+ /** Whether the listings are filtered by scope (`filterToolsByScope`). */
124
+ readonly filterToolsByScope: boolean;
125
+ /**
126
+ * Serve the metadata, or verify the request's token. `true` when the request may go on to its
127
+ * route with credentials admitted; `false` when the layer answered it.
128
+ */
129
+ admit(req: IncomingMessage, res: ServerResponse, url: URL): Promise<boolean>;
130
+ /**
131
+ * The credentials this layer admitted for `req`.
132
+ *
133
+ * @throws HttpRequestError 401 when it admitted none (M1: fail closed)
134
+ */
135
+ credentialsFor(req: IncomingMessage): Credentials;
136
+ /** The scope view of an admitted request, decided once as it arrived. */
137
+ viewFor(req: IncomingMessage): ScopeView | undefined;
138
+ /**
139
+ * Admit `credentials` a host's own layer vouches for, for `req` alone (`handler.admit`).
140
+ *
141
+ * @throws Error when `req` carries a bearer token or was admitted before, or the credentials
142
+ * fail the checks a verifier's do
143
+ */
144
+ hostAdmit(req: IncomingMessage, credentials: Credentials): void;
145
+ /** The decision before dispatch for a host's own layer (`handler.preDispatchCheck`). */
146
+ preDispatchCheck(options?: PreDispatchCheckOptions): PreDispatchCheck;
147
+ }
148
+ /**
149
+ * The authorization layer of one HTTP handler.
150
+ *
151
+ * @throws Error for invalid options: the resource, an authorization server or a published scope
152
+ * malformed; a verifier missing or whose rules name another resource or binding requirement;
153
+ * a required scope or a command's declared scope that is not a scope token; a resolver without
154
+ * `resolve` and `visible`
155
+ */
156
+ export declare function createAuthLayer(options: McpAuthOptions, server: AuthLayerContext): AuthLayer;
157
+ //# sourceMappingURL=mcp-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-auth.d.ts","sourceRoot":"","sources":["../src/mcp-auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,KAAK,EAAe,MAAM,sBAAsB,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAStD,OAAO,EAMN,KAAK,WAAW,EAChB,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAGN,KAAK,iBAAiB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