DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Build a Simple MCP Server with Node.js 22

Build a small TypeScript MCP server with the official SDK v2, register a validated tool, and exercise it through stdio with MCP Inspector.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a small MCP server in TypeScript with the official TypeScript SDK v2, register one validated tool, and run it over stdio for a host to launch. The SDK guide requires Node.js 20 or later, so Node.js 22 meets its stated runtime minimum; the guide does not report a separate Node.js 22 compatibility test.

What you’ll build and which SDK this uses

This walkthrough follows the official TypeScript SDK v2 first-server guide. The server exposes one tool that takes a name and returns a greeting. An MCP host or client can discover and call that tool; the SDK checks its input against the declared schema before invoking the handler.

As an Amazon Associate I earn from qualifying purchases.

Use the v2 documentation for the v2 package and API shown here. The official repository describes v2 as the stable SDK release line implementing the 2026-07-28 specification; it also says v1.x will continue to receive bug fixes and security updates for at least six months after v2’s release. The v1 and v2 documentation use different package names and API examples, so do not mix snippets across generations. If you install v1, follow the matching v1 server documentation instead.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set up an ES-module TypeScript project

The v2 guide specifies Node.js 20 or later. Check your installed runtime before starting:

#1 Best Overall
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
  • Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized
node --version

If it reports Node.js 22, it is above the guide’s stated minimum. The guide uses TypeScript with tsx, so you can run the source directly without adding a separate compile step.

  1. Create a project directory and initialize its package metadata:

    mkdir first-mcp-server
    cd first-mcp-server
    npm init -y
  2. Set the package to ES modules and add a start script in package.json:

    What’s actually slowing this PC down?

    Pick the symptom - the matching free tool is one click away.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    Rank #2
    CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
    • Includes Raspberry Pi 5 16GB with 2.4Ghz 64-bit quad-core CPU (16GB RAM)
    • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
    • CanaKit Turbine Black Case for the Raspberry Pi 5
    • CanaKit Low Noise Bearing System Fan
    • Mega Heat Sink - Black Anodized
    {
      "type": "module",
      "scripts": {
        "start": "tsx server.ts"
      }
    }
  3. Install the packages used by the v2 tutorial:

    npm install @modelcontextprotocol/server zod
    npm install --save-dev tsx

Create a server and register a tool

Create server.ts in the project directory. The example below registers a greet tool. Its schema requires a string named name; the handler receives validated input and returns text content.

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

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

server.registerTool(
  "greet",
  {
    description: "Greet a person by name",
    inputSchema: {
      name: z.string().min(1),
    },
  },
  async ({ name }) => ({
    content: [{ type: "text", text: `Hello, ${name}!` }],
  }),
);

await serveStdio(server);

The registration binds together a tool name, a description, an input schema, and an asynchronous handler. Here z.string().min(1) rejects an empty name before the handler runs. Keep tool descriptions specific: a host can use them to understand what a capability does.

Run over stdio without corrupting the protocol

Start the server with:

npm start

For stdio, standard output is reserved for MCP protocol messages. Do not use console.log for diagnostics: even one stray line can corrupt the JSON-RPC stream. Send debugging output to standard error with console.error. The official tutorial states: “stdout is the protocol channel. Log with console.error — one console.log corrupts the JSON-RPC stream.”

Rank #3
RasTech Raspberry Pi 5 8GB Kit 64GB Edition with Active Cooler,27W GaN 5.1V5A USB-C Power Supply,Pi5 8GB Board,64GB Card Readers Kit,Pi 5 Case,Dual 4K Micro HD Out Cables and User Manual
  • Pi5 8GB Pack: RasTech Pi 5 8GB kit includes 1 x Pi5 8GB board ,1 x 64GB Card, 2 x Card Readers,1 x Active Cooler,1 x Case for Pi5, 2 x 4K Micro HD Out Cable,1 x GaN 27W 5A USB-C Power supply,1 x Screwdriver and 1 x instructions.
  • Pi5 8GB Board: The Pi5 board is equipped with a 64-bit quad-core Arm Cortex-A76 processor running at 2.4GHz and an 800MHz VideoCore VII GPU with support for OpenGL ES 3.1 and Vulkan 1.2, which delivers a significant increase in graphics performance. Dual HD Out 4Kp60 display outputs and a built-in dual 4-channel MIPI camera/display transceiver provide state-of-the-art camera support. The Pi 5 offers a 2-3 times increase in CPU performance compare to Pi4.
  • Important Graphics Features: Equipped with an 800MHz VideoCore VII GPU and providing better graphics performance, suitable for multimedia applications,gaming,and graphics intensive tasks.Provides 1 UART interface,1 card slot that supports high-speed operation, 2 USB. 3 0.5 ports that support synchronous 0Gbps operation,2 USB 2.0 port ports,2 4Kp60 display outputs that support HDR.Built-in dedicated dual 4-channel 1Gbps MIPI DSI/CSI connectors,triple the total bandwidth.
  • Cooling Kit for Pi 5: Compatible with Active Cooler for Raspberry Pi5, It can provide Pi 5 board with better cooling effect in using. The Case can accurately access usb-c power jack,Micro HD Out ports, usb ports, Ethernet jack, card slot, power button, 4-lane MIPI DSI/CSI connectors and so on, and it also supports installation of cooling fan.
  • 64GB Card Kit and GaN 27W USB-C Power Supply: With extra 64GB card to store more files and card readers for multiple medium, keep better performance for Raspberry Pi 5, 27W USB C Power Supply is Compatible with Pi5 8GB, offers a variety of output voltage options, including 5.1V at 5A, 9.0V at 3.0A, 12.0V at 2.25A, and 15.0V at 1.8A, providing for different device requirements.

A stdio server is generally launched by the local host as a child process rather than opened as an ordinary web page or left running as a public service. That process relationship is why stdio is the straightforward choice for a local integration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Connect with MCP Inspector and call the tool

The official tutorial exercises the server with MCP Inspector over stdio. In a separate terminal, launch the Inspector through npx:

npx @modelcontextprotocol/inspector

In Inspector, choose the stdio transport and configure it to launch the project’s command, npm start, from the project directory. Connect, open the tools view, select greet, enter a non-empty value for name, and invoke it. The result should contain text such as Hello, Ada! when the supplied name is Ada. If the tool rejects an empty name, schema validation is doing its job.

Rank #4
Vilros Raspberry Pi 5 Starter Kit MAX – Official 8GB RAM Pi 5 Board, 128GB Preloaded Micro SD, Case, Power Supply & Cooling – Complete Plug-and-Play Kit for Beginners & Advanced Users
  • 𝗦𝗲𝗮𝗺𝗹𝗲𝘀𝘀 𝗦𝗲𝘁𝘂𝗽 𝘄𝗶𝘁𝗵 𝗣𝗿𝗲-𝗜𝗻𝘀𝘁𝗮𝗹𝗹𝗲𝗱 𝗢𝗦: Start creating right out of the box—our kit arrives with Raspberry Pi OS already on the microSD card, saving you time and effort from day one.
  • 𝗘𝘃𝗲𝗿𝘆𝘁𝗵𝗶𝗻𝗴 𝗬𝗼𝘂 𝗡𝗲𝗲𝗱, 𝗔𝗹𝗹 𝗶𝗻 𝗢𝗻𝗲 𝗕𝗼𝘅: From the case to the power supply and a generous microSD card, we’ve bundled every essential so you can skip the extra shopping and focus on building your dream project.
  • 𝗔𝗱𝘃𝗮𝗻𝗰𝗲𝗱 𝗖𝗼𝗼𝗹𝗶𝗻𝗴 𝗳𝗼𝗿 𝗣𝗲𝗮𝗸 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲: Enjoy smooth, reliable operation as our whisper-quiet fan and heat sinks work together to keep your Pi running cool—even during intensive tasks.
  • 𝗩𝗲𝗿𝘀𝗮𝘁𝗶𝗹𝗶𝘁𝘆 𝗳𝗼𝗿 𝗔𝗻𝘆 𝗣𝗿𝗼𝗷𝗲𝗰𝘁: Whether it’s coding lessons, retro gaming, smart home setups, or robotics experiments, our kit powers unlimited possibilities, letting you tailor your Pi adventure to your passion.
  • 𝗚𝗹𝗼𝗯𝗮𝗹𝗹𝘆 𝗧𝗿𝘂𝘀𝘁𝗲𝗱 𝗯𝘆 𝗘𝗻𝘁𝗵𝘂𝘀𝗶𝗮𝘀𝘁𝘀 & 𝗘𝗱𝘂𝗰𝗮𝘁𝗼𝗿𝘀: Join a worldwide community of hobbyists, teachers, and first-time makers who rely on Vilros for top-tier quality, comprehensive support, and ongoing inspiration.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a transport that matches deployment

The server factory can be served over different transports; the right choice depends on who launches the process and where clients connect.

Transport Best fit Connection model
stdio Local use with a host that launches the server process The host communicates with the local process through standard input and output.
Streamable HTTP A remotely reachable server used by multiple clients Clients connect to an HTTP endpoint instead of relying on a host-spawned local process.
HTTP+SSE Compatibility with older integrations The v1 server guide describes it as backwards compatibility, not the modern remote transport.

The v2 first-server tutorial uses stdio for a local process and notes that the same server factory can be served over HTTP for one endpoint shared by multiple clients. The v1 guide describes stdio as the simplest local transport and Streamable HTTP as the modern remote transport. For remote exposure, follow the transport instructions for the SDK generation and package you actually use; do not assume a stdio launch configuration is itself a remote deployment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common issues to check

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.