@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
|
@@ -25,4 +25,8 @@ export type TaskStreamEvent = {
|
|
|
25
25
|
};
|
|
26
26
|
export declare function emitTaskEvent(event: TaskStreamEvent): void;
|
|
27
27
|
export declare function subscribeToTask(taskId: string, handler: (event: TaskStreamEvent) => void): () => void;
|
|
28
|
+
export declare function subscribeToAllTasks(handler: (event: TaskStreamEvent) => void): () => void;
|
|
29
|
+
export declare function subscribeToTaskDone(handler: (event: TaskStreamEvent & {
|
|
30
|
+
type: "done";
|
|
31
|
+
}) => void): () => void;
|
|
28
32
|
//# sourceMappingURL=event-bus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../../../../entrypoint/agent-mcp/src/streaming/event-bus.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GACrB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAS,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAK,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC/F;IAAE,IAAI,EAAE,aAAa,CAAC;IAAG,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAC/E;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAU,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAK7F,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAG1D;AAED,wBAAgB,eAAe,CAC3B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GAC1C,MAAM,IAAI,CAIZ;AAED,wBAAgB,mBAAmB,CAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GAC1C,MAAM,IAAI,CAGZ;AAED,wBAAgB,mBAAmB,CAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KAAK,IAAI,GAC7D,MAAM,IAAI,CAMZ"}
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
2
|
const emitter = new EventEmitter();
|
|
3
|
-
emitter.setMaxListeners(500);
|
|
3
|
+
emitter.setMaxListeners(500);
|
|
4
4
|
export function emitTaskEvent(event) {
|
|
5
5
|
emitter.emit(`task:${event.taskId}`, event);
|
|
6
|
+
emitter.emit("task-event", event);
|
|
6
7
|
}
|
|
7
8
|
export function subscribeToTask(taskId, handler) {
|
|
8
9
|
const key = `task:${taskId}`;
|
|
9
10
|
emitter.on(key, handler);
|
|
10
11
|
return () => emitter.off(key, handler);
|
|
11
12
|
}
|
|
13
|
+
export function subscribeToAllTasks(handler) {
|
|
14
|
+
emitter.on("task-event", handler);
|
|
15
|
+
return () => emitter.off("task-event", handler);
|
|
16
|
+
}
|
|
17
|
+
export function subscribeToTaskDone(handler) {
|
|
18
|
+
const wrapped = (event) => {
|
|
19
|
+
if (event.type === "done")
|
|
20
|
+
handler(event);
|
|
21
|
+
};
|
|
22
|
+
emitter.on("task-event", wrapped);
|
|
23
|
+
return () => emitter.off("task-event", wrapped);
|
|
24
|
+
}
|
|
12
25
|
//# sourceMappingURL=event-bus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../../../../../entrypoint/agent-mcp/src/streaming/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAS3C,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;AACnC,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;AAE7B,MAAM,UAAU,aAAa,CAAC,KAAsB;IAChD,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,CAAC;IAC5C,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,eAAe,CAC3B,MAAc,EACd,OAAyC;IAEzC,MAAM,GAAG,GAAG,QAAQ,MAAM,EAAE,CAAC;IAC7B,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACzB,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAC/B,OAAyC;IAEzC,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAC/B,OAA4D;IAE5D,MAAM,OAAO,GAAG,CAAC,KAAsB,EAAE,EAAE;QACvC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;YAAE,OAAO,CAAC,KAA2C,CAAC,CAAC;IACpF,CAAC,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import http from "node:http";
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* @param port port to bind (default config.sse.port, else 3001). Pass `0` for an
|
|
7
|
-
* ephemeral port (used by tests).
|
|
8
|
-
* @param host host to bind (default config.sse.host, else 127.0.0.1).
|
|
9
|
-
*
|
|
10
|
-
* A bind failure (e.g. `EADDRINUSE` when the port is already taken) is handled
|
|
11
|
-
* gracefully: it is logged and SSE streaming is left unavailable, but the
|
|
12
|
-
* process does NOT crash — the stdio MCP transport, which never needed the
|
|
13
|
-
* port, keeps serving. (BUG-001)
|
|
14
|
-
*/
|
|
15
|
-
export declare function startSseServer(taskStore: TaskStore, port?: number, host?: string): http.Server;
|
|
2
|
+
import { type GatewayDepsRef } from "./chat-gateway.js";
|
|
3
|
+
import type { TaskStore } from "@adhd/agent-store-runtime";
|
|
4
|
+
export declare function startSseServer(taskStore: TaskStore, port?: number, host?: string, gatewayDepsRef?: GatewayDepsRef): http.Server;
|
|
16
5
|
//# sourceMappingURL=sse-server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse-server.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"sse-server.d.ts","sourceRoot":"","sources":["../../../../../entrypoint/agent-mcp/src/streaming/sse-server.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAA0C,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAChG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAO3D,wBAAgB,cAAc,CAC1B,SAAS,EAAE,SAAS,EACpB,IAAI,GAAE,MAAwB,EAC9B,IAAI,GAAE,MAAwB,EAC9B,cAAc,CAAC,EAAE,cAAc,GAChC,IAAI,CAAC,MAAM,CA8Hb"}
|
|
@@ -1,31 +1,50 @@
|
|
|
1
1
|
import http from "node:http";
|
|
2
2
|
import { subscribeToTask } from "./event-bus.js";
|
|
3
|
+
import { handleGetModels, handleChatCompletions } from "./chat-gateway.js";
|
|
3
4
|
import { logger } from "../logger.js";
|
|
4
5
|
import { config } from "../config.js";
|
|
5
6
|
const KEEPALIVE_INTERVAL_MS = 15_000;
|
|
6
7
|
const TERMINAL_STATUSES = ["completed", "failed", "cancelled"];
|
|
7
|
-
|
|
8
|
-
* Start the task-streaming SSE server.
|
|
9
|
-
*
|
|
10
|
-
* @param port port to bind (default config.sse.port, else 3001). Pass `0` for an
|
|
11
|
-
* ephemeral port (used by tests).
|
|
12
|
-
* @param host host to bind (default config.sse.host, else 127.0.0.1).
|
|
13
|
-
*
|
|
14
|
-
* A bind failure (e.g. `EADDRINUSE` when the port is already taken) is handled
|
|
15
|
-
* gracefully: it is logged and SSE streaming is left unavailable, but the
|
|
16
|
-
* process does NOT crash — the stdio MCP transport, which never needed the
|
|
17
|
-
* port, keeps serving. (BUG-001)
|
|
18
|
-
*/
|
|
19
|
-
export function startSseServer(taskStore, port = config.sse.port, host = config.sse.host) {
|
|
8
|
+
export function startSseServer(taskStore, port = config.sse.port, host = config.sse.host, gatewayDepsRef) {
|
|
20
9
|
const server = http.createServer((req, res) => {
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
10
|
+
const url = req.url ?? "";
|
|
11
|
+
const method = req.method ?? "GET";
|
|
12
|
+
if (url === "/v1/models" && method === "GET") {
|
|
13
|
+
if (!gatewayDepsRef?.value) {
|
|
14
|
+
res.writeHead(503, { "Content-Type": "application/json" });
|
|
15
|
+
res.end(JSON.stringify({ error: { message: "Gateway not yet initialized", type: "server_error" } }));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
handleGetModels(res, gatewayDepsRef.value);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (url === "/v1/chat/completions" && method === "POST") {
|
|
22
|
+
if (!gatewayDepsRef?.value) {
|
|
23
|
+
res.writeHead(503, { "Content-Type": "application/json" });
|
|
24
|
+
res.end(JSON.stringify({ error: { message: "Gateway not yet initialized", type: "server_error" } }));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
handleChatCompletions(req, res, gatewayDepsRef.value).catch((err) => {
|
|
28
|
+
logger.error({ err }, "chat-gateway: unhandled error in handleChatCompletions");
|
|
29
|
+
if (!res.headersSent) {
|
|
30
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
31
|
+
res.end(JSON.stringify({ error: { message: "Internal server error", type: "server_error" } }));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const match = url.match(/^\/tasks\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/stream$/i);
|
|
37
|
+
if (!match || method !== "GET") {
|
|
24
38
|
res.writeHead(404);
|
|
25
39
|
res.end("Not found");
|
|
26
40
|
return;
|
|
27
41
|
}
|
|
28
42
|
const taskId = match[1];
|
|
43
|
+
if (!taskId) {
|
|
44
|
+
res.writeHead(404);
|
|
45
|
+
res.end("Not found");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
29
48
|
res.writeHead(200, {
|
|
30
49
|
"Content-Type": "text/event-stream",
|
|
31
50
|
"Cache-Control": "no-cache",
|
|
@@ -33,26 +52,17 @@ export function startSseServer(taskStore, port = config.sse.port, host = config.
|
|
|
33
52
|
"X-Accel-Buffering": "no",
|
|
34
53
|
});
|
|
35
54
|
res.flushHeaders?.();
|
|
36
|
-
// Keep-alive ping
|
|
37
55
|
const pingTimer = setInterval(() => {
|
|
38
56
|
res.write(": ping\n\n");
|
|
39
57
|
}, KEEPALIVE_INTERVAL_MS);
|
|
40
|
-
// Terminal-on-connect short-circuit: if the task is already in a terminal
|
|
41
|
-
// state when the client connects, emit status_change + done and close
|
|
42
|
-
// immediately — prevents clients from hanging forever waiting for events
|
|
43
|
-
// that already fired before they connected.
|
|
44
58
|
let existingTask = null;
|
|
45
59
|
try {
|
|
46
60
|
existingTask = taskStore.read(taskId);
|
|
47
61
|
}
|
|
48
62
|
catch {
|
|
49
|
-
// TASK_NOT_FOUND — let the client wait
|
|
63
|
+
// TASK_NOT_FOUND — let the client wait
|
|
50
64
|
}
|
|
51
65
|
if (existingTask && TERMINAL_STATUSES.includes(existingTask.status)) {
|
|
52
|
-
// Write directly to THIS response. The connection has not subscribed
|
|
53
|
-
// yet, so emitting on the shared bus would miss this client entirely
|
|
54
|
-
// and would also spuriously close any OTHER client still subscribed to
|
|
55
|
-
// the same task (their handler would see a second done and clean up).
|
|
56
66
|
const statusEvent = {
|
|
57
67
|
type: "status_change",
|
|
58
68
|
taskId,
|
|
@@ -70,10 +80,6 @@ export function startSseServer(taskStore, port = config.sse.port, host = config.
|
|
|
70
80
|
res.end();
|
|
71
81
|
return;
|
|
72
82
|
}
|
|
73
|
-
// `cleaned` flag prevents double-call: done handler calls cleanup() which
|
|
74
|
-
// calls res.end(); req.on("close") fires because res.end() closes the
|
|
75
|
-
// connection and would call cleanup() again — the second res.end() throws
|
|
76
|
-
// ERR_HTTP_HEADERS_SENT.
|
|
77
83
|
let cleaned = false;
|
|
78
84
|
function cleanup() {
|
|
79
85
|
if (cleaned)
|
|
@@ -83,10 +89,9 @@ export function startSseServer(taskStore, port = config.sse.port, host = config.
|
|
|
83
89
|
unsubscribe();
|
|
84
90
|
res.end();
|
|
85
91
|
}
|
|
86
|
-
// Subscribe to task events
|
|
87
92
|
const unsubscribe = subscribeToTask(taskId, (event) => {
|
|
88
93
|
if (cleaned)
|
|
89
|
-
return;
|
|
94
|
+
return;
|
|
90
95
|
const data = JSON.stringify(event);
|
|
91
96
|
res.write(`event: ${event.type}\ndata: ${data}\n\n`);
|
|
92
97
|
if (event.type === "done") {
|
|
@@ -95,9 +100,6 @@ export function startSseServer(taskStore, port = config.sse.port, host = config.
|
|
|
95
100
|
});
|
|
96
101
|
req.on("close", cleanup);
|
|
97
102
|
});
|
|
98
|
-
// Handle bind/runtime errors so an unhandled 'error' event can't crash the
|
|
99
|
-
// whole MCP process (BUG-001). EADDRINUSE (port already taken) is the common
|
|
100
|
-
// case — degrade to "SSE unavailable" rather than taking down the server.
|
|
101
103
|
server.on("error", (err) => {
|
|
102
104
|
if (err.code === "EADDRINUSE") {
|
|
103
105
|
logger.warn({ host, port, err: err.message }, "SSE server could not bind (port already in use) — task SSE streaming is DISABLED; the MCP server continues normally. Set SSE_PORT to a free port to enable streaming.");
|
|
@@ -107,8 +109,6 @@ export function startSseServer(taskStore, port = config.sse.port, host = config.
|
|
|
107
109
|
}
|
|
108
110
|
});
|
|
109
111
|
server.listen(port, host, () => {
|
|
110
|
-
// Use the pino logger (stderr) — never console.log, which writes to
|
|
111
|
-
// stdout and corrupts the MCP JSON-RPC transport on the shared process.
|
|
112
112
|
const addr = server.address();
|
|
113
113
|
const boundPort = addr && typeof addr === "object" ? addr.port : port;
|
|
114
114
|
logger.info({ host, port: boundPort }, "SSE server listening");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse-server.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"sse-server.js","sourceRoot":"","sources":["../../../../../entrypoint/agent-mcp/src/streaming/sse-server.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAwB,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAuB,MAAM,mBAAmB,CAAC;AAEhG,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,qBAAqB,GAA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E,SAAS,EAAE,EAAE,sBAAsB,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/src/utils/load-env.d.ts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Load the `.env` hierarchy into `process.env` with most-specific wins:
|
|
3
|
-
*
|
|
4
|
-
* 1. `<cwd>/.env` (highest precedence)
|
|
5
|
-
* 2. `<cwd>/.adhd/.env`
|
|
6
|
-
* 3. `~/.adhd/.env` (lowest precedence)
|
|
7
|
-
*
|
|
8
|
-
* Each file is loaded only if it exists — missing files are silently skipped
|
|
9
|
-
* by dotenv. Already-set vars from a more-specific file are not overridden by
|
|
10
|
-
* a less-specific one (load least-specific first; use `override:true` for each
|
|
11
|
-
* successive, more-specific load).
|
|
12
|
-
*
|
|
13
|
-
* Call this once before taking a `process.env` snapshot (i.e. from `config.ts`).
|
|
14
|
-
*/
|
|
15
1
|
export declare function loadEnvHierarchy(cwd?: string): void;
|
|
16
2
|
//# sourceMappingURL=load-env.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-env.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"load-env.d.ts","sourceRoot":"","sources":["../../../../../entrypoint/agent-mcp/src/utils/load-env.ts"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,CAAC,GAAG,GAAE,MAAsB,GAAG,IAAI,CAIlE"}
|
package/src/utils/load-env.js
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import { config as dotenvConfig } from "dotenv";
|
|
4
|
-
/**
|
|
5
|
-
* Load the `.env` hierarchy into `process.env` with most-specific wins:
|
|
6
|
-
*
|
|
7
|
-
* 1. `<cwd>/.env` (highest precedence)
|
|
8
|
-
* 2. `<cwd>/.adhd/.env`
|
|
9
|
-
* 3. `~/.adhd/.env` (lowest precedence)
|
|
10
|
-
*
|
|
11
|
-
* Each file is loaded only if it exists — missing files are silently skipped
|
|
12
|
-
* by dotenv. Already-set vars from a more-specific file are not overridden by
|
|
13
|
-
* a less-specific one (load least-specific first; use `override:true` for each
|
|
14
|
-
* successive, more-specific load).
|
|
15
|
-
*
|
|
16
|
-
* Call this once before taking a `process.env` snapshot (i.e. from `config.ts`).
|
|
17
|
-
*/
|
|
18
4
|
export function loadEnvHierarchy(cwd = process.cwd()) {
|
|
19
|
-
// 3. ~/.adhd/.env — lowest precedence, load first without override flag so
|
|
20
|
-
// POSIX vars already in process.env (PATH, HOME, …) are not disturbed.
|
|
21
5
|
dotenvConfig({ path: path.join(os.homedir(), ".adhd", ".env") });
|
|
22
|
-
// 2. <cwd>/.adhd/.env — project-specific beats global
|
|
23
6
|
dotenvConfig({ path: path.join(cwd, ".adhd", ".env"), override: true });
|
|
24
|
-
// 1. <cwd>/.env — highest precedence
|
|
25
7
|
dotenvConfig({ path: path.join(cwd, ".env"), override: true });
|
|
26
8
|
}
|
|
27
9
|
//# sourceMappingURL=load-env.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-env.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"load-env.js","sourceRoot":"","sources":["../../../../../entrypoint/agent-mcp/src/utils/load-env.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEhD,MAAM,UAAU,gBAAgB,CAAC,MAAc,OAAO,CAAC,GAAG,EAAE;IACxD,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACjE,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACxE,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -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":["../../../../../../packages/ai/agent-mcp/src/clients/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,6BAA6B,EAAE,M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CAAC,CAAC;IACpC,CAAC;CACJ;AAED,MAAM,OAAO,YAAa,SAAQ,iBAAiB;IAG1B;IAFrB,YACI,UAAkB,EACD,MAAoB;QAErC,KAAK,CAAC,UAAU,CAAC,CAAC;QAFD,WAAM,GAAN,MAAM,CAAc;IAGzC,CAAC;IAED,KAAK,CAAC,OAAO;QACT,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,SAAS,GAAG,IAAI,kBAAkB,CAAC,GAAG,EAAE;YAC1C,eAAe,EAAE;gBACb,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CACnB,KAAK,CAAC,KAAK,EAAE;oBACT,GAAG,IAAI;oBACP,OAAO,EAAE;wBACL,GAAI,IAAI,EAAE,OAAkC;wBAC5C,GAAI,IAAI,CAAC,MAAM,CAAC,OAAkC;qBACtC;oBAChB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;wBACzB,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;wBAC5C,CAAC,CAAC,SAAS;iBAClB,CAAC;aACT;SACJ,CAAC,CAAC;QAEH,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,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;CACJ"}
|
|
@@ -1,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,E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