agentfootprint 7.12.0 → 7.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/dist/core/Agent.js +118 -7
  2. package/dist/core/Agent.js.map +1 -1
  3. package/dist/core/agent/AgentBuilder.js +59 -1
  4. package/dist/core/agent/AgentBuilder.js.map +1 -1
  5. package/dist/core/agent/buildAgentChart.js +6 -0
  6. package/dist/core/agent/buildAgentChart.js.map +1 -1
  7. package/dist/core/agent/buildDynamicAgentChart.js +14 -0
  8. package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
  9. package/dist/core/agent/stages/callLLM.js +10 -4
  10. package/dist/core/agent/stages/callLLM.js.map +1 -1
  11. package/dist/core/agent/stages/seed.js +16 -0
  12. package/dist/core/agent/stages/seed.js.map +1 -1
  13. package/dist/core/slots/buildSystemPromptSlot.js +2 -1
  14. package/dist/core/slots/buildSystemPromptSlot.js.map +1 -1
  15. package/dist/esm/core/Agent.d.ts +54 -3
  16. package/dist/esm/core/Agent.js +118 -7
  17. package/dist/esm/core/Agent.js.map +1 -1
  18. package/dist/esm/core/agent/AgentBuilder.d.ts +48 -1
  19. package/dist/esm/core/agent/AgentBuilder.js +59 -1
  20. package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
  21. package/dist/esm/core/agent/buildAgentChart.js +6 -0
  22. package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
  23. package/dist/esm/core/agent/buildDynamicAgentChart.js +14 -0
  24. package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
  25. package/dist/esm/core/agent/stages/callLLM.d.ts +9 -0
  26. package/dist/esm/core/agent/stages/callLLM.js +10 -4
  27. package/dist/esm/core/agent/stages/callLLM.js.map +1 -1
  28. package/dist/esm/core/agent/stages/seed.d.ts +10 -1
  29. package/dist/esm/core/agent/stages/seed.js +16 -0
  30. package/dist/esm/core/agent/stages/seed.js.map +1 -1
  31. package/dist/esm/core/agent/types.d.ts +44 -0
  32. package/dist/esm/core/slots/buildSystemPromptSlot.d.ts +19 -4
  33. package/dist/esm/core/slots/buildSystemPromptSlot.js +2 -1
  34. package/dist/esm/core/slots/buildSystemPromptSlot.js.map +1 -1
  35. package/dist/esm/hosting/envelope.d.ts +33 -0
  36. package/dist/esm/hosting/envelope.js +49 -0
  37. package/dist/esm/hosting/envelope.js.map +1 -0
  38. package/dist/esm/hosting/errors.d.ts +78 -0
  39. package/dist/esm/hosting/errors.js +119 -0
  40. package/dist/esm/hosting/errors.js.map +1 -0
  41. package/dist/esm/hosting/index.d.ts +53 -0
  42. package/dist/esm/hosting/index.js +52 -0
  43. package/dist/esm/hosting/index.js.map +1 -0
  44. package/dist/esm/hosting/memorySessions.d.ts +22 -0
  45. package/dist/esm/hosting/memorySessions.js +31 -0
  46. package/dist/esm/hosting/memorySessions.js.map +1 -0
  47. package/dist/esm/hosting/nodeHost.d.ts +64 -0
  48. package/dist/esm/hosting/nodeHost.js +245 -0
  49. package/dist/esm/hosting/nodeHost.js.map +1 -0
  50. package/dist/esm/hosting/standingAgent.d.ts +62 -0
  51. package/dist/esm/hosting/standingAgent.js +192 -0
  52. package/dist/esm/hosting/standingAgent.js.map +1 -0
  53. package/dist/esm/hosting/types.d.ts +206 -0
  54. package/dist/esm/hosting/types.js +21 -0
  55. package/dist/esm/hosting/types.js.map +1 -0
  56. package/dist/esm/lib/injection-engine/index.d.ts +1 -0
  57. package/dist/esm/lib/injection-engine/index.js +4 -0
  58. package/dist/esm/lib/injection-engine/index.js.map +1 -1
  59. package/dist/esm/lib/injection-engine/skillsFromDir.d.ts +80 -0
  60. package/dist/esm/lib/injection-engine/skillsFromDir.js +243 -0
  61. package/dist/esm/lib/injection-engine/skillsFromDir.js.map +1 -0
  62. package/dist/esm/lib/mcp/index.d.ts +6 -5
  63. package/dist/esm/lib/mcp/index.js +5 -4
  64. package/dist/esm/lib/mcp/index.js.map +1 -1
  65. package/dist/esm/lib/mcp/mcpClient.js +21 -9
  66. package/dist/esm/lib/mcp/mcpClient.js.map +1 -1
  67. package/dist/esm/lib/mcp/mcpServe.d.ts +70 -0
  68. package/dist/esm/lib/mcp/mcpServe.js +374 -0
  69. package/dist/esm/lib/mcp/mcpServe.js.map +1 -0
  70. package/dist/esm/lib/mcp/types.d.ts +130 -17
  71. package/dist/esm/lib/mcp/types.js +10 -10
  72. package/dist/esm/tool-providers/index.d.ts +8 -2
  73. package/dist/esm/tool-providers/index.js +7 -1
  74. package/dist/esm/tool-providers/index.js.map +1 -1
  75. package/dist/hosting/envelope.js +54 -0
  76. package/dist/hosting/envelope.js.map +1 -0
  77. package/dist/hosting/errors.js +126 -0
  78. package/dist/hosting/errors.js.map +1 -0
  79. package/dist/hosting/index.js +64 -0
  80. package/dist/hosting/index.js.map +1 -0
  81. package/dist/hosting/memorySessions.js +35 -0
  82. package/dist/hosting/memorySessions.js.map +1 -0
  83. package/dist/hosting/nodeHost.js +272 -0
  84. package/dist/hosting/nodeHost.js.map +1 -0
  85. package/dist/hosting/standingAgent.js +196 -0
  86. package/dist/hosting/standingAgent.js.map +1 -0
  87. package/dist/hosting/types.js +22 -0
  88. package/dist/hosting/types.js.map +1 -0
  89. package/dist/lib/injection-engine/index.js +6 -1
  90. package/dist/lib/injection-engine/index.js.map +1 -1
  91. package/dist/lib/injection-engine/skillsFromDir.js +270 -0
  92. package/dist/lib/injection-engine/skillsFromDir.js.map +1 -0
  93. package/dist/lib/mcp/index.js +7 -5
  94. package/dist/lib/mcp/index.js.map +1 -1
  95. package/dist/lib/mcp/mcpClient.js +21 -9
  96. package/dist/lib/mcp/mcpClient.js.map +1 -1
  97. package/dist/lib/mcp/mcpServe.js +401 -0
  98. package/dist/lib/mcp/mcpServe.js.map +1 -0
  99. package/dist/lib/mcp/types.js +10 -10
  100. package/dist/tool-providers/index.js +8 -1
  101. package/dist/tool-providers/index.js.map +1 -1
  102. package/dist/types/core/Agent.d.ts +54 -3
  103. package/dist/types/core/Agent.d.ts.map +1 -1
  104. package/dist/types/core/agent/AgentBuilder.d.ts +48 -1
  105. package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
  106. package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
  107. package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
  108. package/dist/types/core/agent/stages/callLLM.d.ts +9 -0
  109. package/dist/types/core/agent/stages/callLLM.d.ts.map +1 -1
  110. package/dist/types/core/agent/stages/seed.d.ts +10 -1
  111. package/dist/types/core/agent/stages/seed.d.ts.map +1 -1
  112. package/dist/types/core/agent/types.d.ts +44 -0
  113. package/dist/types/core/agent/types.d.ts.map +1 -1
  114. package/dist/types/core/slots/buildSystemPromptSlot.d.ts +19 -4
  115. package/dist/types/core/slots/buildSystemPromptSlot.d.ts.map +1 -1
  116. package/dist/types/hosting/envelope.d.ts +34 -0
  117. package/dist/types/hosting/envelope.d.ts.map +1 -0
  118. package/dist/types/hosting/errors.d.ts +79 -0
  119. package/dist/types/hosting/errors.d.ts.map +1 -0
  120. package/dist/types/hosting/index.d.ts +54 -0
  121. package/dist/types/hosting/index.d.ts.map +1 -0
  122. package/dist/types/hosting/memorySessions.d.ts +23 -0
  123. package/dist/types/hosting/memorySessions.d.ts.map +1 -0
  124. package/dist/types/hosting/nodeHost.d.ts +65 -0
  125. package/dist/types/hosting/nodeHost.d.ts.map +1 -0
  126. package/dist/types/hosting/standingAgent.d.ts +63 -0
  127. package/dist/types/hosting/standingAgent.d.ts.map +1 -0
  128. package/dist/types/hosting/types.d.ts +207 -0
  129. package/dist/types/hosting/types.d.ts.map +1 -0
  130. package/dist/types/lib/injection-engine/index.d.ts +1 -0
  131. package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
  132. package/dist/types/lib/injection-engine/skillsFromDir.d.ts +81 -0
  133. package/dist/types/lib/injection-engine/skillsFromDir.d.ts.map +1 -0
  134. package/dist/types/lib/mcp/index.d.ts +6 -5
  135. package/dist/types/lib/mcp/index.d.ts.map +1 -1
  136. package/dist/types/lib/mcp/mcpClient.d.ts.map +1 -1
  137. package/dist/types/lib/mcp/mcpServe.d.ts +71 -0
  138. package/dist/types/lib/mcp/mcpServe.d.ts.map +1 -0
  139. package/dist/types/lib/mcp/types.d.ts +130 -17
  140. package/dist/types/lib/mcp/types.d.ts.map +1 -1
  141. package/dist/types/tool-providers/index.d.ts +8 -2
  142. package/dist/types/tool-providers/index.d.ts.map +1 -1
  143. package/package.json +15 -1
@@ -52,7 +52,7 @@ const DEFAULT_CLIENT_INFO = {
52
52
  */
53
53
  export async function mcpClient(opts) {
54
54
  const name = opts.name ?? 'mcp';
55
- const sdk = opts._client ?? (await resolveClient(opts.transport, opts.clientInfo));
55
+ const sdk = opts._client ?? (await resolveClient(opts.transport, opts.clientInfo, opts.signal));
56
56
  // Tool cache so consumers calling `.tools()` more than once don't
57
57
  // hammer the server. `.refresh()` invalidates it.
58
58
  let cache = null;
@@ -63,7 +63,11 @@ export async function mcpClient(opts) {
63
63
  }
64
64
  };
65
65
  const buildTools = async () => {
66
- const listed = await sdk.listTools();
66
+ // `signal` rides in the SDK's THIRD argument (RequestOptions), not in
67
+ // the request params — see `wrapMcpTool`.
68
+ const listed = opts.signal
69
+ ? await sdk.listTools(undefined, { signal: opts.signal })
70
+ : await sdk.listTools();
67
71
  return listed.tools.map((t) => wrapMcpTool(name, sdk, t, opts.signal));
68
72
  };
69
73
  return {
@@ -89,7 +93,7 @@ export async function mcpClient(opts) {
89
93
  };
90
94
  }
91
95
  // ─── SDK construction (lazy require) ───────────────────────────────
92
- async function resolveClient(transport, clientInfo) {
96
+ async function resolveClient(transport, clientInfo, signal) {
93
97
  let mod;
94
98
  try {
95
99
  mod = lazyRequire('@modelcontextprotocol/sdk/client/index.js');
@@ -103,7 +107,11 @@ async function resolveClient(transport, clientInfo) {
103
107
  capabilities: {},
104
108
  });
105
109
  const transportImpl = await buildTransport(transport);
106
- await client.connect(transportImpl);
110
+ // Same rule as callTool: options ride beside the transport, never inside it.
111
+ if (signal)
112
+ await client.connect(transportImpl, { signal });
113
+ else
114
+ await client.connect(transportImpl);
107
115
  return client;
108
116
  }
109
117
  async function buildTransport(t) {
@@ -151,11 +159,15 @@ function wrapMcpTool(serverName, sdk, mcp, signal) {
151
159
  const argsObj = args !== null && typeof args === 'object' && !Array.isArray(args)
152
160
  ? args
153
161
  : {};
154
- const result = await sdk.callTool({
155
- name: mcp.name,
156
- arguments: argsObj,
157
- ...(signal && { signal }),
158
- });
162
+ // The abort signal is NOT a request param — it belongs to the SDK's
163
+ // third argument (`RequestOptions`). Put it in the params object and
164
+ // it gets serialized onto the wire as an empty `{}` and the call is
165
+ // uncancellable: a silent no-op that only a real transport reveals.
166
+ // `resultSchema` (2nd arg) is left to the SDK's own default.
167
+ const params = { name: mcp.name, arguments: argsObj };
168
+ const result = signal
169
+ ? await sdk.callTool(params, undefined, { signal })
170
+ : await sdk.callTool(params);
159
171
  // MCP returns content blocks. We concatenate text blocks into
160
172
  // a single string for the agent's tool-result event payload.
161
173
  // Non-text blocks (images, resources) are summarized with their
@@ -1 +1 @@
1
- {"version":3,"file":"mcpClient.js","sourceRoot":"","sources":["../../../../src/lib/mcp/mcpClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qEAAqE;AACrE,uEAAuE;AACvE,mEAAmE;AACnE,MAAM,mBAAmB,GAAG;IAC1B,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,OAAO;CACjB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAsB;IACpD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAE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AAM,GAAG,MAAM;gBACnB,CAAC,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC;gBACnD,CAAC,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC/B,8DAA8D;YAC9D,6DAA6D;YAC7D,gEAAgE;YAChE,iEAAiE;YACjE,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO;iBACxB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;iBAClE,IAAI,CAAC,IAAI,CAAC,CAAC;YACd,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,MAAM,IAAI,KAAK,CACb,aAAa,GAAG,CAAC,IAAI,cAAc,UAAU,yBAAyB,IAAI,EAAE,CAC7E,CAAC;YACJ,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * mcpServe — expose your agentfootprint tools AS an MCP server.
3
+ *
4
+ * const handle = await mcpServe([lookupTool, refundTool], {
5
+ * name: 'support-desk',
6
+ * version: '1.0.0',
7
+ * });
8
+ *
9
+ * // …later
10
+ * await handle.close();
11
+ *
12
+ * `mcpClient` pulls someone else's tools in. This pushes yours out, so
13
+ * the tool you already wrote, tested and governed can be called by any
14
+ * MCP client — a desktop host, another team's agent, an IDE — without
15
+ * being rewritten against a second tool interface.
16
+ *
17
+ * Pattern: Adapter (GoF), pointed the other way. `mcpClient` translates
18
+ * MCP → `Tool`; this translates `Tool` → MCP. Same SDK, same
19
+ * lazy-require discipline, mirrored lifecycle (`close()`).
20
+ *
21
+ * ── The one promise worth stating plainly ────────────────────────────
22
+ * A served tool is THE SAME OBJECT you passed in. `mcpServe` holds your
23
+ * `Tool` by reference and calls `tool.execute(args, ctx)` — it never
24
+ * copies the schema and re-implements the body, never unwraps a
25
+ * decorator, never reaches past a wrapper to an inner tool. So whatever
26
+ * governance you composed around that tool — a permission check inside
27
+ * `execute`, a redaction step, an audit hook — is still the thing that
28
+ * runs when a remote client calls it. Serving is not a second door into
29
+ * your tool; it is the same door with a longer corridor.
30
+ *
31
+ * Two demands the library CANNOT keep over MCP are refused at
32
+ * construction rather than silently dropped:
33
+ * - `checkIn` (human consent before the tool runs) needs a pause
34
+ * channel that a request/response protocol does not have.
35
+ * - `needs` (declare-and-push credentials) needs a provider; without
36
+ * one the tool would run with `ctx.credential` undefined.
37
+ *
38
+ * ── Schemas ──────────────────────────────────────────────────────────
39
+ * Tools already carry JSON Schema in `schema.inputSchema`, and MCP's
40
+ * `tools/list` wants JSON Schema, so the mapping is the identity
41
+ * function. That is also why this builds on the SDK's low-level
42
+ * `Server` rather than its `McpServer` convenience wrapper — the latter
43
+ * takes zod schemas, which would mean converting a JSON Schema you
44
+ * already have into zod (a new dependency) to convert it straight back.
45
+ */
46
+ import type { Tool } from '../../core/tools.js';
47
+ import type { McpServeHandle, McpServeOptions } from './types.js';
48
+ /**
49
+ * Serve `tools` over MCP. Resolves once the transport is connected (for
50
+ * `http`, once the socket is listening), so holding the handle means the
51
+ * server is live.
52
+ *
53
+ * @throws at construction when `tools` is empty, when two tools share a
54
+ * name, when a tool declares `checkIn`, or when a tool declares `needs`
55
+ * without `opts.credentials` — see the module header. Also throws when
56
+ * `@modelcontextprotocol/sdk` is not installed.
57
+ */
58
+ export declare function mcpServe(tools: readonly Tool[], opts?: McpServeOptions): Promise<McpServeHandle>;
59
+ /**
60
+ * Sentinels handed to an injected `_server` in place of the SDK's zod
61
+ * schemas. Exported so a test can tell the two handlers apart.
62
+ * @internal
63
+ */
64
+ export declare const LIST_TOOLS_SENTINEL: Readonly<{
65
+ method: "tools/list";
66
+ }>;
67
+ /** @internal @see LIST_TOOLS_SENTINEL */
68
+ export declare const CALL_TOOL_SENTINEL: Readonly<{
69
+ method: "tools/call";
70
+ }>;
@@ -0,0 +1,374 @@
1
+ /**
2
+ * mcpServe — expose your agentfootprint tools AS an MCP server.
3
+ *
4
+ * const handle = await mcpServe([lookupTool, refundTool], {
5
+ * name: 'support-desk',
6
+ * version: '1.0.0',
7
+ * });
8
+ *
9
+ * // …later
10
+ * await handle.close();
11
+ *
12
+ * `mcpClient` pulls someone else's tools in. This pushes yours out, so
13
+ * the tool you already wrote, tested and governed can be called by any
14
+ * MCP client — a desktop host, another team's agent, an IDE — without
15
+ * being rewritten against a second tool interface.
16
+ *
17
+ * Pattern: Adapter (GoF), pointed the other way. `mcpClient` translates
18
+ * MCP → `Tool`; this translates `Tool` → MCP. Same SDK, same
19
+ * lazy-require discipline, mirrored lifecycle (`close()`).
20
+ *
21
+ * ── The one promise worth stating plainly ────────────────────────────
22
+ * A served tool is THE SAME OBJECT you passed in. `mcpServe` holds your
23
+ * `Tool` by reference and calls `tool.execute(args, ctx)` — it never
24
+ * copies the schema and re-implements the body, never unwraps a
25
+ * decorator, never reaches past a wrapper to an inner tool. So whatever
26
+ * governance you composed around that tool — a permission check inside
27
+ * `execute`, a redaction step, an audit hook — is still the thing that
28
+ * runs when a remote client calls it. Serving is not a second door into
29
+ * your tool; it is the same door with a longer corridor.
30
+ *
31
+ * Two demands the library CANNOT keep over MCP are refused at
32
+ * construction rather than silently dropped:
33
+ * - `checkIn` (human consent before the tool runs) needs a pause
34
+ * channel that a request/response protocol does not have.
35
+ * - `needs` (declare-and-push credentials) needs a provider; without
36
+ * one the tool would run with `ctx.credential` undefined.
37
+ *
38
+ * ── Schemas ──────────────────────────────────────────────────────────
39
+ * Tools already carry JSON Schema in `schema.inputSchema`, and MCP's
40
+ * `tools/list` wants JSON Schema, so the mapping is the identity
41
+ * function. That is also why this builds on the SDK's low-level
42
+ * `Server` rather than its `McpServer` convenience wrapper — the latter
43
+ * takes zod schemas, which would mean converting a JSON Schema you
44
+ * already have into zod (a new dependency) to convert it straight back.
45
+ */
46
+ import { unconfiguredCredentialProvider } from '../../identity/types.js';
47
+ import { lazyRequire } from '../lazyRequire.js';
48
+ const DEFAULT_SERVER_NAME = 'agentfootprint';
49
+ const DEFAULT_SERVER_VERSION = '0.0.0';
50
+ const DEFAULT_HTTP_PATH = '/mcp';
51
+ /**
52
+ * Serve `tools` over MCP. Resolves once the transport is connected (for
53
+ * `http`, once the socket is listening), so holding the handle means the
54
+ * server is live.
55
+ *
56
+ * @throws at construction when `tools` is empty, when two tools share a
57
+ * name, when a tool declares `checkIn`, or when a tool declares `needs`
58
+ * without `opts.credentials` — see the module header. Also throws when
59
+ * `@modelcontextprotocol/sdk` is not installed.
60
+ */
61
+ export async function mcpServe(tools, opts = {}) {
62
+ const name = opts.name ?? DEFAULT_SERVER_NAME;
63
+ const version = opts.version ?? DEFAULT_SERVER_VERSION;
64
+ const byName = validateServableTools(tools, name, opts.credentials);
65
+ const credentials = opts.credentials ?? unconfiguredCredentialProvider();
66
+ const listing = tools.map((t) => ({
67
+ name: t.schema.name,
68
+ ...(t.schema.description !== undefined && { description: t.schema.description }),
69
+ inputSchema: t.schema.inputSchema ?? { type: 'object', properties: {} },
70
+ }));
71
+ // Order matters: the server is resolved FIRST so that a missing SDK is
72
+ // reported by the message that tells you how to install it, rather than
73
+ // by the narrower one about a single submodule.
74
+ const rootServer = opts._server ?? (await resolveServer(name, version));
75
+ const { listSchema, callSchema } = await resolveRequestSchemas(opts._server !== undefined);
76
+ let callCounter = 0;
77
+ const handleCall = async (request, extra) => {
78
+ // Everything below this line is inside one try/catch on purpose. A
79
+ // client we do not control chose this request; a bad choice is a tool
80
+ // error reported back over the protocol, never an exception that
81
+ // escapes the SDK's dispatch loop and takes the server down with it.
82
+ try {
83
+ const toolName = request?.params?.name;
84
+ const tool = typeof toolName === 'string' ? byName.get(toolName) : undefined;
85
+ if (!tool) {
86
+ return toolError(`Unknown tool '${String(toolName)}'. Served tools: ${listing
87
+ .map((t) => t.name)
88
+ .join(', ')}.`);
89
+ }
90
+ const ctx = await buildExecutionContext(tool, `mcp-${name}-${++callCounter}`, {
91
+ credentials,
92
+ hasCredentials: opts.credentials !== undefined,
93
+ ...(extra?.signal && { signal: extra.signal }),
94
+ });
95
+ if ('blocked' in ctx)
96
+ return toolError(ctx.blocked);
97
+ // Args are forwarded EXACTLY as the client sent them. Validating
98
+ // them here would mean a second, weaker copy of the tool's own
99
+ // contract — and a tool that already rejects bad input is the one
100
+ // place that rejection belongs.
101
+ const result = await tool.execute(request?.params?.arguments, ctx.context);
102
+ return { content: [{ type: 'text', text: stringifyResult(result) }] };
103
+ }
104
+ catch (error) {
105
+ return toolError(error instanceof Error ? error.message : String(error));
106
+ }
107
+ };
108
+ /**
109
+ * Put our two handlers on one SDK server. Factored out of the body
110
+ * because the streamable-HTTP path cannot reuse a single server: the
111
+ * SDK's stateless transport refuses a second request ("Stateless
112
+ * transport cannot be reused across requests"), so that path builds a
113
+ * fresh server + transport per request and needs to install the same
114
+ * two handlers on each one. `listing` and `byName` are captured, so
115
+ * every server instance serves the same tools — the same objects.
116
+ */
117
+ const install = (server) => {
118
+ server.setRequestHandler(listSchema, () => ({ tools: listing }));
119
+ server.setRequestHandler(callSchema, handleCall);
120
+ return server;
121
+ };
122
+ const sdk = install(rootServer);
123
+ const connection = await connectTransport(sdk, opts.transport ?? { transport: 'stdio' }, opts, async () => install(await resolveServer(name, version)));
124
+ let closed = false;
125
+ return {
126
+ name,
127
+ toolNames: listing.map((t) => t.name),
128
+ async close() {
129
+ if (closed)
130
+ return;
131
+ closed = true;
132
+ await connection.close();
133
+ await sdk.close();
134
+ },
135
+ };
136
+ }
137
+ // ─── Construction-time refusals ────────────────────────────────────
138
+ /**
139
+ * Build the dispatch map and refuse, by name, every tool this transport
140
+ * cannot honour. All of these are author mistakes, and all of them are
141
+ * invisible at run time if we let them through — a duplicate name means
142
+ * one tool silently shadows another; a dropped `checkIn` means a
143
+ * consent gate that quietly stopped gating.
144
+ */
145
+ function validateServableTools(tools, serverName, credentials) {
146
+ if (tools.length === 0) {
147
+ throw new Error(`mcpServe('${serverName}'): no tools to serve. Pass at least one Tool — a server ` +
148
+ `advertising an empty tool list is indistinguishable from a broken one.`);
149
+ }
150
+ const byName = new Map();
151
+ for (const tool of tools) {
152
+ const name = tool.schema.name;
153
+ if (byName.has(name)) {
154
+ throw new Error(`mcpServe('${serverName}'): duplicate tool name '${name}'. MCP clients dispatch by ` +
155
+ `name, so one of the two could never be reached.`);
156
+ }
157
+ if (tool.checkIn !== undefined) {
158
+ throw new Error(`mcpServe('${serverName}'): tool '${name}' declares checkIn, which asks a human to ` +
159
+ `approve the call before it runs. MCP is request/response — there is no pause to ` +
160
+ `carry that ask — so serving it would drop the consent gate silently. Serve a ` +
161
+ `variant without checkIn, or keep this tool inside an agent that can pause.`);
162
+ }
163
+ if (tool.needs !== undefined && credentials === undefined) {
164
+ throw new Error(`mcpServe('${serverName}'): tool '${name}' declares needs.credential ` +
165
+ `'${tool.needs.credential}' but no credential provider was passed. Pass ` +
166
+ `mcpServe(tools, { credentials }) so the credential is resolved before execute, ` +
167
+ `the same way the Agent resolves it.`);
168
+ }
169
+ byName.set(name, tool);
170
+ }
171
+ return byName;
172
+ }
173
+ // ─── Per-call execution context ────────────────────────────────────
174
+ /**
175
+ * Assemble the `ToolExecutionContext` for one served call, resolving a
176
+ * declared credential first. Returns `{ blocked }` instead of throwing
177
+ * when the credential is unavailable, so the client is told WHY in a
178
+ * tool-error result rather than seeing a generic failure.
179
+ */
180
+ async function buildExecutionContext(tool, toolCallId, wiring) {
181
+ const { credentials, hasCredentials, signal } = wiring;
182
+ let credential;
183
+ const need = tool.needs;
184
+ if (need) {
185
+ const resolved = await credentials.getCredential({
186
+ service: need.credential,
187
+ ...(need.scopes && { scopes: need.scopes }),
188
+ ...(need.mode && { mode: need.mode }),
189
+ });
190
+ // Fail-closed, mirroring the Agent's tool-call stage: a tool that
191
+ // asked for a credential never runs without one.
192
+ if (resolved.status !== 'issued') {
193
+ return {
194
+ blocked: `authorization required for '${need.credential}': ${resolved.authorizationUrl}`,
195
+ };
196
+ }
197
+ credential = resolved.credential;
198
+ }
199
+ return {
200
+ context: {
201
+ toolCallId,
202
+ // There is no ReAct loop out here — a served call is a single
203
+ // request, so the iteration a tool might branch on is zero.
204
+ iteration: 0,
205
+ credentials,
206
+ hasCredentials,
207
+ ...(signal && { signal }),
208
+ ...(credential && { credential }),
209
+ },
210
+ };
211
+ }
212
+ // ─── Result mapping ────────────────────────────────────────────────
213
+ /** MCP carries text blocks; a Tool returns anything JSON-serializable. */
214
+ function stringifyResult(result) {
215
+ if (typeof result === 'string')
216
+ return result;
217
+ if (result === undefined)
218
+ return '';
219
+ try {
220
+ return JSON.stringify(result) ?? String(result);
221
+ }
222
+ catch {
223
+ // Circular or otherwise unserializable — say so rather than throwing
224
+ // from the happy path.
225
+ return String(result);
226
+ }
227
+ }
228
+ /** A tool-level error: reported IN the result, per the MCP spec, not thrown. */
229
+ function toolError(message) {
230
+ return { content: [{ type: 'text', text: message }], isError: true };
231
+ }
232
+ // ─── SDK construction (lazy require) ───────────────────────────────
233
+ async function resolveServer(name, version) {
234
+ let mod;
235
+ try {
236
+ mod = lazyRequire('@modelcontextprotocol/sdk/server/index.js');
237
+ }
238
+ catch {
239
+ throw new Error('mcpServe requires @modelcontextprotocol/sdk.\n' +
240
+ ' Install: npm install @modelcontextprotocol/sdk\n' +
241
+ ' Or pass `_server` for test injection.');
242
+ }
243
+ return new mod.Server({ name, version }, { capabilities: { tools: {} } });
244
+ }
245
+ /**
246
+ * The request schemas the SDK dispatches on. With an injected `_server`
247
+ * there is no SDK to read them from, so tests get stable sentinel
248
+ * objects — the injected server decides what to do with them.
249
+ */
250
+ async function resolveRequestSchemas(injected) {
251
+ if (injected) {
252
+ return { listSchema: LIST_TOOLS_SENTINEL, callSchema: CALL_TOOL_SENTINEL };
253
+ }
254
+ let types;
255
+ try {
256
+ types = lazyRequire('@modelcontextprotocol/sdk/types.js');
257
+ }
258
+ catch {
259
+ throw new Error('mcpServe requires @modelcontextprotocol/sdk/types.js — check that ' +
260
+ '@modelcontextprotocol/sdk is installed at the latest version.');
261
+ }
262
+ return { listSchema: types.ListToolsRequestSchema, callSchema: types.CallToolRequestSchema };
263
+ }
264
+ /**
265
+ * Sentinels handed to an injected `_server` in place of the SDK's zod
266
+ * schemas. Exported so a test can tell the two handlers apart.
267
+ * @internal
268
+ */
269
+ export const LIST_TOOLS_SENTINEL = Object.freeze({ method: 'tools/list' });
270
+ /** @internal @see LIST_TOOLS_SENTINEL */
271
+ export const CALL_TOOL_SENTINEL = Object.freeze({ method: 'tools/call' });
272
+ /**
273
+ * For stdio and for an injected test server there is nothing extra to
274
+ * unwind: the SDK's own `server.close()` closes the transport it is
275
+ * connected to. Only the HTTP path owns a socket of its own.
276
+ */
277
+ const NOTHING_TO_UNWIND = { close: () => Promise.resolve() };
278
+ async function connectTransport(sdk, transport, opts, newServer) {
279
+ // An injected server is a test double: there is no real transport to
280
+ // build, and building one would spawn a listener or seize stdio.
281
+ if (opts._server) {
282
+ await sdk.connect(undefined);
283
+ return NOTHING_TO_UNWIND;
284
+ }
285
+ if (transport.transport === 'stdio') {
286
+ let stdioMod;
287
+ try {
288
+ stdioMod = lazyRequire('@modelcontextprotocol/sdk/server/stdio.js');
289
+ }
290
+ catch {
291
+ throw new Error('mcpServe(stdio) requires @modelcontextprotocol/sdk/server/stdio.js — ' +
292
+ 'check that @modelcontextprotocol/sdk is installed at the latest version.');
293
+ }
294
+ await sdk.connect(new stdioMod.StdioServerTransport());
295
+ return NOTHING_TO_UNWIND;
296
+ }
297
+ // HTTP deliberately does not use `sdk`: it mints a server per request
298
+ // (see connectHttp). The root server stays unconnected, which makes the
299
+ // handle's `sdk.close()` a harmless no-op on this path.
300
+ return connectHttp(transport, newServer);
301
+ }
302
+ /**
303
+ * Streamable HTTP. The SDK's transport handles the protocol but does not
304
+ * own a socket — it expects to be driven from a request handler — so the
305
+ * listener is ours, built on node:http (built in; no new dependency).
306
+ *
307
+ * Stateless (`sessionIdGenerator: undefined`): no session table to keep,
308
+ * nothing to expire, and several replicas can serve the same tools.
309
+ *
310
+ * Statelessness is not just a config flag here — it decides the shape of
311
+ * this function. The SDK's stateless transport is single-use by design
312
+ * (reusing one would let two clients collide on JSON-RPC message ids), so
313
+ * it throws on its second request. Each request therefore gets its own
314
+ * transport, and — because one SDK server can only be attached to one
315
+ * transport — its own server. Both are thrown away when the response
316
+ * closes. The tools they serve are the same objects either way.
317
+ */
318
+ async function connectHttp(transport, newServer) {
319
+ let httpMod;
320
+ try {
321
+ httpMod = lazyRequire('@modelcontextprotocol/sdk/server/streamableHttp.js');
322
+ }
323
+ catch {
324
+ throw new Error('mcpServe(http) requires @modelcontextprotocol/sdk/server/streamableHttp.js — ' +
325
+ 'check that @modelcontextprotocol/sdk is installed at the latest version.');
326
+ }
327
+ const { createServer } = await import('node:http');
328
+ const serveOne = async (req, res) => {
329
+ const server = await newServer();
330
+ const mcpTransport = new httpMod.StreamableHTTPServerTransport({
331
+ sessionIdGenerator: undefined,
332
+ });
333
+ // The pair lives exactly as long as the response does.
334
+ res.on('close', () => {
335
+ void mcpTransport.close();
336
+ void server.close();
337
+ });
338
+ await server.connect(mcpTransport);
339
+ await mcpTransport.handleRequest(req, res);
340
+ };
341
+ const path = transport.path ?? DEFAULT_HTTP_PATH;
342
+ const listener = createServer((req, res) => {
343
+ // Route on the path only; the transport itself decides which HTTP
344
+ // methods it accepts on the MCP endpoint.
345
+ const url = req.url ?? '';
346
+ if (url.split('?')[0] !== path) {
347
+ res.statusCode = 404;
348
+ res.end();
349
+ return;
350
+ }
351
+ // One failed request must not take the listener down. The client is
352
+ // told (500 is a protocol-level error it surfaces); the next request
353
+ // is served normally.
354
+ void serveOne(req, res).catch(() => {
355
+ if (!res.headersSent) {
356
+ res.statusCode = 500;
357
+ res.end();
358
+ }
359
+ });
360
+ });
361
+ await new Promise((resolve, reject) => {
362
+ listener.once('error', reject);
363
+ if (transport.host !== undefined)
364
+ listener.listen(transport.port, transport.host, resolve);
365
+ else
366
+ listener.listen(transport.port, resolve);
367
+ });
368
+ return {
369
+ close: () => new Promise((resolve, reject) => {
370
+ listener.close((err) => (err ? reject(err) : resolve()));
371
+ }),
372
+ };
373
+ }
374
+ //# sourceMappingURL=mcpServe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcpServe.js","sourceRoot":"","sources":["../../../../src/lib/mcp/mcpServe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAQH,OAAO,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AASzE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AAC7C,MAAM,sBAAsB,GAAG,OAAO,CAAC;AACvC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEjC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,KAAsB,EACtB,OAAwB,EAAE;IAE1B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,mBAAmB,CAAC;IAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,sBAAsB,CAAC;IACvD,MAAM,MAAM,GAAG,qBAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACpE,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,8BAA8B,EAAE,CAAC;IAEzE,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAChC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI;QACnB,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,KAAK,SAAS,I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