-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp-servers.ts
More file actions
38 lines (37 loc) · 1003 Bytes
/
mcp-servers.ts
File metadata and controls
38 lines (37 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* MCP server integration — import MCP servers before running a query.
*
* The SDK calls `forge mcp import` for each configured server before
* starting the query. This makes the server's tools available to the agent.
*
* Run: bun run examples/mcp-servers.ts
*/
import { query } from "../src";
for await (const message of query({
prompt: "What MCP tools are available to you? List them briefly.",
options: {
mcpServers: {
"my-filesystem": {
command: "npx",
args: ["-y", "@anthropic-ai/mcp-filesystem-server", "/tmp"],
transport: "stdio",
},
},
cwd: import.meta.dir,
},
})) {
switch (message.type) {
case "system":
console.log(`[session] ${message.session_id}`);
break;
case "assistant":
process.stdout.write(message.content);
break;
case "result":
console.log(`\n[result] ${message.result}`);
break;
case "error":
console.error(`[error] ${message.error}`);
break;
}
}