@zauso-ai/capstan-agent 0.2.0 → 0.3.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/dist/a2a.d.ts +21 -0
- package/dist/a2a.d.ts.map +1 -1
- package/dist/a2a.js +152 -11
- package/dist/a2a.js.map +1 -1
- package/dist/commerce.d.ts +62 -0
- package/dist/commerce.d.ts.map +1 -0
- package/dist/commerce.js +39 -0
- package/dist/commerce.js.map +1 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/langchain.d.ts +52 -0
- package/dist/langchain.d.ts.map +1 -0
- package/dist/langchain.js +157 -0
- package/dist/langchain.js.map +1 -0
- package/dist/llm.d.ts +41 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +166 -0
- package/dist/llm.js.map +1 -0
- package/dist/mcp-client.d.ts +45 -0
- package/dist/mcp-client.d.ts.map +1 -0
- package/dist/mcp-client.js +289 -0
- package/dist/mcp-client.js.map +1 -0
- package/dist/mcp.d.ts +32 -0
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +167 -15
- package/dist/mcp.js.map +1 -1
- package/dist/openapi.js +1 -1
- package/dist/registry.d.ts +23 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +48 -1
- package/dist/registry.js.map +1 -1
- package/dist/telemetry.d.ts +8 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +48 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/testing.d.ts +84 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +490 -0
- package/dist/testing.js.map +1 -0
- package/package.json +13 -3
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Client — connect to external MCP servers and consume their tools.
|
|
3
|
+
*
|
|
4
|
+
* Uses the official `@modelcontextprotocol/sdk` Client and
|
|
5
|
+
* StreamableHTTPClientTransport for spec-compliant communication.
|
|
6
|
+
* Falls back to a raw JSON-RPC 2.0 implementation when the SDK
|
|
7
|
+
* transport encounters issues (e.g. the remote server does not
|
|
8
|
+
* support Streamable HTTP).
|
|
9
|
+
*/
|
|
10
|
+
// SDK imports are dynamic to avoid resolution failures when subpath
|
|
11
|
+
// exports are not declared in the package.json exports map.
|
|
12
|
+
import { withSpan } from "./telemetry.js";
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// SDK-backed implementation
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
class SdkMcpClient {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
client;
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
transport;
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
constructor(client, transport) {
|
|
23
|
+
this.client = client;
|
|
24
|
+
this.transport = transport;
|
|
25
|
+
}
|
|
26
|
+
async listTools() {
|
|
27
|
+
return withSpan("capstan.mcp_client.listTools", {}, async () => {
|
|
28
|
+
const result = await this.client.listTools();
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
return result.tools.map((t) => ({
|
|
31
|
+
name: t.name,
|
|
32
|
+
description: t.description,
|
|
33
|
+
inputSchema: t.inputSchema,
|
|
34
|
+
}));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async callTool(name, args) {
|
|
38
|
+
return withSpan(`capstan.mcp_client.callTool.${name}`, { "capstan.mcp_client.tool": name }, async () => {
|
|
39
|
+
const result = await this.client.callTool({
|
|
40
|
+
name,
|
|
41
|
+
arguments: args,
|
|
42
|
+
});
|
|
43
|
+
// The SDK returns a union type; the standard shape has a `content`
|
|
44
|
+
// array of text/image/audio/resource items.
|
|
45
|
+
if ("content" in result && Array.isArray(result.content)) {
|
|
46
|
+
// If there's a single text content item, unwrap it for convenience.
|
|
47
|
+
if (result.content.length === 1 &&
|
|
48
|
+
result.content[0] != null &&
|
|
49
|
+
"type" in result.content[0] &&
|
|
50
|
+
result.content[0].type === "text") {
|
|
51
|
+
const text = result.content[0].text;
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(text);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return text;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result.content;
|
|
60
|
+
}
|
|
61
|
+
// Compatibility result shape (`toolResult` field).
|
|
62
|
+
if ("toolResult" in result) {
|
|
63
|
+
return result.toolResult;
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async close() {
|
|
69
|
+
await this.transport.close();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// Raw JSON-RPC 2.0 fallback implementation
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
class RawMcpClient {
|
|
76
|
+
url;
|
|
77
|
+
headers;
|
|
78
|
+
sessionId;
|
|
79
|
+
nextId = 1;
|
|
80
|
+
constructor(url, headers) {
|
|
81
|
+
this.url = url;
|
|
82
|
+
this.headers = headers;
|
|
83
|
+
}
|
|
84
|
+
/** Perform the MCP initialize handshake. */
|
|
85
|
+
async initialize(clientName) {
|
|
86
|
+
await this.sendRequest("initialize", {
|
|
87
|
+
protocolVersion: "2025-03-26",
|
|
88
|
+
capabilities: {},
|
|
89
|
+
clientInfo: { name: clientName, version: "1.0.0" },
|
|
90
|
+
});
|
|
91
|
+
// Send initialized notification (no response expected).
|
|
92
|
+
await this.sendNotification("notifications/initialized", {});
|
|
93
|
+
}
|
|
94
|
+
async listTools() {
|
|
95
|
+
return withSpan("capstan.mcp_client.listTools", {}, async () => {
|
|
96
|
+
const result = (await this.sendRequest("tools/list", {}));
|
|
97
|
+
return (result.tools ?? []).map((t) => ({
|
|
98
|
+
name: t.name,
|
|
99
|
+
description: t.description,
|
|
100
|
+
inputSchema: t.inputSchema,
|
|
101
|
+
}));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async callTool(name, args) {
|
|
105
|
+
return withSpan(`capstan.mcp_client.callTool.${name}`, { "capstan.mcp_client.tool": name }, async () => {
|
|
106
|
+
const result = (await this.sendRequest("tools/call", {
|
|
107
|
+
name,
|
|
108
|
+
arguments: args ?? {},
|
|
109
|
+
}));
|
|
110
|
+
if (result.content && Array.isArray(result.content)) {
|
|
111
|
+
if (result.content.length === 1 &&
|
|
112
|
+
result.content[0]?.type === "text" &&
|
|
113
|
+
result.content[0].text != null) {
|
|
114
|
+
try {
|
|
115
|
+
return JSON.parse(result.content[0].text);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return result.content[0].text;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return result.content;
|
|
122
|
+
}
|
|
123
|
+
if (result.toolResult !== undefined) {
|
|
124
|
+
return result.toolResult;
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async close() {
|
|
130
|
+
if (this.sessionId) {
|
|
131
|
+
try {
|
|
132
|
+
await fetch(this.url, {
|
|
133
|
+
method: "DELETE",
|
|
134
|
+
headers: {
|
|
135
|
+
...this.headers,
|
|
136
|
+
"Mcp-Session-Id": this.sessionId,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
// Best-effort session termination — ignore errors.
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// -----------------------------------------------------------------------
|
|
146
|
+
// Internal helpers
|
|
147
|
+
// -----------------------------------------------------------------------
|
|
148
|
+
async sendRequest(method, params) {
|
|
149
|
+
const id = this.nextId++;
|
|
150
|
+
const body = {
|
|
151
|
+
jsonrpc: "2.0",
|
|
152
|
+
id,
|
|
153
|
+
method,
|
|
154
|
+
params,
|
|
155
|
+
};
|
|
156
|
+
const reqHeaders = {
|
|
157
|
+
...this.headers,
|
|
158
|
+
"Content-Type": "application/json",
|
|
159
|
+
Accept: "application/json, text/event-stream",
|
|
160
|
+
};
|
|
161
|
+
if (this.sessionId) {
|
|
162
|
+
reqHeaders["Mcp-Session-Id"] = this.sessionId;
|
|
163
|
+
}
|
|
164
|
+
const res = await fetch(this.url, {
|
|
165
|
+
method: "POST",
|
|
166
|
+
headers: reqHeaders,
|
|
167
|
+
body: JSON.stringify(body),
|
|
168
|
+
});
|
|
169
|
+
// Capture session ID from the response.
|
|
170
|
+
const newSessionId = res.headers.get("mcp-session-id");
|
|
171
|
+
if (newSessionId) {
|
|
172
|
+
this.sessionId = newSessionId;
|
|
173
|
+
}
|
|
174
|
+
if (!res.ok) {
|
|
175
|
+
const text = await res.text().catch(() => "");
|
|
176
|
+
throw new Error(`MCP request ${method} failed: HTTP ${String(res.status)} ${text}`);
|
|
177
|
+
}
|
|
178
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
179
|
+
// The server may respond with SSE (text/event-stream) or plain JSON.
|
|
180
|
+
if (contentType.includes("text/event-stream")) {
|
|
181
|
+
return this.parseSseResponse(res, id);
|
|
182
|
+
}
|
|
183
|
+
const json = (await res.json());
|
|
184
|
+
if (json.error) {
|
|
185
|
+
throw new Error(`MCP error ${String(json.error.code)}: ${json.error.message}`);
|
|
186
|
+
}
|
|
187
|
+
return json.result;
|
|
188
|
+
}
|
|
189
|
+
async sendNotification(method, params) {
|
|
190
|
+
const body = {
|
|
191
|
+
jsonrpc: "2.0",
|
|
192
|
+
method,
|
|
193
|
+
params,
|
|
194
|
+
};
|
|
195
|
+
const reqHeaders = {
|
|
196
|
+
...this.headers,
|
|
197
|
+
"Content-Type": "application/json",
|
|
198
|
+
};
|
|
199
|
+
if (this.sessionId) {
|
|
200
|
+
reqHeaders["Mcp-Session-Id"] = this.sessionId;
|
|
201
|
+
}
|
|
202
|
+
const res = await fetch(this.url, {
|
|
203
|
+
method: "POST",
|
|
204
|
+
headers: reqHeaders,
|
|
205
|
+
body: JSON.stringify(body),
|
|
206
|
+
});
|
|
207
|
+
// Capture session ID.
|
|
208
|
+
const newSessionId = res.headers.get("mcp-session-id");
|
|
209
|
+
if (newSessionId) {
|
|
210
|
+
this.sessionId = newSessionId;
|
|
211
|
+
}
|
|
212
|
+
// Notifications may return 202 Accepted or 204 No Content — either is fine.
|
|
213
|
+
if (!res.ok && res.status !== 202 && res.status !== 204) {
|
|
214
|
+
const text = await res.text().catch(() => "");
|
|
215
|
+
throw new Error(`MCP notification ${method} failed: HTTP ${String(res.status)} ${text}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async parseSseResponse(res, expectedId) {
|
|
219
|
+
const text = await res.text();
|
|
220
|
+
// Parse SSE events and find the JSON-RPC response matching our request ID.
|
|
221
|
+
for (const line of text.split("\n")) {
|
|
222
|
+
if (line.startsWith("data: ")) {
|
|
223
|
+
try {
|
|
224
|
+
const parsed = JSON.parse(line.slice(6));
|
|
225
|
+
if (parsed.id === expectedId) {
|
|
226
|
+
if (parsed.error) {
|
|
227
|
+
throw new Error(`MCP error ${String(parsed.error.code)}: ${parsed.error.message}`);
|
|
228
|
+
}
|
|
229
|
+
return parsed.result;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
catch (e) {
|
|
233
|
+
if (e instanceof Error && e.message.startsWith("MCP error")) {
|
|
234
|
+
throw e;
|
|
235
|
+
}
|
|
236
|
+
// Skip unparseable SSE data lines.
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
throw new Error("No matching JSON-RPC response found in SSE stream");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// ---------------------------------------------------------------------------
|
|
244
|
+
// Factory function
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
/**
|
|
247
|
+
* Create an MCP client connected to a remote server.
|
|
248
|
+
*
|
|
249
|
+
* Attempts to connect using the official SDK `Client` +
|
|
250
|
+
* `StreamableHTTPClientTransport` first. Falls back to a raw JSON-RPC 2.0
|
|
251
|
+
* implementation if the SDK transport fails (e.g. unsupported server).
|
|
252
|
+
*
|
|
253
|
+
* @param options - Connection options (URL, auth, client name).
|
|
254
|
+
* @returns A connected `McpClient` ready to list and call tools.
|
|
255
|
+
*/
|
|
256
|
+
export async function createMcpClient(options) {
|
|
257
|
+
const clientName = options.clientName ?? "capstan-mcp-client";
|
|
258
|
+
const url = new URL(options.url);
|
|
259
|
+
const requestInit = {};
|
|
260
|
+
if (options.authorization) {
|
|
261
|
+
requestInit.headers = {
|
|
262
|
+
Authorization: options.authorization,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
// --- Attempt 1: SDK transport (lazy import) ---
|
|
266
|
+
try {
|
|
267
|
+
const clientMod = await import("@modelcontextprotocol/sdk/client/index.js");
|
|
268
|
+
const transportMod = await import("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
269
|
+
const SdkClient = clientMod.Client;
|
|
270
|
+
const SdkTransport = transportMod.StreamableHTTPClientTransport;
|
|
271
|
+
const transport = new SdkTransport(url, { requestInit });
|
|
272
|
+
const client = new SdkClient({ name: clientName, version: "1.0.0" }, { capabilities: {} });
|
|
273
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
274
|
+
await client.connect(transport);
|
|
275
|
+
return new SdkMcpClient(client, transport);
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
// SDK transport failed or not available — fall back to raw JSON-RPC.
|
|
279
|
+
}
|
|
280
|
+
// --- Attempt 2: Raw JSON-RPC 2.0 ---
|
|
281
|
+
const headers = {};
|
|
282
|
+
if (options.authorization) {
|
|
283
|
+
headers["Authorization"] = options.authorization;
|
|
284
|
+
}
|
|
285
|
+
const rawClient = new RawMcpClient(options.url, headers);
|
|
286
|
+
await rawClient.initialize(clientName);
|
|
287
|
+
return rawClient;
|
|
288
|
+
}
|
|
289
|
+
//# sourceMappingURL=mcp-client.js.map
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
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { ZodTypeAny } from "zod";
|
|
2
3
|
import type { AgentConfig, RouteRegistryEntry } from "./types.js";
|
|
3
4
|
/**
|
|
4
5
|
* Convert an HTTP method + URL path into a snake_case MCP tool name.
|
|
@@ -11,6 +12,14 @@ import type { AgentConfig, RouteRegistryEntry } from "./types.js";
|
|
|
11
12
|
* DELETE /orgs/:orgId/members/:memberId -> "delete_orgs_by_orgId_members_by_memberId"
|
|
12
13
|
*/
|
|
13
14
|
export declare function routeToToolName(method: string, path: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Convert a route's `inputSchema` (JSON Schema object) into a Zod raw shape
|
|
17
|
+
* suitable for the MCP SDK's `server.tool()` method.
|
|
18
|
+
*
|
|
19
|
+
* If the route has no input schema, returns an empty shape so the tool
|
|
20
|
+
* accepts no arguments.
|
|
21
|
+
*/
|
|
22
|
+
export declare function inputSchemaToZodShape(inputSchema: Record<string, unknown> | undefined): Record<string, ZodTypeAny>;
|
|
14
23
|
/**
|
|
15
24
|
* Create an MCP server that exposes all Capstan API routes as MCP tools.
|
|
16
25
|
*
|
|
@@ -38,4 +47,27 @@ export declare function createMcpServer(config: AgentConfig, routes: RouteRegist
|
|
|
38
47
|
* that communicates over stdin/stdout.
|
|
39
48
|
*/
|
|
40
49
|
export declare function serveMcpStdio(server: McpServer): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Create a Streamable HTTP handler for an MCP server.
|
|
52
|
+
*
|
|
53
|
+
* The MCP specification (2025-03-26) introduced Streamable HTTP as the
|
|
54
|
+
* recommended remote transport, deprecating the older SSE transport.
|
|
55
|
+
* This function returns a `(req: Request) => Promise<Response>` handler
|
|
56
|
+
* that can be mounted in any web-standard framework (Hono, Cloudflare
|
|
57
|
+
* Workers, Deno, Bun, etc.).
|
|
58
|
+
*
|
|
59
|
+
* The handler supports:
|
|
60
|
+
* - **POST** — JSON-RPC messages (tool calls, initialization)
|
|
61
|
+
* - **GET** — SSE stream for server-initiated notifications
|
|
62
|
+
* - **DELETE** — session termination
|
|
63
|
+
*
|
|
64
|
+
* Session management is enabled by default using `crypto.randomUUID()`.
|
|
65
|
+
* Each session maintains its own transport instance, which is connected
|
|
66
|
+
* to a freshly built `McpServer` that shares the same tool registrations.
|
|
67
|
+
*
|
|
68
|
+
* @param registry - The CapabilityRegistry (or equivalent) providing
|
|
69
|
+
* agent configuration and registered routes.
|
|
70
|
+
* @returns A web-standard request handler.
|
|
71
|
+
*/
|
|
72
|
+
export declare function createMcpHttpHandler(config: AgentConfig, routes: RouteRegistryEntry[], executeRoute: (method: string, path: string, input: unknown) => Promise<unknown>): (req: Request) => Promise<Response>;
|
|
41
73
|
//# sourceMappingURL=mcp.d.ts.map
|
package/dist/mcp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGlE;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAkBpE;AA4DD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAC/C,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAqB5B;AAYD;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,kBAAkB,EAAE,EAC5B,YAAY,EAAE,CACZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,KACX,OAAO,CAAC,OAAO,CAAC,GACpB;IACD,MAAM,EAAE,SAAS,CAAC;IAClB,kBAAkB,EAAE,MAAM,KAAK,CAAC;QAC9B,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,OAAO,CAAC;KACtB,CAAC,CAAC;CACJ,CAuDA;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAGpE;AAMD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,kBAAkB,EAAE,EAC5B,YAAY,EAAE,CACZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,KACX,OAAO,CAAC,OAAO,CAAC,GACpB,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAuErC"}
|
package/dist/mcp.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { withSpan } from "./telemetry.js";
|
|
4
5
|
/**
|
|
5
6
|
* Convert an HTTP method + URL path into a snake_case MCP tool name.
|
|
6
7
|
*
|
|
@@ -30,6 +31,80 @@ export function routeToToolName(method, path) {
|
|
|
30
31
|
}
|
|
31
32
|
return `${prefix}_${parts.join("_")}`;
|
|
32
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Convert a JSON Schema type string to the corresponding Zod type.
|
|
36
|
+
*/
|
|
37
|
+
function jsonSchemaTypeToZod(prop) {
|
|
38
|
+
const type = prop["type"];
|
|
39
|
+
switch (type) {
|
|
40
|
+
case "string": {
|
|
41
|
+
const enumValues = prop["enum"];
|
|
42
|
+
if (enumValues && enumValues.length > 0) {
|
|
43
|
+
return z.enum(enumValues);
|
|
44
|
+
}
|
|
45
|
+
return z.string();
|
|
46
|
+
}
|
|
47
|
+
case "number":
|
|
48
|
+
case "integer":
|
|
49
|
+
return z.number();
|
|
50
|
+
case "boolean":
|
|
51
|
+
return z.boolean();
|
|
52
|
+
case "array": {
|
|
53
|
+
const items = prop["items"];
|
|
54
|
+
if (items) {
|
|
55
|
+
return z.array(jsonSchemaTypeToZod(items));
|
|
56
|
+
}
|
|
57
|
+
return z.array(z.unknown());
|
|
58
|
+
}
|
|
59
|
+
case "object": {
|
|
60
|
+
const nested = prop["properties"];
|
|
61
|
+
if (nested) {
|
|
62
|
+
const nestedRequired = prop["required"] ?? [];
|
|
63
|
+
return jsonSchemaToZodObject(nested, nestedRequired);
|
|
64
|
+
}
|
|
65
|
+
return z.record(z.string(), z.unknown());
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
return z.unknown();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Convert a JSON Schema `properties` object into a `z.object()` schema.
|
|
73
|
+
*
|
|
74
|
+
* Properties listed in `required` are kept mandatory; all others become
|
|
75
|
+
* `.optional()`.
|
|
76
|
+
*/
|
|
77
|
+
function jsonSchemaToZodObject(properties, required) {
|
|
78
|
+
const shape = {};
|
|
79
|
+
for (const [key, prop] of Object.entries(properties)) {
|
|
80
|
+
const base = jsonSchemaTypeToZod(prop);
|
|
81
|
+
shape[key] = required.includes(key) ? base : base.optional();
|
|
82
|
+
}
|
|
83
|
+
return z.object(shape);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Convert a route's `inputSchema` (JSON Schema object) into a Zod raw shape
|
|
87
|
+
* suitable for the MCP SDK's `server.tool()` method.
|
|
88
|
+
*
|
|
89
|
+
* If the route has no input schema, returns an empty shape so the tool
|
|
90
|
+
* accepts no arguments.
|
|
91
|
+
*/
|
|
92
|
+
export function inputSchemaToZodShape(inputSchema) {
|
|
93
|
+
if (!inputSchema) {
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
const properties = inputSchema["properties"];
|
|
97
|
+
if (!properties) {
|
|
98
|
+
return {};
|
|
99
|
+
}
|
|
100
|
+
const required = inputSchema["required"] ?? [];
|
|
101
|
+
const shape = {};
|
|
102
|
+
for (const [key, prop] of Object.entries(properties)) {
|
|
103
|
+
const base = jsonSchemaTypeToZod(prop);
|
|
104
|
+
shape[key] = required.includes(key) ? base : base.optional();
|
|
105
|
+
}
|
|
106
|
+
return shape;
|
|
107
|
+
}
|
|
33
108
|
/**
|
|
34
109
|
* Build a tool description from a route.
|
|
35
110
|
*/
|
|
@@ -57,11 +132,6 @@ export function createMcpServer(config, routes, executeRoute) {
|
|
|
57
132
|
version: "1.0.0",
|
|
58
133
|
});
|
|
59
134
|
const toolDefinitions = [];
|
|
60
|
-
// A permissive Zod schema that accepts any object and passes all
|
|
61
|
-
// properties through. This lets the MCP SDK forward client-supplied
|
|
62
|
-
// arguments to our handler while avoiding the need to convert each
|
|
63
|
-
// route's JSON Schema into a Zod type at registration time.
|
|
64
|
-
const passthroughShape = { _input: z.unknown().optional() };
|
|
65
135
|
for (const route of routes) {
|
|
66
136
|
const toolName = routeToToolName(route.method, route.path);
|
|
67
137
|
const description = buildToolDescription(route);
|
|
@@ -71,19 +141,18 @@ export function createMcpServer(config, routes, executeRoute) {
|
|
|
71
141
|
description,
|
|
72
142
|
inputSchema: route.inputSchema ?? { type: "object", properties: {} },
|
|
73
143
|
});
|
|
144
|
+
// Convert the route's JSON Schema inputSchema to a Zod shape so MCP
|
|
145
|
+
// clients receive proper parameter validation and documentation.
|
|
146
|
+
const zodShape = inputSchemaToZodShape(route.inputSchema);
|
|
74
147
|
// Register the tool with the MCP server.
|
|
75
148
|
//
|
|
76
|
-
// We use the `tool(name, description, paramsSchema, callback)` overload
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
server.tool(toolName, description, passthroughShape, async (args) => {
|
|
82
|
-
// Forward all arguments (minus our synthetic _input marker) to the
|
|
83
|
-
// route handler. Agents will send the actual input properties
|
|
84
|
-
// directly in the tool arguments object.
|
|
149
|
+
// We use the `tool(name, description, paramsSchema, callback)` overload.
|
|
150
|
+
// The Zod shape gives the MCP SDK real type information for each
|
|
151
|
+
// parameter, so clients see proper names, types, and required markers
|
|
152
|
+
// instead of a permissive passthrough.
|
|
153
|
+
server.tool(toolName, description, zodShape, async (args) => {
|
|
85
154
|
const input = Object.keys(args).length > 0 ? args : undefined;
|
|
86
|
-
const result = await executeRoute(route.method, route.path, input);
|
|
155
|
+
const result = await withSpan(`capstan.mcp.tool.${toolName}`, { "capstan.mcp.toolName": toolName, "capstan.mcp.inputSize": JSON.stringify(args).length }, async () => executeRoute(route.method, route.path, input));
|
|
87
156
|
return {
|
|
88
157
|
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
89
158
|
};
|
|
@@ -104,4 +173,87 @@ export async function serveMcpStdio(server) {
|
|
|
104
173
|
const transport = new StdioServerTransport();
|
|
105
174
|
await server.connect(transport);
|
|
106
175
|
}
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
// Streamable HTTP transport
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
/**
|
|
180
|
+
* Create a Streamable HTTP handler for an MCP server.
|
|
181
|
+
*
|
|
182
|
+
* The MCP specification (2025-03-26) introduced Streamable HTTP as the
|
|
183
|
+
* recommended remote transport, deprecating the older SSE transport.
|
|
184
|
+
* This function returns a `(req: Request) => Promise<Response>` handler
|
|
185
|
+
* that can be mounted in any web-standard framework (Hono, Cloudflare
|
|
186
|
+
* Workers, Deno, Bun, etc.).
|
|
187
|
+
*
|
|
188
|
+
* The handler supports:
|
|
189
|
+
* - **POST** — JSON-RPC messages (tool calls, initialization)
|
|
190
|
+
* - **GET** — SSE stream for server-initiated notifications
|
|
191
|
+
* - **DELETE** — session termination
|
|
192
|
+
*
|
|
193
|
+
* Session management is enabled by default using `crypto.randomUUID()`.
|
|
194
|
+
* Each session maintains its own transport instance, which is connected
|
|
195
|
+
* to a freshly built `McpServer` that shares the same tool registrations.
|
|
196
|
+
*
|
|
197
|
+
* @param registry - The CapabilityRegistry (or equivalent) providing
|
|
198
|
+
* agent configuration and registered routes.
|
|
199
|
+
* @returns A web-standard request handler.
|
|
200
|
+
*/
|
|
201
|
+
export function createMcpHttpHandler(config, routes, executeRoute) {
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
203
|
+
const sessions = new Map();
|
|
204
|
+
/**
|
|
205
|
+
* Build a new McpServer with all the current routes registered.
|
|
206
|
+
* This mirrors `createMcpServer` but returns only the server — we
|
|
207
|
+
* don't need the `getToolDefinitions` helper here.
|
|
208
|
+
*/
|
|
209
|
+
function buildServer() {
|
|
210
|
+
return createMcpServer(config, routes, executeRoute).server;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Create a fresh transport + server pair, wire them together, and
|
|
214
|
+
* store in the session map.
|
|
215
|
+
*/
|
|
216
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
217
|
+
async function createSession() {
|
|
218
|
+
const { WebStandardStreamableHTTPServerTransport } = await import("@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js");
|
|
219
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
220
|
+
sessionIdGenerator: () => crypto.randomUUID(),
|
|
221
|
+
onsessioninitialized(sessionId) {
|
|
222
|
+
// Store the session once the MCP handshake completes.
|
|
223
|
+
sessions.set(sessionId, entry);
|
|
224
|
+
},
|
|
225
|
+
onsessionclosed(sessionId) {
|
|
226
|
+
sessions.delete(sessionId);
|
|
227
|
+
},
|
|
228
|
+
enableJsonResponse: true,
|
|
229
|
+
});
|
|
230
|
+
const server = buildServer();
|
|
231
|
+
const entry = { transport, server };
|
|
232
|
+
// Connect the server to the transport (registers handlers).
|
|
233
|
+
await server.connect(transport);
|
|
234
|
+
return entry;
|
|
235
|
+
}
|
|
236
|
+
return async function handleMcpHttp(req) {
|
|
237
|
+
// Look up an existing session from the request header.
|
|
238
|
+
const sessionId = req.headers.get("mcp-session-id");
|
|
239
|
+
if (sessionId) {
|
|
240
|
+
const existing = sessions.get(sessionId);
|
|
241
|
+
if (existing) {
|
|
242
|
+
return existing.transport.handleRequest(req);
|
|
243
|
+
}
|
|
244
|
+
// Unknown session ID — return 404 per the MCP spec.
|
|
245
|
+
return new Response(JSON.stringify({
|
|
246
|
+
jsonrpc: "2.0",
|
|
247
|
+
error: { code: -32000, message: "Session not found" },
|
|
248
|
+
id: null,
|
|
249
|
+
}), {
|
|
250
|
+
status: 404,
|
|
251
|
+
headers: { "Content-Type": "application/json" },
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
// No session header — create a new session for initialization.
|
|
255
|
+
const { transport } = await createSession();
|
|
256
|
+
return transport.handleRequest(req);
|
|
257
|
+
};
|
|
258
|
+
}
|
|
107
259
|
//# sourceMappingURL=mcp.js.map
|
package/dist/mcp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,IAAY;IAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CA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C;QAEH,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QAEpC,4DAA4D;QAC5D,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAEhC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,UAAU,aAAa,CAAC,GAAY;QAC9C,uDAAuD;QACvD,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAEpD,IAAI,SAAS,EAAE,CAAC;YACd,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACzC,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,QAAQ,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YAC/C,CAAC;YAED,oDAAoD;YACpD,OAAO,IAAI,QAAQ,CACjB,IAAI,CAAC,SAAS,CAAC;gBACb,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE;gBACrD,EAAE,EAAE,IAAI;aACT,CAAC,EACF;gBACE,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAChD,CACF,CAAC;QACJ,CAAC;QAED,+DAA+D;QAC/D,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,aAAa,EAAE,CAAC;QAC5C,OAAO,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/openapi.js
CHANGED
|
@@ -195,7 +195,7 @@ export function generateOpenApiSpec(config, routes) {
|
|
|
195
195
|
...(config.description !== undefined
|
|
196
196
|
? { description: config.description }
|
|
197
197
|
: {}),
|
|
198
|
-
version: "0.
|
|
198
|
+
version: "0.3.0",
|
|
199
199
|
},
|
|
200
200
|
...(config.baseUrl !== undefined
|
|
201
201
|
? { servers: [{ url: config.baseUrl }] }
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { AgentConfig, AgentManifest, RouteRegistryEntry } from "./types.js";
|
|
2
|
-
import type { A2AAgentCard } from "./a2a.js";
|
|
2
|
+
import type { A2AAgentCard, A2AStreamEvent } from "./a2a.js";
|
|
3
|
+
import type { McpClient, McpClientOptions } from "./mcp-client.js";
|
|
4
|
+
import type { LangChainToolDefinition, ToLangChainOptions } from "./langchain.js";
|
|
3
5
|
/**
|
|
4
6
|
* Unified capability registry — the central abstraction for Capstan's
|
|
5
7
|
* multi-protocol adapter layer.
|
|
@@ -44,6 +46,18 @@ export declare class CapabilityRegistry {
|
|
|
44
46
|
inputSchema: unknown;
|
|
45
47
|
}>;
|
|
46
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Project to MCP Streamable HTTP handler.
|
|
51
|
+
*
|
|
52
|
+
* Returns a web-standard `(req: Request) => Promise<Response>` handler
|
|
53
|
+
* implementing the MCP Streamable HTTP transport (2025-03-26 spec).
|
|
54
|
+
* Mount it on any route (e.g. `/mcp`) to serve MCP over HTTP.
|
|
55
|
+
*
|
|
56
|
+
* @param executeRoute - Callback that invokes the actual route handler
|
|
57
|
+
* given an HTTP method, path, and input payload.
|
|
58
|
+
* @returns A web-standard request handler.
|
|
59
|
+
*/
|
|
60
|
+
toMcpHttp(executeRoute: (method: string, path: string, input: unknown) => Promise<unknown>): (req: Request) => Promise<Response>;
|
|
47
61
|
/**
|
|
48
62
|
* Project to A2A agent card and JSON-RPC handler.
|
|
49
63
|
*
|
|
@@ -53,7 +67,15 @@ export declare class CapabilityRegistry {
|
|
|
53
67
|
*/
|
|
54
68
|
toA2A(executeRoute: (method: string, path: string, input: unknown) => Promise<unknown>): {
|
|
55
69
|
handleRequest: (body: unknown) => Promise<unknown>;
|
|
70
|
+
handleStreamRequest: (body: unknown) => AsyncGenerator<A2AStreamEvent, void, unknown>;
|
|
56
71
|
getAgentCard: () => A2AAgentCard;
|
|
57
72
|
};
|
|
73
|
+
private mcpClients;
|
|
74
|
+
/** Connect to an external MCP server and import its tools. */
|
|
75
|
+
connectMcp(options: McpClientOptions): Promise<McpClient>;
|
|
76
|
+
/** Close all MCP client connections. */
|
|
77
|
+
closeMcpClients(): Promise<void>;
|
|
78
|
+
/** Project to LangChain-compatible tool definitions. */
|
|
79
|
+
toLangChain(options: ToLangChainOptions): LangChainToolDefinition[];
|
|
58
80
|
}
|
|
59
81
|
//# sourceMappingURL=registry.d.ts.map
|