@yaks/mcp-client 0.0.0-stage → 0.2.36

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/mod.js ADDED
@@ -0,0 +1,371 @@
1
+ /** MCP tools over Streamable HTTP, with no dependency on a session or a UI. */ // The SDK maps a subpath's types to `<subpath>.d.ts`, so a type is imported
2
+ // without `.js` (`sdk/types`, not `sdk/types.js`, which Deno types as any);
3
+ // code is still loaded from the `.js` path.
4
+ import { argsOf } from "@yaks/graph/call";
5
+ import { errorsText, toolCheck } from "@yaks/vocab/tools";
6
+ // `client` has its own entry in the SDK's export map. The rest load from their
7
+ // `.js` path, which the map types from its JS source, so each is typed by its
8
+ // subpath's declarations instead.
9
+ let typed = (code)=>code;
10
+ // The runtime keeps each module once loaded, so no promise of them is kept
11
+ // here: one kept at module scope would be shared by every request of a Worker's
12
+ // isolate (@yaks/fp `Scope`).
13
+ let loaded = ()=>Promise.all([
14
+ import("@modelcontextprotocol/sdk/client"),
15
+ typed(import("@modelcontextprotocol/sdk/client/streamableHttp.js")),
16
+ typed(import("@modelcontextprotocol/sdk/types.js")),
17
+ typed(import("@modelcontextprotocol/sdk/client/auth.js"))
18
+ ]).then(([client, http, types, auth])=>({
19
+ Client: client.Client,
20
+ Transport: http.StreamableHTTPClientTransport,
21
+ listChanged: types.ToolListChangedNotificationSchema,
22
+ challenge: auth.extractWWWAuthenticateParams
23
+ }));
24
+ // The SDK's default output validator is 2020-only; remote servers also declare
25
+ // draft-07. Use the same dialect-aware validation as local graph tools.
26
+ const schemas = {
27
+ getValidator (schema) {
28
+ const check = toolCheck(schema);
29
+ return (input)=>{
30
+ const errors = check(input);
31
+ return errors.length ? {
32
+ valid: false,
33
+ data: undefined,
34
+ errorMessage: errorsText(errors)
35
+ } : {
36
+ valid: true,
37
+ data: input,
38
+ errorMessage: undefined
39
+ };
40
+ };
41
+ }
42
+ };
43
+ /**
44
+ * A reply's structured content as the text a model reads, when the reply has
45
+ * no text of its own. A server sends its answer twice, as text for a reader
46
+ * and as `structuredContent` for a parser, and a model reads one of them: the
47
+ * text, which the spec has carry the structured content's JSON and which is
48
+ * all a client that reads only text sees. A reply that wrote no text is read
49
+ * as its structured content.
50
+ *
51
+ * ```ts
52
+ * import { assertEquals } from '@std/assert'
53
+ * let text = { type: 'text', text: 'https://example.test/mockup/1' }
54
+ * let structuredContent = { saved: '<h1>mockup</h1>' }
55
+ * assertEquals(unsaid({ content: [text], structuredContent }), undefined)
56
+ * assertEquals(
57
+ * unsaid({ content: [], structuredContent }),
58
+ * '{"saved":"<h1>mockup</h1>"}',
59
+ * )
60
+ * ```
61
+ */ export const unsaid = (reply)=>reply.structuredContent == null || (reply.content ?? []).some((b)=>b?.type == 'text') ? undefined : JSON.stringify(reply.structuredContent);
62
+ export class MCPError extends Error {
63
+ server;
64
+ constructor(message, server){
65
+ super(message), this.server = server;
66
+ }
67
+ }
68
+ export class MCPAuthorizationRequired extends MCPError {
69
+ challenge;
70
+ constructor(server, challenge = {}){
71
+ super('MCP sign-in required; open authorization in the host', server), this.challenge = challenge;
72
+ }
73
+ }
74
+ /** Where a server on a machine stands: a tunnel reaches one machine whatever
75
+ * host a request names, so its address is this origin and the server's path. */ export const MACHINE = 'http://machine';
76
+ /** Normalize only the local namespace, never the server's opaque tool name. */ export const namespaceOf = (name)=>{
77
+ const namespace = name.trim().replace(/[^a-zA-Z0-9_-]+/g, '_');
78
+ if (!namespace || !/[a-zA-Z0-9]/.test(namespace)) {
79
+ throw new Error('MCP server name needs a readable alphanumeric namespace');
80
+ }
81
+ return namespace;
82
+ };
83
+ /** A provider-safe name with the exact remote name retained after the separator. */ export const nameOf = (server, name)=>{
84
+ const namespace = namespaceOf(server);
85
+ if (!/^[a-zA-Z0-9_-]+$/.test(name)) {
86
+ throw new Error('MCP remote tool name cannot be exposed unchanged: ' + name);
87
+ }
88
+ const exposed = namespace + '__' + name;
89
+ if (exposed.length > 64) {
90
+ throw new Error('MCP tool name exceeds 64 characters: ' + exposed + '. Use a shorter server name or ask the server for a shorter tool name.');
91
+ }
92
+ return exposed;
93
+ };
94
+ /** Refuse normalized namespace collisions rather than hiding them behind hashes. */ export const checkNamespaces = (servers)=>{
95
+ const used = new Set();
96
+ for (const server of servers){
97
+ const namespace = namespaceOf(server.namespace ?? server.name);
98
+ if (used.has(namespace)) {
99
+ throw new Error('Duplicate MCP namespace: ' + namespace);
100
+ }
101
+ used.add(namespace);
102
+ }
103
+ };
104
+ /** Separators in opaque remote names can also create a cross-server collision. */ export const checkToolNames = (tools)=>{
105
+ const names = new Set();
106
+ for (const tool of tools){
107
+ if (names.has(tool.name)) {
108
+ throw new Error('Duplicate MCP tool name: ' + tool.name);
109
+ }
110
+ names.add(tool.name);
111
+ }
112
+ };
113
+ /** One owned connection. connect/list are lazy; calls are never automatically replayed. */ export const connect = (server, options = {})=>{
114
+ const url = new URL(server.url);
115
+ if (![
116
+ 'http:',
117
+ 'https:'
118
+ ].includes(url.protocol) || url.username || url.password) throw new Error('MCP requires an HTTP(S) URL without embedded credentials');
119
+ if (server.machine && !options.fetch) {
120
+ throw new MCPError('An MCP server on a machine is asked through its tunnel', server.name);
121
+ }
122
+ let ready, closed = false, generation = 0;
123
+ let closePromise;
124
+ let listing;
125
+ let unauthorized = false;
126
+ let challenge = {};
127
+ const fetcher = async (input, init)=>{
128
+ const headers = new Headers(init?.headers);
129
+ const token = await options.token?.(server);
130
+ if (token) {
131
+ const target = new URL(input instanceof Request ? input.url : String(input));
132
+ if (target.origin !== url.origin) {
133
+ throw new MCPError('Refusing cross-origin credential forwarding', server.name);
134
+ }
135
+ if (url.protocol !== 'https:' && ![
136
+ 'localhost',
137
+ '127.0.0.1',
138
+ '[::1]'
139
+ ].includes(url.hostname)) throw new MCPError('Credentials require HTTPS', server.name);
140
+ if (server.header) headers.set(server.header, token);
141
+ else headers.set('authorization', `Bearer ${token}`);
142
+ }
143
+ const response = await (options.fetch ?? fetch)(input, {
144
+ ...init,
145
+ headers,
146
+ redirect: 'manual',
147
+ signal: init?.signal ? AbortSignal.any([
148
+ init.signal,
149
+ AbortSignal.timeout(options.timeout ?? 60000)
150
+ ]) : AbortSignal.timeout(options.timeout ?? 60000)
151
+ });
152
+ // A machine's tunnel is its host's already: a 401 there asks for no sign-in.
153
+ if (response.status === 401 && !server.machine) {
154
+ unauthorized = true;
155
+ const found = (await loaded()).challenge(response);
156
+ challenge = {
157
+ resourceMetadataUrl: found.resourceMetadataUrl?.href,
158
+ scope: found.scope
159
+ };
160
+ }
161
+ return response;
162
+ };
163
+ // The client and its transport, made the first time the connection is used.
164
+ let opened;
165
+ const open = ()=>opened ??= loaded().then((m)=>{
166
+ const sdk = new m.Client({
167
+ name: 'yaks-mcp-client',
168
+ version: '0.1.0'
169
+ }, {
170
+ jsonSchemaValidator: schemas,
171
+ capabilities: {}
172
+ });
173
+ sdk.setNotificationHandler(m.listChanged, ()=>{
174
+ generation++;
175
+ listing = undefined;
176
+ });
177
+ return [
178
+ sdk,
179
+ new m.Transport(url, {
180
+ fetch: fetcher
181
+ })
182
+ ];
183
+ });
184
+ const ensure = async ()=>{
185
+ if (closed) throw new MCPError('MCP connection is closed', server.name);
186
+ const [sdk, transport] = await open();
187
+ await (ready ??= sdk.connect(transport).catch(async ()=>{
188
+ await sdk.close().catch(()=>{});
189
+ if (unauthorized) {
190
+ throw new MCPAuthorizationRequired(server.name, challenge);
191
+ }
192
+ throw new MCPError(server.machine ? 'MCP connection failed; the machine may be off, or not open this path to its tunnel' : 'MCP connection failed; check server URL and sign-in', server.name);
193
+ }));
194
+ return sdk;
195
+ };
196
+ const list = async ()=>{
197
+ const sdk = await ensure();
198
+ if (!listing) {
199
+ unauthorized = false;
200
+ const observed = generation;
201
+ const pending = (async ()=>{
202
+ const all = [], cursors = new Set();
203
+ let cursor;
204
+ do {
205
+ const page = await sdk.listTools(cursor ? {
206
+ cursor
207
+ } : {}, {
208
+ timeout: options.timeout ?? 60000
209
+ });
210
+ all.push(...page.tools);
211
+ cursor = page.nextCursor;
212
+ if (cursor && cursors.has(cursor)) {
213
+ throw new MCPError('Repeated tools/list cursor', server.name);
214
+ }
215
+ if (cursor) cursors.add(cursor);
216
+ if (all.length > 1000) {
217
+ throw new MCPError('MCP discovery exceeded 1000 tools', server.name);
218
+ }
219
+ }while (cursor)
220
+ const seen = new Set();
221
+ for (const t of all){
222
+ if (seen.has(t.name)) {
223
+ throw new MCPError('Duplicate remote tool name', server.name);
224
+ }
225
+ seen.add(t.name);
226
+ }
227
+ return all.filter((t)=>!server.allow || server.allow.includes(t.name));
228
+ })().catch((e)=>{
229
+ if (unauthorized) {
230
+ throw new MCPAuthorizationRequired(server.name, challenge);
231
+ }
232
+ throw e;
233
+ });
234
+ listing = pending;
235
+ pending.catch(()=>{
236
+ if (listing === pending) listing = undefined;
237
+ });
238
+ const answer = await pending;
239
+ if (observed !== generation) listing = undefined;
240
+ return answer;
241
+ }
242
+ return listing;
243
+ };
244
+ const call = async (name, args, signal)=>{
245
+ const sdk = await ensure();
246
+ if (server.allow && !server.allow.includes(name)) {
247
+ throw new MCPError('Tool not allowed', server.name);
248
+ }
249
+ unauthorized = false;
250
+ try {
251
+ return await sdk.callTool({
252
+ name,
253
+ arguments: args
254
+ }, undefined, {
255
+ signal,
256
+ timeout: options.timeout ?? 60000
257
+ });
258
+ } catch {
259
+ if (unauthorized) {
260
+ throw new MCPAuthorizationRequired(server.name, challenge);
261
+ }
262
+ // Do not expose endpoint response bodies or credentials, or retry uncertain writes.
263
+ throw new MCPError('MCP call failed; remote outcome may be unknown. No retry was performed.', server.name);
264
+ }
265
+ };
266
+ return {
267
+ list,
268
+ instructions: async ()=>(await ensure()).getInstructions() || undefined,
269
+ about: async ()=>{
270
+ const info = (await ensure()).getServerVersion();
271
+ return info?.title?.trim() || info?.name?.trim() || undefined;
272
+ },
273
+ call,
274
+ refresh: ()=>{
275
+ generation++;
276
+ listing = undefined;
277
+ },
278
+ tools: async ()=>{
279
+ const listed = await list();
280
+ if (new Set(listed.map((t)=>t.name)).size !== listed.length) {
281
+ throw new Error('Duplicate remote MCP tool name');
282
+ }
283
+ return Promise.all(listed.map(async (t)=>({
284
+ name: await nameOf(server.namespace ?? server.name, t.name),
285
+ ...t.title ?? t.annotations?.title ? {
286
+ title: t.title ?? t.annotations?.title
287
+ } : {},
288
+ step: {
289
+ doing: `Using ${server.label ?? server.name}…`,
290
+ done: `Used ${server.label ?? server.name}`
291
+ },
292
+ description: `[${server.label ?? server.name}] ${t.description ?? t.name}`,
293
+ inputSchema: t.inputSchema,
294
+ readOnly: t.annotations?.readOnlyHint,
295
+ destructive: t.annotations?.destructiveHint,
296
+ idempotent: t.annotations?.idempotentHint,
297
+ openWorld: t.annotations?.openWorldHint,
298
+ meta: {
299
+ server: server.name,
300
+ remoteName: t.name
301
+ },
302
+ // A tool on another server replies in the MCP result format, and this
303
+ // graph stores text: the reply's text blocks, or its structured
304
+ // content where it wrote none ({@link unsaid}), written as one entity
305
+ // recording which call produced it. A caller that needs the reply
306
+ // whole — artifacts, resources, the error flag — calls the
307
+ // connection's own `call` instead.
308
+ run: async (asked)=>{
309
+ let reply = await call(t.name, argsOf(asked));
310
+ let blocks = reply.content ?? [];
311
+ let said = blocks.filter((block)=>block.type == 'text').map((block)=>String(block.text ?? ''));
312
+ let structured = unsaid(reply);
313
+ if (structured) said.push(structured);
314
+ return [
315
+ {
316
+ entity: {
317
+ eid: '$said'
318
+ },
319
+ content: {
320
+ body: said.join('\n')
321
+ },
322
+ output: {
323
+ source: asked.entity.eid
324
+ },
325
+ ...reply.isError ? {
326
+ refusal: {
327
+ code: 'mcp_tool'
328
+ }
329
+ } : {}
330
+ }
331
+ ];
332
+ }
333
+ })));
334
+ },
335
+ close: ()=>closePromise ??= (async ()=>{
336
+ closed = true;
337
+ // Never used, nothing was opened; an opening under way ends first.
338
+ if (!opened) return;
339
+ const [sdk, transport] = await opened;
340
+ // A transport failure must not strand the local event stream.
341
+ try {
342
+ if (transport.sessionId) await transport.terminateSession();
343
+ } finally{
344
+ await sdk.close();
345
+ }
346
+ })()
347
+ };
348
+ };
349
+ /** Several configured connections at once, usable from a CLI, from graph
350
+ * tools, or from anywhere else. */ export const clients = (servers, options = {})=>{
351
+ checkNamespaces(servers);
352
+ const names = new Set();
353
+ for (const s of servers){
354
+ if (!s.name || names.has(s.name)) {
355
+ throw new Error('MCP server names must be nonempty and unique');
356
+ }
357
+ names.add(s.name);
358
+ }
359
+ const all = servers.map((s)=>connect(s, options));
360
+ return {
361
+ tools: async ()=>{
362
+ const tools = (await Promise.all(all.map((c)=>c.tools()))).flat();
363
+ checkToolNames(tools);
364
+ return tools;
365
+ },
366
+ close: async ()=>{
367
+ await Promise.all(all.map((c)=>c.close()));
368
+ }
369
+ };
370
+ };
371
+ //# sourceMappingURL=mod.js.map
package/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA,6EAA6E,GAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,4CAA4C;AAQ5C,SAAS,MAAM,gCAAqC;AACpD,SAAS,UAAU,EAAE,SAAS,iCAAsC;AAgBpE,+EAA+E;AAC/E,8EAA8E;AAC9E,kCAAkC;AAClC,IAAI,QAAQ,CAAI,OAA2B;AAC3C,2EAA2E;AAC3E,gFAAgF;AAChF,8BAA8B;AAC9B,IAAI,SAAS,IACX,QAAQ,GAAG,CAAC;IACV,MAAM,CAAC;IACP,MACE,MAAM,CAAC;IAET,MACE,MAAM,CAAC;IAET,MACE,MAAM,CAAC;GAEV,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,MAAM,OAAO,KAAK,GAAK,CAAC;MACxC,QAAQ,OAAO,MAAM;MACrB,WAAW,KAAK,6BAA6B;MAC7C,aAAa,MAAM,iCAAiC;MACpD,WAAW,KAAK,4BAA4B;IAC9C,CAAC;AAEH,+EAA+E;AAC/E,wEAAwE;AACxE,MAAM,UAA+B;EACnC,cAAgB,MAA+B;IAC7C,MAAM,QAAQ,U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