← Back to Blog

Creating a Custom MCP Server with TypeScript

Vibe Manager Team

If you prefer the Node.js ecosystem, the TypeScript SDK for MCP is excellent. It provides strong typing, which is helpful when defining the schemas for your tools.

Prerequisites

  • Node.js 18+
  • npm install @modelcontextprotocol/sdk zod

The Code (index.ts)

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

// Create server instance
const server = new McpServer({
  name: "greeting-server",
  version: "1.0.0",
});

// Define a tool
server.tool(
  "greet_user",
  "Greets a user by name",
  {
    name: z.string().describe("The name of the user"),
  },
  async ({ name }) => {
    return {
      content: [
        {
          type: "text",
          text: `Hello, ${name}! Welcome to MCP.`,
        },
      ],
    };
  },
);

// Connect via Stdio
const transport = new StdioServerTransport();
await server.connect(transport);

Key Concepts

  1. Zod Schemas: MCP uses JSON Schema to define tool arguments. The SDK uses Zod to make this easy. The description you add to the Zod schema is what the AI reads to understand what the argument expects.
  2. Transports: We use StdioServerTransport. This means the server communicates by printing to stdout and reading from stdin. This is the standard for local Desktop apps.

Running It

  1. Compile: tsc
  2. Add to Config:
    "greeting-server": {
      "command": "node",
      "args": ["/path/to/dist/index.js"]
    }

Why TypeScript?

For complex tools with many parameters, TypeScript’s type safety prevents runtime errors. Plus, if you are integrating with existing JS/TS libraries (like Drizzle ORM or Octokit), it’s the natural choice.

Manage Configs

Sync your Claude, Cursor, and Codex configurations in one click with Vibe Manager.

Download Vibe Manager

Find Verified Skills

Discover and install secure, community-verified MCP skills and agent rules from SkillMap.

Browse SkillMap ↗

Related Articles