Skip to content

Commit 01d2d54

Browse files
committed
Better API + addMcpServers
1 parent 0d8d6aa commit 01d2d54

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/mcp-client/src/McpClient.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2+
import type { StdioServerParameters } from "@modelcontextprotocol/sdk/client/stdio.js";
23
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
34
import { homedir } from "os";
45
import { join } from "path";
@@ -26,11 +27,14 @@ export class McpClient {
2627
this.model = model;
2728
}
2829

29-
async addMcpServer(command: string, args: string[], env: Record<string, string>): Promise<void> {
30+
async addMcpServers(servers: StdioServerParameters[]): Promise<void> {
31+
await Promise.all(servers.map((s) => this.addMcpServer(s)));
32+
}
33+
34+
async addMcpServer(server: StdioServerParameters): Promise<void> {
3035
const transport = new StdioClientTransport({
31-
command,
32-
args,
33-
env: { ...env, PATH: process.env.PATH ?? "" },
36+
...server,
37+
env: { ...server.env, PATH: process.env.PATH ?? "" },
3438
});
3539
const mcp = new Client({ name: "@huggingface/mcp-client", version: packageVersion });
3640
await mcp.connect(transport);
@@ -131,13 +135,13 @@ async function main() {
131135
});
132136

133137
try {
134-
await client.addMcpServer(
135-
"node",
136-
["--disable-warning=ExperimentalWarning", join(homedir(), "Desktop/hf-mcp/index.ts")],
137-
{
138+
await client.addMcpServer({
139+
command: "node",
140+
args: ["--disable-warning=ExperimentalWarning", join(homedir(), "Desktop/hf-mcp/index.ts")],
141+
env: {
138142
HF_TOKEN: process.env.HF_TOKEN,
139-
}
140-
);
143+
},
144+
});
141145

142146
const response = await client.processQuery(`
143147
find an app that generates 3D models from text,

0 commit comments

Comments
 (0)