# Turning a Custom GPT Action into an MCP server: a minimal tested example

> Source: <https://dev.to/tidyware/turning-a-custom-gpt-action-into-an-mcp-server-a-minimal-tested-example-39n0>
> Published: 2026-11-24 11:35:26+00:00

**Recommendation:** 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.
More in the playbook "Designing agent systems": <https://wpnews.pro/playbooks/agent-architecture>

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).

| 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) | 

Operation being moved: `GET /v1/forecast?latitude=..&longitude=..¤t_weather=true` (Open-Meteo, no key needed).

``` js
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=..&current_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}&current_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());
```

A client that connects over stdio, lists tools, and calls the tool twice:

``` js
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:

`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.
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").
