@adhd/agent-mcp 2.0.1 → 2.1.1
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/adhd-agent-mcp-2.1.1.tgz +0 -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/drizzle/0007_smart_callisto.sql +40 -0
- package/drizzle/0008_cache_and_peak_context_usage.sql +19 -0
- package/drizzle/0009_restore_sessions_agent_fk.sql +29 -0
- package/drizzle/meta/0007_snapshot.json +658 -0
- package/drizzle/meta/_journal.json +22 -1
- package/llms.txt +133 -0
- package/package.json +30 -51
- 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 +3 -42
- package/src/index.d.ts.map +1 -1
- package/src/index.js +32 -123
- 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/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
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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AC,CAAC;QAClD,OAAO,CAAC,KAAK,CAAC,CAAC;YACX,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE;YAC1C,CAAC,CAAC;gBACI,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;gBAC9B,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,mBAAmB,CAAC,MAAM,CAAC;aACzD,CAAC;IACZ,CAAC;IAED,uEAAuE;IACvE,KAAK,CAAC,QAAQ;QACV,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CACxD,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;YACrB,IAAI,CAAC;gBACD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;gBACrB,MAAM,CAAC,KAAK,CAAC,EAAE,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,UAAkB,EAClB,MAAsB;QADtB,eAAU,GAAV,UAAU,CAAQ;QAClB,WAAM,GAAN,MAAM,CAAgB;IACxC,CAAC;IAEJ,KAAK,CAAC,OAAO;QACT,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC;YACvC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE;YAC5B,GAAG,EAAE;gBACD,GAAG,MAAM,CAAC,aAAa,EAAE;gBACzB,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG;aACK;SAC9B,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,4DAA4D;QAC5D,qDAAqD;QACrD,MAAM,MAAM,GAAG,IAAI,MAAM,CACrB,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,EAAE,EAC9C,EAAE,YAAY,EAAE,EAAE,EAAE,CACvB,CAAC;QAEF,IAAI,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,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"}
|
|
@@ -1,65 +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 const TOOL_NAME_SEPARATOR = "__";
|
|
18
|
-
/** Normalize a tool name to the charset models restrict function names to. */
|
|
19
|
-
export function normalizeToolName(name) {
|
|
20
|
-
return name.replace(/[^A-Za-z0-9_]/g, "_");
|
|
21
|
-
}
|
|
22
|
-
/** Split a name on the first separator into { server, tool } (no resolution). */
|
|
23
|
-
function splitToolName(name) {
|
|
24
|
-
const i = name.indexOf(TOOL_NAME_SEPARATOR);
|
|
25
|
-
return i === -1
|
|
26
|
-
? { server: name, tool: name }
|
|
27
|
-
: { server: name.slice(0, i), tool: name.slice(i + TOOL_NAME_SEPARATOR.length) };
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Resolve a tool name AS RETURNED BY A MODEL into { server, tool }.
|
|
31
|
-
*
|
|
32
|
-
* - A qualified `<server>__<tool>` name splits on the separator (prior behavior).
|
|
33
|
-
* - A **bare** `<tool>` name (no separator) is resolved against the tool names the
|
|
34
|
-
* model was actually advertised: if exactly one advertised tool has that
|
|
35
|
-
* tool-part it is used; if several do, an actionable error lists the qualified
|
|
36
|
-
* candidates; if none do, it falls back to a literal split so downstream
|
|
37
|
-
* "unknown tool / no server config" handling still applies.
|
|
38
|
-
*
|
|
39
|
-
* Background (BACKLOG DEBT-004): capable models frequently emit the bare tool
|
|
40
|
-
* name (`agent` / `task`) instead of the advertised `agent-mcp__agent`, which used
|
|
41
|
-
* to hard-fail the whole task with "Invalid tool name (missing server prefix)".
|
|
42
|
-
* Since the separator is unambiguous in advertised names, a bare name that maps to
|
|
43
|
-
* exactly one advertised tool can be resolved deterministically.
|
|
44
|
-
*
|
|
45
|
-
* @param rawName the tool name the model returned
|
|
46
|
-
* @param advertised the advertised tool names the model was given (`<server>__<tool>`)
|
|
47
|
-
*/
|
|
48
|
-
export function resolveToolCallName(rawName, advertised = []) {
|
|
49
|
-
if (rawName.includes(TOOL_NAME_SEPARATOR))
|
|
50
|
-
return splitToolName(rawName);
|
|
51
|
-
const norm = normalizeToolName(rawName);
|
|
52
|
-
const candidates = Array.from(new Set(advertised)).filter((a) => {
|
|
53
|
-
const { tool } = splitToolName(a);
|
|
54
|
-
return tool === rawName || normalizeToolName(tool) === norm;
|
|
55
|
-
});
|
|
56
|
-
if (candidates.length === 1)
|
|
57
|
-
return splitToolName(candidates[0]);
|
|
58
|
-
if (candidates.length > 1) {
|
|
59
|
-
throw new Error(`Ambiguous tool name '${rawName}': multiple servers expose it — qualify with a server prefix, one of: ${candidates.join(", ")}`);
|
|
60
|
-
}
|
|
61
|
-
// No advertised match — preserve prior split (server = tool = rawName); the
|
|
62
|
-
// registry then surfaces a normal "no server config" / unknown-tool error.
|
|
63
|
-
return splitToolName(rawName);
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=tool-naming.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-naming.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/tool-naming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAA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AC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACX,wBAAwB,OAAO,yEAAyE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAClI,CAAC;IACN,CAAC;IACD,4EAA4E;IAC5E,2EAA2E;IAC3E,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC"}
|
package/src/clients/types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from "../providers/types.js";
|
|
2
|
-
export interface IMcpClient {
|
|
3
|
-
/** Returns all tools advertised by this MCP server */
|
|
4
|
-
listTools(): Promise<ToolDefinition[]>;
|
|
5
|
-
/**
|
|
6
|
-
* Call a single tool on this server.
|
|
7
|
-
* @param toolName the tool name (without server prefix)
|
|
8
|
-
* @param args the arguments to pass
|
|
9
|
-
* @param signal optional abort signal — when the task is cancelled (or
|
|
10
|
-
* times out) this fires, so an in-flight tool call is
|
|
11
|
-
* interrupted instead of running to completion. Composed
|
|
12
|
-
* with any client-level timeout.
|
|
13
|
-
*/
|
|
14
|
-
callTool(toolName: string, args: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
15
|
-
/** Tear down the client (kill child processes, close connections) */
|
|
16
|
-
close(): Promise<void>;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,WAAW,UAAU;IACvB,sDAAsD;IACtD,SAAS,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAEvC;;;;;;;;OAQG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAElF,qEAAqE;IACrE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
|
package/src/clients/types.js
DELETED
package/src/clients/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/clients/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { BetterSQLite3Database } from "drizzle-orm/better-sqlite3";
|
|
2
|
-
import type { TaskStore } from "../store/task-store.js";
|
|
3
|
-
import type { BackgroundQueue } from "./queue.js";
|
|
4
|
-
/**
|
|
5
|
-
* DagEngine manages task dependency resolution.
|
|
6
|
-
*
|
|
7
|
-
* Two public methods:
|
|
8
|
-
* - `validateNoCycle()` — synchronous BFS cycle check; called BEFORE row insert.
|
|
9
|
-
* - `dispatchReady()` — post-terminal fan-in dispatch; called in the queue runFn
|
|
10
|
-
* `finally` block so it fires on every terminal event (completed/failed/cancelled).
|
|
11
|
-
*
|
|
12
|
-
* The `dispatchFn` is injected at server startup (built in src/index.ts) to avoid
|
|
13
|
-
* circular imports: DagEngine must NOT import from tools/task.ts.
|
|
14
|
-
*/
|
|
15
|
-
export declare class DagEngine {
|
|
16
|
-
private readonly db;
|
|
17
|
-
private readonly queue;
|
|
18
|
-
private readonly taskStore;
|
|
19
|
-
/**
|
|
20
|
-
* Injected at server startup to avoid circular imports with tools/task.ts.
|
|
21
|
-
* Signature: (taskId: string) => Promise<void>
|
|
22
|
-
* Built in index.ts by closing over the TaskDeps.
|
|
23
|
-
*/
|
|
24
|
-
private readonly dispatchFn;
|
|
25
|
-
constructor(db: BetterSQLite3Database<Record<string, never>>, queue: BackgroundQueue, taskStore: TaskStore,
|
|
26
|
-
/**
|
|
27
|
-
* Injected at server startup to avoid circular imports with tools/task.ts.
|
|
28
|
-
* Signature: (taskId: string) => Promise<void>
|
|
29
|
-
* Built in index.ts by closing over the TaskDeps.
|
|
30
|
-
*/
|
|
31
|
-
dispatchFn: (taskId: string) => Promise<void>);
|
|
32
|
-
/**
|
|
33
|
-
* BFS cycle detection. Call BEFORE inserting the new task row.
|
|
34
|
-
*
|
|
35
|
-
* Walks the existing dependency graph upward from each member of `dependsOn`.
|
|
36
|
-
* If `newTaskId` appears as an ancestor, adding it would create a cycle.
|
|
37
|
-
*
|
|
38
|
-
* Throws ToolError("VALIDATION_ERROR") if a cycle is detected.
|
|
39
|
-
* Does NOT write any rows — purely a read operation.
|
|
40
|
-
*
|
|
41
|
-
* Invariant: [inv:cycle-check-synchronous]
|
|
42
|
-
*/
|
|
43
|
-
validateNoCycle(newTaskId: string, dependsOn: string[]): void;
|
|
44
|
-
/**
|
|
45
|
-
* Called after a task reaches a terminal state (completed/failed/cancelled).
|
|
46
|
-
*
|
|
47
|
-
* Scans all `waiting` tasks for those that include `completedTaskId` in their
|
|
48
|
-
* `depends_on`. For each:
|
|
49
|
-
* - If all deps are in a terminal state, evaluate `on_upstream_failure`:
|
|
50
|
-
* - "fail" (default): mark the downstream as failed immediately.
|
|
51
|
-
* - "skip": dispatch anyway; only include completed upstreams in `inputs`.
|
|
52
|
-
*
|
|
53
|
-
* Uses optimistic locking (`AND status='waiting'` on the UPDATE) to prevent
|
|
54
|
-
* double-enqueue when two concurrent terminal events race for the same fan-in
|
|
55
|
-
* task.
|
|
56
|
-
*
|
|
57
|
-
* Invariants: [inv:waiting-no-queue], [inv:dispatch-on-completion],
|
|
58
|
-
* [inv:inputs-populated-at-dispatch]
|
|
59
|
-
*/
|
|
60
|
-
dispatchReady(completedTaskId: string): Promise<void>;
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=dag-engine.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dag-engine.d.ts","sourceRoot":"","sources":["../../../../../../packages/ai/agent-mcp/src/engine/dag-engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAIxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIlD;;;;;;;;;;GAUG;AACH,qBAAa,SAAS;IAEd,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU;gBARV,EAAE,EAAE,qBAAqB,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAChD,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,SAAS;IACrC;;;;OAIG;IACc,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;IAGlE;;;;;;;;;;OAUG;IACH,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI;IAgC7D;;;;;;;;;;;;;;;OAeG;IACG,aAAa,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAkG9D"}
|