example.ts 838 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. async function main() {
  6. logger.info("Connecting to server...");
  7. const client = await createClient(conf.mcpServers.everything, "everything");
  8. const primitives = await listPrimitives(client);
  9. logger.success(`Connected to server everything`);
  10. logger.info(
  11. `server capabilities: ${Object.keys(
  12. client.getServerCapabilities() ?? [],
  13. ).join(", ")}`,
  14. );
  15. logger.info("Server supports the following primitives:");
  16. primitives.forEach((primitive) => {
  17. logger.info("\n" + JSON.stringify(primitive, null, 2));
  18. });
  19. }
  20. main().catch((error) => {
  21. logger.error(error);
  22. process.exit(1);
  23. });