How to build an MCP server: 7 steps from the first tool to production

Building an MCP server takes seven steps. Pick the tasks an AI assistant should do in your system, choose an official SDK, and write one tool per task with a clear description and an input schema. Run the server over stdio on the user's computer or over Streamable HTTP as a web service, add OAuth for a remote server, test it with the MCP Inspector and real AI applications, then deploy and maintain it like any other API.
The steps and code examples follow the current revision of the Model Context Protocol, 2026-07-28, and the official TypeScript and Python SDKs. If you are still deciding whether your product needs a server, start with what an MCP server is and when you need one.
What you need before you start
An MCP server wraps functions that already exist, so much of the preparation happens outside the protocol. Before the first line of code, check these four things:
- An API or a data source. The server calls your product's API, a database, or files. If the system has no API for a task, building that API is a separate project that comes first.
- A list of tasks. Write down what users will ask the assistant to do, such as “find an order” or “create a ticket”. These tasks become your tools.
- The users. Your own developers can run a local server on their computers. Customers or a whole company need a remote server with sign-in.
- A language. Use the language of the team that owns the system the server connects to.
Step 1: Pick the tasks and design the tools
Each tool should match one task from your list, not one API endpoint. A tool has a name, a description that tells the model when to use it, and an input schema that lists its parameters. The model chooses tools by reading their descriptions, so a vague description leads to wrong calls even when the code is correct.

- Keep the list short. Every tool description takes space in the model's context, and similar tools make a wrong choice more likely. Start with three to five tools for the most common tasks.
- Separate reading from changing. A tool that looks up an order and a tool that refunds it need different permission checks, and an AI application may ask the user to confirm the second one.
- Return errors the model can fix. The tools specification reports a failed call as a normal result with
isError: trueand a message such as “the date must be in the future”, so the model can correct its input and try again. - Use a stable order. The specification asks servers to return the list of tools in the same order every time, which lets clients cache it.
Tools are one of three kinds of capability a server can offer. The other two, resources for data and prompts for ready-made instructions, are useful later; a first business server usually needs tools only.
Step 2: Choose an SDK
Use an official SDK: it handles the protocol messages, schema validation, and transports, so your code only describes tools and calls your system. The MCP project groups its official SDKs into tiers by feature completeness and maintenance commitment.
| Tier | Languages | When to choose |
|---|---|---|
| Tier 1 | TypeScript, Python, C#, Go, Rust, Ruby | The default choice for a production server |
| Tier 2 | Java | When the system and the team already run on Java |
| Tier 3 | Swift, PHP, Kotlin | After you check in its documentation that the SDK supports the features you need |
The SDKs adopt new protocol revisions on their own schedules, so check which revision your SDK supports. In TypeScript, the stable v2 line implements the 2026-07-28 revision and ships as two packages, @modelcontextprotocol/server and @modelcontextprotocol/client. Many tutorials still use the older @modelcontextprotocol/sdk package: that is v1, which gets bug fixes and security updates for at least six months after the v2 release on July 27, 2026. A new server should start on v2.
Step 3: Write a first server
A first server registers one tool and connects a transport. This minimal TypeScript example follows the SDK's first-server tutorial: a factory function builds a server with a greet tool, and serveStdio serves it over stdio. The input schema uses Zod, and the SDK also accepts other schema libraries such as Valibot and ArkType.
import { McpServer } from '@modelcontextprotocol/server';
import { serveStdio } from '@modelcontextprotocol/server/stdio';
import * as z from 'zod/v4';
function createServer(): McpServer {
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}!` }]
})
);
return server;
}
void serveStdio(createServer);Many tutorials still end with server.connect(new StdioServerTransport()). According to the SDK's protocol versions guide, that line serves only clients of the 2025 revisions, while serveStdio serves both.
The Python SDK needs Python 3.11 or newer and builds the input schema from type hints, so a tool is an ordinary function. This is the start of its own example:
from mcp.server import MCPServer
mcp = MCPServer("Demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + bIn a real server, the body of the tool calls your API, checks the result, and returns text the model can use. From the first day, a stdio server must not print anything to standard output except protocol messages, because the client reads them from there. Write logs to standard error, for example with console.error() in Node.js or the logging module in Python.
Step 4: Choose stdio or Streamable HTTP
Choose stdio for a server that runs on the user's own computer and Streamable HTTP for a server that runs on the web for many users. The specification defines both, and the protocol messages are the same on each, so the tool code does not change.
| Transport | How it runs | Credentials | Typical use |
|---|---|---|---|
| stdio | The AI application starts the server as a process and exchanges messages through its input and output | From the local environment, such as an API key in a variable | Developer tools, file access, internal tools for one team |
| Streamable HTTP | Each message is an HTTP POST to one endpoint, such as /mcp | OAuth access tokens for each user | A server for customers or for a whole company |
In TypeScript, a remote server is the same McpServer behind an HTTP handler. The SDK's Express example mounts it on one route:
import { createMcpExpressApp } from '@modelcontextprotocol/express';
import { toNodeHandler } from '@modelcontextprotocol/node';
import { createMcpHandler, McpServer } from '@modelcontextprotocol/server';
import * as z from 'zod/v4';
const handler = createMcpHandler(() => {
const server = new McpServer({ name: 'notes', version: '1.0.0' });
server.registerTool(
'add-note',
{
description: 'Append a note',
inputSchema: z.object({ text: z.string() })
},
async ({ text }) => ({
content: [{ type: 'text', text: `Saved: ${text}` }]
})
);
return server;
});
const app = createMcpExpressApp();
const node = toNodeHandler(handler);
app.all('/mcp', (req, res) => void node(req, res, req.body));In Python, the same server file runs over HTTP with mcp run server.py --transport streamable-http. The Streamable HTTP specification sets two rules: every server must check the Origin header of incoming requests to block DNS rebinding attacks, where a remote website reaches a local server, and a server that runs locally should listen only on 127.0.0.1. The Express helper above applies that check by default when it listens on 127.0.0.1; a server bound to all network interfaces has to list the hosts it serves.
What the 2026-07-28 revision changed
The 2026-07-28 revision is the release that some developers call MCP 2.0, although the specification itself uses only dated names. It removed protocol sessions and the initialize handshake. Every request now carries its protocol version and client capabilities, and servers must answer a new server/discover request that lists the revisions and capabilities they support. If a task needs state across several calls, such as a draft order, the server creates an ID for it and the model passes that ID back as an ordinary tool argument. Other changes affect the server code too:
- Questions go back in the result. A server can no longer send its own requests to the client mid-call. Under the Multi Round-Trip Requests pattern, a tool that needs a confirmation from the user returns a result of type
input_requiredwith its questions, and the client repeats the call with the answers. - Notifications use one stream. The separate GET stream,
ping,logging/setLevel, and resource subscriptions are gone. A client that wants to know when the tool list changes opens onesubscriptions/listenrequest instead. - Headers repeat the body. Every Streamable HTTP request carries
Mcp-Methodand, for a tool call,Mcp-Name, so a gateway can route by tool without reading the JSON. The transport specification tells the server to reject a request whose headers do not match its body with HTTP 400. - Tasks became an extension. Long-running tasks left the core protocol for the optional
io.modelcontextprotocol/tasksextension, which a client and a server enable only when both support it.
Moving an existing server to the new revision
The release announcement lists TypeScript, Python, Go, and C# as the SDKs that supported the new revision on its release day. Python SDK v2.0.0, out on July 28, 2026, renames FastMCP to MCPServer and serves old and new clients from one server. Its new Resolve parameter lets a tool ask the user a question in either protocol version. The v1 line now gets only critical fixes and security patches, as its release notes say.
For TypeScript, the migration guide starts with npx @modelcontextprotocol/codemod@latest v1-to-v2 ., a script that rewrites imports and renamed APIs. After it, move the entry point to serveStdio or createMcpHandler: the package upgrade alone does not serve the new revision. In Go, v1.7.0 accepts 2026-07-28 requests over HTTP only with StreamableHTTPOptions.Stateless = true.
Step 5: Add authorization
A local stdio server does not use the protocol's authorization flow: the authorization specification tells it to read credentials from the environment. A remote server with private data acts as an OAuth 2.1 resource server: your identity provider issues tokens, and the server checks them on every request.
- Publish where to sign in. The server must publish a Protected Resource Metadata document (RFC 9728), which tells the AI application which authorization server to use.
- Accept only your own tokens. The server must check that each access token was issued for this server. The official security best practices call accepting a client's token without checking that it was issued to the MCP server and passing it on to another API “token passthrough” and treat it as an anti-pattern. Our open-source MCP server for Open WebUI knowledge bases was built for a team's internal use: in its remote mode each user sends their own Open WebUI API token, and the server passes it on to Open WebUI, with no OAuth. A server for customers needs the OAuth flow above instead.
- Grant the smallest scope first. The same guide recommends a small starting set of permissions for reading and a request for more when the user first tries a privileged action.
- Support the new client registration. The 2026-07-28 revision deprecated Dynamic Client Registration, and its client registration rules recommend Client ID Metadata Documents instead: the AI application's ID is an HTTPS URL of a JSON file with its name and redirect addresses. Check that your identity provider supports them and returns the
issparameter (RFC 9207), which clients now check. - Check permissions in each tool. A valid token says who the user is, not what this user may do with a given record. An ID that the server returned earlier is not proof of access either.
- Set limits in the database as well. If a tool queries a database directly, give the server its own database role with only the grants its tools need, and put the limits on that role, where a model's request cannot talk its way around them. Arpit Bhayani suggests a PostgreSQL
statement_timeoutof 5 seconds and anidle_in_transaction_session_timeoutof 10 seconds for an agent's role, because an agent can keep a transaction open while the model is still deciding on its next step.
The TypeScript SDK provides requireBearerAuth middleware for Express that verifies the token before the MCP handler runs. You supply the function that checks the token with your identity provider.
“Decide whose rights the server uses before you write the first tool. If the server calls your API with one service account that can see everything, then everyone who connects an AI assistant can see everything too. Have the server act for the signed-in user with a token issued for your API, and let your API refuse what that user may not do.”
Evgeny Leonov, CTO at Ronas IT
Step 6: Test the server
Test in three layers: call the tools by hand in the MCP Inspector, cover them with automated tests, and then try the server in the AI applications your users have. Each layer catches different problems: a wrong schema, a broken permission check, or a tool description that the model misreads.

The MCP Inspector
The MCP Inspector is the reference tool for testing servers. It runs through npx without installation, needs Node.js 22.19.0 or newer, and has a browser interface, a terminal interface, and a command-line mode for scripts and CI:
npx @modelcontextprotocol/inspector node build/index.js
npx @modelcontextprotocol/inspector --cli node build/index.js \
--protocol-era modern --method tools/listThe Inspector connects in the pre-2026 way by default. The --protocol-era modern flag in the second command checks that the server also answers clients of the 2026-07-28 revision.
Automated tests and real clients
The TypeScript SDK's testing guide connects a real SDK client to the server in the same process, without a port or a mock, and checks both a normal result and an isError result. Add a test for each permission rule: a user without access should get an error instead of someone else's data.
After that, connect the server to the AI applications your users work in. In Claude Code, a remote server is added with claude mcp add --transport http and the server URL. Ask the questions your users would ask and check that the model picks the right tool. If it does not, rewrite the tool descriptions before you change the code.
Step 7: Deploy and maintain the server
A remote MCP server is deployed like any other web API: in a container, behind HTTPS, with monitoring and logs. The TypeScript SDK v2 HTTP handler builds a fresh server for every request and holds nothing between requests, and the SDK's scaling guide calls such a server stateless and horizontally scalable by default. A stdio server is distributed as a package that users install, such as an npm package started with npx.
How we did it for the Open WebUI server
Open WebUI is a self-hosted AI chat platform with knowledge bases of internal documents. Our team published an open-source MCP server for these knowledge bases in TypeScript, with a separate Python version. The TypeScript version shows what a production setup adds to a tutorial server:
- Both transports from one code base. An environment variable switches it between stdio and HTTP, and the HTTP mode has a separate health endpoint for monitoring.
- Limits. Requests are rate-limited per API token, or per IP address when a request carries no token, and request size is capped.
- Tests. Unit tests and end-to-end tests run in CI on pull requests and pushes to the main branch.
- Packaging. It runs through
npxon a developer's computer or as a Docker container on a server. - Instructions for the AI. A template tells the assistant when to search the knowledge bases and which base fits which question, because a working tool is not used if the model does not know when to call it.
What maintenance includes
- Protocol revisions. The specification is published in dated revisions. Under its feature lifecycle policy, a deprecated feature stays for at least twelve months before removal. The 2026-07-28 revision deprecated Roots, Sampling, and Logging, so a new server should not depend on them: take folders and files as tool parameters, call your model provider's API directly instead of Sampling, and write logs to standard error or OpenTelemetry. New revisions now follow a six-month schedule, and the next one is planned for March 30, 2027.
- SDK updates. Our Open WebUI server was built on the v1 TypeScript package before v2 came out, so moving it to v2 is part of its maintenance.
- Changes in your API. When the system behind the server changes, the tools and their tests change with it.
- Audit logs. Log every tool call with the user and the arguments, so you can answer what the AI did and on whose behalf. The specification describes how to pass OpenTelemetry trace context with each request.
Build it yourself or hire a team
Build it yourself when the server is a local tool for your own developers or an internal server with a few read-only tools, and your team already knows the system behind it. Hire a team when customers will connect to the server, when it needs OAuth and per-user permissions, or when it connects several systems and your developers are busy with the product.
| Factor | Build in-house | Hire a team |
|---|---|---|
| Users | Your own developers or one internal team | Customers or the whole company |
| Transport and sign-in | stdio with an API key from the environment | Streamable HTTP with OAuth and per-user permissions |
| Tools | A few read-only tools for one system | Tools that change data or connect several systems |
| Operations | Runs on developers' computers | Hosting, monitoring, audit logs, and updates for new protocol revisions |
We price an MCP server as one AI feature: AI integration work starts at $3,000 per AI feature and takes from one week. Connecting the server to your product's existing API is part of that price. Hosting and monitoring in your own cloud account start at $200 per month if you want us to run them. The scope of custom MCP server development depends on how many systems the server connects to and how detailed its permission rules are.
What to do next
- List three to five tasks that users should be able to do through an AI assistant in your system.
- For each task, check that an API exists and decide which users may run it.
- Decide who will connect: your own team, which a local stdio server can serve, or customers, who need a remote server with OAuth.
- Build the first tool with an official SDK and test it in the MCP Inspector.
Deciding whether to build your MCP server in-house? Send us the tasks it should handle and the systems behind them, and we will suggest a first set of tools and a preliminary estimate.






