{"slug": "turning-a-custom-gpt-action-into-an-mcp-server-a-minimal-tested-example", "title": "Turning a Custom GPT Action into an MCP server: a minimal tested example", "summary": "A developer published a minimal, tested example of migrating a Custom GPT Action to an MCP server using the official TypeScript SDK (@modelcontextprotocol/sdk 1.32.2, zod 4, Node 24). The demo wraps Open-Meteo's current-weather endpoint as a get_current_weather tool, with a stdio test client confirming tool listing, a successful call returning 2.6°C and 9 km/h wind, and a validation error for out-of-range latitude. The author notes the example is a happy-path demo, not production-hardened, and that HTTP error and network-failure branches remain untested.", "body_md": "If you have a Custom GPT that calls your own API through an Action, the same API can also be exposed to MCP clients such as Claude. This is a minimal, tested example of moving one Action operation into an MCP server. I ran the code below with the official TypeScript SDK (`@modelcontextprotocol/sdk` 1.32.2, zod 4, Node 24). It is a happy-path demo, not production-hardened.\n\nSetup: `npm i @modelcontextprotocol/sdk zod`, save the server as `server.mjs` and the test client as `test.mjs` (both ES modules).\n\n| Custom GPT Action (OpenAPI) | MCP server | \n|---|---|\n| `operationId` | tool name | \n| `summary` /`description` | tool description (the model reads this to decide when to call it) | \n| parameters + request schema | `inputSchema` : a zod shape you write by hand (no OpenAPI import) | \n| HTTP error response | you map it to `isError: true` yourself, with a message the model can act on | \n| API key / OAuth in the Action | your server's own auth (not shown here) | \n\nOperation being moved: `GET /v1/forecast?latitude=..&longitude=..¤t_weather=true` (Open-Meteo, no key needed).\n\n``` js\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { z } from \"zod\";\n\nconst server = new McpServer({ name: \"weather-actions\", version: \"1.0.0\" });\n\n// OpenAPI operation: GET /v1/forecast?latitude=..&longitude=..&current_weather=true  (operationId: getCurrentWeather)\nserver.registerTool(\n  \"get_current_weather\",\n  {\n    description: \"Current temperature (°C) and wind speed (km/h) for a latitude/longitude.\",\n    inputSchema: { latitude: z.number().min(-90).max(90), longitude: z.number().min(-180).max(180) },\n  },\n  async ({ latitude, longitude }) => {\n    const url = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current_weather=true`;\n    const res = await fetch(url);\n    if (!res.ok) {\n      return { isError: true, content: [{ type: \"text\", text: `Weather API returned ${res.status}. Check the coordinates and retry.` }] };\n    }\n    const { current_weather: w } = await res.json();\n    return { content: [{ type: \"text\", text: JSON.stringify({ temperature_c: w.temperature, windspeed_kmh: w.windspeed }) }] };\n  }\n);\n\nawait server.connect(new StdioServerTransport());\n```\n\nA client that connects over stdio, lists tools, and calls the tool twice:\n\n``` js\nimport { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { StdioClientTransport } from \"@modelcontextprotocol/sdk/client/stdio.js\";\nconst c = new Client({ name: \"t\", version: \"1\" });\nawait c.connect(new StdioClientTransport({ command: \"node\", args: [\"server.mjs\"] }));\nconsole.log(JSON.stringify((await c.listTools()).tools.map(t=>({name:t.name,required:t.inputSchema.required}))));\nconsole.log(JSON.stringify(await c.callTool({ name: \"get_current_weather\", arguments: { latitude: 52.52, longitude: 13.41 } })));\nconsole.log(JSON.stringify(await c.callTool({ name: \"get_current_weather\", arguments: { latitude: 999, longitude: 0 } })).slice(0,200));\nawait c.close();\n```\n\nResults:\n\n`listTools` returned one tool, `get_current_weather`, with `latitude` and `longitude` required.`{\"temperature_c\":2.6,\"windspeed_kmh\":9}`.` isError: true`: `Too big: expected number to be <=90 at latitude`. The `!res.ok` branch in the handler is not covered by this test, and network failures (a thrown `fetch`) are not handled.\nIf you would rather hand it off, I offer this migration as a fixed-price Upwork project (search for \"Custom GPT Actions rebuilt as a tested MCP server\").", "url": "https://wpnews.pro/news/turning-a-custom-gpt-action-into-an-mcp-server-a-minimal-tested-example", "canonical_source": "https://dev.to/tidyware/turning-a-custom-gpt-action-into-an-mcp-server-a-minimal-tested-example-39n0", "published_at": "2026-11-24 11:35:26+00:00", "updated_at": "2026-11-24 11:43:50.547742+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-tools", "developer-tools"], "entities": ["Model Context Protocol", "@modelcontextprotocol/sdk", "Open-Meteo", "Claude", "OpenAI", "Upwork", "Node.js", "zod"], "also_reported_by": [], "takeaway": "MCP tools require hand-written zod inputSchema rather than OpenAPI import, and handler errors must be mapped manually to isError: true with a model-actionable message, as shown by the out-of-range latitude returning 'Too big: expected number to be <=90'.", "recommendation": {"advice": "When porting an OpenAPI Action to an MCP tool, rewrite parameters as a zod inputSchema and explicitly return isError: true with an actionable message on failures, then test both success and validation paths via a stdio client.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/turning-a-custom-gpt-action-into-an-mcp-server-a-minimal-tested-example", "markdown": "https://wpnews.pro/news/turning-a-custom-gpt-action-into-an-mcp-server-a-minimal-tested-example.md", "text": "https://wpnews.pro/news/turning-a-custom-gpt-action-into-an-mcp-server-a-minimal-tested-example.txt", "jsonld": "https://wpnews.pro/news/turning-a-custom-gpt-action-into-an-mcp-server-a-minimal-tested-example.jsonld"}}