clanka 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -0
- package/dist/Acp.d.ts +1 -1
- package/dist/Acp.d.ts.map +1 -1
- package/dist/Acp.js +112 -7
- package/dist/Acp.js.map +1 -1
- package/dist/Acp.test.js +178 -0
- package/dist/Acp.test.js.map +1 -1
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +26 -8
- package/dist/Agent.js.map +1 -1
- package/dist/AgentExecutor.js +15 -1
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentTools.d.ts +7 -0
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +7 -0
- package/dist/AgentTools.js.map +1 -1
- package/dist/McpConfig.d.ts +36 -0
- package/dist/McpConfig.d.ts.map +1 -0
- package/dist/McpConfig.js +182 -0
- package/dist/McpConfig.js.map +1 -0
- package/dist/McpConfig.test.d.ts +2 -0
- package/dist/McpConfig.test.d.ts.map +1 -0
- package/dist/McpConfig.test.js +163 -0
- package/dist/McpConfig.test.js.map +1 -0
- package/dist/McpServers.d.ts +176 -0
- package/dist/McpServers.d.ts.map +1 -0
- package/dist/McpServers.js +707 -0
- package/dist/McpServers.js.map +1 -0
- package/dist/McpServers.test.d.ts +2 -0
- package/dist/McpServers.test.d.ts.map +1 -0
- package/dist/McpServers.test.js +717 -0
- package/dist/McpServers.test.js.map +1 -0
- package/dist/TypeBuilder.d.ts +9 -0
- package/dist/TypeBuilder.d.ts.map +1 -1
- package/dist/TypeBuilder.js +24 -11
- package/dist/TypeBuilder.js.map +1 -1
- package/dist/TypeBuilder.test.js +33 -0
- package/dist/TypeBuilder.test.js.map +1 -1
- package/dist/bin/{Effect-zUBunSAW.mjs → Effect-DuThyCJ1.mjs} +87 -9
- package/dist/bin/Effect-DuThyCJ1.mjs.map +1 -0
- package/dist/bin/McpClient-CIiPyMDJ.mjs +36 -0
- package/dist/bin/McpClient-CIiPyMDJ.mjs.map +1 -0
- package/dist/bin/{OutputFormatter-BPdc6RmH.mjs → OutputFormatter-BvIjvUmT.mjs} +3 -3
- package/dist/bin/{OutputFormatter-BPdc6RmH.mjs.map → OutputFormatter-BvIjvUmT.mjs.map} +1 -1
- package/dist/bin/{Schema-C2Y2y3tU.mjs → Schema-DcXUXpRg.mjs} +831 -35
- package/dist/bin/Schema-DcXUXpRg.mjs.map +1 -0
- package/dist/bin/{SemanticSearch-BKZxP19F.mjs → SemanticSearch-CdGA4CIC.mjs} +5 -5
- package/dist/bin/{SemanticSearch-BKZxP19F.mjs.map → SemanticSearch-CdGA4CIC.mjs.map} +1 -1
- package/dist/bin/{Stream-BvmRbTMu.mjs → Stream-I9SRMlLj.mjs} +20 -22
- package/dist/bin/Stream-I9SRMlLj.mjs.map +1 -0
- package/dist/bin/cli.mjs +17642 -802
- package/dist/bin/cli.mjs.map +1 -1
- package/dist/bin/{index.min-DbZbUHX3.mjs → index.min-Bkz7vIWv.mjs} +5 -5
- package/dist/bin/{index.min-DbZbUHX3.mjs.map → index.min-Bkz7vIWv.mjs.map} +1 -1
- package/dist/bin/rolldown-runtime-zY4HT0JA.mjs +30 -0
- package/dist/bin/{turndown.cjs-DK29wZw3.mjs → turndown.cjs-LntFxFyd.mjs} +2 -2
- package/dist/bin/{turndown.cjs-DK29wZw3.mjs.map → turndown.cjs-LntFxFyd.mjs.map} +1 -1
- package/dist/cli.js +24 -2
- package/dist/cli.js.map +1 -1
- package/dist/fixtures/McpFakeServer.d.ts +47 -0
- package/dist/fixtures/McpFakeServer.d.ts.map +1 -0
- package/dist/fixtures/McpFakeServer.js +112 -0
- package/dist/fixtures/McpFakeServer.js.map +1 -0
- package/dist/fixtures/McpStdioServer.d.ts +2 -0
- package/dist/fixtures/McpStdioServer.d.ts.map +1 -0
- package/dist/fixtures/McpStdioServer.js +53 -0
- package/dist/fixtures/McpStdioServer.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +242 -0
- package/src/Acp.ts +141 -5
- package/src/Agent.ts +38 -10
- package/src/AgentExecutor.ts +14 -1
- package/src/AgentTools.ts +8 -0
- package/src/McpConfig.test.ts +238 -0
- package/src/McpConfig.ts +255 -0
- package/src/McpServers.test.ts +1050 -0
- package/src/McpServers.ts +1072 -0
- package/src/TypeBuilder.test.ts +70 -0
- package/src/TypeBuilder.ts +41 -14
- package/src/cli.ts +46 -0
- package/src/fixtures/McpFakeServer.ts +162 -0
- package/src/fixtures/McpStdioServer.ts +60 -0
- package/src/index.ts +5 -0
- package/dist/bin/Effect-zUBunSAW.mjs.map +0 -1
- package/dist/bin/McpClient-CnP2P7c9.mjs +0 -14179
- package/dist/bin/McpClient-CnP2P7c9.mjs.map +0 -1
- package/dist/bin/Schema-C2Y2y3tU.mjs.map +0 -1
- package/dist/bin/Stream-BvmRbTMu.mjs.map +0 -1
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import { assert, describe, it } from "@effect/vitest";
|
|
2
|
+
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
|
|
3
|
+
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
4
|
+
import * as Duration from "effect/Duration";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as FileSystem from "effect/FileSystem";
|
|
7
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
8
|
+
import * as HttpServer from "effect/http/HttpServer";
|
|
9
|
+
import * as Layer from "effect/Layer";
|
|
10
|
+
import * as Path from "effect/Path";
|
|
11
|
+
import * as Redacted from "effect/Redacted";
|
|
12
|
+
import * as Schedule from "effect/Schedule";
|
|
13
|
+
import * as Schema from "effect/Schema";
|
|
14
|
+
import * as Stream from "effect/Stream";
|
|
15
|
+
import * as LanguageModel from "effect/ai/LanguageModel";
|
|
16
|
+
import * as Model from "effect/ai/Model";
|
|
17
|
+
import * as Tool from "effect/ai/Tool";
|
|
18
|
+
import * as Toolkit from "effect/ai/Toolkit";
|
|
19
|
+
import * as RpcClient from "effect/rpc/RpcClient";
|
|
20
|
+
import * as RpcSerialization from "effect/rpc/RpcSerialization";
|
|
21
|
+
import * as RpcServer from "effect/rpc/RpcServer";
|
|
22
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
23
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
24
|
+
import * as Agent from "./Agent.js";
|
|
25
|
+
import * as AgentExecutor from "./AgentExecutor.js";
|
|
26
|
+
import * as McpServers from "./McpServers.js";
|
|
27
|
+
import { listenHttp, makeFakeServer, text, } from "./fixtures/McpFakeServer.js";
|
|
28
|
+
import { tinyPng } from "./fixtures/TestImages.js";
|
|
29
|
+
const modes = ["local", "rpc"];
|
|
30
|
+
const localExecutor = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
31
|
+
const fs = yield* FileSystem.FileSystem;
|
|
32
|
+
const directory = yield* fs.makeTempDirectoryScoped();
|
|
33
|
+
return AgentExecutor.layerLocal({ directory, ...options });
|
|
34
|
+
})).pipe(Layer.provide(Layer.mergeAll(NodeServices.layer, FetchHttpClient.layer)));
|
|
35
|
+
const rpcExecutor = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
36
|
+
const fs = yield* FileSystem.FileSystem;
|
|
37
|
+
const directory = yield* fs.makeTempDirectoryScoped();
|
|
38
|
+
const { protocol, httpEffect } = yield* RpcServer.makeProtocolWithHttpEffect();
|
|
39
|
+
yield* Layer.build(AgentExecutor.layerRpcServer({ directory, ...options }).pipe(Layer.provide(Layer.succeed(RpcServer.Protocol, protocol))));
|
|
40
|
+
yield* HttpServer.serveEffect(httpEffect);
|
|
41
|
+
return AgentExecutor.layerRpc.pipe(Layer.provide(RpcClient.layerProtocolHttp({ url: "" })));
|
|
42
|
+
})).pipe(Layer.provide(Layer.mergeAll(RpcSerialization.layerNdjson, NodeHttpServer.layerTest, NodeServices.layer)));
|
|
43
|
+
const executorLayer = (mode, options = {}) => mode === "local" ? localExecutor(options) : rpcExecutor(options);
|
|
44
|
+
const messageText = (message) => typeof message.content === "string"
|
|
45
|
+
? message.content
|
|
46
|
+
: message.content
|
|
47
|
+
.map((part) => (part.type === "text" ? part.text : ""))
|
|
48
|
+
.join("");
|
|
49
|
+
const systemText = (prompt) => prompt.content
|
|
50
|
+
.filter((message) => message.role === "system")
|
|
51
|
+
.map(messageText)
|
|
52
|
+
.join("\n");
|
|
53
|
+
const firstUserText = (prompt) => {
|
|
54
|
+
const message = prompt.content.find((message) => message.role === "user");
|
|
55
|
+
return message ? messageText(message) : "";
|
|
56
|
+
};
|
|
57
|
+
const lastToolResult = (prompt) => {
|
|
58
|
+
const message = prompt.content.findLast((message) => message.role === "tool");
|
|
59
|
+
if (message === undefined)
|
|
60
|
+
return "";
|
|
61
|
+
return message.content
|
|
62
|
+
.map((part) => (part.type === "tool-result" ? String(part.result) : ""))
|
|
63
|
+
.join("");
|
|
64
|
+
};
|
|
65
|
+
const hasPngAttachment = (prompt) => prompt.content.some((message) => message.role === "user" &&
|
|
66
|
+
typeof message.content !== "string" &&
|
|
67
|
+
message.content.some((part) => part.type === "file" && part.mediaType === "image/png"));
|
|
68
|
+
const toolCall = (call, script) => ({
|
|
69
|
+
type: "tool-call",
|
|
70
|
+
id: `call-${call.role}-${call.index}`,
|
|
71
|
+
name: "execute",
|
|
72
|
+
params: { script },
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Runs the Agent with whatever `McpServers` the surrounding context provides.
|
|
76
|
+
* A string script must end with `taskComplete`; a function answers every
|
|
77
|
+
* model call.
|
|
78
|
+
*/
|
|
79
|
+
const runAgent = (options) => Effect.gen(function* () {
|
|
80
|
+
const calls = [];
|
|
81
|
+
const counts = { root: 0, child: 0 };
|
|
82
|
+
const languageModel = yield* LanguageModel.make({
|
|
83
|
+
generateText: () => Effect.die("unexpected generateText call"),
|
|
84
|
+
streamText: (providerOptions) => {
|
|
85
|
+
const role = firstUserText(providerOptions.prompt).includes("TASK-CHILD")
|
|
86
|
+
? "child"
|
|
87
|
+
: "root";
|
|
88
|
+
const call = {
|
|
89
|
+
role,
|
|
90
|
+
index: counts[role]++,
|
|
91
|
+
prompt: providerOptions.prompt,
|
|
92
|
+
};
|
|
93
|
+
calls.push(call);
|
|
94
|
+
if (typeof options.script !== "string") {
|
|
95
|
+
return Stream.make(toolCall(call, options.script(call)));
|
|
96
|
+
}
|
|
97
|
+
return call.index === 0
|
|
98
|
+
? Stream.make(toolCall(call, options.script))
|
|
99
|
+
: Stream.die(`the script did not call taskComplete: ${lastToolResult(call.prompt)}`);
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
const modelLayer = Layer.mergeAll(Layer.succeed(LanguageModel.LanguageModel, languageModel), Layer.succeed(Model.ProviderName, "test-provider"), Layer.succeed(Model.ModelName, "test-model"));
|
|
103
|
+
const agent = yield* Agent.makeWith(options.agent ?? {});
|
|
104
|
+
const summary = yield* agent.send({ prompt: "hello" }).pipe(Effect.flatMap(Stream.runDrain), Effect.as(""), Effect.catchTag("AgentFinished", (finished) => Effect.succeed(finished.summary)), Effect.provide(modelLayer));
|
|
105
|
+
return { system: systemText(calls[0].prompt), summary, calls };
|
|
106
|
+
}).pipe(Effect.scoped, Effect.provide(executorLayer(options.mode ?? "local")), Effect.timeout("4 seconds"));
|
|
107
|
+
// Turns a rejection into a value, so one script can report several calls.
|
|
108
|
+
const attempt = `const attempt = (call) => call.then((value) => value, (error) => "ERR " + error.message)
|
|
109
|
+
`;
|
|
110
|
+
/**
|
|
111
|
+
* A fake server reached over `InMemoryTransport`. Every connect builds a new
|
|
112
|
+
* server, so `connections` counts the connections the library opened.
|
|
113
|
+
*/
|
|
114
|
+
const fake = (options) => {
|
|
115
|
+
const state = {
|
|
116
|
+
connections: 0,
|
|
117
|
+
transport: () => {
|
|
118
|
+
state.connections++;
|
|
119
|
+
const [client, server] = InMemoryTransport.createLinkedPair();
|
|
120
|
+
void makeFakeServer(options).connect(server);
|
|
121
|
+
return client;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
return state;
|
|
125
|
+
};
|
|
126
|
+
// A server that cannot be reached.
|
|
127
|
+
const refused = () => ({
|
|
128
|
+
start: () => Promise.reject(new Error("connection refused: boom")),
|
|
129
|
+
send: () => Promise.resolve(),
|
|
130
|
+
close: () => Promise.resolve(),
|
|
131
|
+
});
|
|
132
|
+
// A server that never answers `initialize`.
|
|
133
|
+
const silent = () => InMemoryTransport.createLinkedPair()[0];
|
|
134
|
+
const named = (...names) => names.map((name) => ({ name, call: () => text(name) }));
|
|
135
|
+
const currentStatus = Effect.gen(function* () {
|
|
136
|
+
const servers = yield* McpServers.McpServers;
|
|
137
|
+
return yield* servers.status;
|
|
138
|
+
});
|
|
139
|
+
const failure = (status, name) => {
|
|
140
|
+
const server = status[name];
|
|
141
|
+
if (server?._tag !== "Failed") {
|
|
142
|
+
return assert.fail(`expected ${name} to have failed`);
|
|
143
|
+
}
|
|
144
|
+
return server.error;
|
|
145
|
+
};
|
|
146
|
+
const count = (text, pattern) => (text.match(pattern) ?? []).length;
|
|
147
|
+
const isRunning = (pid) => {
|
|
148
|
+
try {
|
|
149
|
+
process.kill(pid, 0);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const exited = (pid) => Effect.sync(() => isRunning(pid)).pipe(Effect.repeat({
|
|
157
|
+
while: (running) => running,
|
|
158
|
+
schedule: Schedule.spaced("50 millis"),
|
|
159
|
+
}), Effect.timeout("3 seconds"));
|
|
160
|
+
const fixture = (path) => path.join(import.meta.dirname, "fixtures", "McpStdioServer.ts");
|
|
161
|
+
// Builds an Agent, returning "built" or the defect that stopped it.
|
|
162
|
+
const build = (effect) => effect.pipe(Effect.as("built"), Effect.scoped, Effect.catchDefect((defect) => Effect.succeed(String(defect))));
|
|
163
|
+
// A session the server ended is terminal, whichever layer built the
|
|
164
|
+
// transport.
|
|
165
|
+
const endedSession = (layer) => Effect.gen(function* () {
|
|
166
|
+
// The `end` tool ends the session it is called in.
|
|
167
|
+
let endSession;
|
|
168
|
+
const remote = yield* Effect.acquireRelease(Effect.promise(() => listenHttp(makeFakeServer({
|
|
169
|
+
tools: [
|
|
170
|
+
{ name: "ping", call: () => text("pong") },
|
|
171
|
+
{
|
|
172
|
+
name: "end",
|
|
173
|
+
call: () => {
|
|
174
|
+
endSession?.();
|
|
175
|
+
return text("ended");
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
}))), (remote) => Effect.promise(remote.close));
|
|
180
|
+
endSession = remote.endSession;
|
|
181
|
+
const { summary, status } = yield* Effect.gen(function* () {
|
|
182
|
+
const { summary } = yield* runAgent({
|
|
183
|
+
script: `${attempt}
|
|
184
|
+
await mcp.remote.end({})
|
|
185
|
+
const first = await attempt(mcp.remote.ping({}))
|
|
186
|
+
await taskComplete(JSON.stringify({ first, second: await attempt(mcp.remote.ping({})) }))`,
|
|
187
|
+
});
|
|
188
|
+
return { summary, status: yield* currentStatus };
|
|
189
|
+
}).pipe(Effect.provide(layer(remote.url)));
|
|
190
|
+
const { first, second } = JSON.parse(summary);
|
|
191
|
+
// The 404 ends the session; the next call is rejected locally.
|
|
192
|
+
assert.match(first, /^ERR mcp\.remote\.ping: /);
|
|
193
|
+
assert.match(second, /^ERR mcp\.remote\.ping: MCP server "remote" is not connected: /);
|
|
194
|
+
failure(status, "remote");
|
|
195
|
+
assert.deepStrictEqual(remote.afterEnd.filter((request) => request.startsWith("POST")), ["POST tools/call"]);
|
|
196
|
+
}).pipe(Effect.scoped);
|
|
197
|
+
// --- lifecycle and prompt ----------------------------------------------------
|
|
198
|
+
describe("McpServers", () => {
|
|
199
|
+
it.live("a failed server never stops the Agent and is listed in the prompt", () => {
|
|
200
|
+
const github = fake({
|
|
201
|
+
instructions: `GITHUB-INSTRUCTIONS ${"x".repeat(3000)} INSTRUCTIONS-TAIL`,
|
|
202
|
+
tools: [
|
|
203
|
+
{
|
|
204
|
+
name: "create_issue",
|
|
205
|
+
description: "PRIVATE-DESCRIPTION",
|
|
206
|
+
call: () => text("created"),
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
});
|
|
210
|
+
return Effect.gen(function* () {
|
|
211
|
+
const { system, summary } = yield* runAgent({
|
|
212
|
+
script: "await taskComplete([typeof mcp.github.create_issue, typeof searchTools].join())",
|
|
213
|
+
});
|
|
214
|
+
const status = yield* currentStatus;
|
|
215
|
+
assert.strictEqual(summary, "function,function");
|
|
216
|
+
assert.strictEqual(github.connections, 1);
|
|
217
|
+
assert.strictEqual(status["github"]?._tag, "Connected");
|
|
218
|
+
assert.include(failure(status, "broken"), "boom");
|
|
219
|
+
failure(status, "slow");
|
|
220
|
+
// Instructions are capped; failed servers get one line with the reason.
|
|
221
|
+
assert.include(system, "GITHUB-INSTRUCTIONS");
|
|
222
|
+
assert.notInclude(system, "INSTRUCTIONS-TAIL");
|
|
223
|
+
assert.match(system, /broken.*boom/);
|
|
224
|
+
assert.include(system, "slow");
|
|
225
|
+
assert.include(system, "declare function searchTools(");
|
|
226
|
+
// Each connected server shows the call that lists its tools.
|
|
227
|
+
assert.include(system, 'searchTools({ server: "github" })');
|
|
228
|
+
assert.notInclude(system, 'searchTools({ server: "broken" })');
|
|
229
|
+
// Tool types are only returned by `searchTools`.
|
|
230
|
+
assert.notInclude(system, "PRIVATE-DESCRIPTION");
|
|
231
|
+
assert.notInclude(system, "declare namespace mcp");
|
|
232
|
+
}).pipe(Effect.provide(McpServers.layerTransports({
|
|
233
|
+
github: { transport: github.transport },
|
|
234
|
+
broken: { transport: refused },
|
|
235
|
+
slow: { transport: silent, connectTimeout: Duration.millis(50) },
|
|
236
|
+
})));
|
|
237
|
+
});
|
|
238
|
+
it.live("without a connected server nothing MCP is bound or declared", () => Effect.gen(function* () {
|
|
239
|
+
const script = "await taskComplete([typeof mcp, typeof searchTools].join())";
|
|
240
|
+
const without = yield* runAgent({ script });
|
|
241
|
+
assert.strictEqual(without.summary, "undefined,undefined");
|
|
242
|
+
assert.notMatch(without.system, /searchTools|MCP|\bmcp\b/);
|
|
243
|
+
const allFailed = yield* runAgent({ script }).pipe(Effect.provide(McpServers.layerTransports({ broken: { transport: refused } })));
|
|
244
|
+
assert.strictEqual(allFailed.summary, "undefined,undefined");
|
|
245
|
+
assert.match(allFailed.system, /broken.*boom/);
|
|
246
|
+
assert.notInclude(allFailed.system, "searchTools");
|
|
247
|
+
}));
|
|
248
|
+
it.live("mcp and searchTools are reserved even without servers", () => Effect.gen(function* () {
|
|
249
|
+
const LoopTools = Toolkit.make(Tool.make("searchTools", { parameters: Schema.String }));
|
|
250
|
+
const loopSide = yield* build(Agent.makeWith({ loopTools: LoopTools }).pipe(Effect.provide([
|
|
251
|
+
executorLayer("local"),
|
|
252
|
+
LoopTools.toLayer({ searchTools: () => Effect.void }),
|
|
253
|
+
])));
|
|
254
|
+
assert.notStrictEqual(loopSide, "built");
|
|
255
|
+
assert.include(loopSide, "searchTools");
|
|
256
|
+
const ExecutorTools = Toolkit.make(Tool.make("mcp", { parameters: Schema.String }));
|
|
257
|
+
const executorSide = yield* build(Agent.make.pipe(Effect.provide(executorLayer("local", { tools: ExecutorTools }).pipe(Layer.provide(ExecutorTools.toLayer({ mcp: () => Effect.void }))))));
|
|
258
|
+
assert.notStrictEqual(executorSide, "built");
|
|
259
|
+
assert.include(executorSide, "mcp");
|
|
260
|
+
}));
|
|
261
|
+
// --- naming ------------------------------------------------------------------
|
|
262
|
+
it.live("server and tool names are cleaned into identifiers", () => Effect.gen(function* () {
|
|
263
|
+
const { summary } = yield* runAgent({
|
|
264
|
+
script: `const s = mcp.brave_search
|
|
265
|
+
await taskComplete(JSON.stringify({
|
|
266
|
+
calls: await Promise.all([s.web_search({}), s.delete_({}), s._2fa({}), s.a_b({}), s.__proto__({})]),
|
|
267
|
+
types: await searchTools({ server: "brave_search" }),
|
|
268
|
+
none: await searchTools({ query: "zzz" }),
|
|
269
|
+
}))`,
|
|
270
|
+
});
|
|
271
|
+
const { calls, types, none } = JSON.parse(summary);
|
|
272
|
+
// Each call reaches the tool under its original name; of two tools that
|
|
273
|
+
// clean to the same identifier the first is kept.
|
|
274
|
+
assert.deepStrictEqual(calls, [
|
|
275
|
+
"web-search",
|
|
276
|
+
"delete",
|
|
277
|
+
"2fa",
|
|
278
|
+
"a-b",
|
|
279
|
+
"__proto__",
|
|
280
|
+
]);
|
|
281
|
+
assert.include(types, "declare namespace mcp.brave_search {");
|
|
282
|
+
assert.include(types, "function delete_(");
|
|
283
|
+
assert.strictEqual(count(types, /function a_b\(/g), 1);
|
|
284
|
+
assert.notInclude(types, "web-search");
|
|
285
|
+
// The skipped tool still counts.
|
|
286
|
+
assert.strictEqual(none, 'No MCP tools match "zzz". Servers: brave_search (6 tools).');
|
|
287
|
+
// The later server that cleans to a taken identifier fails, naming the
|
|
288
|
+
// server that holds it. Status keeps the original names.
|
|
289
|
+
const status = yield* currentStatus;
|
|
290
|
+
assert.strictEqual(status["brave-search"]?._tag, "Connected");
|
|
291
|
+
assert.include(failure(status, "brave_search"), "brave-search");
|
|
292
|
+
}).pipe(Effect.provide(McpServers.layerTransports({
|
|
293
|
+
"brave-search": {
|
|
294
|
+
transport: fake({
|
|
295
|
+
tools: named("web-search", "delete", "2fa", "a-b", "a_b", "__proto__"),
|
|
296
|
+
}).transport,
|
|
297
|
+
},
|
|
298
|
+
brave_search: {
|
|
299
|
+
transport: fake({ tools: named("other") }).transport,
|
|
300
|
+
},
|
|
301
|
+
}))));
|
|
302
|
+
// --- discovery ---------------------------------------------------------------
|
|
303
|
+
it.live("searchTools finds tools by name, description and parameters", () => Effect.gen(function* () {
|
|
304
|
+
const { summary } = yield* runAgent({
|
|
305
|
+
script: `${attempt}
|
|
306
|
+
await taskComplete(JSON.stringify({
|
|
307
|
+
ranked: await searchTools({ query: "issue" }),
|
|
308
|
+
camel: await searchTools({ query: "pull" }),
|
|
309
|
+
parameter: await searchTools({ query: "owner" }),
|
|
310
|
+
capped: await searchTools({ query: "widget" }),
|
|
311
|
+
server: await searchTools({ server: "many" }),
|
|
312
|
+
neither: await attempt(searchTools({})),
|
|
313
|
+
unknown: await attempt(searchTools({ server: "nope" })),
|
|
314
|
+
none: await searchTools({ query: "zebra" }),
|
|
315
|
+
}))`,
|
|
316
|
+
});
|
|
317
|
+
const result = JSON.parse(summary);
|
|
318
|
+
// An exact name match ranks first, with its doc comments.
|
|
319
|
+
assert.include(result.ranked, "declare namespace mcp.github {");
|
|
320
|
+
assert.include(result.ranked, "/** Get one issue by number */");
|
|
321
|
+
assert.include(result.ranked, "/** Issue number */");
|
|
322
|
+
assert.isBelow(result.ranked.indexOf("function issue("), result.ranked.indexOf("function list_issues("));
|
|
323
|
+
assert.notInclude(result.ranked, "get_me");
|
|
324
|
+
assert.notInclude(result.ranked, "mcp.many");
|
|
325
|
+
assert.include(result.camel, "function createPullRequest(");
|
|
326
|
+
assert.include(result.parameter, "function list_issues(");
|
|
327
|
+
assert.notInclude(result.parameter, "function issue(");
|
|
328
|
+
// A query returns at most 10 tools; `server` alone lists all of them.
|
|
329
|
+
assert.strictEqual(count(result.capped, /function widget_/g), 10);
|
|
330
|
+
assert.strictEqual(count(result.server, /function widget_/g), 25);
|
|
331
|
+
for (const rejected of [result.neither, result.unknown]) {
|
|
332
|
+
assert.match(rejected, /^ERR /);
|
|
333
|
+
assert.include(rejected, "github");
|
|
334
|
+
assert.include(rejected, "many");
|
|
335
|
+
}
|
|
336
|
+
assert.strictEqual(result.none, 'No MCP tools match "zebra". Servers: github (4 tools), many (25 tools).');
|
|
337
|
+
}).pipe(Effect.provide(McpServers.layerTransports({
|
|
338
|
+
github: {
|
|
339
|
+
transport: fake({
|
|
340
|
+
tools: [
|
|
341
|
+
{
|
|
342
|
+
name: "issue",
|
|
343
|
+
description: "Get one issue by number",
|
|
344
|
+
inputSchema: {
|
|
345
|
+
type: "object",
|
|
346
|
+
properties: {
|
|
347
|
+
number: { type: "integer", description: "Issue number" },
|
|
348
|
+
},
|
|
349
|
+
required: ["number"],
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: "list_issues",
|
|
354
|
+
description: "List issues in a repository",
|
|
355
|
+
inputSchema: {
|
|
356
|
+
type: "object",
|
|
357
|
+
properties: { repository_owner: { type: "string" } },
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
name: "createPullRequest",
|
|
362
|
+
description: "Open a pull request",
|
|
363
|
+
},
|
|
364
|
+
{ name: "get_me", description: "Get the authenticated user" },
|
|
365
|
+
],
|
|
366
|
+
}).transport,
|
|
367
|
+
},
|
|
368
|
+
many: {
|
|
369
|
+
transport: fake({
|
|
370
|
+
tools: Array.from({ length: 25 }, (_, i) => ({
|
|
371
|
+
name: `widget_${i}`,
|
|
372
|
+
description: "Widget tool",
|
|
373
|
+
})),
|
|
374
|
+
}).transport,
|
|
375
|
+
},
|
|
376
|
+
}))));
|
|
377
|
+
// --- calls -------------------------------------------------------------------
|
|
378
|
+
it.live("calls validate arguments and map results and errors", () => Effect.gen(function* () {
|
|
379
|
+
const { summary } = yield* runAgent({
|
|
380
|
+
script: `${attempt}
|
|
381
|
+
await taskComplete(JSON.stringify({
|
|
382
|
+
echo: await mcp.fake.echo({ text: "hi" }),
|
|
383
|
+
excess: await attempt(mcp.fake.echo({ text: "hi", extra: 1 })),
|
|
384
|
+
blocks: await mcp.fake.blocks({}),
|
|
385
|
+
empty: await mcp.fake.empty({}),
|
|
386
|
+
structured: await mcp.fake.structured({}),
|
|
387
|
+
badOutput: await attempt(mcp.fake.bad_output({})),
|
|
388
|
+
fails: await attempt(mcp.fake.fails({})),
|
|
389
|
+
failsSilently: await attempt(mcp.fake.fails_silently({})),
|
|
390
|
+
conditional: await mcp.fake.conditional({ anything: 1 }),
|
|
391
|
+
types: await searchTools({ server: "fake" }),
|
|
392
|
+
}))`,
|
|
393
|
+
});
|
|
394
|
+
const result = JSON.parse(summary);
|
|
395
|
+
assert.strictEqual(result.echo, '{"text":"hi"}');
|
|
396
|
+
assert.match(result.excess, /^ERR mcp\.fake\.echo: /);
|
|
397
|
+
assert.include(result.excess, "extra");
|
|
398
|
+
assert.match(result.blocks, /^first\n\[Image attached: fake\.blocks-\d+\.png\]\n\[Image omitted \(image\/bmp\): [^\]\n]+\]\n\[Audio omitted \(audio\/wav\)\]\n\[Resource file:\/\/\/notes\.txt\]\s+NOTES\n\[Binary resource omitted: file:\/\/\/data\.bin \(application\/octet-stream\)\]\n\[Resource link: design file:\/\/\/design\.md\]$/);
|
|
399
|
+
assert.strictEqual(result.empty, "");
|
|
400
|
+
// With an `outputSchema` the result is `structuredContent`.
|
|
401
|
+
assert.deepStrictEqual(result.structured, { login: "octocat" });
|
|
402
|
+
// `bad_output` is on the first page: every page's output validator is
|
|
403
|
+
// kept.
|
|
404
|
+
assert.match(result.badOutput, /^ERR mcp\.fake\.bad_output: /);
|
|
405
|
+
assert.strictEqual(result.fails, "ERR mcp.fake.fails: rate limited");
|
|
406
|
+
assert.strictEqual(result.failsSilently, "ERR mcp.fake.fails_silently: tool returned an error with no message");
|
|
407
|
+
// A schema that cannot be imported is not validated.
|
|
408
|
+
assert.strictEqual(result.conditional, '{"anything":1}');
|
|
409
|
+
assert.match(result.types, /function echo\([^]*?\): Promise<string>/);
|
|
410
|
+
assert.match(result.types, /function structured\([^]*?\): Promise<\{\s*readonly login: string;\s*\}>/);
|
|
411
|
+
assert.include(result.types, "function conditional(options: Record<string, unknown>)");
|
|
412
|
+
assert.include(result.types, '"then"');
|
|
413
|
+
}).pipe(Effect.provide(McpServers.layerTransports({
|
|
414
|
+
fake: {
|
|
415
|
+
transport: fake({
|
|
416
|
+
// One tool per page.
|
|
417
|
+
pageSize: 1,
|
|
418
|
+
tools: [
|
|
419
|
+
{
|
|
420
|
+
name: "bad_output",
|
|
421
|
+
outputSchema: {
|
|
422
|
+
type: "object",
|
|
423
|
+
properties: { login: { type: "string" } },
|
|
424
|
+
required: ["login"],
|
|
425
|
+
},
|
|
426
|
+
call: () => ({
|
|
427
|
+
content: [],
|
|
428
|
+
structuredContent: { login: 42 },
|
|
429
|
+
}),
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
name: "echo",
|
|
433
|
+
inputSchema: {
|
|
434
|
+
type: "object",
|
|
435
|
+
properties: { text: { type: "string" } },
|
|
436
|
+
required: ["text"],
|
|
437
|
+
additionalProperties: false,
|
|
438
|
+
},
|
|
439
|
+
call: (args) => text(JSON.stringify(args)),
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
name: "blocks",
|
|
443
|
+
call: () => ({
|
|
444
|
+
content: [
|
|
445
|
+
{ type: "text", text: "first" },
|
|
446
|
+
{
|
|
447
|
+
type: "image",
|
|
448
|
+
data: Buffer.from(tinyPng).toString("base64"),
|
|
449
|
+
mimeType: "image/png",
|
|
450
|
+
},
|
|
451
|
+
{ type: "image", data: "AAAA", mimeType: "image/bmp" },
|
|
452
|
+
{ type: "audio", data: "AAAA", mimeType: "audio/wav" },
|
|
453
|
+
{
|
|
454
|
+
type: "resource",
|
|
455
|
+
resource: {
|
|
456
|
+
uri: "file:///notes.txt",
|
|
457
|
+
mimeType: "text/plain",
|
|
458
|
+
text: "NOTES",
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
type: "resource",
|
|
463
|
+
resource: {
|
|
464
|
+
uri: "file:///data.bin",
|
|
465
|
+
mimeType: "application/octet-stream",
|
|
466
|
+
blob: "AAAA",
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
type: "resource_link",
|
|
471
|
+
name: "design",
|
|
472
|
+
uri: "file:///design.md",
|
|
473
|
+
},
|
|
474
|
+
],
|
|
475
|
+
}),
|
|
476
|
+
},
|
|
477
|
+
{ name: "empty", call: () => ({ content: [] }) },
|
|
478
|
+
{
|
|
479
|
+
name: "structured",
|
|
480
|
+
outputSchema: {
|
|
481
|
+
type: "object",
|
|
482
|
+
properties: { login: { type: "string" } },
|
|
483
|
+
required: ["login"],
|
|
484
|
+
},
|
|
485
|
+
call: () => ({
|
|
486
|
+
content: [{ type: "text", text: "ignored" }],
|
|
487
|
+
structuredContent: { login: "octocat" },
|
|
488
|
+
}),
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
name: "fails",
|
|
492
|
+
call: () => ({ ...text("rate limited"), isError: true }),
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
name: "fails_silently",
|
|
496
|
+
call: () => ({ content: [], isError: true }),
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
name: "conditional",
|
|
500
|
+
inputSchema: {
|
|
501
|
+
type: "object",
|
|
502
|
+
if: { properties: { kind: { const: "a" } } },
|
|
503
|
+
// oxlint-disable-next-line unicorn/no-thenable
|
|
504
|
+
then: { required: ["a"] },
|
|
505
|
+
else: { required: ["b"] },
|
|
506
|
+
},
|
|
507
|
+
call: (args) => text(JSON.stringify(args)),
|
|
508
|
+
},
|
|
509
|
+
],
|
|
510
|
+
}).transport,
|
|
511
|
+
},
|
|
512
|
+
}))));
|
|
513
|
+
it.live("a dropped server is not reconnected", () => {
|
|
514
|
+
const server = fake({
|
|
515
|
+
tools: [
|
|
516
|
+
{ name: "echo", call: () => text("echo") },
|
|
517
|
+
{
|
|
518
|
+
name: "crash",
|
|
519
|
+
call: (_, { close }) => {
|
|
520
|
+
void close();
|
|
521
|
+
return new Promise(() => { });
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
],
|
|
525
|
+
});
|
|
526
|
+
return Effect.gen(function* () {
|
|
527
|
+
const { summary } = yield* runAgent({
|
|
528
|
+
script: `${attempt}
|
|
529
|
+
const crashed = await attempt(mcp.fake.crash({}))
|
|
530
|
+
await taskComplete(JSON.stringify({ crashed, after: await attempt(mcp.fake.echo({})) }))`,
|
|
531
|
+
});
|
|
532
|
+
const { crashed, after } = JSON.parse(summary);
|
|
533
|
+
assert.match(crashed, /^ERR mcp\.fake\.crash: /);
|
|
534
|
+
assert.match(after, /^ERR mcp\.fake\.echo: MCP server "fake" is not connected: /);
|
|
535
|
+
assert.strictEqual(server.connections, 1);
|
|
536
|
+
}).pipe(Effect.provide(McpServers.layerTransports({ fake: { transport: server.transport } })));
|
|
537
|
+
});
|
|
538
|
+
it.live("a call that times out is cancelled on the server", () => {
|
|
539
|
+
const cancelled = Promise.withResolvers();
|
|
540
|
+
return Effect.gen(function* () {
|
|
541
|
+
const { summary } = yield* runAgent({
|
|
542
|
+
script: 'await taskComplete(await mcp.fake.wait({}).then(() => "resolved", (error) => error.message))',
|
|
543
|
+
});
|
|
544
|
+
assert.strictEqual(summary, "mcp.fake.wait: timed out after 50ms");
|
|
545
|
+
yield* Effect.promise(() => cancelled.promise).pipe(Effect.timeout("2 seconds"));
|
|
546
|
+
}).pipe(Effect.provide(McpServers.layerTransports({
|
|
547
|
+
fake: {
|
|
548
|
+
callTimeout: Duration.millis(50),
|
|
549
|
+
transport: fake({
|
|
550
|
+
tools: [
|
|
551
|
+
{
|
|
552
|
+
name: "wait",
|
|
553
|
+
call: (_, { signal }) => {
|
|
554
|
+
signal.addEventListener("abort", () => cancelled.resolve());
|
|
555
|
+
return new Promise(() => { });
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
],
|
|
559
|
+
}).transport,
|
|
560
|
+
},
|
|
561
|
+
})));
|
|
562
|
+
});
|
|
563
|
+
// --- the Agent -----------------------------------------------------------------
|
|
564
|
+
for (const mode of modes) {
|
|
565
|
+
it.live(`${mode} executor: sub-agents share the connection and images reach the model`, () => {
|
|
566
|
+
const server = fake({
|
|
567
|
+
tools: [
|
|
568
|
+
{ name: "ping", call: () => text("pong") },
|
|
569
|
+
{
|
|
570
|
+
name: "screenshot",
|
|
571
|
+
call: () => ({
|
|
572
|
+
content: [
|
|
573
|
+
{
|
|
574
|
+
type: "image",
|
|
575
|
+
data: Buffer.from(tinyPng).toString("base64"),
|
|
576
|
+
mimeType: "image/png",
|
|
577
|
+
},
|
|
578
|
+
],
|
|
579
|
+
}),
|
|
580
|
+
},
|
|
581
|
+
],
|
|
582
|
+
});
|
|
583
|
+
return Effect.gen(function* () {
|
|
584
|
+
const { summary, calls } = yield* runAgent({
|
|
585
|
+
mode,
|
|
586
|
+
script: (call) => {
|
|
587
|
+
if (call.role === "child") {
|
|
588
|
+
return "await taskComplete(await mcp.fake.ping({}))";
|
|
589
|
+
}
|
|
590
|
+
return call.index === 0
|
|
591
|
+
? `const child = await delegate({ prompt: "TASK-CHILD" })
|
|
592
|
+
console.log(JSON.stringify(child))
|
|
593
|
+
console.log(await mcp.fake.screenshot({}))`
|
|
594
|
+
: 'await taskComplete("done")';
|
|
595
|
+
},
|
|
596
|
+
});
|
|
597
|
+
assert.strictEqual(summary, "done");
|
|
598
|
+
assert.strictEqual(server.connections, 1);
|
|
599
|
+
const root = calls.filter((call) => call.role === "root");
|
|
600
|
+
assert.strictEqual(root.length, 2);
|
|
601
|
+
const output = lastToolResult(root[1].prompt);
|
|
602
|
+
assert.include(output, "pong");
|
|
603
|
+
assert.match(output, /\[Image attached: fake\.screenshot-\d+\.png\]/);
|
|
604
|
+
assert.isTrue(hasPngAttachment(root[1].prompt));
|
|
605
|
+
}).pipe(Effect.provide(McpServers.layerTransports({
|
|
606
|
+
fake: { transport: server.transport },
|
|
607
|
+
})));
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
// --- transports ----------------------------------------------------------------
|
|
611
|
+
it.live("stdio servers get the merged environment, report stderr and end with the scope", () => Effect.gen(function* () {
|
|
612
|
+
const fs = yield* FileSystem.FileSystem;
|
|
613
|
+
const path = yield* Path.Path;
|
|
614
|
+
const out = path.join(yield* fs.makeTempDirectoryScoped(), "out.json");
|
|
615
|
+
yield* Effect.acquireRelease(Effect.sync(() => {
|
|
616
|
+
process.env["FIXTURE_PARENT"] = "from-parent";
|
|
617
|
+
process.env["FIXTURE_TOKEN"] = "from-parent";
|
|
618
|
+
}), () => Effect.sync(() => {
|
|
619
|
+
delete process.env["FIXTURE_PARENT"];
|
|
620
|
+
delete process.env["FIXTURE_TOKEN"];
|
|
621
|
+
}));
|
|
622
|
+
const status = yield* currentStatus.pipe(Effect.provide(McpServers.layer({
|
|
623
|
+
fixture: {
|
|
624
|
+
type: "stdio",
|
|
625
|
+
command: process.execPath,
|
|
626
|
+
args: [fixture(path)],
|
|
627
|
+
cwd: "src",
|
|
628
|
+
env: {
|
|
629
|
+
FIXTURE_OUT: Redacted.make(out),
|
|
630
|
+
FIXTURE_TOKEN: Redacted.make("from-config"),
|
|
631
|
+
},
|
|
632
|
+
},
|
|
633
|
+
exploding: {
|
|
634
|
+
type: "stdio",
|
|
635
|
+
command: process.execPath,
|
|
636
|
+
args: [fixture(path)],
|
|
637
|
+
env: { FIXTURE_FAIL: Redacted.make("fixture exploded") },
|
|
638
|
+
},
|
|
639
|
+
})));
|
|
640
|
+
assert.strictEqual(status["fixture"]?._tag, "Connected");
|
|
641
|
+
assert.include(failure(status, "exploding"), "fixture exploded");
|
|
642
|
+
const started = JSON.parse(yield* fs.readFileString(out));
|
|
643
|
+
// A relative `cwd` resolves against the process cwd.
|
|
644
|
+
assert.strictEqual(started.cwd, path.resolve("src"));
|
|
645
|
+
assert.deepStrictEqual(started.env, {
|
|
646
|
+
FIXTURE_PARENT: "from-parent",
|
|
647
|
+
FIXTURE_TOKEN: "from-config",
|
|
648
|
+
});
|
|
649
|
+
// The layer's scope has closed.
|
|
650
|
+
yield* exited(started.pid);
|
|
651
|
+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)));
|
|
652
|
+
it.live("a stdio server that fails to initialize has exited when the scope closes", () => Effect.gen(function* () {
|
|
653
|
+
const fs = yield* FileSystem.FileSystem;
|
|
654
|
+
const path = yield* Path.Path;
|
|
655
|
+
const out = path.join(yield* fs.makeTempDirectoryScoped(), "out.json");
|
|
656
|
+
const status = yield* currentStatus.pipe(Effect.provide(McpServers.layer({
|
|
657
|
+
rejecting: {
|
|
658
|
+
type: "stdio",
|
|
659
|
+
command: process.execPath,
|
|
660
|
+
args: [fixture(path)],
|
|
661
|
+
env: {
|
|
662
|
+
FIXTURE_OUT: Redacted.make(out),
|
|
663
|
+
FIXTURE_REJECT_INIT: Redacted.make("1"),
|
|
664
|
+
},
|
|
665
|
+
},
|
|
666
|
+
})));
|
|
667
|
+
assert.include(failure(status, "rejecting"), "initialize rejected");
|
|
668
|
+
// The server outlives its stdin, so it only ends once the shutdown
|
|
669
|
+
// the failed connect started is awaited.
|
|
670
|
+
const started = JSON.parse(yield* fs.readFileString(out));
|
|
671
|
+
assert.isFalse(isRunning(started.pid));
|
|
672
|
+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)));
|
|
673
|
+
it.live("an http session the server ended is not connected", () => endedSession((url) => McpServers.layer({ remote: { type: "http", url } })));
|
|
674
|
+
it.live("an ended session on a caller-built SDK transport is not connected", () => endedSession((url) => McpServers.layerTransports({
|
|
675
|
+
remote: {
|
|
676
|
+
transport: () => new StreamableHTTPClientTransport(new URL(url)),
|
|
677
|
+
},
|
|
678
|
+
})));
|
|
679
|
+
it.live("an http response resumes after its stream closes", () => Effect.gen(function* () {
|
|
680
|
+
const remote = yield* Effect.acquireRelease(Effect.promise(() => listenHttp(makeFakeServer({
|
|
681
|
+
tools: [
|
|
682
|
+
{
|
|
683
|
+
name: "slow",
|
|
684
|
+
call: async (_, { closeStream }) => {
|
|
685
|
+
closeStream();
|
|
686
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
687
|
+
return text("resumed");
|
|
688
|
+
},
|
|
689
|
+
},
|
|
690
|
+
],
|
|
691
|
+
}), "/mcp", { resumable: true })), (remote) => Effect.promise(remote.close));
|
|
692
|
+
const { summary, status } = yield* Effect.gen(function* () {
|
|
693
|
+
const { summary } = yield* runAgent({
|
|
694
|
+
script: "await taskComplete(await mcp.remote.slow({}))",
|
|
695
|
+
});
|
|
696
|
+
return { summary, status: yield* currentStatus };
|
|
697
|
+
}).pipe(Effect.provide(McpServers.layer({ remote: { type: "http", url: remote.url } })));
|
|
698
|
+
assert.strictEqual(summary, "resumed");
|
|
699
|
+
assert.strictEqual(status["remote"]?._tag, "Connected");
|
|
700
|
+
}).pipe(Effect.scoped));
|
|
701
|
+
it.live("http servers are sent the static headers", () => Effect.gen(function* () {
|
|
702
|
+
const remote = yield* Effect.acquireRelease(Effect.promise(() => listenHttp(makeFakeServer({ tools: named("ping") }))), (remote) => Effect.promise(remote.close));
|
|
703
|
+
const status = yield* currentStatus.pipe(Effect.provide(McpServers.layer({
|
|
704
|
+
remote: {
|
|
705
|
+
type: "http",
|
|
706
|
+
url: remote.url,
|
|
707
|
+
headers: { Authorization: Redacted.make("Bearer secret") },
|
|
708
|
+
},
|
|
709
|
+
})));
|
|
710
|
+
assert.strictEqual(status["remote"]?._tag, "Connected");
|
|
711
|
+
assert.isNotEmpty(remote.authorization);
|
|
712
|
+
for (const header of remote.authorization) {
|
|
713
|
+
assert.strictEqual(header, "Bearer secret");
|
|
714
|
+
}
|
|
715
|
+
}).pipe(Effect.scoped));
|
|
716
|
+
});
|
|
717
|
+
//# sourceMappingURL=McpServers.test.js.map
|