Running an MCP server over a 109-model gateway
An MCP server is the least glamorous part of an LLM stack and the one most likely to be written badly, because it looks like plumbing: expose a few tools, return strings, done.
Here is what it actually took to put an MCP server in front of a gateway that routes 109 models, and the three decisions that mattered.
Decision 1: keep the tool surface tiny
The tempting move is one tool per model, so the assistant can "choose gpt-4o-mini" explicitly. That fails for a mechanical reason: a tool list with 109 entries consumes context on every turn, and model selection by tool name is a bad use of a language model.
Three tools were enough:
list_models- what can this key call, with pricing and capabilitieschat- model + messages, non-streaming, returns text plus usagecheck_compatibility- four probes against the configured base URL, returns a pass/fail report
Everything else - price comparison, capability questions, "which model is cheaper" - is a query over list_models, not a new tool. Fewer tools means fewer failure modes and a much smaller system prompt.
Decision 2: stdio, not hosted, for the first version
A stdio server distributed as npx -y longai-mcp works everywhere: Claude Desktop, Claude Code, Cursor, Codex, VS Code. No endpoint to secure, no OAuth flow, no uptime to promise.
The trade-off is honest: no remote clients, no shared deployment. A hosted Streamable HTTP variant is a different product with a different support burden, and most MCP directories that list remote servers require a live endpoint that answers initialize - which is a commitment you should make deliberately, not by accident.
{
"mcpServers": {
"longai": {
"command": "npx",
"args": ["-y", "longai-mcp"],
"env": {
"LONGAI_API_KEY": "sk-..."
}
}
}
}
That config is the entire onboarding. The key stays in the client's env, never in the server's code.
Decision 3: return text, but make it boring
Tool results are read by a model, so the shape matters as much as the content:
- one compact block, not pretty-printed JSON with 40 lines of indentation
- explicit units ("$0.15 per 1M input tokens", never "0.15")
- a stable order, so an assistant that compares two calls sees the same fields in the same place
- failures returned as
isError: truewith the upstream body quoted, not swallowed into a friendly sentence
That last point is the one that saves support time. A 429 from a specific upstream seller, quoted verbatim, is actionable. "Something went wrong" is not.
What the gateway adds to the MCP layer
The server holds no model list of its own. It asks the gateway: GET /v1/models, then POST /v1/chat/completions. So a model added upstream appears in the MCP tool output without a release, and a model retired disappears the same way.
The one thing that must not be lazy is auth failure. If the key is missing or rejected, the tool should say exactly that, in one line, because the alternative is a model apologising to the user on behalf of your infrastructure.
Distribution is part of the design
The server ships a server.json for the official MCP Registry, publishes to npm as longai-mcp, and is listed in a couple of third-party indexes. Each listing is a different kind of maintenance: registries want a server.json, directories want a description under 80 characters, and awesome-lists want a public repository with a license file.
None of it is hard; all of it is easy to get subtly wrong, which is why the repository carries the license and the install instructions rather than a link to a docs site.
If you are building one of these for your own gateway, start with three tools and stdio, and resist the fourth tool for at least a month. I maintain LONG AI, a gateway over 109 models, and the MCP server described here. The model catalog the tools read from is the model plaza.
Comments
No comments yet. Start the discussion.