- Calls
tools/listonhttps://mcp.ngrok.aito get every tool the access key may call, with itsinputSchemaandoutputSchema. - Generates TypeScript declarations from those schemas, so the model writes typed calls and the harness can typecheck the script before it runs.
- Gives the script one function,
callTool(name, args), that sends one statelesstools/callrequest per call.
What you’ll need
- An access key whose access key configuration allows the MCP servers and tools the script should reach. See Control tool access.
- At least one MCP server registered in MCP Gateway.
- Node.js 22 or later.
Send stateless calls
MCP protocol version2026-07-28 needs no initialize request and no session.
Each request is one POST https://mcp.ngrok.ai/ that carries everything the gateway needs:
The headers must match the body.
A mismatch returns HTTP 400 with JSON-RPC error
-32020, such as Mcp-Name must match params.name.
The Accept header above returns JSON for every method.
When application/json and text/event-stream have equal weight, the gateway streams tools/call results as server-sent events, which a script then has to parse.
<label>__<tool>, with the upstream descriptor unchanged.
That includes inputSchema, outputSchema when the upstream declares one, and annotations.
tools/list is free and returns the full catalog in one response, with no pagination.
Example harness
This TypeScript file lists the tools, writes their declarations tomcp-tools.d.ts, and runs a script with parallel calls.
It uses json-schema-to-typescript for the type generation.
codemode.ts.
The script at the end calls docs__search from the setup example; change it to a tool your key can call.
codemode.ts
Wrote types for <n> tools to mcp-tools.d.ts.
Each tool becomes a declaration like this one, which the harness shows to the model and typechecks scripts against:
{ q: "oauth" } fails the typecheck with Property 'query' is missing, before any call reaches the gateway.
A tool without an outputSchema returns unknown, so the script has to inspect its content blocks.
Run calls in parallel
EachcallTool is an independent HTTPS request, so Promise.all sends them at the same time.
The script’s wall time is close to its slowest call, not the sum of all of them.
Don’t use JSON-RPC batches for Code Mode.
The gateway accepts batches only on protocol version 2025-03-26, runs the items one after another, and limits a batch to 16 items.
Handle errors and cost
- A tool that fails returns a result with
isError: true, which the example turns into a thrown error.Promise.allrejects on the first one; usePromise.allSettledwhen the script should keep the other results. - A denied tool returns JSON-RPC error
-32003, and an account with no credits returns HTTP 402. See Control tool access and Pricing. - Every completed
tools/callis one billable operation, including anisErrorresult. A script that loops over a tool bills each iteration. - Each call can run up to the server’s call timeout. See Limits.
- Each call appears as its own request in Activity under MCP calls.
Use Claude Code’s Code Mode
Claude Code’s Code Mode is experimental and off by default. With it on, Claude writes JavaScript that calls MCP tools by name, so the tools of an MCP Gateway you added withclaude mcp add work in that code like any other MCP server’s tools.
Claude Code does the type generation and the calls itself; you don’t need the harness on this page.