Your Second MCP Server: Validation, Errors, Auth and Versioning That Survive Real Use
13 November 2026 · Updated 28 November 2026 · 11 min read · by Yang Kai
Your first MCP server worked in a demo. Your second has to survive bad input, real users and updates — here is the production-readiness pattern.
Checklist inside: Production-readiness checklist + error-handling code pattern
Contents
Your first MCP server is a magic trick. You expose one tool, the model calls it, something useful happens, and it feels like the hard part is over.
Then someone else tries it. They pass an empty string where a path should be, call the tool twice at once, or use an older client sending parameters in a shape you stopped supporting. Nothing crashes loudly — the server just returns nonsense, silently, and the model reports it with confidence.
This article is the production-readiness pattern that closes that gap: validate at the boundary, treat errors as part of the interface, add authentication in proportion to the risk, and version your tools like a public API. It assumes you have a working first server — if you followed Build Your First MCP Server, you already have the transport, tool registration, and a happy path. Everything here is about what surrounds that happy path.
The short version — the four upgrades a second server needs:
| Upgrade | The demo habit it replaces | What breaks without it |
|---|---|---|
| Schema validation at the boundary | Trusting the arguments the model sends | Garbage input reaches your logic and returns plausible nonsense |
| Structured errors with hints | Throwing, or returning empty results | The model retries blindly or reports failure as “nothing found” |
| Auth proportionate to exposure | Whatever the machine happens to allow | Anyone who can reach an HTTP server can run its tools |
| Tool schemas under versioning | Renaming and reshaping tools freely | Every existing user’s workflow breaks on your next release |
Why the second server is a different job
A demo server has one user who knows what the tools expect: you. A shared server has users who will explore its edges accidentally.
Three things change. First, input can no longer be trusted, including input from a model. Models hallucinate arguments, omit optional fields, and pass plausible-looking paths that do not exist. Second, errors stop being debugging aids and become instructions for the caller. A vague error produces a vague retry; a precise error often produces a self-correction. Third, you are now maintaining something. Once a tool name and schema are in someone’s workflow, changing them casually breaks that workflow.
None of that is visible in a demo. All of it is visible in the first week of real use.
Validate at the boundary, not in the tool
The most common mistake in second servers is validation scattered inside tool logic: a null check here, a parseInt there, a quiet fallback to a default. The result is inconsistent behaviour that is almost impossible to test.
Validate everything in one place, at the point the request arrives, with a schema. In TypeScript, that usually means a Zod schema per tool that both documents and enforces the input — the shape the TypeScript starter server already uses with registerTool. If validation fails, the tool body should never run.
Be specific about what “valid” means:
- A string is not a file path. Check ranges, lengths, and enum values, not just types.
- For anything touching the filesystem or network, confirm the target sits inside the places this server is allowed to touch. An allowlist is safer than a blocklist of things you remembered to forbid.
- Decide what you do with extra fields. Strict schemas that reject unknown properties catch hallucinated arguments early; lenient ones hide bugs. For shared servers, strict wins.
The Python side of the ecosystem makes the same point from the other direction: the Python server tutorial builds its whole safety model out of one boundary check — reduce the input to a bare file name, resolve it, and confirm it lives inside the allowed folder before reading a byte.
Errors are part of the interface
A tool error has two audiences: the human reading logs later, and the model deciding what to do next. Write for both.
That means errors should be structured, stable, and honest. Never return a success-shaped result for a failure — a tool that returns an empty list when the underlying API actually failed teaches the model to report “nothing found” with confidence. Never leak a raw stack trace or an internal path to the caller either; log the detail server-side, and return a clean category with a short, actionable message.
Here is the pattern worth copying into every server:
type ToolErrorCode =
| "INVALID_INPUT"
| "NOT_FOUND"
| "PERMISSION_DENIED"
| "UPSTREAM_FAILED"
| "RATE_LIMITED";
function toolError(code: ToolErrorCode, message: string, hint?: string) {
// Full detail goes to the server log, not to the caller.
console.error(`[${code}] ${message}`);
return {
isError: true,
content: [
{
type: "text" as const,
text: JSON.stringify({ error: code, message, hint }),
},
],
};
}
// Inside a tool handler:
try {
const result = await doTheWork(input);
return { content: [{ type: "text", text: JSON.stringify(result) }] };
} catch (err) {
if (err instanceof NotFoundError) {
return toolError("NOT_FOUND", "That record does not exist.", "Check the ID and try again.");
}
return toolError("UPSTREAM_FAILED", "The upstream service did not respond.", "Retry in a few seconds.");
}
Two details in that shape matter. The isError: true flag is what makes the client treat the result as a failed call rather than data — an error message returned as an ordinary result can be quoted by the model as if it were the answer. And the hint field is the highest-value line in the pattern: “file not found” makes a model guess, while “file not found — check the path is relative to the project root” makes it fix the call.
Keep the error codes few and stable. Callers, tests, and your own habits will start to depend on them, which is exactly the point.
One error-adjacent habit belongs here too: assume calls repeat. Models retry after timeouts, users double-click, and clients reconnect — so a tool that creates, sends, or charges can be invoked twice with the same intent. Read-only tools get this for free. For anything that changes state, accept a caller-supplied ID or key for the operation and make the second identical call return the first call’s result instead of doing the work again. It is a small schema addition, and it is far easier to add before the first duplicate incident than after.
Auth basics, proportionate to the server
Not every server needs authentication. A local, stdio-only server that only you run, on your own machine, inherits your machine’s security — adding a login flow to it adds friction without adding protection.
Auth starts to matter the moment any of these are true: the server runs over HTTP, it is reachable by anyone other than you, it holds credentials for other services, or it can spend money or change data. At that point, the minimum viable posture is straightforward:
- Put a real credential on the transport — a bearer token or API key at minimum — and reject unauthenticated requests before any tool runs.
- For a remote server other people connect to, expect the protocol’s OAuth-based authorisation flow rather than a shared static token; MCP auth explained walks through how that flow works and where it stops.
- Store secrets in environment variables or a secret manager, never in the repo, never in the tool schema, and never in logs.
- Give the server its own scoped credentials for upstream services. If your server talks to a database, it should use an account that can only do what its tools need — read-only where read-only is enough.
- Rotate any credential that has ever appeared in a log, a screenshot, or a chat transcript. Treat appearance as compromise.
If you are exposing tools that write, delete, or pay, read MCP in Production alongside this — the operational habits there (logging, limits, kill switches) are the other half of this picture.
Publishing and versioning without breaking people
Discoverability is no longer the hard part — the official registry and the public directories list thousands of servers between them. Trust is the scarce part, and a clear version history is one of the cheapest trust signals you can publish.
Practical versioning for a solo builder looks like this. Use semantic versioning for the server package, and treat tool schemas as your public API: adding an optional parameter is a minor change; removing or renaming a tool or a required parameter is a major one. When you must make a breaking change, ship the new tool alongside the old one for a release, mark the old one deprecated in its description, and only then remove it. Models read descriptions — a deprecation note there genuinely reaches your users.
Versioning has a second layer in 2026: the protocol itself. The 2026-07-28 specification revision made MCP stateless and retired the connection handshake, and the current SDKs serve both that revision and the 2025-era one. Pin your SDK version, state which protocol revisions and client versions you tested against, and bump deliberately — “latest” is not a version your users can plan around.
Publish with a README that states what each tool does, what it can access, and what credentials it needs. That document is also your security disclosure, and it connects directly to the habits in the MCP security checklist: a server that is honest about its permissions is one people can safely install. It is also what a listing in the MCP Registry surfaces to anyone deciding whether to trust your server.
Finally, pin your own dependencies and test against the client versions you claim to support. “Works on my machine” is a demo standard, not a publishing standard.
The production-readiness checklist
Run through this before you call a server done:
- Every tool input is validated by a schema at the boundary; invalid input never reaches tool logic
- Filesystem and network access is limited to an explicit allowlist
- Errors use a small, stable set of codes, with a human message and a fix-it hint
- Failures are flagged as errors, never returned as success-shaped empty results
- Stack traces and internal paths are logged server-side only, never returned
- Secrets live in environment variables; none appear in the repo, schemas, or logs
- Upstream credentials are scoped to the least access the tools need
- HTTP transports require authentication before any tool executes
- Tool names and required parameters are treated as a public API under semantic versioning
- Breaking changes ship with a deprecation period, noted in the tool description
- README states each tool’s purpose, access, and required credentials
- You have tested: empty input, wrong types, a missing file, an upstream outage, and a duplicate call
How we researched this
The pattern in this article is assembled from the MCP specification’s own contracts — schema-validated tool calls, error results flagged with isError, the authorisation flow for HTTP servers — and the current SDK documentation, checked November 2026, including the protocol’s 2026-07-28 revision notes. meetBlogging is a desk-research site: nothing here rests on a server we shipped, and the checklist is written so you can run it against any server, including ours.
What to do next
Run the checklist against your first server honestly. Most demo servers fail half of it. Fix validation and error shape first — those two change how the server behaves on its worst day, not its best. Then browse MCP servers worth installing and apply the checklist in reverse to judge other people’s servers.
Before a server like this goes live, run it through testing MCP servers — the failure-injection pass — and if it will be shared, hosting MCP servers decides where it should run.
FAQ
Why does the second server need so much more rigour than the first? Because the first usually serves one user — you, watching it. The second gets real callers, real bad input, and updates after people depend on it. Every item in this article’s checklist traces to one of those three changes.
What is the most important error-handling rule? Errors must say what failed and what to try instead, in the response itself — and they must be flagged as errors, not returned as ordinary results. An agent reading “invalid input” retries blindly; an agent reading “date must be YYYY-MM-DD” fixes its call in one step.
How should I version my server’s tools? Additively, for as long as you can: new optional parameters and new tools are safe; renamed tools and changed meanings are breaking changes that need a version bump, a deprecation period, and a migration note in the tool description. The versioning section shows the pattern.
Should my server validate input if the agent is ‘careful’?
Yes — agents are probabilistic callers. They will eventually send the empty string, the wrong type, and the path with ../ in it. Validation is not distrust; it is the contract that makes the tool callable at all.
Does the 2026 protocol revision change any of this? It changes the transport layer, not the discipline. The 2026-07-28 revision removed sessions and the handshake, and current SDKs serve both eras — which makes pinning your SDK and naming the client versions you tested against part of the versioning job, as the publishing section covers.
Category: MCP Servers & Security · Tags: #mcp #typescript #ai-coding
Next step: this article is part of MCP guides, which covers the full topic from first setup to advanced use.