@yolk-sdk/mcp 0.1.0-canary.76 → 0.1.0-canary.78
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/README.md +28 -2
- package/dist/client/client.d.mts.map +1 -1
- package/dist/client/client.mjs +67 -44
- package/dist/client/client.mjs.map +1 -1
- package/dist/client/effect-fetch.d.mts.map +1 -1
- package/dist/client/effect-fetch.mjs.map +1 -1
- package/dist/client/errors.d.mts.map +1 -1
- package/dist/client/errors.mjs +1 -1
- package/dist/client/errors.mjs.map +1 -1
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.mjs +2 -2
- package/dist/client/protocol.d.mts +31 -14
- package/dist/client/protocol.d.mts.map +1 -1
- package/dist/client/protocol.mjs +41 -18
- package/dist/client/protocol.mjs.map +1 -1
- package/dist/server/errors.mjs +1 -1
- package/dist/server/errors.mjs.map +1 -1
- package/dist/server/server.d.mts.map +1 -1
- package/dist/server/server.mjs +53 -53
- package/dist/server/server.mjs.map +1 -1
- package/package.json +4 -4
- package/src/client/client.ts +119 -54
- package/src/client/effect-fetch.ts +3 -0
- package/src/client/errors.ts +2 -1
- package/src/client/index.ts +10 -0
- package/src/client/protocol.ts +87 -26
- package/src/server/errors.ts +1 -1
- package/src/server/index.ts +3 -0
- package/src/server/server.ts +73 -42
package/README.md
CHANGED
|
@@ -4,14 +4,22 @@ MCP v2 (`2026-07-28`) client/server/protocol APIs, Effect/Yolk adapters, and leg
|
|
|
4
4
|
|
|
5
5
|
The root export is intentionally empty. Import APIs from explicit subpaths.
|
|
6
6
|
|
|
7
|
+
## Tool schema admission
|
|
8
|
+
|
|
9
|
+
Yolk's `tools/list` adapter admits `inputSchema` as the object arm of
|
|
10
|
+
`@yolk-sdk/agent/protocol`'s `ToolJsonSchema`. This is plain finite JSON-data representation admission,
|
|
11
|
+
not JSON Schema meta-validation. Boolean roots fail in the typed `McpError` validation channel;
|
|
12
|
+
omitted schemas still default to `{ type: 'object', additionalProperties: true }`.
|
|
13
|
+
Tool arguments/results remain opaque until their execution/provider boundary.
|
|
14
|
+
|
|
7
15
|
## Install
|
|
8
16
|
|
|
9
17
|
```bash
|
|
10
|
-
pnpm add @yolk-sdk/mcp@canary @yolk-sdk/agent@canary effect@4.0.0-
|
|
18
|
+
pnpm add @yolk-sdk/mcp@canary @yolk-sdk/agent@canary effect@4.0.0-rc.115
|
|
11
19
|
```
|
|
12
20
|
|
|
13
21
|
Canary APIs are unstable. Keep all `@yolk-sdk/*` packages on the same version.
|
|
14
|
-
Use the SDK's matching Effect version (`4.0.0-
|
|
22
|
+
Use the SDK's matching Effect version (`4.0.0-rc.115`) in host code.
|
|
15
23
|
Published package metadata requires Node.js 22+; `client/node` and `server/node` are Node-only.
|
|
16
24
|
|
|
17
25
|
## Subpaths
|
|
@@ -28,6 +36,20 @@ Published package metadata requires Node.js 22+; `client/node` and `server/node`
|
|
|
28
36
|
Use `core` for the official full MCP wire-schema surface. Use `protocol` only for Yolk adapters and
|
|
29
37
|
legacy JSON-RPC helpers; it is not a replacement for the full-core APIs.
|
|
30
38
|
|
|
39
|
+
Yolk JSON-RPC initialize and tools/call construction uses Schema owners on both
|
|
40
|
+
`@yolk-sdk/mcp/client` and `@yolk-sdk/mcp/protocol` (same `protocol.ts`; no new export subpath):
|
|
41
|
+
|
|
42
|
+
| Symbol | Role |
|
|
43
|
+
| ------------------------- | ------------------------------------------------------------------------------ |
|
|
44
|
+
| `InitializeClientInfo` | `{ name, version }` |
|
|
45
|
+
| `InitializeParams` | `{ protocolVersion, capabilities, clientInfo }` |
|
|
46
|
+
| `InitializedNotification` | `{ jsonrpc: '2.0', method: 'notifications/initialized' }` (no `id` / `params`) |
|
|
47
|
+
| `ToolsCallParams` | `{ name, arguments? }` |
|
|
48
|
+
|
|
49
|
+
Prefer those Schema owners for new construction. Compatibility constructors
|
|
50
|
+
`makeJsonRpcRequest`, `makeInitializeParams`, and `makeInitializedNotification` remain and build
|
|
51
|
+
through the schemas. `makeJsonRpcRequest` still omits `params` when `undefined`.
|
|
52
|
+
|
|
31
53
|
## Imports
|
|
32
54
|
|
|
33
55
|
```ts
|
|
@@ -132,6 +154,10 @@ import { makeMcpToolServer, runStdioMcpServer } from '@yolk-sdk/mcp/server'
|
|
|
132
154
|
|
|
133
155
|
`makeMcpToolServer` exposes approved Yolk tools. Its HTTP handler accepts both stateless v2 and legacy requests, validates browser origins against the endpoint hostname by default, and preserves MCP content and structured results. `runStdioMcpServer` remains the Effect-native minimal stdio adapter; use `serveStdio` for the full modern stdio surface.
|
|
134
156
|
|
|
157
|
+
For legacy HTTP requests, an unreadable or already consumed body produces a JSON-RPC
|
|
158
|
+
invalid-request error (`-32600`) rather than an Effect defect. Malformed JSON remains a parse error
|
|
159
|
+
(`-32700`).
|
|
160
|
+
|
|
135
161
|
## Host responsibilities
|
|
136
162
|
|
|
137
163
|
- Own persisted server config, credentials, authorization policy, and enabled capabilities.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.mts","names":[],"sources":["../../src/client/client.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":[],"sources":["../../src/client/client.ts"],"mappings":";;;;;;;;;;KA8CY,gBAAA;EAAA,SACD,UAAA,GAAa,aAAA;EAAA,SACb,cAAA,GAAiB,iBAAA;EAAA,SACjB,SAAA;EAAA,SACA,GAAA,GAAM,aAAA;EAAA,SACN,eAAA,IAAmB,MAAA,EAAQ,MAAA;AAAA;AAAA,KAG1B,eAAA;EAAA,SACD,UAAA;EAAA,SACA,WAAA;EAAA,SACA,KAAA;EAAA,SACA,YAAA;EAAA,SACA,WAAA,GAAc,kBAAA;EAAA,SACd,GAAA,EAAK,UAAA,QAAkB,gBAAA;AAAA;AAAA,cAoUrB,wBAAA,GACX,MAAA,EAAQ,qBAAA,EACR,OAAA,GAAU,gBAAA,KACT,MAAA,CAAO,MAAA,CAAO,aAAA,CAAc,eAAA,GAAkB,QAAA,EAAU,UAAA,CA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ecurityPolicy } from "./config.mjs";
|
|
2
2
|
import { McpError } from "./errors.mjs";
|
|
3
|
-
import { decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, encodeJsonRpcMessage, jsonRpcErrorToMcpError,
|
|
3
|
+
import { InitializeClientInfo, InitializeParams, InitializedNotification, JsonRpcRequest, ToolsCallParams, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, encodeJsonRpcMessage, jsonRpcErrorToMcpError, legacyMcpProtocolVersion, mcpToolToToolDef, toolCallResultToToolResult } from "./protocol.mjs";
|
|
4
4
|
import { makeEffectFetch } from "./effect-fetch.mjs";
|
|
5
5
|
import { Duration, Effect, Option, Stream } from "effect";
|
|
6
6
|
import * as Schema from "effect/Schema";
|
|
@@ -122,29 +122,45 @@ const requestLocal = (config, requests, expectedResponses, options) => Effect.ge
|
|
|
122
122
|
line
|
|
123
123
|
})))), expectedResponses, options);
|
|
124
124
|
});
|
|
125
|
-
const initializeRequest = (options) =>
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
const initializeRequest = (options) => {
|
|
126
|
+
const info = clientInfo(options);
|
|
127
|
+
return JsonRpcRequest.make({
|
|
128
|
+
jsonrpc: "2.0",
|
|
129
|
+
id: 1,
|
|
130
|
+
method: "initialize",
|
|
131
|
+
params: InitializeParams.make({
|
|
132
|
+
protocolVersion: legacyMcpProtocolVersion,
|
|
133
|
+
capabilities: {},
|
|
134
|
+
clientInfo: InitializeClientInfo.make({
|
|
135
|
+
name: info.name,
|
|
136
|
+
version: info.version
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
const listToolsRequest = () => JsonRpcRequest.make({
|
|
142
|
+
jsonrpc: "2.0",
|
|
131
143
|
id: 2,
|
|
132
144
|
method: "tools/list"
|
|
133
145
|
});
|
|
134
|
-
const callToolRequest = (input) =>
|
|
146
|
+
const callToolRequest = (input) => JsonRpcRequest.make({
|
|
147
|
+
jsonrpc: "2.0",
|
|
135
148
|
id: 3,
|
|
136
149
|
method: "tools/call",
|
|
137
|
-
params: {
|
|
150
|
+
params: ToolsCallParams.make({
|
|
138
151
|
name: input.toolName,
|
|
139
152
|
arguments: input.params
|
|
140
|
-
}
|
|
153
|
+
})
|
|
141
154
|
});
|
|
142
155
|
const responseById = (responses, id) => Option.fromNullishOr(responses.find((response) => response.id === id));
|
|
143
156
|
const requestLocalSession = (config, request, options) => Effect.gen(function* () {
|
|
144
157
|
const initialize = initializeRequest(options);
|
|
145
158
|
const responses = yield* requestLocal(config, [
|
|
146
159
|
initialize,
|
|
147
|
-
|
|
160
|
+
InitializedNotification.make({
|
|
161
|
+
jsonrpc: "2.0",
|
|
162
|
+
method: "notifications/initialized"
|
|
163
|
+
}),
|
|
148
164
|
request
|
|
149
165
|
], 2, options);
|
|
150
166
|
const initializeResponse = responseById(responses, initialize.id);
|
|
@@ -155,67 +171,74 @@ const requestLocalSession = (config, request, options) => Effect.gen(function* (
|
|
|
155
171
|
const response = responseById(responses, request.id);
|
|
156
172
|
return Option.isNone(response) ? fail(config.name, "Local MCP did not return expected response", "protocol") : unwrapResponse(config.name, response.value);
|
|
157
173
|
}));
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
174
|
+
const resolvedMcpTools = (config, listed) => listed.tools.map((tool) => ({
|
|
175
|
+
serverName: config.name,
|
|
176
|
+
mcpToolName: tool.name,
|
|
177
|
+
title: tool.title,
|
|
178
|
+
outputSchema: tool.outputSchema,
|
|
179
|
+
annotations: tool.annotations,
|
|
180
|
+
def: mcpToolToToolDef({
|
|
164
181
|
serverName: config.name,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
annotations: tool.annotations,
|
|
169
|
-
def: mcpToolToToolDef({
|
|
170
|
-
serverName: config.name,
|
|
171
|
-
tool
|
|
172
|
-
})
|
|
173
|
-
}));
|
|
174
|
-
});
|
|
182
|
+
tool
|
|
183
|
+
})
|
|
184
|
+
}));
|
|
175
185
|
const listRemoteMcpServerTools = (config, options) => Effect.gen(function* () {
|
|
176
186
|
if (config.enabled === false) return [];
|
|
177
|
-
return
|
|
187
|
+
return resolvedMcpTools(config, yield* decodeToolsListResult(yield* withRemoteSdkClient(config, options, (client) => client.listTools(void 0, sdkRequestOptions(options)))).pipe(Effect.mapError((error) => new McpError({
|
|
188
|
+
server: config.name,
|
|
189
|
+
message: `Invalid tools/list result: ${unknownToMessage(error)}`,
|
|
190
|
+
cause: "validation"
|
|
191
|
+
}))));
|
|
178
192
|
});
|
|
179
193
|
const listLocalMcpServerTools = (config, options) => Effect.gen(function* () {
|
|
180
194
|
if (config.enabled === false) return [];
|
|
181
195
|
yield* validateLocal(config, securityPolicy(options));
|
|
182
|
-
return
|
|
196
|
+
return resolvedMcpTools(config, yield* decodeToolsListResult(yield* requestLocalSession(config, listToolsRequest(), options)).pipe(Effect.mapError((error) => new McpError({
|
|
197
|
+
server: config.name,
|
|
198
|
+
message: `Invalid tools/list result: ${unknownToMessage(error)}`,
|
|
199
|
+
cause: "validation"
|
|
200
|
+
}))));
|
|
183
201
|
});
|
|
184
202
|
const listMcpServerTools = (config, options) => Effect.gen(function* () {
|
|
185
203
|
if (config.enabled === false) return [];
|
|
186
204
|
if (config.type === "local") return yield* listLocalMcpServerTools(config, options);
|
|
187
205
|
return yield* listRemoteMcpServerTools(config, options);
|
|
188
206
|
});
|
|
189
|
-
const resolveMcpToolResult = (input, result) => Effect.gen(function* () {
|
|
190
|
-
const toolCallResult = yield* decodeToolCallResult(result).pipe(Effect.mapError((error) => new McpError({
|
|
191
|
-
server: input.config.name,
|
|
192
|
-
message: `Invalid tools/call result: ${unknownToMessage(error)}`,
|
|
193
|
-
cause: "validation"
|
|
194
|
-
})));
|
|
195
|
-
return toolCallResultToToolResult({
|
|
196
|
-
toolCallId: input.toolCallId,
|
|
197
|
-
result: toolCallResult
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
207
|
const callRemoteMcpServerTool = (input) => Effect.gen(function* () {
|
|
201
208
|
const args = yield* decodeToolArguments(input.params).pipe(Effect.mapError((error) => new McpError({
|
|
202
209
|
server: input.config.name,
|
|
203
210
|
message: `Invalid tools/call arguments: ${unknownToMessage(error)}`,
|
|
204
211
|
cause: "validation"
|
|
205
212
|
})));
|
|
206
|
-
|
|
213
|
+
const toolCallResult = yield* decodeToolCallResult(yield* withRemoteSdkClient(input.config, input.options, async (client) => {
|
|
207
214
|
await client.listTools(void 0, sdkRequestOptions(input.options));
|
|
208
215
|
return client.callTool({
|
|
209
216
|
name: input.mcpToolName,
|
|
210
217
|
arguments: args
|
|
211
218
|
}, sdkRequestOptions(input.options));
|
|
212
|
-
}))
|
|
219
|
+
})).pipe(Effect.mapError((error) => new McpError({
|
|
220
|
+
server: input.config.name,
|
|
221
|
+
message: `Invalid tools/call result: ${unknownToMessage(error)}`,
|
|
222
|
+
cause: "validation"
|
|
223
|
+
})));
|
|
224
|
+
return toolCallResultToToolResult({
|
|
225
|
+
toolCallId: input.toolCallId,
|
|
226
|
+
result: toolCallResult
|
|
227
|
+
});
|
|
213
228
|
});
|
|
214
229
|
const callLocalMcpServerTool = (input) => Effect.gen(function* () {
|
|
215
|
-
|
|
230
|
+
const toolCallResult = yield* decodeToolCallResult(yield* requestLocalSession(input.config, callToolRequest({
|
|
216
231
|
toolName: input.mcpToolName,
|
|
217
232
|
params: input.params
|
|
218
|
-
}), input.options))
|
|
233
|
+
}), input.options)).pipe(Effect.mapError((error) => new McpError({
|
|
234
|
+
server: input.config.name,
|
|
235
|
+
message: `Invalid tools/call result: ${unknownToMessage(error)}`,
|
|
236
|
+
cause: "validation"
|
|
237
|
+
})));
|
|
238
|
+
return toolCallResultToToolResult({
|
|
239
|
+
toolCallId: input.toolCallId,
|
|
240
|
+
result: toolCallResult
|
|
241
|
+
});
|
|
219
242
|
});
|
|
220
243
|
const callMcpServerTool = (input) => input.config.type === "local" ? callLocalMcpServerTool({
|
|
221
244
|
config: input.config,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","names":["SdkClient"],"sources":["../../src/client/client.ts"],"sourcesContent":["import { Duration, Effect, Option, Stream } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport {\n Client as SdkClient,\n ProtocolError,\n SdkError,\n SdkErrorCode,\n StreamableHTTPClientTransport,\n type ClientOptions as SdkClientOptions\n} from '@modelcontextprotocol/client'\nimport { HttpClient } from 'effect/unstable/http'\nimport { ChildProcess } from 'effect/unstable/process'\nimport type { ChildProcessSpawner } from 'effect/unstable/process'\nimport type { ToolResult } from '@yolk-sdk/agent/protocol'\nimport type {\n McpClientInfo,\n McpLocalServerConfig,\n McpRemoteServerConfig,\n McpSecurityPolicy,\n McpServerConfig\n} from './config.ts'\nimport { defaultMcpClientInfo, defaultMcpSecurityPolicy } from './config.ts'\nimport { McpError } from './errors.ts'\nimport {\n decodeJsonRpcResponseFromJson,\n decodeToolCallResult,\n decodeToolsListResult,\n encodeJsonRpcMessage,\n jsonRpcErrorToMcpError,\n makeInitializedNotification,\n makeInitializeParams,\n makeJsonRpcRequest,\n mcpToolToToolDef,\n toolCallResultToToolResult,\n type McpToolAnnotations,\n type JsonRpcNotification,\n type JsonRpcRequest,\n type JsonRpcResponse\n} from './protocol.ts'\nimport { makeEffectFetch } from './effect-fetch.ts'\n\nconst defaultRequestTimeoutMs = 30_000\n\nexport type McpClientOptions = {\n readonly clientInfo?: McpClientInfo\n readonly securityPolicy?: McpSecurityPolicy\n readonly timeoutMs?: number\n readonly sdk?: SdkClientOptions\n readonly configureClient?: (client: SdkClient) => void\n}\n\nexport type McpResolvedTool = {\n readonly serverName: string\n readonly mcpToolName: string\n readonly title?: string\n readonly outputSchema?: unknown\n readonly annotations?: McpToolAnnotations\n readonly def: ReturnType<typeof mcpToolToToolDef>\n}\n\nconst unknownToMessage = (error: unknown) =>\n error instanceof Error ? error.message : String(error)\n\nconst timeoutMs = (options?: McpClientOptions) => options?.timeoutMs ?? defaultRequestTimeoutMs\n\nconst clientInfo = (options?: McpClientOptions) => options?.clientInfo ?? defaultMcpClientInfo\n\nconst securityPolicy = (options?: McpClientOptions) =>\n options?.securityPolicy ?? defaultMcpSecurityPolicy\n\nconst fail = (server: string, message: string, cause: McpError['cause']) =>\n Effect.fail(new McpError({ server, message, cause }))\n\nconst validateRemoteUrl = (config: McpRemoteServerConfig, policy: McpSecurityPolicy) =>\n Effect.gen(function* () {\n const url = yield* Effect.try({\n try: () => new URL(config.url),\n catch: error =>\n new McpError({\n server: config.name,\n message: `Invalid MCP server URL: ${unknownToMessage(error)}`,\n cause: 'validation'\n })\n })\n\n if (url.protocol === 'https:') {\n return url.toString()\n }\n\n if (\n policy.allowDevHttpLocalhost &&\n url.protocol === 'http:' &&\n (url.hostname === 'localhost' || url.hostname === '127.0.0.1' || url.hostname === '[::1]')\n ) {\n return url.toString()\n }\n\n return yield* fail(config.name, 'Remote MCP requires https: URL', 'security')\n })\n\nconst validateLocal = (config: McpLocalServerConfig, policy: McpSecurityPolicy) =>\n Effect.gen(function* () {\n if (!policy.allowLocalServers) {\n return yield* fail(config.name, 'Local MCP servers are disabled by policy', 'security')\n }\n\n if (config.command.length === 0) {\n return yield* fail(config.name, 'Local MCP command must not be empty', 'validation')\n }\n })\n\nconst unwrapResponse = (server: string, response: JsonRpcResponse) =>\n 'error' in response\n ? Effect.fail(jsonRpcErrorToMcpError(server, response.error))\n : Effect.succeed(response.result)\n\nconst mapUnknownToMcpError =\n (server: string, message: string, cause: McpError['cause']) => (error: unknown) =>\n error instanceof McpError\n ? error\n : new McpError({\n server,\n message: `${message}: ${unknownToMessage(error)}`,\n cause\n })\n\nconst findDuplicateToolName = (tools: ReadonlyArray<McpResolvedTool>) => {\n const names = tools.map(tool => tool.def.name)\n return Option.fromNullishOr(names.find((name, index) => names.indexOf(name) !== index))\n}\n\nconst sdkFailureCause = (error: unknown): McpError['cause'] => {\n if (error instanceof ProtocolError) {\n return 'protocol'\n }\n\n if (error instanceof SdkError) {\n if (error.code === SdkErrorCode.RequestTimeout) {\n return 'timeout'\n }\n\n const message = error.message.toLowerCase()\n return message.includes('content type') || message.includes('json') || message.includes('parse')\n ? 'protocol'\n : 'transport'\n }\n\n return 'transport'\n}\n\nconst mapSdkError = (server: string, operation: string) => (error: unknown) =>\n error instanceof McpError\n ? error\n : new McpError({\n server,\n message: `${operation}: ${unknownToMessage(error)}`,\n cause: sdkFailureCause(error)\n })\n\nconst withRemoteSdkClient = <A>(\n config: McpRemoteServerConfig,\n options: McpClientOptions | undefined,\n run: (client: SdkClient) => Promise<A>\n): Effect.Effect<A, McpError, HttpClient.HttpClient> =>\n Effect.gen(function* () {\n const url = yield* validateRemoteUrl(config, securityPolicy(options))\n const http = yield* HttpClient.HttpClient\n const sdkClient = yield* Effect.try({\n try: () => {\n const client = new SdkClient(clientInfo(options), {\n ...options?.sdk,\n versionNegotiation: options?.sdk?.versionNegotiation ?? { mode: 'auto' }\n })\n options?.configureClient?.(client)\n return client\n },\n catch: mapSdkError(config.name, 'Could not configure MCP client')\n })\n const transport = new StreamableHTTPClientTransport(new URL(url), {\n fetch: makeEffectFetch(http),\n requestInit: { headers: new Headers(config.headers) }\n })\n\n return yield* Effect.acquireUseRelease(\n Effect.tryPromise({\n try: () =>\n sdkClient\n .connect(transport, {\n timeout: timeoutMs(options),\n maxTotalTimeout: timeoutMs(options)\n })\n .then(() => sdkClient),\n catch: mapSdkError(config.name, 'Could not connect to MCP server')\n }),\n () =>\n Effect.tryPromise({\n try: () => run(sdkClient),\n catch: mapSdkError(config.name, 'MCP request failed')\n }),\n () => Effect.promise(() => sdkClient.close()).pipe(Effect.catch(() => Effect.void))\n )\n })\n\nconst sdkRequestOptions = (options?: McpClientOptions) => ({\n timeout: timeoutMs(options),\n maxTotalTimeout: timeoutMs(options)\n})\n\nconst decodeToolArguments = Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown))\n\ntype EncodedLocalMessage = {\n readonly message: JsonRpcRequest | JsonRpcNotification\n readonly line: string\n}\n\nconst requestLocalEncoded = (\n config: McpLocalServerConfig,\n messages: ReadonlyArray<EncodedLocalMessage>,\n expectedResponses: number,\n options?: McpClientOptions\n) => {\n const policy = securityPolicy(options)\n if (!policy.allowLocalServers) {\n return fail(config.name, 'Local MCP servers are disabled by policy', 'security')\n }\n\n const command = config.command[0]\n if (command === undefined) {\n return fail(config.name, 'Local MCP command must not be empty', 'validation')\n }\n\n return Effect.gen(function* () {\n const stdin = Stream.fromIterable(messages.map(message => `${message.line}\\n`)).pipe(\n Stream.encodeText\n )\n const child = yield* ChildProcess.make(command, config.command.slice(1), {\n env: config.environment ?? {},\n extendEnv: false,\n stdin: { stream: stdin, endOnDone: true },\n stderr: 'ignore'\n })\n const lines = yield* child.stdout.pipe(\n Stream.decodeText,\n Stream.splitLines,\n Stream.filter(line => line.length > 0),\n Stream.take(expectedResponses),\n Stream.runCollect\n )\n const responses = yield* Effect.forEach(lines, line =>\n decodeJsonRpcResponseFromJson(config.name, line)\n )\n\n if (responses.length < expectedResponses) {\n return yield* fail(config.name, 'Local MCP did not return expected response', 'protocol')\n }\n\n return responses\n }).pipe(\n Effect.scoped,\n Effect.timeoutOrElse({\n duration: Duration.millis(timeoutMs(options)),\n orElse: () => fail(config.name, 'Local MCP request timed out', 'timeout')\n }),\n Effect.mapError(mapUnknownToMcpError(config.name, 'Local MCP request failed', 'transport'))\n )\n}\n\nconst requestLocal = (\n config: McpLocalServerConfig,\n requests: ReadonlyArray<JsonRpcRequest | JsonRpcNotification>,\n expectedResponses: number,\n options?: McpClientOptions\n) =>\n Effect.gen(function* () {\n const messages = yield* Effect.forEach(requests, request =>\n encodeJsonRpcMessage(config.name, request).pipe(\n Effect.map(line => ({ message: request, line }))\n )\n )\n\n return yield* requestLocalEncoded(config, messages, expectedResponses, options)\n })\n\nconst initializeRequest = (options?: McpClientOptions) =>\n makeJsonRpcRequest({\n id: 1,\n method: 'initialize',\n params: makeInitializeParams(clientInfo(options))\n })\n\nconst listToolsRequest = () => makeJsonRpcRequest({ id: 2, method: 'tools/list' })\n\nconst callToolRequest = (input: { readonly toolName: string; readonly params: unknown }) =>\n makeJsonRpcRequest({\n id: 3,\n method: 'tools/call',\n params: { name: input.toolName, arguments: input.params }\n })\n\nconst responseById = (responses: ReadonlyArray<JsonRpcResponse>, id: string | number) =>\n Option.fromNullishOr(responses.find(response => response.id === id))\n\nconst requestLocalSession = (\n config: McpLocalServerConfig,\n request: JsonRpcRequest,\n options?: McpClientOptions\n) =>\n Effect.gen(function* () {\n const initialize = initializeRequest(options)\n const responses = yield* requestLocal(\n config,\n [initialize, makeInitializedNotification(), request],\n 2,\n options\n )\n const initializeResponse = responseById(responses, initialize.id)\n if (Option.isNone(initializeResponse)) {\n return yield* fail(config.name, 'Local MCP did not return initialize response', 'protocol')\n }\n yield* unwrapResponse(config.name, initializeResponse.value)\n\n return responses\n }).pipe(\n Effect.flatMap(responses => {\n const response = responseById(responses, request.id)\n return Option.isNone(response)\n ? fail(config.name, 'Local MCP did not return expected response', 'protocol')\n : unwrapResponse(config.name, response.value)\n })\n )\n\nconst resolveMcpTools = (config: McpServerConfig, result: unknown) =>\n Effect.gen(function* () {\n const tools = yield* decodeToolsListResult(result).pipe(\n Effect.mapError(\n error =>\n new McpError({\n server: config.name,\n message: `Invalid tools/list result: ${unknownToMessage(error)}`,\n cause: 'validation'\n })\n )\n )\n\n return tools.tools.map(tool => ({\n serverName: config.name,\n mcpToolName: tool.name,\n title: tool.title,\n outputSchema: tool.outputSchema,\n annotations: tool.annotations,\n def: mcpToolToToolDef({ serverName: config.name, tool })\n }))\n })\n\nexport const listRemoteMcpServerTools = (\n config: McpRemoteServerConfig,\n options?: McpClientOptions\n): Effect.Effect<ReadonlyArray<McpResolvedTool>, McpError, HttpClient.HttpClient> =>\n Effect.gen(function* () {\n if (config.enabled === false) {\n return []\n }\n\n const result = yield* withRemoteSdkClient(config, options, client =>\n client.listTools(undefined, sdkRequestOptions(options))\n )\n return yield* resolveMcpTools(config, result)\n })\n\nexport const listLocalMcpServerTools = (\n config: McpLocalServerConfig,\n options?: McpClientOptions\n): Effect.Effect<\n ReadonlyArray<McpResolvedTool>,\n McpError,\n ChildProcessSpawner.ChildProcessSpawner\n> =>\n Effect.gen(function* () {\n if (config.enabled === false) {\n return []\n }\n\n yield* validateLocal(config, securityPolicy(options))\n const result = yield* requestLocalSession(config, listToolsRequest(), options)\n return yield* resolveMcpTools(config, result)\n })\n\nexport const listMcpServerTools = (config: McpServerConfig, options?: McpClientOptions) =>\n Effect.gen(function* () {\n if (config.enabled === false) {\n return []\n }\n\n if (config.type === 'local') {\n return yield* listLocalMcpServerTools(config, options)\n }\n\n return yield* listRemoteMcpServerTools(config, options)\n })\n\nexport type CallMcpServerToolInput = {\n readonly config: McpServerConfig\n readonly mcpToolName: string\n readonly toolCallId: string\n readonly params: unknown\n readonly options?: McpClientOptions\n}\n\nconst resolveMcpToolResult = (input: CallMcpServerToolInput, result: unknown) =>\n Effect.gen(function* () {\n const toolCallResult = yield* decodeToolCallResult(result).pipe(\n Effect.mapError(\n error =>\n new McpError({\n server: input.config.name,\n message: `Invalid tools/call result: ${unknownToMessage(error)}`,\n cause: 'validation'\n })\n )\n )\n\n return toolCallResultToToolResult({ toolCallId: input.toolCallId, result: toolCallResult })\n })\n\nexport const callRemoteMcpServerTool = (\n input: Omit<CallMcpServerToolInput, 'config'> & { readonly config: McpRemoteServerConfig }\n): Effect.Effect<ToolResult, McpError, HttpClient.HttpClient> =>\n Effect.gen(function* () {\n const args = yield* decodeToolArguments(input.params).pipe(\n Effect.mapError(\n error =>\n new McpError({\n server: input.config.name,\n message: `Invalid tools/call arguments: ${unknownToMessage(error)}`,\n cause: 'validation'\n })\n )\n )\n const result = yield* withRemoteSdkClient(input.config, input.options, async client => {\n await client.listTools(undefined, sdkRequestOptions(input.options))\n return client.callTool(\n { name: input.mcpToolName, arguments: args },\n sdkRequestOptions(input.options)\n )\n })\n return yield* resolveMcpToolResult(input, result)\n })\n\nexport const callLocalMcpServerTool = (\n input: Omit<CallMcpServerToolInput, 'config'> & { readonly config: McpLocalServerConfig }\n): Effect.Effect<ToolResult, McpError, ChildProcessSpawner.ChildProcessSpawner> =>\n Effect.gen(function* () {\n const result = yield* requestLocalSession(\n input.config,\n callToolRequest({ toolName: input.mcpToolName, params: input.params }),\n input.options\n )\n return yield* resolveMcpToolResult(input, result)\n })\n\nexport const callMcpServerTool = (\n input: CallMcpServerToolInput\n): Effect.Effect<\n ToolResult,\n McpError,\n ChildProcessSpawner.ChildProcessSpawner | HttpClient.HttpClient\n> =>\n input.config.type === 'local'\n ? callLocalMcpServerTool({\n config: input.config,\n mcpToolName: input.mcpToolName,\n toolCallId: input.toolCallId,\n params: input.params,\n options: input.options\n })\n : callRemoteMcpServerTool({\n config: input.config,\n mcpToolName: input.mcpToolName,\n toolCallId: input.toolCallId,\n params: input.params,\n options: input.options\n })\n\nexport const listMcpTools = (configs: ReadonlyArray<McpServerConfig>, options?: McpClientOptions) =>\n Effect.flatMap(\n Effect.forEach(configs, config => listMcpServerTools(config, options)),\n tools => {\n const resolved = tools.flat()\n const duplicate = findDuplicateToolName(resolved)\n if (Option.isSome(duplicate)) {\n return fail('mcp', `Duplicate MCP tool name: ${duplicate.value}`, 'validation')\n }\n\n return Effect.succeed(resolved)\n }\n )\n"],"mappings":";;;;;;;;;;AAyCA,MAAM,0BAA0B;AAmBhC,MAAM,oBAAoB,UACxB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAEvD,MAAM,aAAa,YAA+B,SAAS,aAAa;AAExE,MAAM,cAAc,YAA+B,SAAS,cAAc;AAE1E,MAAM,kBAAkB,YACtB,SAAS,kBAAkB;AAE7B,MAAM,QAAQ,QAAgB,SAAiB,UAC7C,OAAO,KAAK,IAAI,SAAS;CAAE;CAAQ;CAAS;AAAM,CAAC,CAAC;AAEtD,MAAM,qBAAqB,QAA+B,WACxD,OAAO,IAAI,aAAa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CAC5B,MAAM,YAAY,sBAAsB,QAAQ;CAChD,IAAI,OAAO,OAAO,SAAS,GACzB,OAAO,KAAK,OAAO,4BAA4B,UAAU,SAAS,YAAY;CAGhF,OAAO,OAAO,QAAQ,QAAQ;AAChC,CACF"}
|
|
1
|
+
{"version":3,"file":"client.mjs","names":["SdkClient"],"sources":["../../src/client/client.ts"],"sourcesContent":["import { Duration, Effect, Option, Stream } from 'effect'\nimport * as Schema from 'effect/Schema'\nimport {\n Client as SdkClient,\n ProtocolError,\n SdkError,\n SdkErrorCode,\n StreamableHTTPClientTransport,\n type ClientOptions as SdkClientOptions\n} from '@modelcontextprotocol/client'\nimport { HttpClient } from 'effect/unstable/http'\nimport { ChildProcess } from 'effect/unstable/process'\nimport type { ChildProcessSpawner } from 'effect/unstable/process'\nimport type { ToolResult } from '@yolk-sdk/agent/protocol'\nimport type {\n McpClientInfo,\n McpLocalServerConfig,\n McpRemoteServerConfig,\n McpSecurityPolicy,\n McpServerConfig\n} from './config.ts'\nimport { defaultMcpClientInfo, defaultMcpSecurityPolicy } from './config.ts'\nimport { McpError } from './errors.ts'\nimport {\n decodeJsonRpcResponseFromJson,\n decodeToolCallResult,\n decodeToolsListResult,\n encodeJsonRpcMessage,\n InitializeClientInfo,\n InitializeParams,\n InitializedNotification,\n jsonRpcErrorToMcpError,\n JsonRpcRequest,\n legacyMcpProtocolVersion,\n mcpToolToToolDef,\n toolCallResultToToolResult,\n ToolsCallParams,\n type McpToolAnnotations,\n type JsonRpcNotification,\n type JsonRpcResponse,\n type ToolsListResult\n} from './protocol.ts'\nimport { makeEffectFetch } from './effect-fetch.ts'\n\nconst defaultRequestTimeoutMs = 30_000\n\nexport type McpClientOptions = {\n readonly clientInfo?: McpClientInfo\n readonly securityPolicy?: McpSecurityPolicy\n readonly timeoutMs?: number\n readonly sdk?: SdkClientOptions\n readonly configureClient?: (client: SdkClient) => void\n}\n\nexport type McpResolvedTool = {\n readonly serverName: string\n readonly mcpToolName: string\n readonly title?: string\n readonly outputSchema?: unknown\n readonly annotations?: McpToolAnnotations\n readonly def: ReturnType<typeof mcpToolToToolDef>\n}\n\nconst unknownToMessage = (error: unknown) =>\n error instanceof Error ? error.message : String(error)\n\nconst timeoutMs = (options?: McpClientOptions) => options?.timeoutMs ?? defaultRequestTimeoutMs\n\nconst clientInfo = (options?: McpClientOptions) => options?.clientInfo ?? defaultMcpClientInfo\n\nconst securityPolicy = (options?: McpClientOptions) =>\n options?.securityPolicy ?? defaultMcpSecurityPolicy\n\nconst fail = (server: string, message: string, cause: McpError['cause']) =>\n Effect.fail(new McpError({ server, message, cause }))\n\nconst validateRemoteUrl = (config: McpRemoteServerConfig, policy: McpSecurityPolicy) =>\n Effect.gen(function* () {\n const url = yield* Effect.try({\n try: () => new URL(config.url),\n catch: error =>\n new McpError({\n server: config.name,\n message: `Invalid MCP server URL: ${unknownToMessage(error)}`,\n cause: 'validation'\n })\n })\n\n if (url.protocol === 'https:') {\n return url.toString()\n }\n\n if (\n policy.allowDevHttpLocalhost &&\n url.protocol === 'http:' &&\n (url.hostname === 'localhost' || url.hostname === '127.0.0.1' || url.hostname === '[::1]')\n ) {\n return url.toString()\n }\n\n return yield* fail(config.name, 'Remote MCP requires https: URL', 'security')\n })\n\nconst validateLocal = (config: McpLocalServerConfig, policy: McpSecurityPolicy) =>\n Effect.gen(function* () {\n if (!policy.allowLocalServers) {\n return yield* fail(config.name, 'Local MCP servers are disabled by policy', 'security')\n }\n\n if (config.command.length === 0) {\n return yield* fail(config.name, 'Local MCP command must not be empty', 'validation')\n }\n })\n\nconst unwrapResponse = (server: string, response: JsonRpcResponse) =>\n 'error' in response\n ? Effect.fail(jsonRpcErrorToMcpError(server, response.error))\n : Effect.succeed(response.result)\n\nconst mapUnknownToMcpError =\n (server: string, message: string, cause: McpError['cause']) => (error: unknown) =>\n error instanceof McpError\n ? error\n : new McpError({\n server,\n message: `${message}: ${unknownToMessage(error)}`,\n cause\n })\n\nconst findDuplicateToolName = (tools: ReadonlyArray<McpResolvedTool>) => {\n const names = tools.map(tool => tool.def.name)\n\n return Option.fromNullishOr(names.find((name, index) => names.indexOf(name) !== index))\n}\n\nconst sdkFailureCause = (error: unknown): McpError['cause'] => {\n if (error instanceof ProtocolError) {\n return 'protocol'\n }\n\n if (error instanceof SdkError) {\n if (error.code === SdkErrorCode.RequestTimeout) {\n return 'timeout'\n }\n\n const message = error.message.toLowerCase()\n\n return message.includes('content type') || message.includes('json') || message.includes('parse')\n ? 'protocol'\n : 'transport'\n }\n\n return 'transport'\n}\n\nconst mapSdkError = (server: string, operation: string) => (error: unknown) =>\n error instanceof McpError\n ? error\n : new McpError({\n server,\n message: `${operation}: ${unknownToMessage(error)}`,\n cause: sdkFailureCause(error)\n })\n\nconst withRemoteSdkClient = <A>(\n config: McpRemoteServerConfig,\n options: McpClientOptions | undefined,\n run: (client: SdkClient) => Promise<A>\n): Effect.Effect<A, McpError, HttpClient.HttpClient> =>\n Effect.gen(function* () {\n const url = yield* validateRemoteUrl(config, securityPolicy(options))\n const http = yield* HttpClient.HttpClient\n\n const sdkClient = yield* Effect.try({\n try: () => {\n const client = new SdkClient(clientInfo(options), {\n ...options?.sdk,\n versionNegotiation: options?.sdk?.versionNegotiation ?? { mode: 'auto' }\n })\n\n options?.configureClient?.(client)\n\n return client\n },\n catch: mapSdkError(config.name, 'Could not configure MCP client')\n })\n\n const transport = new StreamableHTTPClientTransport(new URL(url), {\n fetch: makeEffectFetch(http),\n requestInit: { headers: new Headers(config.headers) }\n })\n\n return yield* Effect.acquireUseRelease(\n Effect.tryPromise({\n try: () =>\n sdkClient\n .connect(transport, {\n timeout: timeoutMs(options),\n maxTotalTimeout: timeoutMs(options)\n })\n .then(() => sdkClient),\n catch: mapSdkError(config.name, 'Could not connect to MCP server')\n }),\n () =>\n Effect.tryPromise({\n try: () => run(sdkClient),\n catch: mapSdkError(config.name, 'MCP request failed')\n }),\n () => Effect.promise(() => sdkClient.close()).pipe(Effect.catch(() => Effect.void))\n )\n })\n\nconst sdkRequestOptions = (options?: McpClientOptions) => ({\n timeout: timeoutMs(options),\n maxTotalTimeout: timeoutMs(options)\n})\n\nconst decodeToolArguments = Schema.decodeUnknownEffect(Schema.Record(Schema.String, Schema.Unknown))\n\ntype EncodedLocalMessage = {\n readonly message: JsonRpcRequest | JsonRpcNotification\n readonly line: string\n}\n\nconst requestLocalEncoded = (\n config: McpLocalServerConfig,\n messages: ReadonlyArray<EncodedLocalMessage>,\n expectedResponses: number,\n options?: McpClientOptions\n) => {\n const policy = securityPolicy(options)\n\n if (!policy.allowLocalServers) {\n return fail(config.name, 'Local MCP servers are disabled by policy', 'security')\n }\n\n const command = config.command[0]\n\n if (command === undefined) {\n return fail(config.name, 'Local MCP command must not be empty', 'validation')\n }\n\n return Effect.gen(function* () {\n const stdin = Stream.fromIterable(messages.map(message => `${message.line}\\n`)).pipe(\n Stream.encodeText\n )\n\n const child = yield* ChildProcess.make(command, config.command.slice(1), {\n env: config.environment ?? {},\n extendEnv: false,\n stdin: { stream: stdin, endOnDone: true },\n stderr: 'ignore'\n })\n\n const lines = yield* child.stdout.pipe(\n Stream.decodeText,\n Stream.splitLines,\n Stream.filter(line => line.length > 0),\n Stream.take(expectedResponses),\n Stream.runCollect\n )\n\n const responses = yield* Effect.forEach(lines, line =>\n decodeJsonRpcResponseFromJson(config.name, line)\n )\n\n if (responses.length < expectedResponses) {\n return yield* fail(config.name, 'Local MCP did not return expected response', 'protocol')\n }\n\n return responses\n }).pipe(\n Effect.scoped,\n Effect.timeoutOrElse({\n duration: Duration.millis(timeoutMs(options)),\n orElse: () => fail(config.name, 'Local MCP request timed out', 'timeout')\n }),\n Effect.mapError(mapUnknownToMcpError(config.name, 'Local MCP request failed', 'transport'))\n )\n}\n\nconst requestLocal = (\n config: McpLocalServerConfig,\n requests: ReadonlyArray<JsonRpcRequest | JsonRpcNotification>,\n expectedResponses: number,\n options?: McpClientOptions\n) =>\n Effect.gen(function* () {\n const messages = yield* Effect.forEach(requests, request =>\n encodeJsonRpcMessage(config.name, request).pipe(\n Effect.map(line => ({ message: request, line }))\n )\n )\n\n return yield* requestLocalEncoded(config, messages, expectedResponses, options)\n })\n\nconst initializeRequest = (options?: McpClientOptions) => {\n const info = clientInfo(options)\n\n return JsonRpcRequest.make({\n jsonrpc: '2.0',\n id: 1,\n method: 'initialize',\n params: InitializeParams.make({\n protocolVersion: legacyMcpProtocolVersion,\n capabilities: {},\n clientInfo: InitializeClientInfo.make({ name: info.name, version: info.version })\n })\n })\n}\n\nconst listToolsRequest = () =>\n JsonRpcRequest.make({\n jsonrpc: '2.0',\n id: 2,\n method: 'tools/list'\n })\n\nconst callToolRequest = (input: { readonly toolName: string; readonly params: unknown }) =>\n JsonRpcRequest.make({\n jsonrpc: '2.0',\n id: 3,\n method: 'tools/call',\n params: ToolsCallParams.make({\n name: input.toolName,\n arguments: input.params\n })\n })\n\nconst responseById = (responses: ReadonlyArray<JsonRpcResponse>, id: string | number) =>\n Option.fromNullishOr(responses.find(response => response.id === id))\n\nconst requestLocalSession = (\n config: McpLocalServerConfig,\n request: JsonRpcRequest,\n options?: McpClientOptions\n) =>\n Effect.gen(function* () {\n const initialize = initializeRequest(options)\n\n const responses = yield* requestLocal(\n config,\n [\n initialize,\n InitializedNotification.make({\n jsonrpc: '2.0',\n method: 'notifications/initialized'\n }),\n request\n ],\n 2,\n options\n )\n\n const initializeResponse = responseById(responses, initialize.id)\n\n if (Option.isNone(initializeResponse)) {\n return yield* fail(config.name, 'Local MCP did not return initialize response', 'protocol')\n }\n\n yield* unwrapResponse(config.name, initializeResponse.value)\n\n return responses\n }).pipe(\n Effect.flatMap(responses => {\n const response = responseById(responses, request.id)\n\n return Option.isNone(response)\n ? fail(config.name, 'Local MCP did not return expected response', 'protocol')\n : unwrapResponse(config.name, response.value)\n })\n )\n\nconst resolvedMcpTools = (config: McpServerConfig, listed: ToolsListResult) =>\n listed.tools.map(tool => ({\n serverName: config.name,\n mcpToolName: tool.name,\n title: tool.title,\n outputSchema: tool.outputSchema,\n annotations: tool.annotations,\n def: mcpToolToToolDef({ serverName: config.name, tool })\n }))\n\nexport const listRemoteMcpServerTools = (\n config: McpRemoteServerConfig,\n options?: McpClientOptions\n): Effect.Effect<ReadonlyArray<McpResolvedTool>, McpError, HttpClient.HttpClient> =>\n Effect.gen(function* () {\n if (config.enabled === false) {\n return []\n }\n\n const result = yield* withRemoteSdkClient(config, options, client =>\n client.listTools(undefined, sdkRequestOptions(options))\n )\n\n const listed = yield* decodeToolsListResult(result).pipe(\n Effect.mapError(\n error =>\n new McpError({\n server: config.name,\n message: `Invalid tools/list result: ${unknownToMessage(error)}`,\n cause: 'validation'\n })\n )\n )\n\n return resolvedMcpTools(config, listed)\n })\n\nexport const listLocalMcpServerTools = (\n config: McpLocalServerConfig,\n options?: McpClientOptions\n): Effect.Effect<\n ReadonlyArray<McpResolvedTool>,\n McpError,\n ChildProcessSpawner.ChildProcessSpawner\n> =>\n Effect.gen(function* () {\n if (config.enabled === false) {\n return []\n }\n\n yield* validateLocal(config, securityPolicy(options))\n const result = yield* requestLocalSession(config, listToolsRequest(), options)\n\n const listed = yield* decodeToolsListResult(result).pipe(\n Effect.mapError(\n error =>\n new McpError({\n server: config.name,\n message: `Invalid tools/list result: ${unknownToMessage(error)}`,\n cause: 'validation'\n })\n )\n )\n\n return resolvedMcpTools(config, listed)\n })\n\nexport const listMcpServerTools = (config: McpServerConfig, options?: McpClientOptions) =>\n Effect.gen(function* () {\n if (config.enabled === false) {\n return []\n }\n\n if (config.type === 'local') {\n return yield* listLocalMcpServerTools(config, options)\n }\n\n return yield* listRemoteMcpServerTools(config, options)\n })\n\nexport type CallMcpServerToolInput = {\n readonly config: McpServerConfig\n readonly mcpToolName: string\n readonly toolCallId: string\n readonly params: unknown\n readonly options?: McpClientOptions\n}\n\nexport const callRemoteMcpServerTool = (\n input: Omit<CallMcpServerToolInput, 'config'> & { readonly config: McpRemoteServerConfig }\n): Effect.Effect<ToolResult, McpError, HttpClient.HttpClient> =>\n Effect.gen(function* () {\n const args = yield* decodeToolArguments(input.params).pipe(\n Effect.mapError(\n error =>\n new McpError({\n server: input.config.name,\n message: `Invalid tools/call arguments: ${unknownToMessage(error)}`,\n cause: 'validation'\n })\n )\n )\n\n const result = yield* withRemoteSdkClient(input.config, input.options, async client => {\n await client.listTools(undefined, sdkRequestOptions(input.options))\n\n return client.callTool(\n { name: input.mcpToolName, arguments: args },\n sdkRequestOptions(input.options)\n )\n })\n\n const toolCallResult = yield* decodeToolCallResult(result).pipe(\n Effect.mapError(\n error =>\n new McpError({\n server: input.config.name,\n message: `Invalid tools/call result: ${unknownToMessage(error)}`,\n cause: 'validation'\n })\n )\n )\n\n return toolCallResultToToolResult({ toolCallId: input.toolCallId, result: toolCallResult })\n })\n\nexport const callLocalMcpServerTool = (\n input: Omit<CallMcpServerToolInput, 'config'> & { readonly config: McpLocalServerConfig }\n): Effect.Effect<ToolResult, McpError, ChildProcessSpawner.ChildProcessSpawner> =>\n Effect.gen(function* () {\n const result = yield* requestLocalSession(\n input.config,\n callToolRequest({ toolName: input.mcpToolName, params: input.params }),\n input.options\n )\n\n const toolCallResult = yield* decodeToolCallResult(result).pipe(\n Effect.mapError(\n error =>\n new McpError({\n server: input.config.name,\n message: `Invalid tools/call result: ${unknownToMessage(error)}`,\n cause: 'validation'\n })\n )\n )\n\n return toolCallResultToToolResult({ toolCallId: input.toolCallId, result: toolCallResult })\n })\n\nexport const callMcpServerTool = (\n input: CallMcpServerToolInput\n): Effect.Effect<\n ToolResult,\n McpError,\n ChildProcessSpawner.ChildProcessSpawner | HttpClient.HttpClient\n> =>\n input.config.type === 'local'\n ? callLocalMcpServerTool({\n config: input.config,\n mcpToolName: input.mcpToolName,\n toolCallId: input.toolCallId,\n params: input.params,\n options: input.options\n })\n : callRemoteMcpServerTool({\n config: input.config,\n mcpToolName: input.mcpToolName,\n toolCallId: input.toolCallId,\n params: input.params,\n options: input.options\n })\n\nexport const listMcpTools = (configs: ReadonlyArray<McpServerConfig>, options?: McpClientOptions) =>\n Effect.flatMap(\n Effect.forEach(configs, config => listMcpServerTools(config, options)),\n tools => {\n const resolved = tools.flat()\n const duplicate = findDuplicateToolName(resolved)\n\n if (Option.isSome(duplicate)) {\n return fail('mcp', `Duplicate MCP tool name: ${duplicate.value}`, 'validation')\n }\n\n return Effect.succeed(resolved)\n }\n )\n"],"mappings":";;;;;;;;;;AA4CA,MAAM,0BAA0B;AAmBhC,MAAM,oBAAoB,UACxB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAEvD,MAAM,aAAa,YAA+B,SAAS,aAAa;AAExE,MAAM,cAAc,YAA+B,SAAS,cAAc;AAE1E,MAAM,kBAAkB,YACtB,SAAS,kBAAkB;AAE7B,MAAM,QAAQ,QAAgB,SAAiB,UAC7C,OAAO,KAAK,IAAI,SAAS;CAAE;CAAQ;CAAS;AAAM,CAAC,CAAC;AAEtD,MAAM,qBAAqB,QAA+B,WACxD,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,OAAO,OAAO,IAAI;EAC5B,WAAW,IAAI,IAAI,OAAO,GAAG;EAC7B,QAAO,UACL,IAAI,SAAS;GACX,QAAQ,OAAO;GACf,SAAS,2BAA2B,iBAAiB,KAAK;GAC1D,OAAO;EACT,CAAC;CACL,CAAC;CAED,IAAI,IAAI,aAAa,UACnB,OAAO,IAAI,SAAS;CAGtB,IACE,OAAO,yBACP,IAAI,aAAa,YAChB,IAAI,aAAa,eAAe,IAAI,aAAa,eAAe,IAAI,aAAa,UAElF,OAAO,IAAI,SAAS;CAGtB,OAAO,OAAO,KAAK,OAAO,MAAM,kCAAkC,UAAU;AAC9E,CAAC;AAEH,MAAM,iBAAiB,QAA8B,WACnD,OAAO,IAAI,aAAa;CACtB,IAAI,CAAC,OAAO,mBACV,OAAO,OAAO,KAAK,OAAO,MAAM,4CAA4C,UAAU;CAGxF,IAAI,OAAO,QAAQ,WAAW,GAC5B,OAAO,OAAO,KAAK,OAAO,MAAM,uCAAuC,YAAY;AAEvF,CAAC;A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1
|
-
{"version":3,"file":"effect-fetch.d.mts","names":[],"sources":["../../src/client/effect-fetch.ts"],"mappings":";;;;cA6Ba,eAAA,GACV,IAAA,EAAM,UAAA,CAAW,UAAA,KAAa,
|
|
1
|
+
{"version":3,"file":"effect-fetch.d.mts","names":[],"sources":["../../src/client/effect-fetch.ts"],"mappings":";;;;cA6Ba,eAAA,GACV,IAAA,EAAM,UAAA,CAAW,UAAA,KAAa,SAiC9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect-fetch.mjs","names":[],"sources":["../../src/client/effect-fetch.ts"],"sourcesContent":["import { Effect } from 'effect'\nimport type { FetchLike } from '@modelcontextprotocol/client'\nimport { HttpClientRequest } from 'effect/unstable/http'\nimport type { HttpClient } from 'effect/unstable/http'\n\nconst makeRequest = (request: Request) => {\n switch (request.method) {\n case 'DELETE':\n return HttpClientRequest.delete(request.url)\n case 'GET':\n return HttpClientRequest.get(request.url)\n case 'HEAD':\n return HttpClientRequest.head(request.url)\n case 'OPTIONS':\n return HttpClientRequest.options(request.url)\n case 'PATCH':\n return HttpClientRequest.patch(request.url)\n case 'POST':\n return HttpClientRequest.post(request.url)\n case 'PUT':\n return HttpClientRequest.put(request.url)\n default:\n throw new TypeError(`Unsupported HTTP method: ${request.method}`)\n }\n}\n\nconst hasResponseBody = (request: Request, status: number) =>\n request.method !== 'HEAD' && status !== 204 && status !== 205 && status !== 304\n\nexport const makeEffectFetch =\n (http: HttpClient.HttpClient): FetchLike =>\n async (input, init) => {\n const webRequest = new Request(input, init)\n const bytes =\n webRequest.method === 'GET' || webRequest.method === 'HEAD'\n ? undefined\n : new Uint8Array(await webRequest.arrayBuffer())\n const headers: Record<string, string> = {}\n webRequest.headers.forEach((value, key) => {\n headers[key] = value\n })\n let request = makeRequest(webRequest).pipe(HttpClientRequest.setHeaders(headers))\n\n if (bytes !== undefined && bytes.length > 0) {\n request = HttpClientRequest.bodyUint8Array(\n request,\n bytes,\n webRequest.headers.get('content-type') ?? undefined\n )\n }\n\n const response = await Effect.runPromise(http.execute(request), { signal: webRequest.signal })\n const body = hasResponseBody(webRequest, response.status)\n ? new Uint8Array(await Effect.runPromise(response.arrayBuffer))\n : undefined\n\n return new Response(body, {\n status: response.status,\n headers: Object.entries(response.headers)\n })\n }\n"],"mappings":";;;AAKA,MAAM,eAAe,YAAqB;CACxC,QAAQ,QAAQ,QAAhB;EACE,KAAK,UACH,OAAO,kBAAkB,OAAO,QAAQ,GAAG;EAC7C,KAAK,OACH,OAAO,kBAAkB,IAAI,QAAQ,GAAG;EAC1C,KAAK,QACH,OAAO,kBAAkB,KAAK,QAAQ,GAAG;EAC3C,KAAK,WACH,OAAO,kBAAkB,QAAQ,QAAQ,GAAG;EAC9C,KAAK,SACH,OAAO,kBAAkB,MAAM,QAAQ,GAAG;EAC5C,KAAK,QACH,OAAO,kBAAkB,KAAK,QAAQ,GAAG;EAC3C,KAAK,OACH,OAAO,kBAAkB,IAAI,QAAQ,GAAG;EAC1C,SACE,MAAM,IAAI,UAAU,4BAA4B,QAAQ,QAAQ;CACpE;AACF;AAEA,MAAM,mBAAmB,SAAkB,WACzC,QAAQ,WAAW,UAAU,WAAW,OAAO,WAAW,OAAO,WAAW;AAE9E,MAAa,mBACV,SACD,OAAO,OAAO,SAAS;CACrB,MAAM,aAAa,IAAI,QAAQ,OAAO,IAAI;
|
|
1
|
+
{"version":3,"file":"effect-fetch.mjs","names":[],"sources":["../../src/client/effect-fetch.ts"],"sourcesContent":["import { Effect } from 'effect'\nimport type { FetchLike } from '@modelcontextprotocol/client'\nimport { HttpClientRequest } from 'effect/unstable/http'\nimport type { HttpClient } from 'effect/unstable/http'\n\nconst makeRequest = (request: Request) => {\n switch (request.method) {\n case 'DELETE':\n return HttpClientRequest.delete(request.url)\n case 'GET':\n return HttpClientRequest.get(request.url)\n case 'HEAD':\n return HttpClientRequest.head(request.url)\n case 'OPTIONS':\n return HttpClientRequest.options(request.url)\n case 'PATCH':\n return HttpClientRequest.patch(request.url)\n case 'POST':\n return HttpClientRequest.post(request.url)\n case 'PUT':\n return HttpClientRequest.put(request.url)\n default:\n throw new TypeError(`Unsupported HTTP method: ${request.method}`)\n }\n}\n\nconst hasResponseBody = (request: Request, status: number) =>\n request.method !== 'HEAD' && status !== 204 && status !== 205 && status !== 304\n\nexport const makeEffectFetch =\n (http: HttpClient.HttpClient): FetchLike =>\n async (input, init) => {\n const webRequest = new Request(input, init)\n\n const bytes =\n webRequest.method === 'GET' || webRequest.method === 'HEAD'\n ? undefined\n : new Uint8Array(await webRequest.arrayBuffer())\n\n const headers: Record<string, string> = {}\n webRequest.headers.forEach((value, key) => {\n headers[key] = value\n })\n let request = makeRequest(webRequest).pipe(HttpClientRequest.setHeaders(headers))\n\n if (bytes !== undefined && bytes.length > 0) {\n request = HttpClientRequest.bodyUint8Array(\n request,\n bytes,\n webRequest.headers.get('content-type') ?? undefined\n )\n }\n\n const response = await Effect.runPromise(http.execute(request), { signal: webRequest.signal })\n\n const body = hasResponseBody(webRequest, response.status)\n ? new Uint8Array(await Effect.runPromise(response.arrayBuffer))\n : undefined\n\n return new Response(body, {\n status: response.status,\n headers: Object.entries(response.headers)\n })\n }\n"],"mappings":";;;AAKA,MAAM,eAAe,YAAqB;CACxC,QAAQ,QAAQ,QAAhB;EACE,KAAK,UACH,OAAO,kBAAkB,OAAO,QAAQ,GAAG;EAC7C,KAAK,OACH,OAAO,kBAAkB,IAAI,QAAQ,GAAG;EAC1C,KAAK,QACH,OAAO,kBAAkB,KAAK,QAAQ,GAAG;EAC3C,KAAK,WACH,OAAO,kBAAkB,QAAQ,QAAQ,GAAG;EAC9C,KAAK,SACH,OAAO,kBAAkB,MAAM,QAAQ,GAAG;EAC5C,KAAK,QACH,OAAO,kBAAkB,KAAK,QAAQ,GAAG;EAC3C,KAAK,OACH,OAAO,kBAAkB,IAAI,QAAQ,GAAG;EAC1C,SACE,MAAM,IAAI,UAAU,4BAA4B,QAAQ,QAAQ;CACpE;AACF;AAEA,MAAM,mBAAmB,SAAkB,WACzC,QAAQ,WAAW,UAAU,WAAW,OAAO,WAAW,OAAO,WAAW;AAE9E,MAAa,mBACV,SACD,OAAO,OAAO,SAAS;CACrB,MAAM,aAAa,IAAI,QAAQ,OAAO,IAAI;CAE1C,MAAM,QACJ,WAAW,WAAW,SAAS,WAAW,WAAW,SACjD,KAAA,IACA,IAAI,WAAW,MAAM,WAAW,YAAY,CAAC;CAEnD,MAAM,UAAkC,CAAC;CACzC,WAAW,QAAQ,SAAS,OAAO,QAAQ;EACzC,QAAQ,OAAO;CACjB,CAAC;CACD,IAAI,UAAU,YAAY,UAAU,EAAE,KAAK,kBAAkB,WAAW,OAAO,CAAC;CAEhF,IAAI,UAAU,KAAA,KAAa,MAAM,SAAS,GACxC,UAAU,kBAAkB,eAC1B,SACA,OACA,WAAW,QAAQ,IAAI,cAAc,KAAK,KAAA,CAC5C;CAGF,MAAM,WAAW,MAAM,OAAO,WAAW,KAAK,QAAQ,OAAO,GAAG,EAAE,QAAQ,WAAW,OAAO,CAAC;CAE7F,MAAM,OAAO,gBAAgB,YAAY,SAAS,MAAM,IACpD,IAAI,WAAW,MAAM,OAAO,WAAW,SAAS,WAAW,CAAC,IAC5D,KAAA;CAEJ,OAAO,IAAI,SAAS,MAAM;EACxB,QAAQ,SAAS;EACjB,SAAS,OAAO,QAAQ,SAAS,OAAO;CAC1C,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/client/errors.ts"],"mappings":";;;cAEa,aAAA,EAAa,MAAA,CAAA,QAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/client/errors.ts"],"mappings":";;;cAEa,aAAA,EAAa,MAAA,CAAA,QAAA;AAAA,KAYd,aAAA,UAAuB,aAAA,CAAc,IAAI;AAAA,cAAA,aAAA;;;;;cAExC,QAAA,SAAiB,aAI5B"}
|
package/dist/client/errors.mjs
CHANGED
|
@@ -11,7 +11,7 @@ const McpErrorCause = Schema.Literals([
|
|
|
11
11
|
"validation",
|
|
12
12
|
"tool_error"
|
|
13
13
|
]);
|
|
14
|
-
var McpError = class extends Schema.
|
|
14
|
+
var McpError = class extends Schema.TaggedError()("McpError", {
|
|
15
15
|
server: Schema.String,
|
|
16
16
|
message: Schema.String,
|
|
17
17
|
cause: McpErrorCause
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/client/errors.ts"],"sourcesContent":["import * as Schema from 'effect/Schema'\n\nexport const McpErrorCause = Schema.Literals([\n 'disabled',\n 'security',\n 'transport',\n 'protocol',\n 'parse',\n 'encoding',\n 'timeout',\n 'validation',\n 'tool_error'\n])\nexport type McpErrorCause = typeof McpErrorCause.Type\n\nexport class McpError extends Schema.
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/client/errors.ts"],"sourcesContent":["import * as Schema from 'effect/Schema'\n\nexport const McpErrorCause = Schema.Literals([\n 'disabled',\n 'security',\n 'transport',\n 'protocol',\n 'parse',\n 'encoding',\n 'timeout',\n 'validation',\n 'tool_error'\n])\n\nexport type McpErrorCause = typeof McpErrorCause.Type\n\nexport class McpError extends Schema.TaggedError<McpError>()('McpError', {\n server: Schema.String,\n message: Schema.String,\n cause: McpErrorCause\n}) {}\n"],"mappings":";;AAEA,MAAa,gBAAgB,OAAO,SAAS;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAID,IAAa,WAAb,cAA8B,OAAO,YAAsB,EAAE,YAAY;CACvE,QAAQ,OAAO;CACf,SAAS,OAAO;CAChB,OAAO;AACT,CAAC,EAAE,CAAC"}
|
package/dist/client/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { McpClientInfo, McpLocalServerConfig, McpRemoteServerConfig, McpSecurityPolicy, McpServerConfig, defaultMcpClientInfo, defaultMcpSecurityPolicy } from "./config.mjs";
|
|
2
2
|
import { McpError, McpErrorCause } from "./errors.mjs";
|
|
3
|
-
import { GenericContentBlock, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, McpTool, TextContentBlock, ToolCallResult, ToolsListResult, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, legacyMcpProtocolVersion, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult } from "./protocol.mjs";
|
|
3
|
+
import { GenericContentBlock, InitializeClientInfo, InitializeParams, InitializedNotification, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, McpTool, TextContentBlock, ToolCallResult, ToolsCallParams, ToolsListResult, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, legacyMcpProtocolVersion, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult } from "./protocol.mjs";
|
|
4
4
|
import { CallMcpServerToolInput, McpClientOptions, McpResolvedTool, callLocalMcpServerTool, callMcpServerTool, callRemoteMcpServerTool, listLocalMcpServerTools, listMcpServerTools, listMcpTools, listRemoteMcpServerTools } from "./client.mjs";
|
|
5
5
|
export * from "@modelcontextprotocol/client";
|
|
6
|
-
export { type CallMcpServerToolInput, GenericContentBlock, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, type JsonRpcMessage as JsonRpcMessageType, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, type McpClientInfo, type McpClientOptions, McpError, McpErrorCause, type McpLocalServerConfig, type McpRemoteServerConfig, type McpResolvedTool, type McpSecurityPolicy, type McpServerConfig, McpTool, TextContentBlock, ToolCallResult, ToolsListResult, callLocalMcpServerTool, callMcpServerTool, callRemoteMcpServerTool, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, defaultMcpClientInfo, defaultMcpSecurityPolicy, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, legacyMcpProtocolVersion, listLocalMcpServerTools, listMcpServerTools, listMcpTools, listRemoteMcpServerTools, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult };
|
|
6
|
+
export { type CallMcpServerToolInput, GenericContentBlock, InitializeClientInfo, InitializeParams, InitializedNotification, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, type JsonRpcMessage as JsonRpcMessageType, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, type McpClientInfo, type McpClientOptions, McpError, McpErrorCause, type McpLocalServerConfig, type McpRemoteServerConfig, type McpResolvedTool, type McpSecurityPolicy, type McpServerConfig, McpTool, TextContentBlock, ToolCallResult, ToolsCallParams, ToolsListResult, callLocalMcpServerTool, callMcpServerTool, callRemoteMcpServerTool, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, defaultMcpClientInfo, defaultMcpSecurityPolicy, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, legacyMcpProtocolVersion, listLocalMcpServerTools, listMcpServerTools, listMcpTools, listRemoteMcpServerTools, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult };
|
package/dist/client/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defaultMcpClientInfo, defaultMcpSecurityPolicy } from "./config.mjs";
|
|
2
2
|
import { McpError, McpErrorCause } from "./errors.mjs";
|
|
3
|
-
import { GenericContentBlock, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, McpTool, TextContentBlock, ToolCallResult, ToolsListResult, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, legacyMcpProtocolVersion, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult } from "./protocol.mjs";
|
|
3
|
+
import { GenericContentBlock, InitializeClientInfo, InitializeParams, InitializedNotification, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, McpTool, TextContentBlock, ToolCallResult, ToolsCallParams, ToolsListResult, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, legacyMcpProtocolVersion, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult } from "./protocol.mjs";
|
|
4
4
|
import { callLocalMcpServerTool, callMcpServerTool, callRemoteMcpServerTool, listLocalMcpServerTools, listMcpServerTools, listMcpTools, listRemoteMcpServerTools } from "./client.mjs";
|
|
5
5
|
export * from "@modelcontextprotocol/client";
|
|
6
|
-
export { GenericContentBlock, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, McpError, McpErrorCause, McpTool, TextContentBlock, ToolCallResult, ToolsListResult, callLocalMcpServerTool, callMcpServerTool, callRemoteMcpServerTool, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, defaultMcpClientInfo, defaultMcpSecurityPolicy, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, legacyMcpProtocolVersion, listLocalMcpServerTools, listMcpServerTools, listMcpTools, listRemoteMcpServerTools, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult };
|
|
6
|
+
export { GenericContentBlock, InitializeClientInfo, InitializeParams, InitializedNotification, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, McpError, McpErrorCause, McpTool, TextContentBlock, ToolCallResult, ToolsCallParams, ToolsListResult, callLocalMcpServerTool, callMcpServerTool, callRemoteMcpServerTool, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, defaultMcpClientInfo, defaultMcpSecurityPolicy, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, legacyMcpProtocolVersion, listLocalMcpServerTools, listMcpServerTools, listMcpTools, listRemoteMcpServerTools, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult };
|
|
@@ -72,7 +72,7 @@ declare const McpTool: Schema.Struct<{
|
|
|
72
72
|
readonly name: Schema.String;
|
|
73
73
|
readonly title: Schema.optional<Schema.String>;
|
|
74
74
|
readonly description: Schema.optional<Schema.String>;
|
|
75
|
-
readonly inputSchema: Schema.optional<Schema.
|
|
75
|
+
readonly inputSchema: Schema.optional<Schema.declareConstructor<Schema.JsonObject, Schema.JsonObject, readonly [], Schema.JsonObject>>;
|
|
76
76
|
readonly outputSchema: Schema.optional<Schema.Unknown>;
|
|
77
77
|
readonly annotations: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
78
78
|
}>;
|
|
@@ -82,7 +82,7 @@ declare const ToolsListResult: Schema.Struct<{
|
|
|
82
82
|
readonly name: Schema.String;
|
|
83
83
|
readonly title: Schema.optional<Schema.String>;
|
|
84
84
|
readonly description: Schema.optional<Schema.String>;
|
|
85
|
-
readonly inputSchema: Schema.optional<Schema.
|
|
85
|
+
readonly inputSchema: Schema.optional<Schema.declareConstructor<Schema.JsonObject, Schema.JsonObject, readonly [], Schema.JsonObject>>;
|
|
86
86
|
readonly outputSchema: Schema.optional<Schema.Unknown>;
|
|
87
87
|
readonly annotations: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
88
88
|
}>>;
|
|
@@ -101,6 +101,30 @@ declare const ToolCallResult: Schema.Struct<{
|
|
|
101
101
|
readonly structuredContent: Schema.optional<Schema.Unknown>;
|
|
102
102
|
}>;
|
|
103
103
|
type ToolCallResult = typeof ToolCallResult.Type;
|
|
104
|
+
declare const InitializeClientInfo: Schema.Struct<{
|
|
105
|
+
readonly name: Schema.String;
|
|
106
|
+
readonly version: Schema.String;
|
|
107
|
+
}>;
|
|
108
|
+
type InitializeClientInfo = typeof InitializeClientInfo.Type;
|
|
109
|
+
declare const InitializeParams: Schema.Struct<{
|
|
110
|
+
readonly protocolVersion: Schema.String;
|
|
111
|
+
readonly capabilities: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
112
|
+
readonly clientInfo: Schema.Struct<{
|
|
113
|
+
readonly name: Schema.String;
|
|
114
|
+
readonly version: Schema.String;
|
|
115
|
+
}>;
|
|
116
|
+
}>;
|
|
117
|
+
type InitializeParams = typeof InitializeParams.Type;
|
|
118
|
+
declare const InitializedNotification: Schema.Struct<{
|
|
119
|
+
readonly jsonrpc: Schema.Literal<"2.0">;
|
|
120
|
+
readonly method: Schema.Literal<"notifications/initialized">;
|
|
121
|
+
}>;
|
|
122
|
+
type InitializedNotification = typeof InitializedNotification.Type;
|
|
123
|
+
declare const ToolsCallParams: Schema.Struct<{
|
|
124
|
+
readonly name: Schema.String;
|
|
125
|
+
readonly arguments: Schema.optional<Schema.Unknown>;
|
|
126
|
+
}>;
|
|
127
|
+
type ToolsCallParams = typeof ToolsCallParams.Type;
|
|
104
128
|
declare const makeJsonRpcRequest: (input: {
|
|
105
129
|
readonly id: string | number;
|
|
106
130
|
readonly method: string;
|
|
@@ -110,14 +134,7 @@ declare const makeInitializedNotification: () => JsonRpcNotification;
|
|
|
110
134
|
declare const makeInitializeParams: (input: {
|
|
111
135
|
readonly name: string;
|
|
112
136
|
readonly version: string;
|
|
113
|
-
}) =>
|
|
114
|
-
protocolVersion: string;
|
|
115
|
-
capabilities: {};
|
|
116
|
-
clientInfo: {
|
|
117
|
-
name: string;
|
|
118
|
-
version: string;
|
|
119
|
-
};
|
|
120
|
-
};
|
|
137
|
+
}) => InitializeParams;
|
|
121
138
|
declare const jsonRpcErrorToMcpError: (server: string, error: JsonRpcErrorObject) => McpError;
|
|
122
139
|
declare const mcpToolToToolDef: (input: {
|
|
123
140
|
readonly serverName: string;
|
|
@@ -136,8 +153,8 @@ declare const decodeJsonRpcResponse: (input: unknown, options?: import("effect/S
|
|
|
136
153
|
readonly jsonrpc: "2.0";
|
|
137
154
|
readonly id: string | number | null;
|
|
138
155
|
readonly error: {
|
|
139
|
-
readonly code: number;
|
|
140
156
|
readonly message: string;
|
|
157
|
+
readonly code: number;
|
|
141
158
|
readonly data?: unknown;
|
|
142
159
|
};
|
|
143
160
|
}, Schema.SchemaError, never>;
|
|
@@ -146,7 +163,7 @@ declare const decodeToolsListResult: (input: unknown, options?: import("effect/S
|
|
|
146
163
|
readonly name: string;
|
|
147
164
|
readonly title?: string | undefined;
|
|
148
165
|
readonly description?: string | undefined;
|
|
149
|
-
readonly inputSchema?:
|
|
166
|
+
readonly inputSchema?: Schema.JsonObject | undefined;
|
|
150
167
|
readonly outputSchema?: unknown;
|
|
151
168
|
readonly annotations?: {
|
|
152
169
|
readonly [x: string]: unknown;
|
|
@@ -169,8 +186,8 @@ declare const decodeJsonRpcResponseFromJson: (server: string, text: string) => E
|
|
|
169
186
|
readonly jsonrpc: "2.0";
|
|
170
187
|
readonly id: string | number | null;
|
|
171
188
|
readonly error: {
|
|
172
|
-
readonly code: number;
|
|
173
189
|
readonly message: string;
|
|
190
|
+
readonly code: number;
|
|
174
191
|
readonly data?: unknown;
|
|
175
192
|
};
|
|
176
193
|
}, McpError, never>;
|
|
@@ -185,5 +202,5 @@ declare const decodeJsonRpcMessageFromJson: (server: string, text: string) => Ef
|
|
|
185
202
|
readonly params?: unknown;
|
|
186
203
|
}, McpError, never>;
|
|
187
204
|
//#endregion
|
|
188
|
-
export { GenericContentBlock, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, McpTool, McpToolAnnotations, TextContentBlock, ToolCallResult, ToolsListResult, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, legacyMcpProtocolVersion, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult };
|
|
205
|
+
export { GenericContentBlock, InitializeClientInfo, InitializeParams, InitializedNotification, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcSuccessResponse, McpTool, McpToolAnnotations, TextContentBlock, ToolCallResult, ToolsCallParams, ToolsListResult, decodeJsonRpcMessageFromJson, decodeJsonRpcResponse, decodeJsonRpcResponseFromJson, decodeToolCallResult, decodeToolsListResult, encodeJsonRpcMessage, jsonRpcErrorToMcpError, latestMcpProtocolVersion, legacyMcpProtocolVersion, makeInitializeParams, makeInitializedNotification, makeJsonRpcRequest, mcpToolToToolDef, sanitizeMcpName, toolCallResultToToolResult };
|
|
189
206
|
//# sourceMappingURL=protocol.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.mts","names":[],"sources":["../../src/client/protocol.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"protocol.d.mts","names":[],"sources":["../../src/client/protocol.ts"],"mappings":";;;;;;cAca,wBAAA;AAAA,cAEA,wBAAA;AAAA,cAEA,kBAAA,EAAkB,MAAA,CAAA,MAAA;EAAA;;;;KAMnB,kBAAA,UAA4B,kBAAA,CAAmB,IAAI;AAAA,cAElD,sBAAA,EAAsB,MAAA,CAAA,MAAA;EAAA;;;;KAMvB,sBAAA,UAAgC,sBAAA,CAAuB,IAAI;AAAA,cAE1D,oBAAA,EAAoB,MAAA,CAAA,MAAA;EAAA;;;;;;;;KAMrB,oBAAA,UAA8B,oBAAA,CAAqB,IAAI;AAAA,cAEtD,eAAA,EAAe,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;;;KAEhB,eAAA,UAAyB,eAAA,CAAgB,IAAI;AAAA,cAE5C,cAAA,EAAc,MAAA,CAAA,MAAA;EAAA;;;;;KAOf,cAAA,UAAwB,cAAA,CAAe,IAAI;AAAA,cAE1C,mBAAA,EAAmB,MAAA,CAAA,MAAA;EAAA;;;;KAMpB,mBAAA,UAA6B,mBAAA,CAAoB,IAAI;AAAA,cAEpD,cAAA,EAAc,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MAAA;EAAA;;;;;;;;;KAEf,cAAA,UAAwB,cAAA,CAAe,IAAI;AAAA,cAE1C,kBAAA,EAAkB,MAAA,CAAA,OAAA,CAAA,MAAA,CAAA,MAAA,EAAA,MAAA,CAAA,OAAA;AAAA,KAEnB,kBAAA,UAA4B,kBAAA,CAAmB,IAAI;AAAA,cAElD,OAAA,EAAO,MAAA,CAAA,MAAA;EAAA;;;;;;;KASR,OAAA,UAAiB,OAAA,CAAQ,IAAI;AAAA,cAE5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