example.ts 843 B

12345678910111213141516171819202122232425262728293031
  1. import { createClient, listPrimitives } from "@/app/mcp/client";
  2. import { MCPClientLogger } from "@/app/mcp/logger";
  3. import conf from "./mcp_config.json";
  4. const logger = new MCPClientLogger("MCP Server Example", true);
  5. const TEST_SERVER = "everything";
  6. async function main() {
  7. logger.info(`All MCP servers: ${Object.keys(conf.mcpServers).join(", ")}`);
  8. logger.info(`Connecting to server ${TEST_SERVER}...`);
  9. const client = await createClient(conf.mcpServers[TEST_SERVER], TEST_SERVER);
  10. const primitives = await listPrimitives(client);
  11. logger.success(`Connected to server ${TEST_SERVER}`);
  12. logger.info(
  13. `${TEST_SERVER} supported primitives:\n${JSON.stringify(
  14. primitives.filter((i) => i.type === "tool"),
  15. null,
  16. 2,
  17. )}`,
  18. );
  19. }
  20. main().catch((error) => {
  21. logger.error(error);
  22. process.exit(1);
  23. });