|
1 | 1 | import { Client } from "@modelcontextprotocol/sdk/client/index.js"; |
| 2 | +import type { StdioServerParameters } from "@modelcontextprotocol/sdk/client/stdio.js"; |
2 | 3 | import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; |
3 | 4 | import { homedir } from "os"; |
4 | 5 | import { join } from "path"; |
@@ -26,11 +27,14 @@ export class McpClient { |
26 | 27 | this.model = model; |
27 | 28 | } |
28 | 29 |
|
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> { |
30 | 35 | 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 ?? "" }, |
34 | 38 | }); |
35 | 39 | const mcp = new Client({ name: "@huggingface/mcp-client", version: packageVersion }); |
36 | 40 | await mcp.connect(transport); |
@@ -131,13 +135,13 @@ async function main() { |
131 | 135 | }); |
132 | 136 |
|
133 | 137 | 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: { |
138 | 142 | HF_TOKEN: process.env.HF_TOKEN, |
139 | | - } |
140 | | - ); |
| 143 | + }, |
| 144 | + }); |
141 | 145 |
|
142 | 146 | const response = await client.processQuery(` |
143 | 147 | find an app that generates 3D models from text, |
|
0 commit comments