apcore-mcp 0.12.0 → 0.14.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/LICENSE +190 -0
- package/README.md +165 -19
- package/dist/acl-builder.d.ts +43 -0
- package/dist/acl-builder.d.ts.map +1 -0
- package/dist/acl-builder.js +115 -0
- package/dist/acl-builder.js.map +1 -0
- package/dist/adapters/annotations.d.ts.map +1 -1
- package/dist/adapters/annotations.js +37 -2
- package/dist/adapters/annotations.js.map +1 -1
- package/dist/adapters/errors.d.ts +17 -0
- package/dist/adapters/errors.d.ts.map +1 -1
- package/dist/adapters/errors.js +192 -2
- package/dist/adapters/errors.js.map +1 -1
- package/dist/adapters/id-normalizer.d.ts +40 -0
- package/dist/adapters/id-normalizer.d.ts.map +1 -0
- package/dist/adapters/id-normalizer.js +59 -0
- package/dist/adapters/id-normalizer.js.map +1 -0
- package/dist/adapters/index.d.ts +2 -2
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +2 -2
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/{mcpErrorFormatter.d.ts → mcp-error-formatter.d.ts} +5 -7
- package/dist/adapters/mcp-error-formatter.d.ts.map +1 -0
- package/dist/adapters/mcp-error-formatter.js +30 -0
- package/dist/adapters/mcp-error-formatter.js.map +1 -0
- package/dist/adapters/schema.d.ts +21 -4
- package/dist/adapters/schema.d.ts.map +1 -1
- package/dist/adapters/schema.js +147 -13
- package/dist/adapters/schema.js.map +1 -1
- package/dist/apcore-mcp.d.ts +24 -2
- package/dist/apcore-mcp.d.ts.map +1 -1
- package/dist/apcore-mcp.js +8 -0
- package/dist/apcore-mcp.js.map +1 -1
- package/dist/auth/hooks.d.ts +1 -1
- package/dist/auth/hooks.d.ts.map +1 -1
- package/dist/auth/hooks.js +10 -3
- package/dist/auth/hooks.js.map +1 -1
- package/dist/auth/jwt.d.ts +1 -2
- package/dist/auth/jwt.d.ts.map +1 -1
- package/dist/auth/jwt.js +18 -10
- package/dist/auth/jwt.js.map +1 -1
- package/dist/auth/types.d.ts +6 -3
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +23 -1
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -6
- package/dist/config.js.map +1 -1
- package/dist/converters/openai.d.ts +10 -0
- package/dist/converters/openai.d.ts.map +1 -1
- package/dist/converters/openai.js +100 -5
- package/dist/converters/openai.js.map +1 -1
- package/dist/explorer/index.d.ts +2 -0
- package/dist/explorer/index.d.ts.map +1 -0
- package/dist/explorer/index.js +2 -0
- package/dist/explorer/index.js.map +1 -0
- package/dist/index.d.ts +68 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +346 -60
- package/dist/index.js.map +1 -1
- package/dist/inspector/index.d.ts +2 -0
- package/dist/inspector/index.d.ts.map +1 -0
- package/dist/inspector/index.js +2 -0
- package/dist/inspector/index.js.map +1 -0
- package/dist/middleware-builder.d.ts +41 -0
- package/dist/middleware-builder.d.ts.map +1 -0
- package/dist/middleware-builder.js +129 -0
- package/dist/middleware-builder.js.map +1 -0
- package/dist/server/async-task-bridge.d.ts +190 -0
- package/dist/server/async-task-bridge.d.ts.map +1 -0
- package/dist/server/async-task-bridge.js +393 -0
- package/dist/server/async-task-bridge.js.map +1 -0
- package/dist/server/context.d.ts +9 -2
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/context.js +14 -6
- package/dist/server/context.js.map +1 -1
- package/dist/server/factory.d.ts +25 -2
- package/dist/server/factory.d.ts.map +1 -1
- package/dist/server/factory.js +127 -7
- package/dist/server/factory.js.map +1 -1
- package/dist/server/listener.d.ts +3 -0
- package/dist/server/listener.d.ts.map +1 -1
- package/dist/server/listener.js +13 -2
- package/dist/server/listener.js.map +1 -1
- package/dist/server/observability.d.ts +51 -0
- package/dist/server/observability.d.ts.map +1 -0
- package/dist/server/observability.js +96 -0
- package/dist/server/observability.js.map +1 -0
- package/dist/server/router.d.ts +114 -0
- package/dist/server/router.d.ts.map +1 -1
- package/dist/server/router.js +360 -18
- package/dist/server/router.js.map +1 -1
- package/dist/server/trace-context.d.ts +40 -0
- package/dist/server/trace-context.d.ts.map +1 -0
- package/dist/server/trace-context.js +67 -0
- package/dist/server/trace-context.js.map +1 -0
- package/dist/server/transport.d.ts +39 -0
- package/dist/server/transport.d.ts.map +1 -1
- package/dist/server/transport.js +134 -4
- package/dist/server/transport.js.map +1 -1
- package/dist/types.d.ts +18 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -1
- package/package.json +12 -6
- package/dist/adapters/idNormalizer.d.ts +0 -22
- package/dist/adapters/idNormalizer.d.ts.map +0 -1
- package/dist/adapters/idNormalizer.js +0 -30
- package/dist/adapters/idNormalizer.js.map +0 -1
- package/dist/adapters/mcpErrorFormatter.d.ts.map +0 -1
- package/dist/adapters/mcpErrorFormatter.js +0 -24
- package/dist/adapters/mcpErrorFormatter.js.map +0 -1
package/dist/server/factory.js
CHANGED
|
@@ -10,6 +10,8 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
|
10
10
|
import { ListToolsRequestSchema, CallToolRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
11
11
|
import { SchemaConverter } from "../adapters/schema.js";
|
|
12
12
|
import { AnnotationMapper } from "../adapters/annotations.js";
|
|
13
|
+
import { buildTraceparent } from "./trace-context.js";
|
|
14
|
+
import { APCORE_META_TOOL_PREFIX } from "./async-task-bridge.js";
|
|
13
15
|
/** Metadata keys for AI intent annotations appended to tool descriptions. */
|
|
14
16
|
const AI_INTENT_KEYS = ["x-when-to-use", "x-when-not-to-use", "x-common-mistakes", "x-workflow-hints"];
|
|
15
17
|
export class MCPServerFactory {
|
|
@@ -27,7 +29,18 @@ export class MCPServerFactory {
|
|
|
27
29
|
* @returns A configured Server instance with tools capability
|
|
28
30
|
*/
|
|
29
31
|
createServer(name = "apcore-mcp", version = "0.1.0") {
|
|
30
|
-
|
|
32
|
+
// Advertise listChanged: true so MCP clients receive
|
|
33
|
+
// notifications/tools/list_changed and notifications/resources/list_changed
|
|
34
|
+
// when the registry mutates at runtime. Python's build_init_options and
|
|
35
|
+
// Rust's MCPServerFactory::build_init_options both set this to true;
|
|
36
|
+
// the TS factory previously passed empty objects, breaking dynamic-tool
|
|
37
|
+
// registration on TS-hosted servers. [A-D-004]
|
|
38
|
+
return new Server({ name, version }, {
|
|
39
|
+
capabilities: {
|
|
40
|
+
tools: { listChanged: true },
|
|
41
|
+
resources: { listChanged: true },
|
|
42
|
+
},
|
|
43
|
+
});
|
|
31
44
|
}
|
|
32
45
|
/**
|
|
33
46
|
* Build an MCP Tool object from an apcore module descriptor.
|
|
@@ -38,10 +51,19 @@ export class MCPServerFactory {
|
|
|
38
51
|
* - inputSchema = converted via SchemaConverter
|
|
39
52
|
* - annotations = mapped from AnnotationMapper with camelCase keys
|
|
40
53
|
*/
|
|
41
|
-
buildTool(descriptor) {
|
|
54
|
+
buildTool(descriptor, options) {
|
|
42
55
|
if (!descriptor.moduleId || typeof descriptor.moduleId !== "string") {
|
|
43
56
|
throw new Error("ModuleDescriptor.moduleId is required and must be a string");
|
|
44
57
|
}
|
|
58
|
+
// Reject reserved __apcore_ prefix at the symbol boundary, not just
|
|
59
|
+
// the bulk path. Direct callers (extensions, plugins, tests) would
|
|
60
|
+
// otherwise produce a poisoned Tool that shadows the async-task
|
|
61
|
+
// meta-tools. Python rejects at this same boundary; TS now does too.
|
|
62
|
+
// [A-D-009]
|
|
63
|
+
if (descriptor.moduleId.startsWith(APCORE_META_TOOL_PREFIX)) {
|
|
64
|
+
throw new Error(`Reserved module id: "${descriptor.moduleId}". Module ids starting with ` +
|
|
65
|
+
`"${APCORE_META_TOOL_PREFIX}" are reserved for apcore-mcp meta-tools.`);
|
|
66
|
+
}
|
|
45
67
|
if (descriptor.description !== undefined && descriptor.description !== null && typeof descriptor.description !== "string") {
|
|
46
68
|
throw new Error("ModuleDescriptor.description must be a string");
|
|
47
69
|
}
|
|
@@ -49,7 +71,24 @@ export class MCPServerFactory {
|
|
|
49
71
|
// while Python uses SchemaExporter.export_mcp() for the same mapping.
|
|
50
72
|
// Both produce identical output. If annotation logic changes, update both paths.
|
|
51
73
|
const mcpAnnotations = this._annotationMapper.toMcpAnnotations(descriptor.annotations);
|
|
52
|
-
const
|
|
74
|
+
const strict = options?.strict ?? true;
|
|
75
|
+
let convertedSchema;
|
|
76
|
+
if (strict && options?.registry && typeof options.registry.exportSchema === "function") {
|
|
77
|
+
try {
|
|
78
|
+
const exported = options.registry.exportSchema(descriptor.moduleId, true);
|
|
79
|
+
const inputSchema = exported?.["input_schema"]
|
|
80
|
+
?? exported?.["inputSchema"];
|
|
81
|
+
if (inputSchema && typeof inputSchema === "object") {
|
|
82
|
+
convertedSchema = inputSchema;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Fall through to local conversion
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!convertedSchema) {
|
|
90
|
+
convertedSchema = this._schemaConverter.convertInputSchema(descriptor, { strict });
|
|
91
|
+
}
|
|
53
92
|
const hasApproval = this._annotationMapper.hasRequiresApproval(descriptor.annotations);
|
|
54
93
|
// Resolve display overlay fields (§5.13)
|
|
55
94
|
const metadata = descriptor.metadata ?? {};
|
|
@@ -103,6 +142,9 @@ export class MCPServerFactory {
|
|
|
103
142
|
*
|
|
104
143
|
* Iterates over registry.list(), gets each definition, and builds tools.
|
|
105
144
|
* Skips modules that return null definitions or throw errors (with console.warn).
|
|
145
|
+
*
|
|
146
|
+
* Reserved: module ids starting with `__apcore_` collide with the async
|
|
147
|
+
* task bridge meta-tool namespace and are rejected with a console.error.
|
|
106
148
|
*/
|
|
107
149
|
buildTools(registry, options) {
|
|
108
150
|
const tools = [];
|
|
@@ -111,13 +153,17 @@ export class MCPServerFactory {
|
|
|
111
153
|
prefix: options?.prefix ?? null,
|
|
112
154
|
});
|
|
113
155
|
for (const moduleId of moduleIds) {
|
|
156
|
+
if (moduleId.startsWith(APCORE_META_TOOL_PREFIX)) {
|
|
157
|
+
throw new Error(`Reserved module id "${moduleId}" — ids prefixed with ` +
|
|
158
|
+
`"${APCORE_META_TOOL_PREFIX}" are reserved for apcore-mcp meta-tools.`);
|
|
159
|
+
}
|
|
114
160
|
try {
|
|
115
161
|
const descriptor = registry.getDefinition(moduleId);
|
|
116
162
|
if (descriptor === null) {
|
|
117
163
|
console.warn(`Skipping module "${moduleId}": getDefinition returned null`);
|
|
118
164
|
continue;
|
|
119
165
|
}
|
|
120
|
-
tools.push(this.buildTool(descriptor));
|
|
166
|
+
tools.push(this.buildTool(descriptor, { strict: options?.strict, registry }));
|
|
121
167
|
}
|
|
122
168
|
catch (error) {
|
|
123
169
|
console.warn(`Skipping module "${moduleId}": ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -125,6 +171,27 @@ export class MCPServerFactory {
|
|
|
125
171
|
}
|
|
126
172
|
return tools;
|
|
127
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Merge the four async-task meta-tools onto an existing tool list. Called
|
|
176
|
+
* after `buildTools()` when an `AsyncTaskBridge` is active so meta-tools
|
|
177
|
+
* are advertised via `tools/list`.
|
|
178
|
+
*/
|
|
179
|
+
attachAsyncMetaTools(tools, bridge) {
|
|
180
|
+
if (!bridge || !bridge.enabled)
|
|
181
|
+
return tools;
|
|
182
|
+
const metaTools = bridge.buildMetaTools().map((mt) => ({
|
|
183
|
+
name: mt.name,
|
|
184
|
+
description: mt.description,
|
|
185
|
+
inputSchema: mt.inputSchema,
|
|
186
|
+
annotations: {
|
|
187
|
+
readOnlyHint: false,
|
|
188
|
+
destructiveHint: false,
|
|
189
|
+
idempotentHint: true,
|
|
190
|
+
openWorldHint: false,
|
|
191
|
+
},
|
|
192
|
+
}));
|
|
193
|
+
return [...tools, ...metaTools];
|
|
194
|
+
}
|
|
128
195
|
/**
|
|
129
196
|
* Register resources/list and resources/read handlers for modules with documentation.
|
|
130
197
|
*
|
|
@@ -193,11 +260,18 @@ export class MCPServerFactory {
|
|
|
193
260
|
* @param server - The MCP Server to register handlers on
|
|
194
261
|
* @param tools - Array of MCP Tool objects to serve
|
|
195
262
|
* @param router - ExecutionRouter to handle tool call execution
|
|
263
|
+
* @param options - Optional extra options; `asyncTaskBridge` adds meta-tools
|
|
264
|
+
* and routes meta-tool calls to the bridge (mirrors Python's
|
|
265
|
+
* `register_handlers(server, tools, router, async_bridge)`).
|
|
266
|
+
* [D11-014]
|
|
196
267
|
*/
|
|
197
|
-
registerHandlers(server, tools, router) {
|
|
268
|
+
registerHandlers(server, tools, router, options) {
|
|
269
|
+
// [D11-014] If asyncTaskBridge is provided, extend tools list with meta-tools.
|
|
270
|
+
const bridge = options?.asyncTaskBridge;
|
|
271
|
+
const allTools = bridge ? this.attachAsyncMetaTools(tools, bridge) : tools;
|
|
198
272
|
// Handle tools/list requests
|
|
199
273
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
200
|
-
return { tools };
|
|
274
|
+
return { tools: allTools };
|
|
201
275
|
});
|
|
202
276
|
// Handle tools/call requests
|
|
203
277
|
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
@@ -214,8 +288,44 @@ export class MCPServerFactory {
|
|
|
214
288
|
_meta: extra?._meta
|
|
215
289
|
? { progressToken: extra._meta.progressToken }
|
|
216
290
|
: undefined,
|
|
291
|
+
// [A-D-018] Forward the transport's per-session id so the bridge
|
|
292
|
+
// can record it for cancelSessionTasks() on transport disconnect.
|
|
293
|
+
sessionId: extra?.sessionId,
|
|
217
294
|
};
|
|
218
|
-
const
|
|
295
|
+
const reqMeta = request.params._meta;
|
|
296
|
+
const apcoreMeta = reqMeta?.["apcore"];
|
|
297
|
+
if (apcoreMeta?.version) {
|
|
298
|
+
handleCallExtra._meta = {
|
|
299
|
+
...(handleCallExtra._meta ?? {}),
|
|
300
|
+
apcore: { version: apcoreMeta.version },
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
// F-042: W3C trace_context ↔ MCP `_meta.traceparent` inbound propagation.
|
|
304
|
+
// Prefer request params `_meta.traceparent`; fall back to transport extra.
|
|
305
|
+
const rawTraceparent = reqMeta?.["traceparent"] ??
|
|
306
|
+
extra?._meta?.traceparent;
|
|
307
|
+
if (typeof rawTraceparent === "string" && rawTraceparent.length > 0) {
|
|
308
|
+
handleCallExtra._meta = {
|
|
309
|
+
...(handleCallExtra._meta ?? {}),
|
|
310
|
+
traceparent: rawTraceparent,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
// [A-D-014] Auth-identity propagation: thread the authenticated
|
|
314
|
+
// identity from the AsyncLocalStorage (set by AuthMiddleware) into
|
|
315
|
+
// the call extra so the router can attach it to the apcore Context.
|
|
316
|
+
// Mirrors Python's factory pattern (factory.py:232-234) which reads
|
|
317
|
+
// auth_identity_var.get() and forwards into extra["identity"].
|
|
318
|
+
try {
|
|
319
|
+
const { getCurrentIdentity } = await import("../auth/storage.js");
|
|
320
|
+
const identity = getCurrentIdentity();
|
|
321
|
+
if (identity !== null) {
|
|
322
|
+
handleCallExtra.identity = identity;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
catch {
|
|
326
|
+
// auth module not available — skip silently (auth is optional).
|
|
327
|
+
}
|
|
328
|
+
const [content, isError, traceId] = await router.handleCall(name, toolArgs, handleCallExtra);
|
|
219
329
|
const textContents = content.map(c => ({ type: "text", text: c.text }));
|
|
220
330
|
// NOTE: The MCP SDK decorator always wraps our return in
|
|
221
331
|
// CallToolResult(isError=false). Setting isError=true is not
|
|
@@ -227,6 +337,16 @@ export class MCPServerFactory {
|
|
|
227
337
|
const result = {
|
|
228
338
|
content: textContents,
|
|
229
339
|
};
|
|
340
|
+
// F-042 outbound: attach `_meta.traceparent` so downstream MCP callers
|
|
341
|
+
// can continue the same W3C trace chain. We emit it whenever we have a
|
|
342
|
+
// traceId (i.e. a context was created) — the client can then thread it
|
|
343
|
+
// into any follow-up tool invocations.
|
|
344
|
+
if (traceId) {
|
|
345
|
+
result._meta = {
|
|
346
|
+
...(result._meta ?? {}),
|
|
347
|
+
traceparent: buildTraceparent(traceId),
|
|
348
|
+
};
|
|
349
|
+
}
|
|
230
350
|
return result;
|
|
231
351
|
});
|
|
232
352
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/server/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,oCAAoC,CAAC;AAQ5C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/server/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,oCAAoC,CAAC;AAQ5C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAI9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAwB,MAAM,wBAAwB,CAAC;AAEvF,6EAA6E;AAC7E,MAAM,cAAc,GAAG,CAAC,eAAe,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,kBAAkB,CAAU,CAAC;AAgBhH,MAAM,OAAO,gBAAgB;IACV,gBAAgB,CAAkB;IAClC,iBAA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zD,IAAI,EACJ,QAAQ,EACR,eAAe,CAChB,CAAC;YAEF,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAEjF,yDAAyD;YACzD,6DAA6D;YAC7D,+DAA+D;YAC/D,sDAAsD;YACtD,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,eAAe,CAAC,CAAC;YAC5D,CAAC;YAED,MAAM,MAAM,GAAyD;gBACnE,OAAO,EAAE,YAAY;aACtB,CAAC;YAEF,uEAAuE;YACvE,uEAAuE;YACvE,uEAAuE;YACvE,uCAAuC;YACvC,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,CAAC,KAAK,GAAG;oBACb,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;oBACvB,WAAW,EAAE,gBAAgB,CAAC,OAAO,CAAC;iBACvC,CAAC;YACJ,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -51,6 +51,9 @@ export declare class RegistryListener {
|
|
|
51
51
|
* Handle a module unregistration event.
|
|
52
52
|
*
|
|
53
53
|
* Removes the tool from the internal tools map.
|
|
54
|
+
* - [A-D-011]: gates on `_active` (matches Python+Rust idempotence
|
|
55
|
+
* contract — direct invocation post-stop() is a no-op).
|
|
56
|
+
* - [A-D-011]: only logs when the tool was actually present.
|
|
54
57
|
*
|
|
55
58
|
* @param moduleId - The ID of the unregistered module
|
|
56
59
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../src/server/listener.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE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;;;OAKG;IACH,KAAK,IAAI,IAAI;IAoBb;;;;OAIG;IACH,IAAI,IAAI,IAAI;IAIZ;;;;;;;OAOG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAyBnC;;;;;;;;;OASG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAOtC"}
|
package/dist/server/listener.js
CHANGED
|
@@ -71,6 +71,10 @@ export class RegistryListener {
|
|
|
71
71
|
* @param moduleId - The ID of the newly registered module
|
|
72
72
|
*/
|
|
73
73
|
_onRegister(moduleId) {
|
|
74
|
+
// [D11-001] Mirror Python listener.py:75 and Rust listener.rs:66:
|
|
75
|
+
// guard with _active check so post-stop() invocations are no-ops.
|
|
76
|
+
if (!this._active)
|
|
77
|
+
return;
|
|
74
78
|
try {
|
|
75
79
|
const descriptor = this._registry.getDefinition(moduleId);
|
|
76
80
|
if (descriptor === null) {
|
|
@@ -89,12 +93,19 @@ export class RegistryListener {
|
|
|
89
93
|
* Handle a module unregistration event.
|
|
90
94
|
*
|
|
91
95
|
* Removes the tool from the internal tools map.
|
|
96
|
+
* - [A-D-011]: gates on `_active` (matches Python+Rust idempotence
|
|
97
|
+
* contract — direct invocation post-stop() is a no-op).
|
|
98
|
+
* - [A-D-011]: only logs when the tool was actually present.
|
|
92
99
|
*
|
|
93
100
|
* @param moduleId - The ID of the unregistered module
|
|
94
101
|
*/
|
|
95
102
|
_onUnregister(moduleId) {
|
|
96
|
-
this.
|
|
97
|
-
|
|
103
|
+
if (!this._active)
|
|
104
|
+
return;
|
|
105
|
+
const removed = this._tools.delete(moduleId);
|
|
106
|
+
if (removed) {
|
|
107
|
+
console.log(`RegistryListener: unregistered tool "${moduleId}"`);
|
|
108
|
+
}
|
|
98
109
|
}
|
|
99
110
|
}
|
|
100
111
|
//# sourceMappingURL=listener.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../src/server/listener.ts"],"names":[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,uBAAuB,CAC5E,CAAC;gBACF,OAAO;YACT,CAAC;YAED,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;YACjD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAChC,OAAO,CAAC,GAAG,CAAC,sCAAsC,QAAQ,GAAG,CAAC,CAAC;QACjE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CACV,8CAA8C,QAAQ,MACpD,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACvD,EAAE,CACH,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;;;;;;OASG;IACH,aAAa,CAAC,QAAgB;QAC5B,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO;QAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC7C,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,wCAAwC,QAAQ,GAAG,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observability wiring for apcore-mcp.
|
|
3
|
+
*
|
|
4
|
+
* Bundles apcore-js's `MetricsCollector` + `MetricsMiddleware` and
|
|
5
|
+
* `UsageCollector` + `UsageMiddleware` so the bridge can auto-install them
|
|
6
|
+
* when the caller passes `observability: true` (or `metricsCollector: true`)
|
|
7
|
+
* to `serve()`, `asyncServe()`, or the `APCoreMCP` constructor.
|
|
8
|
+
*
|
|
9
|
+
* Back-compat: when `metricsCollector` is already a concrete
|
|
10
|
+
* `MetricsExporter` instance, it is passed through unchanged (existing
|
|
11
|
+
* behaviour). When it is `true`, a fresh MetricsCollector is created
|
|
12
|
+
* and the matching middleware installed via `executor.use()`.
|
|
13
|
+
*/
|
|
14
|
+
import type { MetricsExporter } from "./transport.js";
|
|
15
|
+
/** Duck-typed collector shapes returned from apcore-js. */
|
|
16
|
+
export interface ObservabilityStack {
|
|
17
|
+
/** Prometheus exporter (also doubles as the /metrics source). */
|
|
18
|
+
metricsCollector: MetricsExporter | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Raw UsageCollector with `getSummary(period)` and `getModule(moduleId, period)`.
|
|
21
|
+
* Typed loose because the bridge never depends on apcore-js at compile time.
|
|
22
|
+
*/
|
|
23
|
+
usageCollector: any | undefined;
|
|
24
|
+
/** Middleware instances already installed on the executor. */
|
|
25
|
+
middleware: unknown[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Flag-style options for observability auto-wiring. When `true` or an empty
|
|
29
|
+
* config is passed, both metrics and usage middleware are installed.
|
|
30
|
+
*/
|
|
31
|
+
export type ObservabilityFlag = boolean | {
|
|
32
|
+
metrics?: boolean;
|
|
33
|
+
usage?: boolean;
|
|
34
|
+
buckets?: number[];
|
|
35
|
+
retentionHours?: number;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Build the observability stack and install middleware on the executor.
|
|
39
|
+
*
|
|
40
|
+
* @param executor - apcore Executor instance (must expose `.use()` to install
|
|
41
|
+
* middleware). When `.use()` is missing, middleware installation is skipped
|
|
42
|
+
* with a warning and any instantiated collectors are still returned.
|
|
43
|
+
* @param metricsCollector - Caller-supplied value. `true` → auto-instantiate.
|
|
44
|
+
* An existing `MetricsExporter` → pass through untouched. `undefined` /
|
|
45
|
+
* `false` → skip metrics.
|
|
46
|
+
* @param observability - Master flag that additionally enables the usage
|
|
47
|
+
* middleware. When `true`, both metrics and usage are installed unless
|
|
48
|
+
* already supplied. Fine-grained sub-toggles supported via the object form.
|
|
49
|
+
*/
|
|
50
|
+
export declare function installObservability(executor: unknown, metricsCollector: MetricsExporter | boolean | undefined, observability: ObservabilityFlag | undefined): Promise<ObservabilityStack>;
|
|
51
|
+
//# sourceMappingURL=observability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observability.d.ts","sourceRoot":"","sources":["../../src/server/observability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,2DAA2D;AAC3D,MAAM,WAAW,kBAAkB;IACjC,iEAAiE;IACjE,gBAAgB,EAAE,eAAe,GAAG,SAAS,CAAC;IAC9C;;;OAGG;IAEH,cAAc,EAAE,GAAG,GAAG,SAAS,CAAC;IAChC,8DAA8D;IAC9D,UAAU,EAAE,OAAO,EAAE,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GACzB,OAAO,GACP;IACE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEN;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,OAAO,EACjB,gBAAgB,EAAE,eAAe,GAAG,OAAO,GAAG,SAAS,EACvD,aAAa,EAAE,iBAAiB,GAAG,SAAS,GAC3C,OAAO,CAAC,kBAAkB,CAAC,CA2F7B"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observability wiring for apcore-mcp.
|
|
3
|
+
*
|
|
4
|
+
* Bundles apcore-js's `MetricsCollector` + `MetricsMiddleware` and
|
|
5
|
+
* `UsageCollector` + `UsageMiddleware` so the bridge can auto-install them
|
|
6
|
+
* when the caller passes `observability: true` (or `metricsCollector: true`)
|
|
7
|
+
* to `serve()`, `asyncServe()`, or the `APCoreMCP` constructor.
|
|
8
|
+
*
|
|
9
|
+
* Back-compat: when `metricsCollector` is already a concrete
|
|
10
|
+
* `MetricsExporter` instance, it is passed through unchanged (existing
|
|
11
|
+
* behaviour). When it is `true`, a fresh MetricsCollector is created
|
|
12
|
+
* and the matching middleware installed via `executor.use()`.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Build the observability stack and install middleware on the executor.
|
|
16
|
+
*
|
|
17
|
+
* @param executor - apcore Executor instance (must expose `.use()` to install
|
|
18
|
+
* middleware). When `.use()` is missing, middleware installation is skipped
|
|
19
|
+
* with a warning and any instantiated collectors are still returned.
|
|
20
|
+
* @param metricsCollector - Caller-supplied value. `true` → auto-instantiate.
|
|
21
|
+
* An existing `MetricsExporter` → pass through untouched. `undefined` /
|
|
22
|
+
* `false` → skip metrics.
|
|
23
|
+
* @param observability - Master flag that additionally enables the usage
|
|
24
|
+
* middleware. When `true`, both metrics and usage are installed unless
|
|
25
|
+
* already supplied. Fine-grained sub-toggles supported via the object form.
|
|
26
|
+
*/
|
|
27
|
+
export async function installObservability(executor, metricsCollector, observability) {
|
|
28
|
+
const stack = {
|
|
29
|
+
metricsCollector: undefined,
|
|
30
|
+
usageCollector: undefined,
|
|
31
|
+
middleware: [],
|
|
32
|
+
};
|
|
33
|
+
const obsObj = typeof observability === "object" && observability !== null ? observability : null;
|
|
34
|
+
const obsOn = observability === true || obsObj !== null;
|
|
35
|
+
const wantMetrics = metricsCollector === true || (obsOn && (obsObj?.metrics ?? true));
|
|
36
|
+
const wantUsage = obsOn && (obsObj?.usage ?? true);
|
|
37
|
+
const hasPreMetrics = metricsCollector !== undefined &&
|
|
38
|
+
metricsCollector !== null &&
|
|
39
|
+
metricsCollector !== true &&
|
|
40
|
+
metricsCollector !== false;
|
|
41
|
+
// Back-compat: pre-instantiated MetricsExporter passed through.
|
|
42
|
+
if (hasPreMetrics) {
|
|
43
|
+
stack.metricsCollector = metricsCollector;
|
|
44
|
+
}
|
|
45
|
+
if (!wantMetrics && !wantUsage) {
|
|
46
|
+
return stack;
|
|
47
|
+
}
|
|
48
|
+
let apcoreMod;
|
|
49
|
+
try {
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
apcoreMod = (await import("apcore-js"));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
console.warn("[apcore-mcp] observability requested but apcore-js is not installed; skipping auto-wire.");
|
|
55
|
+
return stack;
|
|
56
|
+
}
|
|
57
|
+
const apcore = apcoreMod;
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
const executorAny = executor;
|
|
60
|
+
const useFn = typeof executorAny.use === "function" ? executorAny.use.bind(executorAny) : null;
|
|
61
|
+
if (wantMetrics && !hasPreMetrics) {
|
|
62
|
+
const MetricsCollector = apcore.MetricsCollector ??
|
|
63
|
+
apcore.default?.["MetricsCollector"];
|
|
64
|
+
const MetricsMiddleware = apcore.MetricsMiddleware;
|
|
65
|
+
if (MetricsCollector) {
|
|
66
|
+
const collector = new MetricsCollector(obsObj?.buckets);
|
|
67
|
+
stack.metricsCollector = collector;
|
|
68
|
+
if (MetricsMiddleware && useFn) {
|
|
69
|
+
const mw = new MetricsMiddleware(collector);
|
|
70
|
+
useFn(mw);
|
|
71
|
+
stack.middleware.push(mw);
|
|
72
|
+
}
|
|
73
|
+
else if (!useFn) {
|
|
74
|
+
console.warn("[apcore-mcp] Executor does not expose .use() — MetricsMiddleware not installed.");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (wantUsage) {
|
|
79
|
+
const UsageCollector = apcore.UsageCollector;
|
|
80
|
+
const UsageMiddleware = apcore.UsageMiddleware;
|
|
81
|
+
if (UsageCollector) {
|
|
82
|
+
const collector = new UsageCollector(obsObj?.retentionHours);
|
|
83
|
+
stack.usageCollector = collector;
|
|
84
|
+
if (UsageMiddleware && useFn) {
|
|
85
|
+
const mw = new UsageMiddleware(collector);
|
|
86
|
+
useFn(mw);
|
|
87
|
+
stack.middleware.push(mw);
|
|
88
|
+
}
|
|
89
|
+
else if (!useFn) {
|
|
90
|
+
console.warn("[apcore-mcp] Executor does not expose .use() — UsageMiddleware not installed.");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return stack;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=observability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observability.js","sourceRoot":"","sources":["../../src/server/observability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA+BH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,QAAiB,EACjB,gBAAuD,EACvD,aAA4C;IAE5C,MAAM,KAAK,GAAuB;QAChC,gBAAgB,EAAE,SAAS;QAC3B,cAAc,EAAE,SAAS;QACzB,UAAU,EAAE,EAAE;KACf,CAAC;IAEF,MAAM,MAAM,GAAG,OAAO,aAAa,KAAK,QAAQ,IAAI,aAAa,KAAK,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC;IAClG,MAAM,KAAK,GAAG,aAAa,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,CAAC;IAExD,MAAM,WAAW,GACf,gBAAgB,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,EAAE,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC;IACpE,MAAM,SAAS,GAAG,KAAK,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC;IACnD,MAAM,aAAa,GACjB,gBAAgB,KAAK,SAAS;QAC9B,gBAAgB,KAAK,IAAI;QACzB,gBAAgB,KAAK,IAAI;QACzB,gBAAgB,KAAK,KAAK,CAAC;IAE7B,gEAAgE;IAChE,IAAI,aAAa,EAAE,CAAC;QAClB,KAAK,CAAC,gBAAgB,GAAG,gBAAmC,CAAC;IAC/D,CAAC;IAED,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC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M,cAAc,GAAG,MAAM,CAAC,cAEjB,CAAC;QACd,MAAM,eAAe,GAAG,MAAM,CAAC,eAElB,CAAC;QACd,IAAI,cAAc,EAAE,CAAC;YACnB,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;YAC7D,KAAK,CAAC,cAAc,GAAG,SAAS,CAAC;YACjC,IAAI,eAAe,IAAI,KAAK,EAAE,CAAC;gBAC7B,MAAM,EAAE,GAAG,IAAI,eAAe,CAAC,SAAS,CAAC,CAAC;gBAC1C,KAAK,CAAC,EAAE,CAAC,CAAC;gBACV,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC5B,CAAC;iBAAM,IAAI,CAAC,KAAK,EAAE,CAAC;gBAClB,OAAO,CAAC,IAAI,CACV,+EAA+E,CAChF,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/server/router.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* accumulated result.
|
|
10
10
|
*/
|
|
11
11
|
import type { Executor, TextContentDict } from "../types.js";
|
|
12
|
+
import type { AsyncTaskBridge } from "./async-task-bridge.js";
|
|
12
13
|
/** Tuple of [content array, isError flag, traceId] returned from handleCall. */
|
|
13
14
|
export type CallResult = [TextContentDict[], boolean, string | undefined];
|
|
14
15
|
/**
|
|
@@ -18,13 +19,35 @@ export type CallResult = [TextContentDict[], boolean, string | undefined];
|
|
|
18
19
|
* - `sendNotification` — sends an out-of-band notification on the current session
|
|
19
20
|
* - `sendRequest` — sends a request to the client (used for elicitation)
|
|
20
21
|
* - `_meta.progressToken` — opaque token the client attached to the request
|
|
22
|
+
* - `_meta.traceparent` — W3C trace_context header propagated from caller
|
|
21
23
|
*/
|
|
22
24
|
export interface HandleCallExtra {
|
|
23
25
|
sendNotification?: (notification: Record<string, unknown>) => Promise<void>;
|
|
24
26
|
sendRequest?: (request: Record<string, unknown>, resultSchema: unknown) => Promise<unknown>;
|
|
25
27
|
_meta?: {
|
|
26
28
|
progressToken?: string | number;
|
|
29
|
+
apcore?: {
|
|
30
|
+
version?: string;
|
|
31
|
+
};
|
|
32
|
+
traceparent?: string;
|
|
27
33
|
};
|
|
34
|
+
versionHint?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Transport session id (e.g. SSEServerTransport.sessionId or
|
|
37
|
+
* StreamableHTTPServerTransport's per-session UUID). When present and
|
|
38
|
+
* the bridge is wired, it's recorded so transport-disconnect can call
|
|
39
|
+
* `cancelSessionTasks(sessionKey)` for cooperative cancellation.
|
|
40
|
+
* [A-D-018]
|
|
41
|
+
*/
|
|
42
|
+
sessionId?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Per-call id for cooperative cancellation. When omitted, the router
|
|
45
|
+
* derives one from `_meta.progressToken` or generates a UUID. Wired
|
|
46
|
+
* by transport-level handlers parsing inbound MCP
|
|
47
|
+
* `notifications/cancelled` and forwarding to `router.cancel(callId)`.
|
|
48
|
+
* [B-002]
|
|
49
|
+
*/
|
|
50
|
+
callId?: string | number;
|
|
28
51
|
}
|
|
29
52
|
/** Options for the ExecutionRouter constructor. */
|
|
30
53
|
export interface ExecutionRouterOptions {
|
|
@@ -35,12 +58,54 @@ export interface ExecutionRouterOptions {
|
|
|
35
58
|
* Only applied to plain-object results; non-object results always use JSON.stringify.
|
|
36
59
|
*/
|
|
37
60
|
outputFormatter?: (result: Record<string, unknown>) => string;
|
|
61
|
+
/**
|
|
62
|
+
* When true (default), redact sensitive fields from output using apcore's
|
|
63
|
+
* `redactSensitive()` before formatting. Requires apcore-js to be installed
|
|
64
|
+
* and the tool to have an output_schema in `outputSchemaMap`.
|
|
65
|
+
*/
|
|
66
|
+
redactOutput?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* When true, use callWithTrace() (if available on the executor) to include
|
|
69
|
+
* pipeline trace metadata in the response `_meta.trace`. Default: false.
|
|
70
|
+
*/
|
|
71
|
+
trace?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Map of module_id to output_schema, used by redactSensitive() to identify
|
|
74
|
+
* which fields should be redacted.
|
|
75
|
+
*/
|
|
76
|
+
outputSchemaMap?: Record<string, Record<string, unknown>>;
|
|
77
|
+
/**
|
|
78
|
+
* Optional AsyncTaskBridge that intercepts calls to async-hinted modules
|
|
79
|
+
* and the four reserved `__apcore_task_*` meta-tools. When absent, all
|
|
80
|
+
* calls go through the synchronous executor path.
|
|
81
|
+
*/
|
|
82
|
+
asyncTaskBridge?: AsyncTaskBridge;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Cooperative cancellation token. Mirrors apcore-py's CancelToken and
|
|
86
|
+
* Rust's apcore::CancelToken. [B-002]
|
|
87
|
+
*/
|
|
88
|
+
export declare class CancelToken {
|
|
89
|
+
private _cancelled;
|
|
90
|
+
get isCancelled(): boolean;
|
|
91
|
+
cancel(): void;
|
|
38
92
|
}
|
|
39
93
|
export declare class ExecutionRouter {
|
|
40
94
|
private readonly _executor;
|
|
41
95
|
private readonly _errorMapper;
|
|
42
96
|
private readonly _validateInputs;
|
|
43
97
|
private readonly _outputFormatter?;
|
|
98
|
+
private readonly _redactOutput;
|
|
99
|
+
private readonly _outputSchemaMap;
|
|
100
|
+
private readonly _trace;
|
|
101
|
+
private readonly _asyncTaskBridge?;
|
|
102
|
+
/**
|
|
103
|
+
* [B-002] Per-server `call_id → CancelToken` map. Populated on
|
|
104
|
+
* tool-call entry by handleCall(); consulted by cancel(callId).
|
|
105
|
+
* Transport layer should forward inbound MCP `notifications/cancelled`
|
|
106
|
+
* to `router.cancel(callId, reason)`.
|
|
107
|
+
*/
|
|
108
|
+
private readonly _cancelTokens;
|
|
44
109
|
/**
|
|
45
110
|
* Create an ExecutionRouter.
|
|
46
111
|
*
|
|
@@ -48,6 +113,43 @@ export declare class ExecutionRouter {
|
|
|
48
113
|
* @param options - Optional configuration including validateInputs and outputFormatter
|
|
49
114
|
*/
|
|
50
115
|
constructor(executor: Executor, options?: ExecutionRouterOptions);
|
|
116
|
+
/** Expose the async task bridge (for factory tool-list merging). */
|
|
117
|
+
get asyncTaskBridge(): AsyncTaskBridge | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Cooperatively cancel an in-flight tool call. [B-002]
|
|
120
|
+
*
|
|
121
|
+
* Looks up the CancelToken registered for `callId` in handleCall and
|
|
122
|
+
* calls `token.cancel()`. Subsequent checks (e.g., from inside the
|
|
123
|
+
* executing module via `context.cancelToken?.isCancelled`) will see
|
|
124
|
+
* the cancellation. When `callId` is unknown (cancel arrived before
|
|
125
|
+
* submit, or after the call completed), records a tombstone so a
|
|
126
|
+
* subsequent same-id submit immediately sees the cancellation.
|
|
127
|
+
*
|
|
128
|
+
* Returns true when a token was found and cancelled; false when the
|
|
129
|
+
* callId was unknown (tombstone recorded). Wired by transport-level
|
|
130
|
+
* handlers parsing inbound MCP `notifications/cancelled` messages.
|
|
131
|
+
*/
|
|
132
|
+
cancel(callId: string, reason?: string): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Internal: register a CancelToken for the duration of a tool call.
|
|
135
|
+
* Returns the token (already cancelled if a tombstone was recorded
|
|
136
|
+
* before the call landed).
|
|
137
|
+
*/
|
|
138
|
+
_registerCancelToken(callId: string): CancelToken;
|
|
139
|
+
/** Internal: release a token slot after the call completes. */
|
|
140
|
+
_releaseCancelToken(callId: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* [B-002] Cap the cancel-tokens map at CANCEL_TOKENS_MAX. Map preserves
|
|
143
|
+
* insertion order, so iterator gives oldest first.
|
|
144
|
+
*/
|
|
145
|
+
private _evictCancelTokens;
|
|
146
|
+
/**
|
|
147
|
+
* Attempt to redact sensitive fields from the result using apcore's redactSensitive().
|
|
148
|
+
*
|
|
149
|
+
* Returns the original result if apcore-js is not available, redactSensitive is not
|
|
150
|
+
* exported, or if an error occurs during redaction.
|
|
151
|
+
*/
|
|
152
|
+
private _maybeRedact;
|
|
51
153
|
/**
|
|
52
154
|
* Format an execution result into text for LLM consumption.
|
|
53
155
|
*
|
|
@@ -79,5 +181,17 @@ export declare class ExecutionRouter {
|
|
|
79
181
|
* @returns Tuple of [content, isError, traceId] where content is an array of text content dicts
|
|
80
182
|
*/
|
|
81
183
|
handleCall(toolName: string, args: Record<string, unknown>, extra?: HandleCallExtra): Promise<CallResult>;
|
|
184
|
+
private _handleCallInner;
|
|
185
|
+
/**
|
|
186
|
+
* Preflight validation for a tool call without executing it.
|
|
187
|
+
*
|
|
188
|
+
* Delegates to `executor.validate()` if the executor supports it, and
|
|
189
|
+
* returns a structured validation result.
|
|
190
|
+
*
|
|
191
|
+
* @param toolName - The MCP tool name (maps to apcore moduleId)
|
|
192
|
+
* @param arguments_ - The tool call arguments to validate
|
|
193
|
+
* @returns Structured validation result with checks array
|
|
194
|
+
*/
|
|
195
|
+
validateTool(toolName: string, arguments_: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
82
196
|
}
|
|
83
197
|
//# sourceMappingURL=router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/server/router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/server/router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAoB,MAAM,aAAa,CAAC;AAM/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAuC9D,gFAAgF;AAChF,MAAM,MAAM,UAAU,GAAG,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAE1E;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAC9B,gBAAgB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,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