feat: Optimize MCP configuration logic

This commit is contained in:
Kadxy
2025-01-15 16:52:54 +08:00
parent ce13cf61a7
commit 8aa9a500fd
14 changed files with 766 additions and 653 deletions

View File

@@ -1,27 +1,23 @@
import { createClient, listPrimitives } from "@/app/mcp/client";
import { createClient, listTools } from "@/app/mcp/client";
import { MCPClientLogger } from "@/app/mcp/logger";
import conf from "./mcp_config.json";
const logger = new MCPClientLogger("MCP Server Example", true);
const TEST_SERVER = "everything";
const TEST_SERVER = "filesystem";
async function main() {
logger.info(`All MCP servers: ${Object.keys(conf.mcpServers).join(", ")}`);
logger.info(`Connecting to server ${TEST_SERVER}...`);
const client = await createClient(conf.mcpServers[TEST_SERVER], TEST_SERVER);
const primitives = await listPrimitives(client);
const client = await createClient(TEST_SERVER, conf.mcpServers[TEST_SERVER]);
const tools = await listTools(client);
logger.success(`Connected to server ${TEST_SERVER}`);
logger.info(
`${TEST_SERVER} supported primitives:\n${JSON.stringify(
primitives.filter((i) => i.type === "tool"),
null,
2,
)}`,
`${TEST_SERVER} supported primitives:\n${JSON.stringify(tools, null, 2)}`,
);
}