Get a quote

How to build an MCP server in TypeScript (2026 guide)

Published 2026-10-14. 8 min read.

In this guide

  1. What you are building
  2. Project setup
  3. Your first tool
  4. Connecting a client
  5. From demo to production

An MCP server is a small program that exposes tools an AI assistant can call. In this guide you build one in TypeScript with the official SDK, then look at what changes when it has to run for a real team.

Code in this guide follows the official TypeScript SDK v2 (packages @modelcontextprotocol/server and @modelcontextprotocol/client), which is the stable line as of October 2026. v1 still works but only gets bug and security fixes.

1. What you are building

A server with one tool, greet, that takes a name and returns a greeting. It talks to the client over stdio: the AI client starts your server as a local process and exchanges messages through standard input and output. That is the fastest way to test.

2. Project setup

mkdir greeting-server && cd greeting-server
npm init -y
npm install @modelcontextprotocol/server zod
npm install -D typescript tsx

3. Your first tool

Create server.ts:

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}!` }]
    })
);

async function main() {
    const transport = new StdioServerTransport();
    await server.connect(transport);
}

main();

Three things matter here. The name is what the model calls. The description is what the model reads to decide when to call it, so it is effectively a prompt. The input schema is validated before your handler runs, so the handler can trust its arguments.

4. Connecting a client

Most desktop AI clients and coding agents let you add a local server by giving them the command that starts it, for example npx tsx /path/to/server.ts. Restart the client, ask it to greet someone, and you should see it call your tool.

5. From demo to production

The greeting server is a toy. A server that touches a CRM or a database needs more:

  • Fewer, clearer tools. Five to fifteen tools named in your team's language beat a hundred endpoints. See how to design MCP tools models actually use.
  • Server-side limits. Cap result sizes and query time in code, not in the prompt.
  • Guarded writes. Read by default; writes only where you decide, with confirmation for anything risky.
  • Remote transport and auth. For a whole team, run it as a remote server over Streamable HTTP with OAuth. See local vs remote MCP servers.
  • Logging. Record who called which tool with which inputs.

Want this built for your CRM or database instead? See custom MCP server development.

Related guides

Tell us which system your team wants AI to work with.

Fill in a 5-minute brief. Within 48 hours you get a tool list, a fixed price and an honest answer on whether you need us at all. No meetings needed.

Get a fixed quote