Blog6 min read
How to build an MCP server, and when you need one
How to build an MCP server: tools, resources and transports in the Model Context Protocol, testing it, and the security points. Learn when you need one.
By Ali Hassan, Senior engineer for SaaS and AI products
An MCP server is a small program that hands your tools and data to an AI app through one open protocol, so you build the connection once instead of once per client. This post is a plain walk through how to build MCP server tooling: the parts it exposes, the two transports, a short working example, how to test it, the security the spec asks for, and when a plain tool call does the job better. I read the spec dated 2026-07-28 for this.
What is the Model Context Protocol?
The Model Context Protocol, or MCP, is an open standard for connecting AI apps to outside tools and data. It carries JSON-RPC 2.0 messages between three roles: a host, which is the AI app; a client inside that host; and a server, which is the part you write. Build one server and every MCP-aware app can reach your tools, instead of a fresh integration per product.
The protocol is defined in the MCP specification, which is based on a published TypeScript schema. The version I read for this post is dated 2026-07-28. The idea is close to the Language Server Protocol: agree on one way to plug in, and the whole ecosystem can share it.
What parts does an MCP server expose?
An MCP server offers three kinds of thing. Tools are functions the model can call, like sending an email or querying a database. Resources are read-only data the app or model can load, like a file or a record. Prompts are reusable message templates a user can pick. Most servers start with tools alone and add the other two only when they help.
Tools are the usual starting point. In an AI-powered chat-with-PDF app I built, a search over the user's own documents is exactly the kind of function a tool wraps. Resources and prompts are optional: add a resource when the app should load your data directly, and a prompt when you want to ship a ready-made way to ask. The SDK v2 documentation shows how to register all three feature types, and the 2026-07-28 spec defines what each one means.
stdio or Streamable HTTP: which transport?
An MCP server talks to its client over a transport, and there are two. stdio runs the server as a local subprocess: the app starts your program and they exchange messages over standard input and output. Streamable HTTP runs the server as a web service the app calls over the network. Use stdio for a local tool on your own machine, and Streamable HTTP when the server lives somewhere else or is shared.
The official TypeScript SDK ships both, and the 2026-07-28 spec defines how each one frames its messages. stdio is the simplest to start with, because there is no network, no port, and no auth to set up first.
How do you build an MCP server?
People search for how to build MCP server code and expect a wall of setup. It is four steps. Install the SDK for your language. Create a server object with a name and version. Register each tool with a description and an input schema, plus the function that runs when the model calls it. Then connect a transport and start the process. Here is a minimal server in TypeScript that exposes one greet tool over stdio.
import { McpServer } from "@modelcontextprotocol/server";
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
import * as z from "zod/v4";
const server = new McpServer({ name: "greeting-server", version: "1.0.0" });
server.registerTool(
"greet",
{ description: "Greet someone by name", inputSchema: z.object({ name: z.string() }) },
async ({ name }) => ({ content: [{ type: "text", text: `Hello, ${name}!` }] }),
);
const transport = new StdioServerTransport();
await server.connect(transport);
That is the whole server. The example is condensed from the official TypeScript SDK README, whose v2 line targets the 2026-07-28 spec. The input schema matters most: it is the contract the model reads to know how to call your tool, so write clear field names and descriptions.
How do you test it with the MCP Inspector?
Before you wire the server into an app, test it on its own with the MCP Inspector, the reference tool for this. Run it with npx and point it at your server. It lists the tools your server exposes, lets you call each one with sample input, and shows the raw messages that go back and forth. You see what the model would see, without the model in the way.
The MCP Inspector ships as one package you run with npx @modelcontextprotocol/inspector. The Inspector's repository is on GitHub, and it offers a browser interface, a command-line client for scripts, and a terminal interface, so it fits both a quick check and a test in continuous integration.
What security does the MCP spec ask for?
The spec treats a tool as arbitrary code execution, so it puts the user in charge. Its security principles say users must explicitly consent to and understand all data access and operations, and that a host must obtain explicit user consent before invoking any tool. The protocol cannot enforce this itself, so the app around your server has to build the consent and approval flow.
The MCP specification sets this out in its 2026-07-28 security section. For a server exposed over HTTP, it also defines an authorization scheme built on OAuth, and the official SDK ships auth helpers for it. One more rule worth heeding: treat a tool description from a server you do not control as untrusted input, not as a trusted instruction.
When is an MCP server overkill?
An MCP server is overkill when only one app will ever use your tools. If your agent calls functions that live in the same codebase, a plain function call is simpler, faster, and has nothing to secure over a transport. A separate server adds a process, a protocol, and a round trip. That cost pays off when the same tools must serve several apps, or go to people outside your team.
Anthropic's advice in Building effective agents is to start with the simplest thing that works and add moving parts only when they earn it. In 2026 that still means a direct tool call first, and MCP once you need to share. The tools themselves are one piece of a wider AI agent architecture, the same control problem behind agentic RAG.
When should you bring in help?
If you are weighing an MCP server against a plain tool call, or you have one that works locally but not once it is remote and shared, that is the kind of thing I sort out. The hard parts are rarely the first tool; they are auth, consent, and keeping a server safe when other people's apps connect to it.
I build AI features and the servers behind them, and I will tell you when a server is the wrong tool for the job. You can see the shape of that on AI product build. The spec this post follows is dated 2026-07-28, current in late 2026, and the example above comes straight from the official SDK.


