Skip to content
Building MCP Servers: What I Learned the Hard Way

Building MCP Servers: What I Learned the Hard Way

·By Yogimathius·4 min read
mcpai-toolingdeveloper-experiencetypescriptprotocol-designsecurity

Updated November 2026: This revision corrects the authorization roles in the dated MCP specifications and omits unverified first-person development history, throughput, server-count, token-cost, and vulnerability claims.

MCP lets an AI application use tools and read resources through a common protocol. That sounds simple until a tool has real authority: a file it can read, an action it can take, or data it can expose. The useful lesson is to design those boundaries before celebrating the connection.

The Protocol Is Simpler Than Its Consequences

MCP uses JSON-RPC messages. Servers can expose tools, resources, and prompts. A client decides how to present them to a model and how to govern calls. A tool description is part of the interface, but it is not a permission grant. The server must still validate arguments and enforce authority at execution time.

Do not expose an API one endpoint at a time

Design tools around clear tasks and permissions. A large catalog can consume context and make authorization hard to audit. A single catch-all tool can hide equally important distinctions. Choose the smallest interface that remains legible to both the agent and the human reviewing its actions.

Keep stdio Clean

In a stdio transport, protocol messages use stdout. Diagnostic output belongs on stderr; a stray console.log(), print(), or println!() can corrupt the stream. Make this a logging convention and test the server with an MCP client or Inspector. This is a transport rule, not a benchmark claim.

Start with observable failures

Use stderr for diagnostics, return structured tool errors, and test malformed arguments as carefully as successful calls. A useful error tells the agent what failed without exposing secrets or internal paths.

Choosing an SDK

TypeScript, Python, and Rust SDKs offer different development ergonomics. Choose one that fits your team's language, deployment environment, and security review. The original table compared undocumented request rates and release states; those figures are omitted here.

SDK choiceUseful strengthCheck before deployment
TypeScriptSchemas and integration with web applicationsRuntime, transport, validation, and auth configuration
PythonQuick tool and data-service prototypingConcurrency, dependency isolation, and schema behavior
RustExplicit types and controlled resource useSDK maturity and integration effort

The Tool Catalog Trap

Every tool definition has a context cost, but there is no universal token count per tool. Measure the catalog in the client you actually use. Expose only tools that are needed, and consider discovery or scoped catalogs for larger systems.

The original article proposed one operation-enum tool to replace many tools. That can shrink a visible catalog, but it can also concentrate permissions behind a broad interface. Preserve explicit input schemas and action-level authorization. The best abstraction is the one a human can inspect and revoke.

OAuth: Resource Server and Authorization Server Are Different Roles

The June 18, 2025 MCP authorization specification describes a protected HTTP MCP server as an OAuth resource server. The authorization server issues access tokens and may be hosted separately. The MCP server does not have to implement both roles.

The protected MCP server publishes OAuth Protected Resource Metadata, including its authorization-server location. A client discovers the authorization server's metadata, obtains a token through the applicable OAuth flow, and presents that token to the MCP server. The server validates it before handling the request, including that it was issued for this resource as its intended audience. It must reject invalid or expired tokens and must not pass a client's token through to another API. If the MCP server calls an upstream API, that call needs its own appropriate authorization.

The November 25, 2025 specification retains these roles and adds more client-registration options. It says authorization is optional for MCP implementations; when HTTP authorization is used, follow its protected-resource discovery and token requirements. Stdio uses a different credential model. Neither version says every networked MCP server must run its own token endpoint.

Audience is an authorization boundary

A valid token for another service is not a valid token for this MCP server. Validate issuer, expiry, audience, and relevant scopes; prevent token passthrough; and keep consent and least privilege visible.

Design for the Agent and the Human

A tool description should say what the action does and what authority it needs. A human needs to know what happened, which source was used, and whether the action can be reversed. This is where protocol correctness meets stewardship: the model may propose a call, but the system must keep responsibility legible.

The lasting infrastructure opportunity is in secure discovery, narrow permissions, verification, and audit trails. Tool count, downloads, and fashionable orchestration patterns are poor substitutes for those properties.

Sources

Stay in the loop

New posts by email. No noise.