@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.
- package/README.md +468 -6
- package/dist/approval-crypto.d.ts +26 -4
- package/dist/approval-crypto.d.ts.map +1 -1
- package/dist/approval-crypto.js +90 -7
- package/dist/approval-crypto.js.map +1 -1
- package/dist/approval-relay.d.ts +5 -5
- package/dist/approval-relay.d.ts.map +1 -1
- package/dist/approval.d.ts +6 -1
- package/dist/approval.d.ts.map +1 -1
- package/dist/approval.js +43 -32
- package/dist/approval.js.map +1 -1
- package/dist/bootstrap/afd-context.d.ts +2 -27
- package/dist/bootstrap/afd-context.d.ts.map +1 -1
- package/dist/bootstrap/afd-context.js +6 -36
- package/dist/bootstrap/afd-context.js.map +1 -1
- package/dist/bootstrap/afd-help.d.ts +24 -2
- package/dist/bootstrap/afd-help.d.ts.map +1 -1
- package/dist/bootstrap/afd-help.js +17 -2
- package/dist/bootstrap/afd-help.js.map +1 -1
- package/dist/bootstrap/described-command.d.ts +1 -0
- package/dist/bootstrap/described-command.d.ts.map +1 -1
- package/dist/bootstrap/described-command.js.map +1 -1
- package/dist/bootstrap/registry.d.ts +13 -0
- package/dist/bootstrap/registry.d.ts.map +1 -1
- package/dist/bootstrap/registry.js +30 -1
- package/dist/bootstrap/registry.js.map +1 -1
- package/dist/command-allow.d.ts +31 -0
- package/dist/command-allow.d.ts.map +1 -0
- package/dist/command-allow.js +55 -0
- package/dist/command-allow.js.map +1 -0
- package/dist/command-names.d.ts +17 -0
- package/dist/command-names.d.ts.map +1 -1
- package/dist/command-names.js +55 -0
- package/dist/command-names.js.map +1 -1
- package/dist/command-routing.d.ts +10 -3
- package/dist/command-routing.d.ts.map +1 -1
- package/dist/command-routing.js +18 -7
- package/dist/command-routing.js.map +1 -1
- package/dist/confirmation-gate.d.ts +32 -0
- package/dist/confirmation-gate.d.ts.map +1 -0
- package/dist/confirmation-gate.js +140 -0
- package/dist/confirmation-gate.js.map +1 -0
- package/dist/confirmations.d.ts +15 -23
- package/dist/confirmations.d.ts.map +1 -1
- package/dist/confirmations.js +8 -127
- package/dist/confirmations.js.map +1 -1
- package/dist/context-fields-describe.d.ts +18 -0
- package/dist/context-fields-describe.d.ts.map +1 -0
- package/dist/context-fields-describe.js +17 -0
- package/dist/context-fields-describe.js.map +1 -0
- package/dist/context-fields.d.ts +50 -0
- package/dist/context-fields.d.ts.map +1 -0
- package/dist/context-fields.js +146 -0
- package/dist/context-fields.js.map +1 -0
- package/dist/context-scope.d.ts +29 -2
- package/dist/context-scope.d.ts.map +1 -1
- package/dist/context-scope.js +37 -1
- package/dist/context-scope.js.map +1 -1
- package/dist/credentials.d.ts +17 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +16 -0
- package/dist/credentials.js.map +1 -0
- package/dist/define-core.d.ts +213 -0
- package/dist/define-core.d.ts.map +1 -0
- package/dist/define-core.js +161 -0
- package/dist/define-core.js.map +1 -0
- package/dist/define.d.ts +13 -8
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +13 -8
- package/dist/define.js.map +1 -1
- package/dist/direct-registry.d.ts +154 -7
- package/dist/direct-registry.d.ts.map +1 -1
- package/dist/direct-registry.js +111 -13
- package/dist/direct-registry.js.map +1 -1
- package/dist/direct-tool-surface.d.ts +66 -0
- package/dist/direct-tool-surface.d.ts.map +1 -0
- package/dist/direct-tool-surface.js +162 -0
- package/dist/direct-tool-surface.js.map +1 -0
- package/dist/direct.d.ts +68 -0
- package/dist/direct.d.ts.map +1 -0
- package/dist/direct.js +66 -0
- package/dist/direct.js.map +1 -0
- package/dist/execution.d.ts +11 -1
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +18 -4
- package/dist/execution.js.map +1 -1
- package/dist/frontmatter.d.ts +16 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +111 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/http-handler.d.ts +11 -2
- package/dist/http-handler.d.ts.map +1 -1
- package/dist/http-handler.js +46 -15
- package/dist/http-handler.js.map +1 -1
- package/dist/http-security.d.ts.map +1 -1
- package/dist/http-security.js.map +1 -1
- package/dist/http-sessions.d.ts +12 -4
- package/dist/http-sessions.d.ts.map +1 -1
- package/dist/http-sessions.js +4 -4
- package/dist/http-sessions.js.map +1 -1
- package/dist/http-sse.js.map +1 -1
- package/dist/index.d.ts +16 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/dist/issue-message.d.ts +20 -0
- package/dist/issue-message.d.ts.map +1 -0
- package/dist/issue-message.js +55 -0
- package/dist/issue-message.js.map +1 -0
- package/dist/journal-replay.d.ts +7 -0
- package/dist/journal-replay.d.ts.map +1 -1
- package/dist/journal-replay.js +18 -1
- package/dist/journal-replay.js.map +1 -1
- package/dist/journal.d.ts +9 -1
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +44 -1
- package/dist/journal.js.map +1 -1
- package/dist/json-rpc.d.ts +2 -2
- package/dist/json-rpc.d.ts.map +1 -1
- package/dist/json-rpc.js.map +1 -1
- package/dist/json-schema.d.ts +30 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +25 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/lazy-tools.d.ts +3 -0
- package/dist/lazy-tools.d.ts.map +1 -1
- package/dist/lazy-tools.js +2 -0
- package/dist/lazy-tools.js.map +1 -1
- package/dist/mcp-auth-bearer.d.ts +23 -0
- package/dist/mcp-auth-bearer.d.ts.map +1 -0
- package/dist/mcp-auth-bearer.js +50 -0
- package/dist/mcp-auth-bearer.js.map +1 -0
- package/dist/mcp-auth-jwt.d.ts +178 -0
- package/dist/mcp-auth-jwt.d.ts.map +1 -0
- package/dist/mcp-auth-jwt.js +365 -0
- package/dist/mcp-auth-jwt.js.map +1 -0
- package/dist/mcp-auth-resource.d.ts +74 -0
- package/dist/mcp-auth-resource.d.ts.map +1 -0
- package/dist/mcp-auth-resource.js +196 -0
- package/dist/mcp-auth-resource.js.map +1 -0
- package/dist/mcp-auth-rules.d.ts +135 -0
- package/dist/mcp-auth-rules.d.ts.map +1 -0
- package/dist/mcp-auth-rules.js +306 -0
- package/dist/mcp-auth-rules.js.map +1 -0
- package/dist/mcp-auth.d.ts +81 -0
- package/dist/mcp-auth.d.ts.map +1 -0
- package/dist/mcp-auth.js +256 -0
- package/dist/mcp-auth.js.map +1 -0
- package/dist/mcp-modern.d.ts +29 -5
- package/dist/mcp-modern.d.ts.map +1 -1
- package/dist/mcp-modern.js +99 -19
- package/dist/mcp-modern.js.map +1 -1
- package/dist/meta-argument.d.ts +42 -0
- package/dist/meta-argument.d.ts.map +1 -0
- package/dist/meta-argument.js +102 -0
- package/dist/meta-argument.js.map +1 -0
- package/dist/meta-keys.d.ts +29 -0
- package/dist/meta-keys.d.ts.map +1 -0
- package/dist/meta-keys.js +90 -0
- package/dist/meta-keys.js.map +1 -0
- package/dist/meta-tools.d.ts +8 -1
- package/dist/meta-tools.d.ts.map +1 -1
- package/dist/meta-tools.js +17 -7
- package/dist/meta-tools.js.map +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +0 -1
- package/dist/middleware.js.map +1 -1
- package/dist/patterns.d.ts +46 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +38 -0
- package/dist/patterns.js.map +1 -0
- package/dist/principal-binding.d.ts +42 -0
- package/dist/principal-binding.d.ts.map +1 -0
- package/dist/principal-binding.js +70 -0
- package/dist/principal-binding.js.map +1 -0
- package/dist/request-context.d.ts +7 -1
- package/dist/request-context.d.ts.map +1 -1
- package/dist/request-context.js +14 -3
- package/dist/request-context.js.map +1 -1
- package/dist/resources.d.ts +122 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +256 -0
- package/dist/resources.js.map +1 -0
- package/dist/schema.d.ts +7 -171
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +10 -135
- package/dist/schema.js.map +1 -1
- package/dist/server-types.d.ts +94 -7
- package/dist/server-types.d.ts.map +1 -1
- package/dist/server-types.js +2 -0
- package/dist/server-types.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +45 -31
- package/dist/server.js.map +1 -1
- package/dist/skills.d.ts +95 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +340 -0
- package/dist/skills.js.map +1 -0
- package/dist/strict-json.d.ts +17 -0
- package/dist/strict-json.d.ts.map +1 -0
- package/dist/strict-json.js +93 -0
- package/dist/strict-json.js.map +1 -0
- package/dist/tool-router.d.ts +13 -1
- package/dist/tool-router.d.ts.map +1 -1
- package/dist/tool-router.js +44 -10
- package/dist/tool-router.js.map +1 -1
- package/dist/tools.d.ts +10 -5
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +48 -22
- package/dist/tools.js.map +1 -1
- package/dist/validation.d.ts +6 -45
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +25 -58
- package/dist/validation.js.map +1 -1
- package/dist/verified-credentials.d.ts +34 -0
- package/dist/verified-credentials.d.ts.map +1 -0
- package/dist/verified-credentials.js +51 -0
- package/dist/verified-credentials.js.map +1 -0
- package/package.json +18 -6
package/dist/schema.js
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* This module provides utilities for defining commands using Zod schemas,
|
|
5
5
|
* with automatic JSON Schema generation for MCP tool definitions.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import { $ZodObject } from 'zod/v4/core';
|
|
8
|
+
import { defineCommandWithSchema, } from './define-core.js';
|
|
9
|
+
import { zodToJsonSchema } from './json-schema.js';
|
|
10
|
+
export { defineCommandWithSchema, jsonSchemaToParameters, } from './define-core.js';
|
|
11
|
+
export { zodToJsonSchema } from './json-schema.js';
|
|
12
12
|
/**
|
|
13
13
|
* Define a command with Zod schema for type-safe input validation.
|
|
14
14
|
*
|
|
@@ -34,139 +34,14 @@ import { z } from 'zod';
|
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
export function defineCommand(options) {
|
|
37
|
-
const nameCheck = validateCommandName(options.name);
|
|
38
|
-
if (!nameCheck.valid) {
|
|
39
|
-
console.warn(`[AFD] ${nameCheck.reason}`);
|
|
40
|
-
}
|
|
41
37
|
// Input schemas describe what a caller may send (defaults optional, transforms by their
|
|
42
|
-
// input type); output schemas describe what the handler returns.
|
|
43
|
-
|
|
38
|
+
// input type); output schemas describe what the handler returns. An advertised schema is not
|
|
39
|
+
// converted: it replaces the generated one on every surface.
|
|
40
|
+
const jsonSchema = options.advertisedInputSchema ?? zodToJsonSchema(options.input, { io: 'input' });
|
|
44
41
|
const outputJsonSchema = options.output
|
|
45
42
|
? zodToJsonSchema(options.output, { io: 'output' })
|
|
46
43
|
: undefined;
|
|
47
|
-
|
|
48
|
-
const tags = buildHandoffTags(options.tags, options.handoff, options.handoffProtocol);
|
|
49
|
-
// Validate examples against input schema at define-time
|
|
50
|
-
if (options.examples) {
|
|
51
|
-
for (const example of options.examples) {
|
|
52
|
-
const parsed = options.input.safeParse(example.input);
|
|
53
|
-
if (!parsed.success) {
|
|
54
|
-
const issues = parsed.error.issues
|
|
55
|
-
.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`)
|
|
56
|
-
.join(', ');
|
|
57
|
-
throw new Error(`Example "${example.title}" for command "${options.name}" fails schema validation: ${issues}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
name: options.name,
|
|
63
|
-
description: options.description,
|
|
64
|
-
inputSchema: options.input,
|
|
65
|
-
jsonSchema,
|
|
66
|
-
handler: options.handler,
|
|
67
|
-
category: options.category,
|
|
68
|
-
mutation: options.mutation,
|
|
69
|
-
version: options.version,
|
|
70
|
-
tags,
|
|
71
|
-
requires: options.requires,
|
|
72
|
-
executionTime: options.executionTime,
|
|
73
|
-
errors: options.errors,
|
|
74
|
-
handoff: options.handoff,
|
|
75
|
-
handoffProtocol: options.handoffProtocol,
|
|
76
|
-
destructive: options.destructive,
|
|
77
|
-
confirmPrompt: options.confirmPrompt,
|
|
78
|
-
undoable: options.undoable,
|
|
79
|
-
approval: options.approval,
|
|
80
|
-
expose: options.expose,
|
|
81
|
-
examples: options.examples,
|
|
82
|
-
outputSchema: options.output,
|
|
83
|
-
outputJsonSchema,
|
|
84
|
-
contexts: options.contexts,
|
|
85
|
-
toCommandDefinition() {
|
|
86
|
-
return {
|
|
87
|
-
name: options.name,
|
|
88
|
-
description: options.description,
|
|
89
|
-
category: options.category,
|
|
90
|
-
mutation: options.mutation,
|
|
91
|
-
version: options.version,
|
|
92
|
-
tags,
|
|
93
|
-
requires: options.requires,
|
|
94
|
-
executionTime: options.executionTime,
|
|
95
|
-
errors: options.errors,
|
|
96
|
-
handoff: options.handoff,
|
|
97
|
-
handoffProtocol: options.handoffProtocol,
|
|
98
|
-
destructive: options.destructive,
|
|
99
|
-
confirmPrompt: options.confirmPrompt,
|
|
100
|
-
undoable: options.undoable,
|
|
101
|
-
approval: options.approval,
|
|
102
|
-
expose: options.expose,
|
|
103
|
-
// Examples are raw inputs (before defaults and transforms); core types them by the
|
|
104
|
-
// handler input, which differs only for schemas with defaults or transforms.
|
|
105
|
-
examples: options.examples,
|
|
106
|
-
contexts: options.contexts,
|
|
107
|
-
parameters: jsonSchemaToParameters(jsonSchema),
|
|
108
|
-
returns: outputJsonSchema,
|
|
109
|
-
handler: options.handler,
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Build tags array with automatic handoff tags if handoff is enabled.
|
|
116
|
-
* Adds 'handoff' tag and optionally 'handoff:{protocol}' tag.
|
|
117
|
-
*/
|
|
118
|
-
function buildHandoffTags(existingTags, handoff, handoffProtocol) {
|
|
119
|
-
if (!handoff) {
|
|
120
|
-
return existingTags;
|
|
121
|
-
}
|
|
122
|
-
const tags = new Set(existingTags ?? []);
|
|
123
|
-
tags.add('handoff');
|
|
124
|
-
if (handoffProtocol) {
|
|
125
|
-
tags.add(`handoff:${handoffProtocol}`);
|
|
126
|
-
}
|
|
127
|
-
return Array.from(tags);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Convert a Zod schema to JSON Schema (draft-7).
|
|
131
|
-
*
|
|
132
|
-
* @param schema - Zod schema to convert
|
|
133
|
-
* @param options - Conversion options; `io` defaults to `'input'`
|
|
134
|
-
* @returns JSON Schema representation
|
|
135
|
-
*/
|
|
136
|
-
export function zodToJsonSchema(schema, options = {}) {
|
|
137
|
-
const result = z.toJSONSchema(schema, { target: 'draft-7', io: options.io ?? 'input' });
|
|
138
|
-
if (typeof result === 'object' && result !== null) {
|
|
139
|
-
const { $schema, ...rest } = result;
|
|
140
|
-
const jsonSchema = rest;
|
|
141
|
-
if (!jsonSchema.type) {
|
|
142
|
-
return { type: 'object', ...rest };
|
|
143
|
-
}
|
|
144
|
-
return jsonSchema;
|
|
145
|
-
}
|
|
146
|
-
return { type: 'object' };
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Convert JSON Schema to CommandParameter array for @lushly-dev/afd-core compatibility.
|
|
150
|
-
*/
|
|
151
|
-
export function jsonSchemaToParameters(schema) {
|
|
152
|
-
const parameters = [];
|
|
153
|
-
if (schema.type === 'object' && schema.properties) {
|
|
154
|
-
// Handle required - it might be an array or undefined
|
|
155
|
-
const requiredFields = Array.isArray(schema.required) ? schema.required : [];
|
|
156
|
-
for (const [name, propSchema] of Object.entries(schema.properties)) {
|
|
157
|
-
const prop = propSchema;
|
|
158
|
-
parameters.push({
|
|
159
|
-
name,
|
|
160
|
-
type: prop.type ?? 'string',
|
|
161
|
-
description: prop.description ?? `Parameter: ${name}`,
|
|
162
|
-
required: requiredFields.includes(name),
|
|
163
|
-
default: prop.default,
|
|
164
|
-
enum: prop.enum,
|
|
165
|
-
schema: prop,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return parameters;
|
|
44
|
+
return defineCommandWithSchema({ ...options, jsonSchema, outputJsonSchema });
|
|
170
45
|
}
|
|
171
46
|
/**
|
|
172
47
|
* Get the field names a caller must provide for a Zod object schema.
|
|
@@ -181,6 +56,6 @@ export function getRequiredFields(schema) {
|
|
|
181
56
|
* Check if a Zod schema represents an object type.
|
|
182
57
|
*/
|
|
183
58
|
export function isObjectSchema(schema) {
|
|
184
|
-
return schema instanceof
|
|
59
|
+
return schema instanceof $ZodObject;
|
|
185
60
|
}
|
|
186
61
|
//# sourceMappingURL=schema.js.map
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,UAAU,EAAiB,MAAM,aAAa,CAAC;AACxD,OAAO,EACN,uBAAuB,GAGvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EACN,uBAAuB,EACvB,sBAAsB,GAGtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAA+B,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,aAAa,CAC5B,OAA2C;IAE3C,wFAAwF;IACxF,6FAA6F;IAC7F,6DAA6D;IAC7D,MAAM,UAAU,GACf,OAAO,CAAC,qBAAqB,IAAI,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAClF,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM;QACtC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;QACnD,CAAC,CAAC,SAAS,CAAC;IAEb,OAAO,uBAAuB,CAAC,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC,CAAC;AAC9E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAgB;IACjD,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5D,sDAAsD;IACtD,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;AACtE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAe;IAC7C,OAAO,MAAM,YAAY,UAAU,CAAC;AACrC,CAAC"}
|
package/dist/server-types.d.ts
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
5
|
import type { Actor, Clock, CommandContext, CommandMiddleware, CommandResult, PipelineRequest, PipelineResult, RandomSource } from '@lushly-dev/afd-core';
|
|
6
|
+
import type { ContextField } from './context-fields.js';
|
|
7
|
+
import type { McpAuthOptions } from './mcp-auth.js';
|
|
8
|
+
import type { Credentials } from './mcp-auth-rules.js';
|
|
9
|
+
import type { ResourcesOption } from './resources.js';
|
|
6
10
|
import type { ZodCommandDefinition } from './schema.js';
|
|
11
|
+
import type { SkillCatalog } from './skills.js';
|
|
7
12
|
/**
|
|
8
13
|
* Transport type for MCP server.
|
|
9
14
|
*
|
|
@@ -21,6 +26,10 @@ export type McpTransport = 'stdio' | 'http' | 'auto';
|
|
|
21
26
|
* @returns true if stdin is a pipe (not interactive), false if it's a TTY
|
|
22
27
|
*/
|
|
23
28
|
export declare function isStdinPiped(): boolean;
|
|
29
|
+
/** How an MCP server lists its commands as tools (`McpServerOptions.toolStrategy`). */
|
|
30
|
+
export type ToolStrategy = 'individual' | 'grouped' | 'lazy' | 'hybrid';
|
|
31
|
+
/** The most first-class tools a hybrid server lists (`spec/tool-strategies.md`, H5). */
|
|
32
|
+
export declare const MAX_FIRST_CLASS_TOOLS = 8;
|
|
24
33
|
/**
|
|
25
34
|
* MCP Server configuration options.
|
|
26
35
|
*/
|
|
@@ -69,6 +78,23 @@ export interface McpServerOptions {
|
|
|
69
78
|
* every remotely executed command. Use it to pass the authenticated user or the remote
|
|
70
79
|
* address to middleware such as `createRateLimitMiddleware`. Not called for stdio.
|
|
71
80
|
*
|
|
81
|
+
* Its `actor`, and `credentials` (`{ issuer, subject, clientId }` of a token the host
|
|
82
|
+
* verified), are the call's principal: the `requestState` of a confirmation or approval
|
|
83
|
+
* elicitation is bound to them (`principalBinding`, #532), so an answer one caller gave never
|
|
84
|
+
* counts for another. Set them only from what the host verified, never from a header a caller
|
|
85
|
+
* can send. `credentials` without a non-empty `issuer`, `subject` and `clientId` fail such a
|
|
86
|
+
* call with an internal error. The SDK's own `authInfo` contributes only its `clientId`: a
|
|
87
|
+
* host that authenticates people through the SDK must copy their identity into `credentials`
|
|
88
|
+
* (or the `actor`), or every user of one client shares a binding.
|
|
89
|
+
*
|
|
90
|
+
* Credentials set here are the host's, not afd-server's: `isVerifiedCredentials` does not
|
|
91
|
+
* recognise them, so afd-auth's middleware still gates such a call on its own session.
|
|
92
|
+
*
|
|
93
|
+
* With `auth`, it is given the request's verified `credentials` as its second argument, and
|
|
94
|
+
* maps them to the `actor` (M4); the `credentials` it returns are ignored, since only the
|
|
95
|
+
* server sets them. Without an `actor` from it, the actor is `{ kind: 'agent', id: <clientId>,
|
|
96
|
+
* onBehalfOf: <subject> }`. The `Authorization` header is gone from `req` by then.
|
|
97
|
+
*
|
|
72
98
|
* @example
|
|
73
99
|
* ```typescript
|
|
74
100
|
* createContext: (req) => ({ clientId: req.socket.remoteAddress ?? 'unknown' }),
|
|
@@ -77,6 +103,26 @@ export interface McpServerOptions {
|
|
|
77
103
|
* ```
|
|
78
104
|
*/
|
|
79
105
|
createContext?: CreateRequestContext;
|
|
106
|
+
/**
|
|
107
|
+
* MCP authorization (`spec/authorization.md`, M1 to M5 and M7): the server becomes an OAuth
|
|
108
|
+
* 2.1 protected resource. Every HTTP route (`/mcp`, `/sse`, `/message`, `/rpc`, `/batch`,
|
|
109
|
+
* `/stream`, `/health` and any other path) then needs exactly one valid bearer token in the
|
|
110
|
+
* `Authorization` header, verified by `auth.verifier` (`JwtVerifier`, with the audience
|
|
111
|
+
* always checked); a request without one is answered 401 with M5's challenge and body. Only
|
|
112
|
+
* the RFC 9728 metadata, served at its two well-known paths, and CORS preflights are public.
|
|
113
|
+
* stdio, `server.execute` and in-process registries are unaffected.
|
|
114
|
+
*
|
|
115
|
+
* Each call's context carries the verified `credentials` (never the token), frozen, and
|
|
116
|
+
* recognised by `isVerifiedCredentials` until the request ends or they expire. **A host that
|
|
117
|
+
* also runs afd-auth's middleware passes `isVerifiedCredentials` to it**
|
|
118
|
+
* (`createAuthMiddleware(adapter, { isVerifiedCredentials })`, from
|
|
119
|
+
* `@lushly-dev/afd-server/credentials`), so a token's call keeps the actor its credentials
|
|
120
|
+
* map to instead of being gated on the adapter's session.
|
|
121
|
+
*
|
|
122
|
+
* Scopes (M6: `requiredScopes`, `resolver`, `filterToolsByScope`) are not enforced by this
|
|
123
|
+
* version; passing one throws rather than being ignored.
|
|
124
|
+
*/
|
|
125
|
+
auth?: McpAuthOptions;
|
|
80
126
|
/** Maximum concurrent `/sse` connections; more receive HTTP 503 (default: 100). */
|
|
81
127
|
maxSseConnections?: number;
|
|
82
128
|
/**
|
|
@@ -93,6 +139,12 @@ export interface McpServerOptions {
|
|
|
93
139
|
clock?: Clock;
|
|
94
140
|
/** Random source given to handlers as `context.random` when the context has none. Default: `systemRandom`. */
|
|
95
141
|
random?: RandomSource;
|
|
142
|
+
/**
|
|
143
|
+
* Request values the host declares (`spec/context-fields.md`): each one's context key, `_meta`
|
|
144
|
+
* key, schema, and whether the journal keeps it. A call's value is validated before middleware
|
|
145
|
+
* runs, and an invalid or missing required one fails the call with `VALIDATION_ERROR`.
|
|
146
|
+
*/
|
|
147
|
+
contextFields?: readonly ContextField[];
|
|
96
148
|
/**
|
|
97
149
|
* Actor for commands called over MCP (stdio or HTTP) when the context has none.
|
|
98
150
|
* Default: `{ kind: 'agent' }`. `createContext` can set a per-request `actor`, and auth
|
|
@@ -109,7 +161,8 @@ export interface McpServerOptions {
|
|
|
109
161
|
* Freshness hint, in milliseconds, for `tools/list` and `server/discover` results on the
|
|
110
162
|
* MCP 2026-07-28 lane (`ttlMs`, with `cacheScope: "public"`). Default: 300000 (5 minutes),
|
|
111
163
|
* or 0 when `contexts` are configured, because MCP clients cache `tools/list` without its
|
|
112
|
-
* `_meta` and a context-scoped list would be served from the unscoped entry.
|
|
164
|
+
* `_meta` and a context-scoped list would be served from the unscoped entry. The hybrid
|
|
165
|
+
* strategy keeps 300000 under `contexts`: its list does not vary by context. Set 0 when the
|
|
113
166
|
* command set changes at runtime.
|
|
114
167
|
*/
|
|
115
168
|
toolsListTtlMs?: number;
|
|
@@ -140,7 +193,8 @@ export interface McpServerOptions {
|
|
|
140
193
|
*/
|
|
141
194
|
confirmations?: 'off' | 'enforce' | 'require-human';
|
|
142
195
|
/**
|
|
143
|
-
* HMAC key (at least 32 bytes) that signs the `requestState` of confirmation
|
|
196
|
+
* HMAC key (at least 32 bytes) that signs the `requestState` of confirmation and approval
|
|
197
|
+
* elicitations, bound to the call's principal (see `createContext`). Every
|
|
144
198
|
* instance that may receive a retry needs the same key. Without it, each process uses a random
|
|
145
199
|
* key, which works only when one process serves every request.
|
|
146
200
|
*/
|
|
@@ -178,18 +232,28 @@ export interface McpServerOptions {
|
|
|
178
232
|
/** Called on server errors */
|
|
179
233
|
onError?: (error: Error) => void;
|
|
180
234
|
/**
|
|
181
|
-
* Tool strategy for MCP tool listing. `afd-call`, `afd-batch`
|
|
182
|
-
* listed in every strategy.
|
|
235
|
+
* Tool strategy for MCP tool listing (`spec/tool-strategies.md`). `afd-call`, `afd-batch`
|
|
236
|
+
* and `afd-pipe` are listed in every strategy.
|
|
183
237
|
* - "grouped" (default): one tool per group (category, or the first name segment)
|
|
184
238
|
* taking `{ action, params }`. Each grouped tool's `_meta.actions` carries every
|
|
185
239
|
* action's command name, input schema and metadata; small groups also inline the
|
|
186
240
|
* per-action schemas as `params.anyOf`. `afd-detail` is listed too.
|
|
187
241
|
* - "individual": each command is its own tool, with its input schema and `_meta`
|
|
188
242
|
* - "lazy": only the afd-discover and afd-detail meta-tools (plus the three above)
|
|
243
|
+
* - "hybrid": the five meta-tools, the context tools when `contexts` are configured, then
|
|
244
|
+
* the commands named by `firstClassTools` as individual tools. The list never varies by
|
|
245
|
+
* context and never changes while the server runs.
|
|
189
246
|
*
|
|
190
247
|
* @default "grouped"
|
|
191
248
|
*/
|
|
192
|
-
toolStrategy?:
|
|
249
|
+
toolStrategy?: ToolStrategy;
|
|
250
|
+
/**
|
|
251
|
+
* The commands the `"hybrid"` strategy lists as their own tools, in list order: at most
|
|
252
|
+
* {@link MAX_FIRST_CLASS_TOOLS}, each registered and MCP-exposed, none a meta-tool or context
|
|
253
|
+
* tool, none repeated. Required, and not empty, with `toolStrategy: "hybrid"`; refused with any
|
|
254
|
+
* other strategy. Server creation throws on a mistake, naming the entry.
|
|
255
|
+
*/
|
|
256
|
+
firstClassTools?: string[];
|
|
193
257
|
/**
|
|
194
258
|
* Custom function to derive group name from command.
|
|
195
259
|
* Used when toolStrategy is "grouped".
|
|
@@ -214,6 +278,24 @@ export interface McpServerOptions {
|
|
|
214
278
|
* @default false
|
|
215
279
|
*/
|
|
216
280
|
bootstrap?: boolean;
|
|
281
|
+
/**
|
|
282
|
+
* MCP resources (`spec/mcp-resources.md`, R1 to R6): a {@link ResourceProvider}, or an array of
|
|
283
|
+
* static entries. The server then declares the `resources` capability and answers
|
|
284
|
+
* `resources/list`, `resources/read` and `resources/templates/list` on `/mcp` and stdio, in
|
|
285
|
+
* both MCP eras. A list never varies by connection, session or context. Entries are checked
|
|
286
|
+
* when the server is built, and creation throws naming the entry that breaks a rule. A
|
|
287
|
+
* `ui://` entry needs the `text/html;profile=mcp-app` MIME type; its `_meta.ui` goes on the
|
|
288
|
+
* content a read returns. The deprecated `/sse` and `/message` lane serves none of this.
|
|
289
|
+
*/
|
|
290
|
+
resources?: ResourcesOption;
|
|
291
|
+
/**
|
|
292
|
+
* Agent Skills served over MCP (`spec/mcp-resources.md`, S1 to S8): a {@link SkillCatalog}, fixed
|
|
293
|
+
* when it is built. The server declares the `io.modelcontextprotocol/skills` extension and
|
|
294
|
+
* `resources`, answers `skills/list` and `skills/get`, and serves every skill file as a
|
|
295
|
+
* resource (`skill://<path>/<file>`) with its `dev.afd/digest`. `new SkillCatalog(skills, {
|
|
296
|
+
* directoryRead: true })` also serves `resources/directory/read`.
|
|
297
|
+
*/
|
|
298
|
+
skills?: SkillCatalog;
|
|
217
299
|
}
|
|
218
300
|
/**
|
|
219
301
|
* Options for creating an embeddable Node HTTP handler without starting a server.
|
|
@@ -237,14 +319,17 @@ export interface ContextConfig {
|
|
|
237
319
|
export type { CommandMiddleware } from '@lushly-dev/afd-core';
|
|
238
320
|
/**
|
|
239
321
|
* Derive per-request `CommandContext` values from an HTTP request, for example the
|
|
240
|
-
* authenticated user or the remote address.
|
|
322
|
+
* authenticated user or the remote address. On a server with `auth`, `verified.credentials` are
|
|
323
|
+
* the request's verified credentials, to map to an `actor`.
|
|
241
324
|
*
|
|
242
325
|
* The returned object is merged into the context of every command the request executes
|
|
243
326
|
* (`tools/call`, `afd-call`, batch items, pipeline steps, `/rpc`, `/batch` and `/stream`).
|
|
244
327
|
* The reserved keys `traceId`, `signal` and `interface` are set by the server and ignored if
|
|
245
328
|
* returned. A throw is reported to `onError` and answered as an internal error.
|
|
246
329
|
*/
|
|
247
|
-
export type CreateRequestContext = (req: IncomingMessage
|
|
330
|
+
export type CreateRequestContext = (req: IncomingMessage, verified: {
|
|
331
|
+
credentials?: Credentials;
|
|
332
|
+
}) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
248
333
|
/**
|
|
249
334
|
* Embeddable Node HTTP handler returned by `createMcpHandler()`.
|
|
250
335
|
*/
|
|
@@ -265,6 +350,8 @@ export interface McpServer {
|
|
|
265
350
|
getUrl(): string;
|
|
266
351
|
/** Get registered commands */
|
|
267
352
|
getCommands(): ZodCommandDefinition[];
|
|
353
|
+
/** The declared context fields, so `replayJournal` can tell which recorded values still apply. */
|
|
354
|
+
readonly contextFields: readonly ContextField[];
|
|
268
355
|
/**
|
|
269
356
|
* Get the resolved transport mode.
|
|
270
357
|
* Useful for debugging and logging.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-types.d.ts","sourceRoot":"","sources":["../src/server-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EACX,KAAK,EACL,KAAK,EACL,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,cAAc,EACd,YAAY,EACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"server-types.d.ts","sourceRoot":"","sources":["../src/server-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EACX,KAAK,EACL,KAAK,EACL,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,cAAc,EACd,YAAY,EACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAA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C,CAAC;IAEvB,sBAAsB;IACtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB,8DAA8D;IAC9D,MAAM,IAAI,MAAM,CAAC;IAEjB,8BAA8B;IAC9B,WAAW,IAAI,oBAAoB,EAAE,CAAC;IAEtC,kGAAkG;IAClG,QAAQ,CAAC,aAAa,EAAE,SAAS,YAAY,EAAE,CAAC;IAEhD;;;OAGG;IACH,YAAY,IAAI,OAAO,GAAG,MAAM,CAAC;IAEjC,+CAA+C;IAC/C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAExF;;;;;;OAMG;IACH,eAAe,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC7F"}
|
package/dist/server-types.js
CHANGED
package/dist/server-types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-types.js","sourceRoot":"","sources":["../src/server-types.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"server-types.js","sourceRoot":"","sources":["../src/server-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmCH;;;;;GAKG;AACH,MAAM,UAAU,YAAY;IAC3B,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;AAC7B,CAAC;AASD,wFAAwF;AACxF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* execution, tool routing, and transport layers into a single MCP server.
|
|
6
6
|
*/
|
|
7
7
|
import type { McpHandler, McpHandlerOptions, McpServer, McpServerOptions } from './server-types.js';
|
|
8
|
-
export type { CommandMiddleware, ContextConfig, CreateRequestContext, McpHandler, McpHandlerOptions, McpServer, McpServerOptions, McpTransport, } from './server-types.js';
|
|
9
|
-
export { isStdinPiped } from './server-types.js';
|
|
8
|
+
export type { CommandMiddleware, ContextConfig, CreateRequestContext, McpHandler, McpHandlerOptions, McpServer, McpServerOptions, McpTransport, ToolStrategy, } from './server-types.js';
|
|
9
|
+
export { isStdinPiped, MAX_FIRST_CLASS_TOOLS } from './server-types.js';
|
|
10
10
|
/**
|
|
11
11
|
* Create an embeddable Node HTTP handler for MCP endpoints.
|
|
12
12
|
*
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyBH,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAKpG,YAAY,EACX,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,YAAY,GACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAmMxE;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAGvE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA8IpE"}
|
package/dist/server.js
CHANGED
|
@@ -6,29 +6,39 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { createServer } from 'node:http';
|
|
8
8
|
import { isMcpExposed } from '@lushly-dev/afd-core';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { getBootstrapCommands } from './bootstrap/registry.js';
|
|
12
|
-
import { assertValidCommandNames } from './command-names.js';
|
|
9
|
+
import { createContextCommands, getBootstrapCommands } from './bootstrap/registry.js';
|
|
10
|
+
import { assertValidCommandNames, assertValidFirstClassTools } from './command-names.js';
|
|
13
11
|
import { filterByContext } from './command-routing.js';
|
|
14
|
-
import { createConfirmationGate } from './
|
|
15
|
-
import {
|
|
12
|
+
import { createConfirmationGate } from './confirmation-gate.js';
|
|
13
|
+
import { checkContextFields } from './context-fields.js';
|
|
14
|
+
import { createContextState, resolveContextState } from './context-scope.js';
|
|
16
15
|
import { createExecutionEngine } from './execution.js';
|
|
17
16
|
import { createHttpHandler } from './http-handler.js';
|
|
18
17
|
import { createSessionStore } from './http-sessions.js';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
18
|
+
import { createAuthLayer } from './mcp-auth.js';
|
|
19
|
+
import { createModernHttpLane, DEFAULT_TOOLS_LIST_TTL_MS, defaultInstructions, serveModernStdio, } from './mcp-modern.js';
|
|
20
|
+
import { assertToolMeta } from './meta-keys.js';
|
|
21
|
+
import { createResourceService } from './resources.js';
|
|
21
22
|
import { isStdinPiped } from './server-types.js';
|
|
22
23
|
import { createToolRouter } from './tool-router.js';
|
|
23
24
|
import { getToolsList } from './tools.js';
|
|
24
25
|
// Re-export public types so existing imports from './server.js' still work
|
|
25
|
-
export { isStdinPiped } from './server-types.js';
|
|
26
|
+
export { isStdinPiped, MAX_FIRST_CLASS_TOOLS } from './server-types.js';
|
|
26
27
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
27
28
|
// SERVER FACTORY
|
|
28
29
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
29
30
|
function createSharedHttpRuntime(options) {
|
|
30
31
|
const { name, version, commands, port = 3100, host = 'localhost', devMode = false, cors = devMode, middleware = [], onCommand, onError, toolStrategy = 'grouped', groupByFn, contexts, bootstrap = false, } = options;
|
|
32
|
+
// A copy: the set must not change while the server runs.
|
|
33
|
+
const firstClassTools = options.firstClassTools ? [...options.firstClassTools] : undefined;
|
|
31
34
|
assertValidCommandNames(commands, { bootstrap, contexts: Boolean(contexts?.length) });
|
|
35
|
+
// A command built by hand skips `defineCommand`'s check; registration refuses a bad key too.
|
|
36
|
+
for (const command of commands)
|
|
37
|
+
assertToolMeta(command.name, command.toolMeta);
|
|
38
|
+
// Resource entries and the skill catalog are checked now, so a bad one stops the server from
|
|
39
|
+
// being built. Their results do not vary by context, so contexts leave the TTL alone.
|
|
40
|
+
const resourcesTtlMs = options.toolsListTtlMs ?? DEFAULT_TOOLS_LIST_TTL_MS;
|
|
41
|
+
const resources = createResourceService(options.resources, options.skills, resourcesTtlMs);
|
|
32
42
|
// stdio serves one client, so it uses this single state. HTTP callers each get a session
|
|
33
43
|
// state (or none), bound to their command context by the HTTP handler.
|
|
34
44
|
const contextState = contexts?.length ? createContextState() : undefined;
|
|
@@ -42,38 +52,24 @@ function createSharedHttpRuntime(options) {
|
|
|
42
52
|
: undefined;
|
|
43
53
|
const registeredCommands = [...commands];
|
|
44
54
|
if (contextState && contexts) {
|
|
45
|
-
const
|
|
46
|
-
const builtins = [
|
|
47
|
-
defineCommand({
|
|
48
|
-
...createAfdContextListCommand(getContexts, contextState),
|
|
49
|
-
input: z.object({}),
|
|
50
|
-
expose: { mcp: true },
|
|
51
|
-
}),
|
|
52
|
-
defineCommand({
|
|
53
|
-
...createAfdContextEnterCommand(getContexts, contextState),
|
|
54
|
-
input: z.object({ context: z.string().min(1) }),
|
|
55
|
-
expose: { mcp: true },
|
|
56
|
-
}),
|
|
57
|
-
defineCommand({
|
|
58
|
-
...createAfdContextExitCommand(contextState),
|
|
59
|
-
input: z.object({}),
|
|
60
|
-
expose: { mcp: true },
|
|
61
|
-
}),
|
|
62
|
-
];
|
|
63
|
-
for (const command of builtins) {
|
|
55
|
+
for (const command of createContextCommands(contexts, contextState)) {
|
|
64
56
|
if (registeredCommands.some((existing) => existing.name === command.name)) {
|
|
65
57
|
throw new Error(`Reserved context command name: ${command.name}`);
|
|
66
58
|
}
|
|
67
59
|
registeredCommands.push(command);
|
|
68
60
|
}
|
|
69
61
|
}
|
|
62
|
+
const contextFields = checkContextFields(options.contextFields);
|
|
70
63
|
if (bootstrap) {
|
|
71
64
|
// afd-help/afd-docs/afd-schema describe what a remote agent can see and call:
|
|
72
65
|
// MCP-exposed commands in the active context (built-ins included).
|
|
73
66
|
// The caller's context state: the HTTP session's, or the single stdio state.
|
|
74
67
|
const describe = (context) => filterByContext(remoteCommands, resolveContextState(context, contextState)?.getActive());
|
|
75
|
-
registeredCommands.push(...getBootstrapCommands(describe
|
|
68
|
+
registeredCommands.push(...getBootstrapCommands(describe, {
|
|
69
|
+
toolSurface: { toolStrategy, firstClassTools, contextFields },
|
|
70
|
+
}));
|
|
76
71
|
}
|
|
72
|
+
assertValidFirstClassTools({ toolStrategy, firstClassTools, commands: registeredCommands });
|
|
77
73
|
const commandMap = new Map();
|
|
78
74
|
for (const cmd of registeredCommands) {
|
|
79
75
|
commandMap.set(cmd.name, cmd);
|
|
@@ -86,6 +82,7 @@ function createSharedHttpRuntime(options) {
|
|
|
86
82
|
onCommand,
|
|
87
83
|
onError,
|
|
88
84
|
contextDefaults,
|
|
85
|
+
contextFields,
|
|
89
86
|
});
|
|
90
87
|
const remoteCommands = registeredCommands.filter((command) => isMcpExposed(command));
|
|
91
88
|
const remoteEngine = createExecutionEngine({
|
|
@@ -96,6 +93,7 @@ function createSharedHttpRuntime(options) {
|
|
|
96
93
|
onError,
|
|
97
94
|
contextState,
|
|
98
95
|
contextDefaults: { ...contextDefaults, actor: options.actor ?? { kind: 'agent' } },
|
|
96
|
+
contextFields,
|
|
99
97
|
});
|
|
100
98
|
const exposedCommandNames = new Set(remoteCommands.map((c) => c.name));
|
|
101
99
|
const confirmations = createConfirmationGate(options.confirmations ?? 'off', remoteCommands);
|
|
@@ -113,7 +111,11 @@ function createSharedHttpRuntime(options) {
|
|
|
113
111
|
contextState,
|
|
114
112
|
confirmations,
|
|
115
113
|
});
|
|
116
|
-
const boundGetToolsList = (context = {}) => getToolsList(remoteCommands, toolStrategy, groupByFn, resolveContextState(context, contextState)?.getActive(), {
|
|
114
|
+
const boundGetToolsList = (context = {}) => getToolsList(remoteCommands, toolStrategy, groupByFn, resolveContextState(context, contextState)?.getActive(), {
|
|
115
|
+
outputSchema: options.advertiseOutputSchema,
|
|
116
|
+
confirmations: confirmations.mode,
|
|
117
|
+
firstClassTools,
|
|
118
|
+
});
|
|
117
119
|
const modernDeps = {
|
|
118
120
|
name,
|
|
119
121
|
version,
|
|
@@ -121,15 +123,23 @@ function createSharedHttpRuntime(options) {
|
|
|
121
123
|
getToolsList: boundGetToolsList,
|
|
122
124
|
routeToolCall,
|
|
123
125
|
contexts,
|
|
126
|
+
contextFields,
|
|
124
127
|
toolsListTtlMs: options.toolsListTtlMs,
|
|
128
|
+
toolStrategy,
|
|
125
129
|
confirmationKey: options.confirmationKey,
|
|
130
|
+
actor: options.actor ?? { kind: 'agent' },
|
|
131
|
+
resources,
|
|
132
|
+
resourcesTtlMs,
|
|
126
133
|
devMode,
|
|
127
134
|
onError,
|
|
128
135
|
};
|
|
136
|
+
const maxBodyBytes = options.maxBodyBytes ?? 1024 * 1024;
|
|
137
|
+
const auth = options.auth ? createAuthLayer(options.auth, maxBodyBytes, clock) : undefined;
|
|
129
138
|
const modern = createModernHttpLane({
|
|
130
139
|
...modernDeps,
|
|
131
140
|
createContext: options.createContext,
|
|
132
|
-
maxBodyBytes
|
|
141
|
+
maxBodyBytes,
|
|
142
|
+
auth,
|
|
133
143
|
});
|
|
134
144
|
const { handler, dispose } = createHttpHandler({
|
|
135
145
|
name,
|
|
@@ -151,11 +161,14 @@ function createSharedHttpRuntime(options) {
|
|
|
151
161
|
confirmations,
|
|
152
162
|
sessions,
|
|
153
163
|
createContext: options.createContext,
|
|
164
|
+
contextFields,
|
|
154
165
|
onError,
|
|
155
166
|
modern,
|
|
167
|
+
auth,
|
|
156
168
|
});
|
|
157
169
|
return {
|
|
158
170
|
engine,
|
|
171
|
+
contextFields,
|
|
159
172
|
routeToolCall,
|
|
160
173
|
getToolsList: boundGetToolsList,
|
|
161
174
|
handler,
|
|
@@ -286,6 +299,7 @@ export function createMcpServer(options) {
|
|
|
286
299
|
getUrl() {
|
|
287
300
|
return useHttp ? sharedRuntime.url : 'stdio://';
|
|
288
301
|
},
|
|
302
|
+
contextFields: sharedRuntime.contextFields,
|
|
289
303
|
getCommands() {
|
|
290
304
|
return commands;
|
|
291
305
|
},
|