oauth-status-isolation-direct-server.mjs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env node
  2. import { appendFile, mkdir } from "node:fs/promises";
  3. import { createRequire } from "node:module";
  4. import { dirname } from "node:path";
  5. const requireFromMcpAdapter = createRequire(
  6. new URL("../../../../../../apps/zcode-cli/packages/adapters/package.json", import.meta.url),
  7. );
  8. const { McpServer } = requireFromMcpAdapter("@modelcontextprotocol/sdk/server/mcp.js");
  9. const { StdioServerTransport } = requireFromMcpAdapter("@modelcontextprotocol/sdk/server/stdio.js");
  10. const { z } = requireFromMcpAdapter("zod");
  11. const RESULT_PREFIX = "E2E_MCP_DIRECT_PONG";
  12. const callLogPath = process.env.E2E_MCP_DIRECT_CALL_LOG;
  13. await recordEvent({ event: "started", pid: process.pid });
  14. const server = new McpServer({
  15. name: "mcp-oauth-status-isolation-direct-e2e",
  16. version: "0.1.0",
  17. });
  18. server.registerTool(
  19. "ping",
  20. {
  21. title: "Direct MCP Ping",
  22. description: "Return an E2E marker from the unrelated user-level MCP server.",
  23. inputSchema: {
  24. marker: z.string(),
  25. },
  26. annotations: {
  27. destructiveHint: false,
  28. idempotentHint: true,
  29. readOnlyHint: true,
  30. },
  31. },
  32. async ({ marker }) => {
  33. await recordEvent({ marker, tool: "ping" });
  34. return {
  35. content: [
  36. {
  37. type: "text",
  38. text: `${RESULT_PREFIX}:${marker}`,
  39. },
  40. ],
  41. };
  42. },
  43. );
  44. await server.connect(new StdioServerTransport());
  45. async function recordEvent(event) {
  46. if (!callLogPath) return;
  47. await mkdir(dirname(callLogPath), { recursive: true });
  48. await appendFile(
  49. callLogPath,
  50. `${JSON.stringify({ ...event, ts: new Date().toISOString() })}\n`,
  51. "utf-8",
  52. );
  53. }