Estimate Project

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

A black cat tightens a stacked server box with a wrench on a workbench; a cable runs to a smiling chat bubble beside database, key and gear icons.

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: true and 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.

TierLanguagesWhen to choose
Tier 1TypeScript, Python, C#, Go, Rust, RubyThe default choice for a production server
Tier 2JavaWhen the system and the team already run on Java
Tier 3Swift, PHP, KotlinAfter 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 + b

In 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.

TransportHow it runsCredentialsTypical use
stdioThe AI application starts the server as a process and exchanges messages through its input and outputFrom the local environment, such as an API key in a variableDeveloper tools, file access, internal tools for one team
Streamable HTTPEach message is an HTTP POST to one endpoint, such as /mcpOAuth access tokens for each userA 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_required with 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 one subscriptions/listen request instead.
  • Headers repeat the body. Every Streamable HTTP request carries Mcp-Method and, 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/tasks extension, 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 iss parameter (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_timeout of 5 seconds and an idle_in_transaction_session_timeout of 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/list

The 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 npx on 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.

FactorBuild in-houseHire a team
UsersYour own developers or one internal teamCustomers or the whole company
Transport and sign-instdio with an API key from the environmentStreamable HTTP with OAuth and per-user permissions
ToolsA few read-only tools for one systemTools that change data or connect several systems
OperationsRuns on developers' computersHosting, 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

  1. List three to five tasks that users should be able to do through an AI assistant in your system.
  2. For each task, check that an API exists and decide which users may run it.
  3. Decide who will connect: your own team, which a local stdio server can serve, or customers, who need a remote server with OAuth.
  4. 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.

Frequently Asked Questions (FAQs)

How long does it take to build an MCP server?

The official tutorial builds a local server with two tools around a public weather API in a single walkthrough. A remote server for customers takes longer, because sign-in, permission checks, tests, and hosting take most of the extra time. At Ronas IT, an MCP server is priced as one AI feature, with a timeline from one week.

Which language is best for building an MCP server?

Use the language your team already uses for the system the server connects to. TypeScript, Python, C#, Go, Rust, and Ruby have official SDKs in the top support tier. When the team has no strong preference, TypeScript or Python is the usual choice.

Can I build an MCP server in Python?

Yes. The official Python SDK needs Python 3.11 or newer and installs with pip install "mcp[cli]". A tool is a Python function with type hints and a docstring: the SDK builds the input schema from the type hints, and the mcp dev command opens the server in the MCP Inspector.

Does an MCP server need OAuth?

Only a remote server that protects data needs it. Authorization is optional in the specification, and a local server that runs over stdio should take its credentials from the environment instead. When a remote server holds private data, it takes the OAuth 2.1 resource server role and accepts only tokens issued for itself.

How do I test an MCP server?

Call the tools by hand in the MCP Inspector, add automated tests that call them through an SDK client and check both normal and error results, then connect the server to each AI application your users rely on, because every one of them shows tools and asks for approval in its own way.

How do I connect my MCP server to Claude Code?

For a remote server, run claude mcp add --transport http with a name and the server URL. A local server is added with the command that starts it. Other AI applications, such as Cursor, keep a list of servers in a JSON settings file with the same information: a command for a local server or a URL for a remote one.

Do I need to change an existing MCP server for the 2026-07-28 specification?

Not at once. The new revision describes how clients and servers detect an earlier revision and fall back to it, and v1 of the TypeScript SDK keeps receiving security and bug fixes for no less than six months after v2 came out. Plan the upgrade anyway: the new revision removes sessions and the initialize handshake, and deprecated features stay for at least twelve months before removal.

Should one MCP server cover several systems?

Usually one server per system or per product area works better. Each server keeps a short list of tools, its own credentials, and its own permission rules, and an AI application can connect to several servers at once. One large server mixes permissions of different systems and gives the model a long list of similar tools to choose from.

Related posts

A smiling chat bubble plugs one cable into a socket box wired to database, folder, calendar and wrench icons, while a black cat watches.
Tech
What is an MCP server? How it works and when your product needs one
2026-12-03 • 13 min read
A laptop and a smiling chat bubble holding tool cards plug cables into one socket box with data icons, while a black cat watches.
Tech
MCP vs API: what changes when an AI model calls your product
2026-12-03 • 12 min read
A developer kneels with a wrench to assemble a robot, asking a question in a speech bubble while the robot answers with a smile
How to
How to build a custom AI agent: steps, architecture, and cost
2026-11-16 • 22 min read
Robot arms place cards, a light bulb and a chart around a window with a chat between two users and a robot
How to
AI business integration: how to add AI to the processes you already run
2026-11-17 • 14 min read
Colorful graphic illustrating the MLOps services lifecycle, showing interconnected loops for machine learning (ML) and operations (Ops) with steps like data, model build, test, packaging, deploy, prediction serving, and performance monitoring, surrounded by gears and charts.
Tech
MLOps: From prototype to product — bringing your AI to the real world
2026-01-27 • 10 min read