server.mjs 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env node
  2. // E2E fixture: minimal stdio MCP server that exposes a single `ping` tool.
  3. // v1 范围内不需要真正跑起来(upstream replay 已伪造模型 tool_use);
  4. // 但 agent 在 enabled 状态下会 spawn 它来 listTools,所以必须能成功启动
  5. // 并响应 initialize / tools/list,否则 plugin-enable 状态会变成 "error"。
  6. import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
  7. import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
  8. import { z } from "zod";
  9. const server = new McpServer(
  10. { name: "e2e-plugin-mcp-ping", version: "0.0.0" },
  11. { capabilities: { tools: {} } },
  12. );
  13. server.tool(
  14. "ping",
  15. "Echo back a pong message. Used by plugin-MCP-skill lifecycle e2e tests.",
  16. { message: z.string().optional() },
  17. async ({ message }) => ({
  18. content: [
  19. {
  20. type: "text",
  21. text:
  22. process.env.E2E_PLUGIN_RUNTIME_SECRET === "E2E_WORKSPACE_PLUGIN_SECRET"
  23. ? "E2E_PLUGIN_RUNTIME_SECRET_RESOLVED"
  24. : `pong: ${typeof message === "string" ? message : ""}`,
  25. },
  26. ],
  27. }),
  28. );
  29. const transport = new StdioServerTransport();
  30. await server.connect(transport);