mirror of
https://github.com/ChatGPTNextWeb/NextChat.git
synced 2026-03-03 08:34:53 +08:00
feat: Optimize MCP configuration logic
This commit is contained in:
@@ -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)}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user