Build an MCP Server in Node.js

RAG, AI Agents & MCP · Model Context Protocol (MCP) · 7 min read · Updated

Here is the smallest useful MCP server: one tool that checks a resume for missing sections. Treat the code as a sketch of the idea, because the SDK is updated often; compare with the official TypeScript SDK documentation.

Install

npm install @modelcontextprotocol/sdk zod

The server

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

const server = new McpServer({ name: "resume-tools", version: "1.0.0" });

server.tool(
  "check_sections",
  "Check which standard resume sections are present in the given text.",
  { text: z.string().max(20000) },
  async ({ text }) => {
    const wanted = ["summary", "experience", "education", "skills"];
    const missing = wanted.filter((s) => !text.toLowerCase().includes(s));
    return { content: [{ type: "text", text: missing.length ? "Missing: " + missing.join(", ") : "All sections found" }] };
  }
);

await server.connect(new StdioServerTransport());

Note that logs must not go to standard output with the stdio transport, because it carries the protocol messages. Write logs to standard error.

Test it

Use the MCP Inspector to list the tools, call them and see the raw messages before connecting a real assistant.

npx @modelcontextprotocol/inspector node server.js

Connect it

Add the server to the configuration of an MCP-capable client, giving the command that starts it. For a remote server you would use the Streamable HTTP transport and add authentication.

Good practice

  • Validate all inputs, as with any tool.
  • Expose only the tools you need.
  • Return clear errors.
  • Add logging and tests.

Frequently asked questions

Why does my stdio MCP server break when I use console.log?

Standard output carries the protocol messages, so extra text corrupts them. Log to standard error instead.

How do I debug a server?

Use the MCP Inspector to call tools directly and inspect requests and responses.