@adhd/agent-mcp 2.0.0 → 2.1.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/AGENTS.md +236 -0
- package/CHANGELOG.md +115 -0
- package/LICENSE +21 -0
- package/README.md +201 -0
- package/docs/architecture-and-security.md +405 -0
- package/docs/marketing/.catalog/capabilities.md +143 -0
- package/docs/marketing/.catalog/consumer.md +111 -0
- package/docs/marketing/.catalog/distribution.md +223 -0
- package/docs/marketing/.catalog/doc-conformance.md +237 -0
- package/docs/marketing/.catalog/doc-ops.md +98 -0
- package/docs/marketing/.catalog/metrics.md +119 -0
- package/docs/marketing/.catalog/required-tooling.md +224 -0
- package/docs/marketing/.catalog/review.md +164 -0
- package/docs/provider-call-audit.md +254 -0
- package/llms.txt +133 -0
- package/package.json +31 -50
- package/src/__tests__/integration/harness.d.ts +871 -39
- package/src/__tests__/integration/harness.d.ts.map +1 -1
- package/src/__tests__/integration/harness.js +93 -87
- package/src/__tests__/integration/harness.js.map +1 -1
- package/src/__tests__/integration/scripted-provider.d.ts +1 -2
- package/src/__tests__/integration/scripted-provider.d.ts.map +1 -1
- package/src/__tests__/integration/scripted-provider.js +1 -3
- package/src/__tests__/integration/scripted-provider.js.map +1 -1
- package/src/config.d.ts +6 -69
- package/src/config.d.ts.map +1 -1
- package/src/config.js +1 -50
- package/src/config.js.map +1 -1
- package/src/db/client.d.ts +1516 -2
- package/src/db/client.d.ts.map +1 -1
- package/src/db/client.js +4 -2
- package/src/db/client.js.map +1 -1
- package/src/db/migrate-runner.d.ts +0 -28
- package/src/db/migrate-runner.d.ts.map +1 -1
- package/src/db/migrate-runner.js +0 -24
- package/src/db/migrate-runner.js.map +1 -1
- package/src/db/migrate.d.ts +0 -7
- package/src/db/migrate.d.ts.map +1 -1
- package/src/db/migrate.js +0 -7
- package/src/db/migrate.js.map +1 -1
- package/src/db/schema.d.ts +0 -1260
- package/src/db/schema.d.ts.map +1 -1
- package/src/db/schema.js +2 -179
- package/src/db/schema.js.map +1 -1
- package/src/index.d.ts +4 -27
- package/src/index.d.ts.map +1 -1
- package/src/index.js +43 -114
- package/src/index.js.map +1 -1
- package/src/logger.d.ts +0 -8
- package/src/logger.d.ts.map +1 -1
- package/src/logger.js +1 -12
- package/src/logger.js.map +1 -1
- package/src/scripts/agent-mcp-tail.d.ts +3 -0
- package/src/scripts/agent-mcp-tail.d.ts.map +1 -0
- package/src/scripts/agent-mcp-tail.js +227 -0
- package/src/scripts/agent-mcp-tail.js.map +1 -0
- package/src/server.d.ts +13 -34
- package/src/server.d.ts.map +1 -1
- package/src/server.js +234 -326
- package/src/server.js.map +1 -1
- package/src/store/agent-store.d.ts +3 -16
- package/src/store/agent-store.d.ts.map +1 -1
- package/src/store/agent-store.js +38 -41
- package/src/store/agent-store.js.map +1 -1
- package/src/streaming/chat-gateway.d.ts +17 -0
- package/src/streaming/chat-gateway.d.ts.map +1 -0
- package/src/streaming/chat-gateway.js +336 -0
- package/src/streaming/chat-gateway.js.map +1 -0
- package/src/streaming/event-bus.d.ts +4 -0
- package/src/streaming/event-bus.d.ts.map +1 -1
- package/src/streaming/event-bus.js +14 -1
- package/src/streaming/event-bus.js.map +1 -1
- package/src/streaming/sse-server.d.ts +3 -14
- package/src/streaming/sse-server.d.ts.map +1 -1
- package/src/streaming/sse-server.js +37 -37
- package/src/streaming/sse-server.js.map +1 -1
- package/src/utils/load-env.d.ts +0 -14
- package/src/utils/load-env.d.ts.map +1 -1
- package/src/utils/load-env.js +0 -18
- package/src/utils/load-env.js.map +1 -1
- package/drizzle/0000_nifty_sasquatch.sql +0 -55
- package/drizzle/0001_task_usage.sql +0 -16
- package/drizzle/0002_lumpy_silver_centurion.sql +0 -2
- package/drizzle/0003_nifty_shriek.sql +0 -2
- package/drizzle/0004_brief_shocker.sql +0 -4
- package/drizzle/0005_clear_lenny_balinger.sql +0 -25
- package/drizzle/0006_composed_prompts_cache.sql +0 -24
- package/drizzle/meta/0000_snapshot.json +0 -387
- package/drizzle/meta/0001_snapshot.json +0 -495
- package/drizzle/meta/0002_snapshot.json +0 -509
- package/drizzle/meta/0003_snapshot.json +0 -523
- package/drizzle/meta/0004_snapshot.json +0 -551
- package/drizzle/meta/0005_snapshot.json +0 -545
- package/drizzle/meta/0006_snapshot.json +0 -651
- package/drizzle/meta/_journal.json +0 -55
- package/src/clients/http-client.d.ts +0 -24
- package/src/clients/http-client.d.ts.map +0 -1
- package/src/clients/http-client.js +0 -98
- package/src/clients/http-client.js.map +0 -1
- package/src/clients/in-process.d.ts +0 -27
- package/src/clients/in-process.d.ts.map +0 -1
- package/src/clients/in-process.js +0 -37
- package/src/clients/in-process.js.map +0 -1
- package/src/clients/index.d.ts +0 -7
- package/src/clients/index.d.ts.map +0 -1
- package/src/clients/index.js +0 -5
- package/src/clients/index.js.map +0 -1
- package/src/clients/registry.d.ts +0 -54
- package/src/clients/registry.d.ts.map +0 -1
- package/src/clients/registry.js +0 -164
- package/src/clients/registry.js.map +0 -1
- package/src/clients/stdio-client.d.ts +0 -16
- package/src/clients/stdio-client.d.ts.map +0 -1
- package/src/clients/stdio-client.js +0 -97
- package/src/clients/stdio-client.js.map +0 -1
- package/src/clients/tool-naming.d.ts +0 -44
- package/src/clients/tool-naming.d.ts.map +0 -1
- package/src/clients/tool-naming.js +0 -65
- package/src/clients/tool-naming.js.map +0 -1
- package/src/clients/types.d.ts +0 -18
- package/src/clients/types.d.ts.map +0 -1
- package/src/clients/types.js +0 -2
- package/src/clients/types.js.map +0 -1
- package/src/engine/dag-engine.d.ts +0 -62
- package/src/engine/dag-engine.d.ts.map +0 -1
- package/src/engine/dag-engine.js +0 -158
- package/src/engine/dag-engine.js.map +0 -1
- package/src/engine/hooks.d.ts +0 -24
- package/src/engine/hooks.d.ts.map +0 -1
- package/src/engine/hooks.js +0 -50
- package/src/engine/hooks.js.map +0 -1
- package/src/engine/orchestrator.d.ts +0 -40
- package/src/engine/orchestrator.d.ts.map +0 -1
- package/src/engine/orchestrator.js +0 -507
- package/src/engine/orchestrator.js.map +0 -1
- package/src/engine/policy.d.ts +0 -66
- package/src/engine/policy.d.ts.map +0 -1
- package/src/engine/policy.js +0 -112
- package/src/engine/policy.js.map +0 -1
- package/src/engine/prompt-resolver.d.ts +0 -89
- package/src/engine/prompt-resolver.d.ts.map +0 -1
- package/src/engine/prompt-resolver.js +0 -96
- package/src/engine/prompt-resolver.js.map +0 -1
- package/src/engine/queue.d.ts +0 -29
- package/src/engine/queue.d.ts.map +0 -1
- package/src/engine/queue.js +0 -56
- package/src/engine/queue.js.map +0 -1
- package/src/plugins/index.d.ts +0 -2
- package/src/plugins/index.d.ts.map +0 -1
- package/src/plugins/index.js +0 -2
- package/src/plugins/index.js.map +0 -1
- package/src/plugins/loader.d.ts +0 -65
- package/src/plugins/loader.d.ts.map +0 -1
- package/src/plugins/loader.js +0 -222
- package/src/plugins/loader.js.map +0 -1
- package/src/plugins/usage-plugin.d.ts +0 -27
- package/src/plugins/usage-plugin.d.ts.map +0 -1
- package/src/plugins/usage-plugin.js +0 -148
- package/src/plugins/usage-plugin.js.map +0 -1
- package/src/providers/anthropic.d.ts +0 -13
- package/src/providers/anthropic.d.ts.map +0 -1
- package/src/providers/anthropic.js +0 -260
- package/src/providers/anthropic.js.map +0 -1
- package/src/providers/claudecli.d.ts +0 -153
- package/src/providers/claudecli.d.ts.map +0 -1
- package/src/providers/claudecli.js +0 -510
- package/src/providers/claudecli.js.map +0 -1
- package/src/providers/factory.d.ts +0 -10
- package/src/providers/factory.d.ts.map +0 -1
- package/src/providers/factory.js +0 -24
- package/src/providers/factory.js.map +0 -1
- package/src/providers/index.d.ts +0 -6
- package/src/providers/index.d.ts.map +0 -1
- package/src/providers/index.js +0 -5
- package/src/providers/index.js.map +0 -1
- package/src/providers/openai.d.ts +0 -14
- package/src/providers/openai.d.ts.map +0 -1
- package/src/providers/openai.js +0 -162
- package/src/providers/openai.js.map +0 -1
- package/src/providers/types.d.ts +0 -36
- package/src/providers/types.d.ts.map +0 -1
- package/src/providers/types.js +0 -2
- package/src/providers/types.js.map +0 -1
- package/src/store/composed-prompt-store.d.ts +0 -24
- package/src/store/composed-prompt-store.d.ts.map +0 -1
- package/src/store/composed-prompt-store.js +0 -75
- package/src/store/composed-prompt-store.js.map +0 -1
- package/src/store/index.d.ts +0 -5
- package/src/store/index.d.ts.map +0 -1
- package/src/store/index.js +0 -5
- package/src/store/index.js.map +0 -1
- package/src/store/session-store.d.ts +0 -45
- package/src/store/session-store.d.ts.map +0 -1
- package/src/store/session-store.js +0 -197
- package/src/store/session-store.js.map +0 -1
- package/src/store/task-store.d.ts +0 -55
- package/src/store/task-store.d.ts.map +0 -1
- package/src/store/task-store.js +0 -186
- package/src/store/task-store.js.map +0 -1
- package/src/tools/agent-crud.d.ts +0 -15
- package/src/tools/agent-crud.d.ts.map +0 -1
- package/src/tools/agent-crud.js +0 -32
- package/src/tools/agent-crud.js.map +0 -1
- package/src/tools/session.d.ts +0 -33
- package/src/tools/session.d.ts.map +0 -1
- package/src/tools/session.js +0 -73
- package/src/tools/session.js.map +0 -1
- package/src/tools/task.d.ts +0 -86
- package/src/tools/task.d.ts.map +0 -1
- package/src/tools/task.js +0 -406
- package/src/tools/task.js.map +0 -1
- package/src/tools/usage.d.ts +0 -60
- package/src/tools/usage.d.ts.map +0 -1
- package/src/tools/usage.js +0 -174
- package/src/tools/usage.js.map +0 -1
- package/src/types/agent.d.ts +0 -2
- package/src/types/agent.d.ts.map +0 -1
- package/src/types/agent.js +0 -3
- package/src/types/agent.js.map +0 -1
- package/src/types/execution.d.ts +0 -2
- package/src/types/execution.d.ts.map +0 -1
- package/src/types/execution.js +0 -3
- package/src/types/execution.js.map +0 -1
- package/src/types/index.d.ts +0 -2
- package/src/types/index.d.ts.map +0 -1
- package/src/types/index.js +0 -2
- package/src/types/index.js.map +0 -1
- package/src/types/mcp.d.ts +0 -2
- package/src/types/mcp.d.ts.map +0 -1
- package/src/types/mcp.js +0 -3
- package/src/types/mcp.js.map +0 -1
- package/src/types/message.d.ts +0 -2
- package/src/types/message.d.ts.map +0 -1
- package/src/types/message.js +0 -3
- package/src/types/message.js.map +0 -1
- package/src/types/session.d.ts +0 -2
- package/src/types/session.d.ts.map +0 -1
- package/src/types/session.js +0 -3
- package/src/types/session.js.map +0 -1
- package/src/types/task.d.ts +0 -2
- package/src/types/task.d.ts.map +0 -1
- package/src/types/task.js +0 -3
- package/src/types/task.js.map +0 -1
- package/src/utils/ids.d.ts +0 -2
- package/src/utils/ids.d.ts.map +0 -1
- package/src/utils/ids.js +0 -5
- package/src/utils/ids.js.map +0 -1
- package/src/utils/logger.d.ts +0 -2
- package/src/utils/logger.d.ts.map +0 -1
- package/src/utils/logger.js +0 -5
- package/src/utils/logger.js.map +0 -1
- package/src/utils/timestamps.d.ts +0 -2
- package/src/utils/timestamps.d.ts.map +0 -1
- package/src/utils/timestamps.js +0 -4
- package/src/utils/timestamps.js.map +0 -1
- package/src/validation/agent.d.ts +0 -400
- package/src/validation/agent.d.ts.map +0 -1
- package/src/validation/agent.js +0 -251
- package/src/validation/agent.js.map +0 -1
- package/src/validation/agents.d.ts +0 -2
- package/src/validation/agents.d.ts.map +0 -1
- package/src/validation/agents.js +0 -3
- package/src/validation/agents.js.map +0 -1
- package/src/validation/errors.d.ts +0 -32
- package/src/validation/errors.d.ts.map +0 -1
- package/src/validation/errors.js +0 -42
- package/src/validation/errors.js.map +0 -1
- package/src/validation/execution.d.ts +0 -86
- package/src/validation/execution.d.ts.map +0 -1
- package/src/validation/execution.js +0 -28
- package/src/validation/execution.js.map +0 -1
- package/src/validation/index.d.ts +0 -9
- package/src/validation/index.d.ts.map +0 -1
- package/src/validation/index.js +0 -9
- package/src/validation/index.js.map +0 -1
- package/src/validation/mcp.d.ts +0 -42
- package/src/validation/mcp.d.ts.map +0 -1
- package/src/validation/mcp.js +0 -28
- package/src/validation/mcp.js.map +0 -1
- package/src/validation/message.d.ts +0 -43
- package/src/validation/message.d.ts.map +0 -1
- package/src/validation/message.js +0 -23
- package/src/validation/message.js.map +0 -1
- package/src/validation/session.d.ts +0 -49
- package/src/validation/session.d.ts.map +0 -1
- package/src/validation/session.js +0 -34
- package/src/validation/session.js.map +0 -1
- package/src/validation/task.d.ts +0 -146
- package/src/validation/task.d.ts.map +0 -1
- package/src/validation/task.js +0 -95
- package/src/validation/task.js.map +0 -1
- package/src/validation/tasks.d.ts +0 -2
- package/src/validation/tasks.d.ts.map +0 -1
- package/src/validation/tasks.js +0 -3
- package/src/validation/tasks.js.map +0 -1
- package/src/validation/usage.d.ts +0 -89
- package/src/validation/usage.d.ts.map +0 -1
- package/src/validation/usage.js +0 -98
- package/src/validation/usage.js.map +0 -1
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
-
import type { ToolDefinition } from "../providers/types.js";
|
|
3
|
-
import type { McpHttpConfig, McpSseConfig } from "../validation/index.js";
|
|
4
|
-
import type { IMcpClient } from "./types.js";
|
|
5
|
-
declare abstract class BaseHttpMcpClient implements IMcpClient {
|
|
6
|
-
protected readonly serverName: string;
|
|
7
|
-
protected client: Client | null;
|
|
8
|
-
constructor(serverName: string);
|
|
9
|
-
listTools(): Promise<ToolDefinition[]>;
|
|
10
|
-
callTool(toolName: string, args: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
11
|
-
close(): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export declare class HttpMcpClient extends BaseHttpMcpClient {
|
|
14
|
-
private readonly config;
|
|
15
|
-
constructor(serverName: string, config: McpHttpConfig);
|
|
16
|
-
connect(): Promise<void>;
|
|
17
|
-
}
|
|
18
|
-
export declare class SseMcpClient extends BaseHttpMcpClient {
|
|
19
|
-
private readonly config;
|
|
20
|
-
constructor(serverName: string, config: McpSseConfig);
|
|
21
|
-
connect(): Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
|
24
|
-
//# sourceMappingURL=http-client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAInE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,uBAAe,iBAAkB,YAAW,UAAU;IAGtC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM;IAFjD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAQ;gBAER,UAAU,EAAE,MAAM;IAE3C,SAAS,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAgBtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IA0BjF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ/B;AAED,qBAAa,aAAc,SAAQ,iBAAiB;IAG5C,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADvB,UAAU,EAAE,MAAM,EACD,MAAM,EAAE,aAAa;IAKpC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAmBjC;AAED,qBAAa,YAAa,SAAQ,iBAAiB;IAG3C,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADvB,UAAU,EAAE,MAAM,EACD,MAAM,EAAE,YAAY;IAKnC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CA0BjC"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
-
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
3
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
|
-
import { ToolError } from "../validation/errors.js";
|
|
5
|
-
class BaseHttpMcpClient {
|
|
6
|
-
serverName;
|
|
7
|
-
client = null;
|
|
8
|
-
constructor(serverName) {
|
|
9
|
-
this.serverName = serverName;
|
|
10
|
-
}
|
|
11
|
-
async listTools() {
|
|
12
|
-
if (!this.client) {
|
|
13
|
-
throw new ToolError("MCP_CLIENT_ERROR", `Client '${this.serverName}' not connected`);
|
|
14
|
-
}
|
|
15
|
-
const response = await this.client.listTools();
|
|
16
|
-
return response.tools.map(tool => ({
|
|
17
|
-
name: tool.name,
|
|
18
|
-
description: tool.description ?? "",
|
|
19
|
-
inputSchema: tool.inputSchema ?? {
|
|
20
|
-
type: "object",
|
|
21
|
-
properties: {},
|
|
22
|
-
},
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
async callTool(toolName, args, signal) {
|
|
26
|
-
if (!this.client) {
|
|
27
|
-
throw new ToolError("MCP_CLIENT_ERROR", `Client '${this.serverName}' not connected`);
|
|
28
|
-
}
|
|
29
|
-
// Thread the caller's cancellation/timeout signal so a task cancel
|
|
30
|
-
// interrupts this in-flight call (DEBT-003).
|
|
31
|
-
const result = await this.client.callTool({
|
|
32
|
-
name: toolName,
|
|
33
|
-
arguments: args,
|
|
34
|
-
}, undefined, signal ? { signal } : undefined);
|
|
35
|
-
if (result.isError) {
|
|
36
|
-
throw new ToolError("MCP_CLIENT_ERROR", `Tool '${toolName}' on server '${this.serverName}' returned an error: ${JSON.stringify(result.content)}`);
|
|
37
|
-
}
|
|
38
|
-
return result.content;
|
|
39
|
-
}
|
|
40
|
-
async close() {
|
|
41
|
-
try {
|
|
42
|
-
await this.client?.close();
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
// ignore close errors
|
|
46
|
-
}
|
|
47
|
-
this.client = null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export class HttpMcpClient extends BaseHttpMcpClient {
|
|
51
|
-
config;
|
|
52
|
-
constructor(serverName, config) {
|
|
53
|
-
super(serverName);
|
|
54
|
-
this.config = config;
|
|
55
|
-
}
|
|
56
|
-
async connect() {
|
|
57
|
-
const url = new URL(this.config.url);
|
|
58
|
-
const transport = new StreamableHTTPClientTransport(url, {
|
|
59
|
-
requestInit: {
|
|
60
|
-
headers: this.config.headers,
|
|
61
|
-
signal: this.config.timeoutMs
|
|
62
|
-
? AbortSignal.timeout(this.config.timeoutMs)
|
|
63
|
-
: undefined,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
const client = new Client({ name: "agent-mcp-client", version: "1.0.0" }, { capabilities: {} });
|
|
67
|
-
this.client = client;
|
|
68
|
-
await client.connect(transport);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
export class SseMcpClient extends BaseHttpMcpClient {
|
|
72
|
-
config;
|
|
73
|
-
constructor(serverName, config) {
|
|
74
|
-
super(serverName);
|
|
75
|
-
this.config = config;
|
|
76
|
-
}
|
|
77
|
-
async connect() {
|
|
78
|
-
const url = new URL(this.config.url);
|
|
79
|
-
const transport = new SSEClientTransport(url, {
|
|
80
|
-
eventSourceInit: {
|
|
81
|
-
fetch: (input, init) => fetch(input, {
|
|
82
|
-
...init,
|
|
83
|
-
headers: {
|
|
84
|
-
...init?.headers,
|
|
85
|
-
...this.config.headers,
|
|
86
|
-
},
|
|
87
|
-
signal: this.config.timeoutMs
|
|
88
|
-
? AbortSignal.timeout(this.config.timeoutMs)
|
|
89
|
-
: undefined,
|
|
90
|
-
}),
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
const client = new Client({ name: "agent-mcp-client", version: "1.0.0" }, { capabilities: {} });
|
|
94
|
-
this.client = client;
|
|
95
|
-
await client.connect(transport);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
//# sourceMappingURL=http-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-client.js","sourceRoot":"","sources":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27 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from "../providers/types.js";
|
|
2
|
-
import type { ExecutionContext } from "../validation/index.js";
|
|
3
|
-
import type { IMcpClient } from "./types.js";
|
|
4
|
-
export type InProcessToolHandler = (toolName: string, args: unknown, ctx: ExecutionContext) => Promise<unknown>;
|
|
5
|
-
export type InProcessToolDescriptor = {
|
|
6
|
-
name: string;
|
|
7
|
-
description: string;
|
|
8
|
-
inputSchema: Record<string, unknown>;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* InProcessMcpClient routes tool calls directly to runtime handler
|
|
12
|
-
* functions without any network round-trip.
|
|
13
|
-
*
|
|
14
|
-
* This is the client used when an agent definition includes an
|
|
15
|
-
* "agent-mcp" server entry — it allows recursive delegation while
|
|
16
|
-
* preserving the ExecutionContext thread.
|
|
17
|
-
*/
|
|
18
|
-
export declare class InProcessMcpClient implements IMcpClient {
|
|
19
|
-
private readonly tools;
|
|
20
|
-
private readonly handler;
|
|
21
|
-
private readonly context;
|
|
22
|
-
constructor(tools: InProcessToolDescriptor[], handler: InProcessToolHandler, context: ExecutionContext);
|
|
23
|
-
listTools(): Promise<ToolDefinition[]>;
|
|
24
|
-
callTool(toolName: string, args: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
25
|
-
close(): Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=in-process.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-process.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/in-process.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,oBAAoB,GAAG,CAC/B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,gBAAgB,KACpB,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,MAAM,MAAM,uBAAuB,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,kBAAmB,YAAW,UAAU;IAE7C,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAFP,KAAK,EAAE,uBAAuB,EAAE,EAChC,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,gBAAgB;IAGxC,SAAS,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAQtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IASjF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* InProcessMcpClient routes tool calls directly to runtime handler
|
|
3
|
-
* functions without any network round-trip.
|
|
4
|
-
*
|
|
5
|
-
* This is the client used when an agent definition includes an
|
|
6
|
-
* "agent-mcp" server entry — it allows recursive delegation while
|
|
7
|
-
* preserving the ExecutionContext thread.
|
|
8
|
-
*/
|
|
9
|
-
export class InProcessMcpClient {
|
|
10
|
-
tools;
|
|
11
|
-
handler;
|
|
12
|
-
context;
|
|
13
|
-
constructor(tools, handler, context) {
|
|
14
|
-
this.tools = tools;
|
|
15
|
-
this.handler = handler;
|
|
16
|
-
this.context = context;
|
|
17
|
-
}
|
|
18
|
-
async listTools() {
|
|
19
|
-
return this.tools.map(t => ({
|
|
20
|
-
name: t.name,
|
|
21
|
-
description: t.description,
|
|
22
|
-
inputSchema: t.inputSchema,
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
async callTool(toolName, args, signal) {
|
|
26
|
-
// If the task was already cancelled/timed out, don't start the in-process
|
|
27
|
-
// call (which would spin up a recursive sub-task). Mid-flight cancellation
|
|
28
|
-
// of an in-process sub-task is handled by that sub-task's own cancellation
|
|
29
|
-
// signal via the task registry, not by this signal. (DEBT-003)
|
|
30
|
-
signal?.throwIfAborted();
|
|
31
|
-
return this.handler(toolName, args, this.context);
|
|
32
|
-
}
|
|
33
|
-
async close() {
|
|
34
|
-
// no-op — in-process, nothing to tear down
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=in-process.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-process.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/in-process.ts"],"names":[],"mappings":"AAgBA;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAkB;IAEN;IACA;IACA;IAHrB,YACqB,KAAgC,EAChC,OAA6B,EAC7B,OAAyB;QAFzB,UAAK,GAAL,KAAK,CAA2B;QAChC,YAAO,GAAP,OAAO,CAAsB;QAC7B,YAAO,GAAP,OAAO,CAAkB;IAC3C,CAAC;IAEJ,KAAK,CAAC,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACxB,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,WAAW,EAAE,CAAC,CAAC,WAAW;YAC1B,WAAW,EAAE,CAAC,CAAC,WAAW;SAC7B,CAAC,CAAC,CAAC;IACR,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,QAAgB,EAAE,IAAa,EAAE,MAAoB;QAChE,0EAA0E;QAC1E,2EAA2E;QAC3E,2EAA2E;QAC3E,+DAA+D;QAC/D,MAAM,EAAE,cAAc,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,KAAK;QACP,2CAA2C;IAC/C,CAAC;CACJ"}
|
package/src/clients/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type { IMcpClient } from "./types.js";
|
|
2
|
-
export { InProcessMcpClient } from "./in-process.js";
|
|
3
|
-
export type { InProcessToolHandler, InProcessToolDescriptor } from "./in-process.js";
|
|
4
|
-
export { StdioMcpClient } from "./stdio-client.js";
|
|
5
|
-
export { HttpMcpClient, SseMcpClient } from "./http-client.js";
|
|
6
|
-
export { McpClientRegistry } from "./registry.js";
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,YAAY,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
|
package/src/clients/index.js
DELETED
package/src/clients/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from "../providers/types.js";
|
|
2
|
-
import type { ExecutionContext, McpServerConfig } from "../validation/index.js";
|
|
3
|
-
import type { InProcessToolDescriptor, InProcessToolHandler } from "./in-process.js";
|
|
4
|
-
import type { IMcpClient } from "./types.js";
|
|
5
|
-
/**
|
|
6
|
-
* McpClientRegistry — per-task lifetime.
|
|
7
|
-
*
|
|
8
|
-
* Created fresh for each task() call and torn down in the Orchestrator's
|
|
9
|
-
* finally block via closeAll(). Never reused across tasks.
|
|
10
|
-
*
|
|
11
|
-
* Self-referential detection (routes to InProcessMcpClient):
|
|
12
|
-
* 1. Key === "agent-mcp" (always applies)
|
|
13
|
-
* 2. URL matches selfUrl (only when selfUrl is defined — http/sse transport)
|
|
14
|
-
* When TRANSPORT=stdio, selfUrl is undefined and only condition 1 applies.
|
|
15
|
-
*/
|
|
16
|
-
export declare class McpClientRegistry {
|
|
17
|
-
private readonly mcpServers;
|
|
18
|
-
private readonly selfUrl;
|
|
19
|
-
private readonly inProcessDescriptors;
|
|
20
|
-
private readonly inProcessHandler;
|
|
21
|
-
private readonly context;
|
|
22
|
-
private readonly clients;
|
|
23
|
-
private readonly connectPromises;
|
|
24
|
-
private readonly toolTargets;
|
|
25
|
-
constructor(mcpServers: Record<string, McpServerConfig>, selfUrl: string | undefined, inProcessDescriptors: InProcessToolDescriptor[], inProcessHandler: InProcessToolHandler, context: ExecutionContext);
|
|
26
|
-
private isSelfReferential;
|
|
27
|
-
/**
|
|
28
|
-
* Map a (possibly model-normalized) server name back to a configured key.
|
|
29
|
-
* OpenAI-compatible/local models rewrite '-' → '_', so a tool call to
|
|
30
|
-
* 'agent_mcp__…' must still resolve to the configured 'agent-mcp' server.
|
|
31
|
-
*/
|
|
32
|
-
private resolveServerName;
|
|
33
|
-
private getOrCreateClient;
|
|
34
|
-
/** Get a client for a specific server, connecting lazily if needed */
|
|
35
|
-
getClient(name: string): Promise<IMcpClient>;
|
|
36
|
-
/**
|
|
37
|
-
* List all tools across all configured servers.
|
|
38
|
-
* Prefixes each tool name with "<server>__<tool>" for disambiguation.
|
|
39
|
-
*/
|
|
40
|
-
listAllTools(): Promise<ToolDefinition[]>;
|
|
41
|
-
/**
|
|
42
|
-
* Resolve a tool name AS RETURNED BY A MODEL back to its real { server, tool }.
|
|
43
|
-
* Tries the exact advertised name, then the normalized form (handles models
|
|
44
|
-
* that rewrite '-' → '_'), then falls back to a literal `__` split for names
|
|
45
|
-
* the registry never advertised (preserves prior behavior).
|
|
46
|
-
*/
|
|
47
|
-
resolveToolName(advertised: string): {
|
|
48
|
-
server: string;
|
|
49
|
-
tool: string;
|
|
50
|
-
};
|
|
51
|
-
/** Tear down all clients — called from Orchestrator's finally block */
|
|
52
|
-
closeAll(): Promise<void>;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,KAAK,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAIrF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C;;;;;;;;;;GAUG;AACH,qBAAa,iBAAiB;IAStB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IACrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAZ5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAoC;IAIpE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuD;gBAG9D,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EAC3C,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,oBAAoB,EAAE,uBAAuB,EAAE,EAC/C,gBAAgB,EAAE,oBAAoB,EACtC,OAAO,EAAE,gBAAgB;IAG9C,OAAO,CAAC,iBAAiB;IAczB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;YAMX,iBAAiB;IAkD/B,sEAAsE;IAChE,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIlD;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IA4B/C;;;;;OAKG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAcrE,uEAAuE;IACjE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAgBlC"}
|
package/src/clients/registry.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { logger } from "../logger.js";
|
|
2
|
-
import { InProcessMcpClient } from "./in-process.js";
|
|
3
|
-
import { HttpMcpClient, SseMcpClient } from "./http-client.js";
|
|
4
|
-
import { StdioMcpClient } from "./stdio-client.js";
|
|
5
|
-
import { TOOL_NAME_SEPARATOR, normalizeToolName } from "./tool-naming.js";
|
|
6
|
-
/**
|
|
7
|
-
* McpClientRegistry — per-task lifetime.
|
|
8
|
-
*
|
|
9
|
-
* Created fresh for each task() call and torn down in the Orchestrator's
|
|
10
|
-
* finally block via closeAll(). Never reused across tasks.
|
|
11
|
-
*
|
|
12
|
-
* Self-referential detection (routes to InProcessMcpClient):
|
|
13
|
-
* 1. Key === "agent-mcp" (always applies)
|
|
14
|
-
* 2. URL matches selfUrl (only when selfUrl is defined — http/sse transport)
|
|
15
|
-
* When TRANSPORT=stdio, selfUrl is undefined and only condition 1 applies.
|
|
16
|
-
*/
|
|
17
|
-
export class McpClientRegistry {
|
|
18
|
-
mcpServers;
|
|
19
|
-
selfUrl;
|
|
20
|
-
inProcessDescriptors;
|
|
21
|
-
inProcessHandler;
|
|
22
|
-
context;
|
|
23
|
-
clients = new Map();
|
|
24
|
-
connectPromises = new Map();
|
|
25
|
-
// advertised tool name (and its normalized form) → real { server, tool }.
|
|
26
|
-
// Populated by listAllTools(); lets resolveToolName() recover the real target
|
|
27
|
-
// even when a model rewrites '-' → '_' in the name it calls back with.
|
|
28
|
-
toolTargets = new Map();
|
|
29
|
-
constructor(mcpServers, selfUrl, inProcessDescriptors, inProcessHandler, context) {
|
|
30
|
-
this.mcpServers = mcpServers;
|
|
31
|
-
this.selfUrl = selfUrl;
|
|
32
|
-
this.inProcessDescriptors = inProcessDescriptors;
|
|
33
|
-
this.inProcessHandler = inProcessHandler;
|
|
34
|
-
this.context = context;
|
|
35
|
-
}
|
|
36
|
-
isSelfReferential(name, config) {
|
|
37
|
-
if (name === "agent-mcp")
|
|
38
|
-
return true;
|
|
39
|
-
if (this.selfUrl &&
|
|
40
|
-
(config.transport === "http" || config.transport === "sse") &&
|
|
41
|
-
config.url === this.selfUrl) {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Map a (possibly model-normalized) server name back to a configured key.
|
|
48
|
-
* OpenAI-compatible/local models rewrite '-' → '_', so a tool call to
|
|
49
|
-
* 'agent_mcp__…' must still resolve to the configured 'agent-mcp' server.
|
|
50
|
-
*/
|
|
51
|
-
resolveServerName(name) {
|
|
52
|
-
if (this.mcpServers[name])
|
|
53
|
-
return name;
|
|
54
|
-
const norm = normalizeToolName(name);
|
|
55
|
-
return Object.keys(this.mcpServers).find((k) => normalizeToolName(k) === norm) ?? name;
|
|
56
|
-
}
|
|
57
|
-
async getOrCreateClient(rawName) {
|
|
58
|
-
const name = this.resolveServerName(rawName);
|
|
59
|
-
const existing = this.clients.get(name);
|
|
60
|
-
if (existing)
|
|
61
|
-
return existing;
|
|
62
|
-
const config = this.mcpServers[name];
|
|
63
|
-
if (!config) {
|
|
64
|
-
throw new Error(`No MCP server config found for server: '${rawName}'`);
|
|
65
|
-
}
|
|
66
|
-
if (this.isSelfReferential(name, config)) {
|
|
67
|
-
const client = new InProcessMcpClient(this.inProcessDescriptors, this.inProcessHandler, this.context);
|
|
68
|
-
this.clients.set(name, client);
|
|
69
|
-
return client;
|
|
70
|
-
}
|
|
71
|
-
// Create and connect the appropriate transport client
|
|
72
|
-
let connectPromise = this.connectPromises.get(name);
|
|
73
|
-
if (connectPromise) {
|
|
74
|
-
await connectPromise;
|
|
75
|
-
return this.clients.get(name);
|
|
76
|
-
}
|
|
77
|
-
let client;
|
|
78
|
-
if (config.transport === "stdio") {
|
|
79
|
-
client = new StdioMcpClient(name, config);
|
|
80
|
-
}
|
|
81
|
-
else if (config.transport === "http") {
|
|
82
|
-
client = new HttpMcpClient(name, config);
|
|
83
|
-
}
|
|
84
|
-
else if (config.transport === "sse") {
|
|
85
|
-
client = new SseMcpClient(name, config);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
const exhaustive = config;
|
|
89
|
-
throw new Error(`Unknown MCP transport: ${exhaustive.transport}`);
|
|
90
|
-
}
|
|
91
|
-
connectPromise = client.connect().then(() => {
|
|
92
|
-
this.clients.set(name, client);
|
|
93
|
-
logger.debug({ server: name }, "MCP client connected");
|
|
94
|
-
});
|
|
95
|
-
this.connectPromises.set(name, connectPromise);
|
|
96
|
-
await connectPromise;
|
|
97
|
-
return this.clients.get(name);
|
|
98
|
-
}
|
|
99
|
-
/** Get a client for a specific server, connecting lazily if needed */
|
|
100
|
-
async getClient(name) {
|
|
101
|
-
return this.getOrCreateClient(name);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* List all tools across all configured servers.
|
|
105
|
-
* Prefixes each tool name with "<server>__<tool>" for disambiguation.
|
|
106
|
-
*/
|
|
107
|
-
async listAllTools() {
|
|
108
|
-
const allTools = [];
|
|
109
|
-
for (const serverName of Object.keys(this.mcpServers)) {
|
|
110
|
-
try {
|
|
111
|
-
const client = await this.getOrCreateClient(serverName);
|
|
112
|
-
const tools = await client.listTools();
|
|
113
|
-
for (const tool of tools) {
|
|
114
|
-
const advertised = `${serverName}${TOOL_NAME_SEPARATOR}${tool.name}`;
|
|
115
|
-
const target = { server: serverName, tool: tool.name };
|
|
116
|
-
// Index both the advertised name and its normalized form so a
|
|
117
|
-
// model that rewrites '-' → '_' still resolves to the real target.
|
|
118
|
-
this.toolTargets.set(advertised, target);
|
|
119
|
-
this.toolTargets.set(normalizeToolName(advertised), target);
|
|
120
|
-
allTools.push({ ...tool, name: advertised });
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
logger.warn({ server: serverName, error }, "Failed to list tools from MCP server");
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return allTools;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Resolve a tool name AS RETURNED BY A MODEL back to its real { server, tool }.
|
|
131
|
-
* Tries the exact advertised name, then the normalized form (handles models
|
|
132
|
-
* that rewrite '-' → '_'), then falls back to a literal `__` split for names
|
|
133
|
-
* the registry never advertised (preserves prior behavior).
|
|
134
|
-
*/
|
|
135
|
-
resolveToolName(advertised) {
|
|
136
|
-
const hit = this.toolTargets.get(advertised) ??
|
|
137
|
-
this.toolTargets.get(normalizeToolName(advertised));
|
|
138
|
-
if (hit)
|
|
139
|
-
return hit;
|
|
140
|
-
const i = advertised.indexOf(TOOL_NAME_SEPARATOR);
|
|
141
|
-
return i === -1
|
|
142
|
-
? { server: advertised, tool: advertised }
|
|
143
|
-
: {
|
|
144
|
-
server: advertised.slice(0, i),
|
|
145
|
-
tool: advertised.slice(i + TOOL_NAME_SEPARATOR.length),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
/** Tear down all clients — called from Orchestrator's finally block */
|
|
149
|
-
async closeAll() {
|
|
150
|
-
const closePromises = Array.from(this.clients.entries()).map(async ([name, client]) => {
|
|
151
|
-
try {
|
|
152
|
-
await client.close();
|
|
153
|
-
logger.debug({ server: name }, "MCP client closed");
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
logger.warn({ server: name, error }, "Error closing MCP client");
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
await Promise.allSettled(closePromises);
|
|
160
|
-
this.clients.clear();
|
|
161
|
-
this.connectPromises.clear();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,MAAM,OAAO,iBAAiB;IASL;IACA;IACA;IACA;IACA;IAZJ,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IACxC,eAAe,GAAG,IAAI,GAAG,EAAyB,CAAC;IACpE,0EAA0E;IAC1E,8EAA8E;IAC9E,uEAAuE;IACtD,WAAW,GAAG,IAAI,GAAG,EAA4C,CAAC;IAEnF,YACqB,UAA2C,EAC3C,OAA2B,EAC3B,oBA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MAAM,EAAE,IAAI,EAAE,EAAE,mBAAmB,CAAC,CAAC;YACxD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,0BAA0B,CAAC,CAAC;YACrE,CAAC;QACL,CAAC,CACJ,CAAC;QAEF,MAAM,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;CACJ"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from "../providers/types.js";
|
|
2
|
-
import type { McpStdioConfig } from "../validation/index.js";
|
|
3
|
-
import type { IMcpClient } from "./types.js";
|
|
4
|
-
export declare class StdioMcpClient implements IMcpClient {
|
|
5
|
-
private readonly serverName;
|
|
6
|
-
private readonly config;
|
|
7
|
-
private client;
|
|
8
|
-
private transport;
|
|
9
|
-
private childProcess;
|
|
10
|
-
constructor(serverName: string, config: McpStdioConfig);
|
|
11
|
-
connect(): Promise<void>;
|
|
12
|
-
listTools(): Promise<ToolDefinition[]>;
|
|
13
|
-
callTool(toolName: string, args: unknown, callerSignal?: AbortSignal): Promise<unknown>;
|
|
14
|
-
close(): Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=stdio-client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stdio-client.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/stdio-client.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,qBAAa,cAAe,YAAW,UAAU;IAMzC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAN3B,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,YAAY,CAA6B;gBAG5B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc;IAGrC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAwCxB,SAAS,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAgBtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAgCvF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAoB/B"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
-
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
-
import { logger } from "../logger.js";
|
|
4
|
-
import { config } from "../config.js";
|
|
5
|
-
import { ToolError } from "../validation/errors.js";
|
|
6
|
-
export class StdioMcpClient {
|
|
7
|
-
serverName;
|
|
8
|
-
config;
|
|
9
|
-
client = null;
|
|
10
|
-
transport = null;
|
|
11
|
-
childProcess = null;
|
|
12
|
-
constructor(serverName, config) {
|
|
13
|
-
this.serverName = serverName;
|
|
14
|
-
this.config = config;
|
|
15
|
-
}
|
|
16
|
-
async connect() {
|
|
17
|
-
const transport = new StdioClientTransport({
|
|
18
|
-
command: this.config.command,
|
|
19
|
-
args: this.config.args ?? [],
|
|
20
|
-
env: {
|
|
21
|
-
...config.subprocessEnv(),
|
|
22
|
-
...this.config.env,
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
this.transport = transport;
|
|
26
|
-
// Capture child process reference for lifecycle management.
|
|
27
|
-
// The StdioClientTransport exposes it after start().
|
|
28
|
-
const client = new Client({ name: "agent-mcp-client", version: "1.0.0" }, { capabilities: {} });
|
|
29
|
-
this.client = client;
|
|
30
|
-
await client.connect(transport);
|
|
31
|
-
// Attach exit handler to the underlying child process.
|
|
32
|
-
// StdioClientTransport exposes `process` after connect().
|
|
33
|
-
const childProc = transport.process;
|
|
34
|
-
if (childProc) {
|
|
35
|
-
this.childProcess = childProc;
|
|
36
|
-
childProc.on("exit", (code, signal) => {
|
|
37
|
-
logger.warn({
|
|
38
|
-
server: this.serverName,
|
|
39
|
-
exitCode: code,
|
|
40
|
-
signal,
|
|
41
|
-
}, "MCP child process exited unexpectedly");
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async listTools() {
|
|
46
|
-
if (!this.client) {
|
|
47
|
-
throw new ToolError("MCP_CLIENT_ERROR", `Client '${this.serverName}' not connected`);
|
|
48
|
-
}
|
|
49
|
-
const response = await this.client.listTools();
|
|
50
|
-
return response.tools.map(tool => ({
|
|
51
|
-
name: tool.name,
|
|
52
|
-
description: tool.description ?? "",
|
|
53
|
-
inputSchema: tool.inputSchema ?? {
|
|
54
|
-
type: "object",
|
|
55
|
-
properties: {},
|
|
56
|
-
},
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
async callTool(toolName, args, callerSignal) {
|
|
60
|
-
if (!this.client) {
|
|
61
|
-
throw new ToolError("MCP_CLIENT_ERROR", `Client '${this.serverName}' not connected`);
|
|
62
|
-
}
|
|
63
|
-
// Compose the caller's cancellation/timeout signal (DEBT-003 — lets a
|
|
64
|
-
// task cancel interrupt this in-flight call) with the client-level
|
|
65
|
-
// per-call timeout. Either may fire first.
|
|
66
|
-
const timeoutSignal = this.config.timeoutMs
|
|
67
|
-
? AbortSignal.timeout(this.config.timeoutMs)
|
|
68
|
-
: undefined;
|
|
69
|
-
const signal = callerSignal && timeoutSignal
|
|
70
|
-
? AbortSignal.any([callerSignal, timeoutSignal])
|
|
71
|
-
: (callerSignal ?? timeoutSignal);
|
|
72
|
-
const result = await this.client.callTool({ name: toolName, arguments: args }, undefined, signal ? { signal } : undefined);
|
|
73
|
-
if (result.isError) {
|
|
74
|
-
throw new ToolError("MCP_CLIENT_ERROR", `Tool '${toolName}' on server '${this.serverName}' returned an error: ${JSON.stringify(result.content)}`);
|
|
75
|
-
}
|
|
76
|
-
return result.content;
|
|
77
|
-
}
|
|
78
|
-
async close() {
|
|
79
|
-
try {
|
|
80
|
-
await this.client?.close();
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
// ignore close errors
|
|
84
|
-
}
|
|
85
|
-
if (this.childProcess && !this.childProcess.killed) {
|
|
86
|
-
this.childProcess.kill("SIGTERM");
|
|
87
|
-
// Force-kill after 5 seconds if still alive
|
|
88
|
-
const killTimer = setTimeout(() => {
|
|
89
|
-
if (this.childProcess && !this.childProcess.killed) {
|
|
90
|
-
this.childProcess.kill("SIGKILL");
|
|
91
|
-
}
|
|
92
|
-
}, 5_000);
|
|
93
|
-
killTimer.unref();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
//# sourceMappingURL=stdio-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stdio-client.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/stdio-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAGjF,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,MAAM,OAAO,cAAc;IAMF;IACA;IANb,MAAM,GAAkB,IAAI,CAAC;IAC7B,SAAS,GAAgC,IAAI,CAAC;IAC9C,YAAY,GAAwB,IAAI,CAAC;IAEjD,YACqB,UAA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AS,CAClC,CAAC;QAEF,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,SAAS,CACf,kBAAkB,EAClB,SAAS,QAAQ,gBAAgB,IAAI,CAAC,UAAU,wBAAwB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAC3G,CAAC;QACN,CAAC;QAED,OAAO,MAAM,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAK;QACP,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACL,sBAAsB;QAC1B,CAAC;QAED,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;YACjD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAElC,4CAA4C;YAC5C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC9B,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;oBACjD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACtC,CAAC;YACL,CAAC,EAAE,KAAK,CAAC,CAAC;YAEV,SAAS,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool-name encoding shared across the registry and the orchestrator.
|
|
3
|
-
*
|
|
4
|
-
* Tools are advertised to the model as `<server>__<tool>`. Many OpenAI-compatible
|
|
5
|
-
* and local models (e.g. LM Studio / qwen) restrict function names to
|
|
6
|
-
* `[A-Za-z0-9_]` and silently rewrite other characters — notably `-` → `_` — so
|
|
7
|
-
* an advertised `agent-mcp__agent` comes back from the model as
|
|
8
|
-
* `agent_mcp__agent`. A literal lookup then fails ("No MCP server config found
|
|
9
|
-
* for server: 'agent_mcp'"), which breaks recursion (the `agent-mcp` key) and any
|
|
10
|
-
* MCP server whose name contains a hyphen. Anthropic preserves the name, so this
|
|
11
|
-
* only bites the OpenAI-compatible providers — but the round-trip must be robust
|
|
12
|
-
* for ALL of them.
|
|
13
|
-
*
|
|
14
|
-
* The fix: index both the advertised name and its normalized form, and normalize
|
|
15
|
-
* the model's returned name the same way before resolving.
|
|
16
|
-
*/
|
|
17
|
-
export declare const TOOL_NAME_SEPARATOR = "__";
|
|
18
|
-
/** Normalize a tool name to the charset models restrict function names to. */
|
|
19
|
-
export declare function normalizeToolName(name: string): string;
|
|
20
|
-
export interface ResolvedToolName {
|
|
21
|
-
server: string;
|
|
22
|
-
tool: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Resolve a tool name AS RETURNED BY A MODEL into { server, tool }.
|
|
26
|
-
*
|
|
27
|
-
* - A qualified `<server>__<tool>` name splits on the separator (prior behavior).
|
|
28
|
-
* - A **bare** `<tool>` name (no separator) is resolved against the tool names the
|
|
29
|
-
* model was actually advertised: if exactly one advertised tool has that
|
|
30
|
-
* tool-part it is used; if several do, an actionable error lists the qualified
|
|
31
|
-
* candidates; if none do, it falls back to a literal split so downstream
|
|
32
|
-
* "unknown tool / no server config" handling still applies.
|
|
33
|
-
*
|
|
34
|
-
* Background (BACKLOG DEBT-004): capable models frequently emit the bare tool
|
|
35
|
-
* name (`agent` / `task`) instead of the advertised `agent-mcp__agent`, which used
|
|
36
|
-
* to hard-fail the whole task with "Invalid tool name (missing server prefix)".
|
|
37
|
-
* Since the separator is unambiguous in advertised names, a bare name that maps to
|
|
38
|
-
* exactly one advertised tool can be resolved deterministically.
|
|
39
|
-
*
|
|
40
|
-
* @param rawName the tool name the model returned
|
|
41
|
-
* @param advertised the advertised tool names the model was given (`<server>__<tool>`)
|
|
42
|
-
*/
|
|
43
|
-
export declare function resolveToolCallName(rawName: string, advertised?: readonly string[]): ResolvedToolName;
|
|
44
|
-
//# sourceMappingURL=tool-naming.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-naming.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/tool-naming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CAChB;AAUD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,SAAS,MAAM,EAAO,GAAG,gBAAgB,CAkBzG"}
|