Tips
How to build an MCP server for an API: 24 read-only tools
An MCP server wraps an API's calls in tools a model can pick from. This is how we built the one for Live Tennis API. Which endpoints became tools, why every tool only reads, and how it is published and tested.
To build an MCP server for an API, wrap the API’s read calls in tools. Describe each one so a model knows when to use it. Read the API key from the client’s config. Turn every failure into a sentence the model can act on. Then publish the server where clients look for it, and test it the way a client calls it.
We did this for Live Tennis API, a tennis data API we built. Its MCP server gives Claude, Cursor, Zed or any other MCP client 24 tools, and every one of them only reads. Here are the choices behind it, with the code they came from.
What does an MCP server add to an API?
The Model Context Protocol lets an assistant find and call tools on a server. The server lists its tools, each with a name, a description and a JSON schema for its inputs. The model reads that list and decides which tool to call, with which arguments. The server makes the API request and sends back text, structured data or both.
A REST API already has endpoints. The server adds the words a model needs to pick the right one.
Which endpoints became tools, and which didn’t?
The Live Tennis API reference lists 48 endpoints. The MCP server has 24 tools. Version 1.0.0 had 12 in July 2026. Seven more came on 3 August and five on 7 August, as the API grew.
Each tool answers a question someone would type into a chat. The server’s own examples include
“What tennis matches are live right now?” and “What’s the all-time head-to-head between Borg and
McEnroe?”. The first goes to get_live_matches, the second to get_h2h. The other tools cover
scores, players, fixtures, tournaments, the results archive from 1968 to 2022, rankings, match
statistics, market prices and the model’s analysis.
These parts of the API have no tool:
- creating and deleting webhooks, the only calls in the API that change anything
- the token for the WebSocket push feed
- the broadcast-graphics feeds
- the monthly bulk history files
- shot-by-shot rally data
The push feed and the monthly files are made for programs that stay connected or download in bulk. A tool call returns one answer to one question.
Why does every tool only read?
Every tool is a GET request, so nothing the server exposes can change any data. The two webhook calls that do change something were left out. The API behind the tools never touches orders or wallets either.
The specification lets a server label its tools with hints such as readOnlyHint and
destructiveHint. Ours sets them on every tool, and the code says why: “Every tool is a read.
Nothing here can modify anything, so these hints are simply true.”
The same specification says clients “MUST consider tool annotations to be untrusted unless they come from trusted servers”. A hint is a label. What keeps this server safe is that no tool has a write to make.
That matters more because the agent isn’t ours. It belongs to the developer, and we can’t see how it plans. We can decide what it can reach. With read-only tools, a bad plan costs a few wasted requests.
How do you describe tools so a model picks the right one?
The model chooses from names and descriptions alone. So every description in this server says
what the tool returns and which plan it needs. Several also say when to use the tool, as
get_match_score does:
server.registerTool(
'get_match_score',
{
title: 'Match score',
description:
'Current score for one match — the fastest, lowest-latency read. Use this when ' +
'you only need the score and already know the match id.' +
' Works on the FREE plan (no card needed).',
inputSchema: { match_id: matchIdField },
outputSchema: { ok: okField, message: messageField, score: /* … */ },
annotations: READ_ONLY,
},
({ match_id }) => guard(async () => { /* client.getMatchScore(match_id) … */ }),
)
Inputs name the tool that produces them. The match_id field reads “Match id, as returned by
get_live_matches, get_upcoming_matches or get_recent_results.” Outputs point the other way. A
match’s id says “Pass to get_match, get_match_score, get_match_events or get_match_odds.” The
model can chain calls without guessing an id.
Since version 1.5.0, every match row also says whether a model analysis and a market exist for it.
The descriptions of get_match_analysis and get_match_odds tell the model to check those two
fields first. On a full day’s schedule, that saves one empty call per match.
How should the server report errors?
As sentences the model can act on. The API answers a request above your plan with a bare 403. The server’s README says what a model does with that: “Handed that, a model will usually invent a reason or retry pointlessly.”
So a plan wall comes back as a normal result that names the plan needed and where to upgrade. The code marks it as a result on purpose. Marked as an error, it tends to make a client retry or give up, and the user never hears which plan would work.
Rate limits come in three kinds, and each gets its own message. Over the per-minute limit, the message says how many seconds to wait. At the daily cap it gives the exact reset time and says a retry can’t succeed before then. After an abuse block it says not to retry at all.
A player name that matches two people returns both names, so the model can ask which one was
meant. Without a key, every tool says where to set one and where to get a free one. And
check_api_status reports whether the API answers and which plan the key is on.
How does the server handle API keys?
It runs in two places, and each gets the key from somewhere else.
Run locally with npx livetennisapi-mcp, it reads LIVETENNISAPI_KEY from the client’s config.
The key is kept on the developer’s machine and sent only to api.livetennisapi.com.
The hosted endpoint, https://mcp.livetennisapi.com/mcp, serves anyone who calls it, so it holds no
key of its own. Every request builds a new server bound to the key that request sent, as a bearer
token or an X-API-Key header. The transport keeps no sessions, so no caller can be handed
another’s server.
There is no fallback to a key in the environment. The code’s comment explains why: a hosted server built that way “serves every anonymous caller on the operator’s key, at the operator’s tier”.
The endpoint’s own rate limit allows 300 requests a minute with a key and 60 without. It counts per key, so two users behind one office network don’t slow each other down. The key is hashed before it goes into the counter, so a customer’s credential never sits in memory dumps or log lines. Callers with no key are counted by address.
How do you publish it to npm and the MCP Registry?
The package is on npm as livetennisapi-mcp, so npx -y livetennisapi-mcp fetches and runs it in
one step. Releases publish from CI with npm’s
trusted publishing, so there is no npm token to leak
or rotate. Every release since 1.0.1 carries a signed provenance attestation. Version 1.0.0 went up
by hand, because npm needs a package to exist before trusted publishing can be set up for it.
The same CI job lists the server in the official
MCP Registry as
io.github.livetennisapi/livetennisapi-mcp. Ownership is proven by two names that match:
mcpName in package.json and name in server.json. The publisher logs in with the CI job’s own
identity token, so that step stores no secret either.
Keep the version numbers in step. The server reports its version to every client that connects. Ours drifted once: the Registry and bundle files said 1.0.4 and 1.2.2 while the package was at 1.2.3. CI now fails if the version in the source and in package.json disagree.
How do you test an MCP server?
Over the protocol, the way a client uses it. Our protocol test starts the built server with no API key. Then it sends what a client sends: initialize, a list of tools, a tool call, then the resource and prompt lists. It fails if any of the 24 tool names is missing or a tool has no description. It also fails if a call made with no key at all comes back as an error.
A second test calls every tool twice, once without a key and once against a stub of the API. Each tool declares an output schema, and the MCP SDK then throws on a normal result with no structured content. A plan wall, a missing key and an empty result are all normal results here. One shared function adds the structured half to every one of them, so no single tool can forget it.
The third check tests the tests. A mutation script puts back each bug the tests claim to catch and expects the suite to fail. The README says why it exists: “the first version of the rate-limit test passed while the limiter was bucketing every caller together.”
One more check is about the package itself. It runs through npx, so a broken first line breaks every install. A duplicated shebang line shipped once, and CI now counts them.
Then try it in a real client. In Claude Code it is one command:
claude mcp add livetennis -e LIVETENNISAPI_KEY=twjp_… -- npx -y livetennisapi-mcp
Ask “What tennis matches are live right now?” and the model should call get_live_matches. A free
key is enough for that, and the reference says which
plan each tool needs.
Where to start with your own API
Write down the questions your users would type. Map each one to a single read endpoint, and leave anything that writes out of the first version. Then spend the time on the descriptions and the error messages, because those are what the model reads.
The Live Tennis API case study covers the rest of that product. Want a server like this built for your API? It is part of our work on agents that act in your systems. Our other public tools are on the open source page.