import { MCPClient } from "mcp-client";
interface ToolCallParams {
name: string;
arguments: Record<string, unknown>;
}
class MCPTestClient {
private client!: MCPClient;
async initialize(): Promise<void> {
const config = {
name: "Test",
version: "1.0.0",
};
this.client = new MCPClient(config);
const connectionConfig: Parameters<typeof this.client.connect>[0] = {
type: "stdio",
command: "node",
args: ["./dist/src/index.js"],
};
await this.client.connect(connectionConfig);
}
listTools(): unknown {
return this.client.getAllTools();
}
/**
* Вызывает инструмент
*/
async callTool(
name: string,
arguments_: Record<string, unknown> = {},
): Promise<unknown> {
const params: ToolCallParams = {
name,
arguments: arguments_,
};
return this.client.callTool(params);
}
async close(): Promise<void> {
this.client.close();
}
}
export async function createTestClient(): Promise<MCPTestClient> {
const client = new MCPTestClient();
await client.initialize();
return client;
}