Turning a Custom GPT Action into an MCP server: a minimal tested example
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.
Setup: npm i @modelcontextprotocol/sdk zod, save the server as server.mjs and the test client as test.mjs (both ES modules).
What maps to what
| Custom GPT Action (OpenAPI) | MCP server |
|---|---|
operationId | tool name |
summary / description | tool description (the model reads this to decide when to call it) |
| parameters + request schema | inputSchema: a zod shape you write by hand (no OpenAPI import) |
| HTTP error response | you map it to isError: true yourself, with a message the model can act on |
| API key / OAuth in the Action | your server's own auth (not shown here) |
The server
Operation being moved: GET /v1/forecast?latitude=..&longitude=..¤t_weather=true (Open-Meteo, no key needed).
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { z } from "zod"; const server = new McpServer({ name: "weather-actions", version: "1.0.0" }); // OpenAPI operation: GET /v1/forecast?latitude=..&longitude=..¤t_weather=true (operationId: getCurrentWeather) server.registerTool( "get_current_weather", { description: "Current temperature (°C) and wind speed (km/h) for a latitude/longitude.", inputSchema: { latitude: z.number().min(-90).max(90), longitude: z.number().min(-180).max(180) }, }, async ({ latitude, longitude }) => { const url = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t_weather=true`; const res = await fetch(url); if (!res.ok) { return { isError: true, content: [{ type: "text", text: `Weather API returned ${res.status}. Check the coordinates and retry.` }] }; } const { current_weather: w } = await res.json(); return { content: [{ type: "text", text: JSON.stringify({ temperature_c: w.temperature, windspeed_kmh: w.windspeed }) }] }; } ); await server.connect(new StdioServerTransport()); How I checked it
A client that connects over stdio, lists tools, and calls the tool twice:
import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; const c = new Client({ name: "t", version: "1" }); await c.connect(new StdioClientTransport({ command: "node", args: ["server.mjs"] })); console.log(JSON.stringify((await c.listTools()).tools.map(t=>({name:t.name,required:t.inputSchema.required})))); console.log(JSON.stringify(await c.callTool({ name: "get_current_weather", arguments: { latitude: 52.52, longitude: 13.41 } }))); console.log(JSON.stringify(await c.callTool({ name: "get_current_weather", arguments: { latitude: 999, longitude: 0 } })).slice(0,200)); await c.close(); Results:
-
listToolsreturned one tool,get_current_weather, withlatitudeandlongituderequired. - Calling it with Berlin coordinates returned
{"temperature_c":2.6,"windspeed_kmh":9}. - Calling it with latitude 999 was rejected by the SDK's schema validation, returned as
isError: true:Too big: expected number to be <=90 at latitude. The!res.okbranch in the handler is not covered by this test, and network failures (a thrownfetch) are not handled.
Things that differ from an Action
- Descriptions matter more. A GPT is configured from your OpenAPI schema. With MCP the model typically sees only tool names, descriptions and argument schemas, so write them like documentation for a new colleague.
- Errors are part of the contract. Return
isError: truewith a plain sentence saying what to fix. A raw stack trace makes the model guess. - Auth moves to your server. With API-key auth, an Action keeps the key in the GPT editor. An MCP server holds it in its environment, or uses OAuth when it is exposed over HTTP.
- I tested this with an MCP client only, not with ChatGPT. Check OpenAI's current documentation for what your plan and workspace allow before promising anything to your users.
Checklist before you ship
- One MCP tool per operation you want the model to use. Skip the rest.
- Each tool has a one-sentence description starting with a verb.
- Bad input returns an actionable message.
If 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").