Example MCP Server

Example MCP Server

A Node.js/TypeScript MCP server template with sample tools (ping and system_info) that demonstrates how to build custom tools for Claude Desktop using stdio transport.

Category
Visit Server

README

Example MCP Server

A simple Model Context Protocol (MCP) server implementation in Node.js with TypeScript for use with Claude Desktop.

What is MCP?

The Model Context Protocol (MCP) is an open protocol that enables AI models like Claude to interact with external tools and data sources. It allows Claude Desktop to call local or remote tools, retrieve information, and perform actions through standardized JSON-RPC messaging.

This server exposes tools that Claude can discover and invoke over a stdio (standard input/output) transport, making it perfect for local integrations.

Project Structure

.
├── src/
│   ├── mcp/
│   │   └── server.ts          # Main MCP server implementation
│   ├── tools/
│   │   ├── ping.ts            # Ping tool example
│   │   ├── system-info.ts     # System info tool example
│   │   └── registry.ts        # Tool registry & dispatcher
│   └── types/
│       └── index.ts           # TypeScript type definitions
├── dist/                      # Compiled JavaScript (generated)
├── package.json
├── tsconfig.json
├── mcp.json                   # Claude Desktop manifest
└── README.md

Features

  • ✅ MCP-compliant JSON-RPC 2.0 server
  • ✅ Stdio transport (works with Claude Desktop local tools)
  • ✅ Two sample tools: ping and system_info
  • ✅ Extensible tool registry system
  • ✅ Proper error handling and validation
  • ✅ TypeScript for type safety

Prerequisites

  • Node.js 16+ (or compatible version)
  • npm or yarn

Getting Started

1. Install Dependencies

npm install

2. Build TypeScript to JavaScript

npm run build

This compiles TypeScript from src/ to JavaScript in dist/.

3. Run the MCP Server

npm start

The server will start and listen for JSON-RPC requests on stdin.

Available Tools

ping

A simple test tool that returns "pong".

Request:

{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "ping"}}

Response:

{"jsonrpc": "2.0", "id": 1, "result": {"content": [{"type": "text", "text": "pong"}]}}

system_info

Returns detailed system information including OS, architecture, CPU count, memory usage, and uptime.

Request:

{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "system_info"}}

Response:

{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "content": [{
      "type": "text",
      "text": "{\n  \"platform\": \"win32\",\n  \"arch\": \"x64\",\n  \"osType\": \"Windows_NT\",\n  ...\n}"
    }]
  }
}

MCP Protocol Methods

tools/list

Lists all available tools.

Request:

{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "tools": [
      {
        "name": "ping",
        "description": "A simple ping tool...",
        "inputSchema": { "type": "object", "properties": {} }
      },
      ...
    ]
  }
}

tools/call

Calls a specific tool with optional arguments.

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "tool_name",
    "arguments": { "arg1": "value1" }
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [
      { "type": "text", "text": "Result here" }
    ]
  }
}

Registering with Claude Desktop

To use this MCP server with Claude Desktop:

  1. Build the project:

    npm run build
    
  2. Locate your Claude Desktop configuration file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • Linux: ~/.config/Claude/claude_desktop_config.json
  3. Add the server to your claude_desktop_config.json:

    {
      "mcpServers": {
        "example-mcp-server": {
          "command": "node",
          "args": ["/absolute/path/to/dist/mcp/server.js"],
          "env": {}
        }
      }
    }
    

    Replace /absolute/path/to with the full path to your project folder.

  4. Restart Claude Desktop to load the new MCP server.

  5. Claude will now be able to discover and call the tools provided by this server.

Adding New Tools

To add a new tool:

  1. Create a new tool file in src/tools/ (e.g., src/tools/my-tool.ts):

    import { Tool, ToolResult, ToolHandler } from "../types/index.js";
    
    export const myTool: Tool = {
      name: "my_tool",
      description: "Description of what the tool does",
      inputSchema: {
        type: "object",
        properties: {
          param1: { type: "string" },
        },
        required: ["param1"],
      },
    };
    
    export const myToolHandler: ToolHandler = async (args) => {
      // Implementation
      return {
        content: [{ type: "text", text: "Result" }],
      };
    };
    
  2. Register it in src/tools/registry.ts:

    import { myTool, myToolHandler } from "./my-tool.js";
    
    const toolRegistry: Map<string, ToolEntry> = new Map([
      // ... existing tools
      ["my_tool", { definition: myTool, handler: myToolHandler }],
    ]);
    
  3. Rebuild and restart the server:

    npm run build
    npm start
    

Development

For development with auto-reload, you can use ts-node:

npm run dev

This will run the TypeScript directly without compilation (requires ts-node to be installed).

Error Handling

The server implements proper JSON-RPC 2.0 error handling:

  • -32700: Parse error
  • -32600: Invalid request
  • -32601: Method not found
  • -32603: Internal error

All errors are returned with descriptive messages to help with debugging.

Architecture

MCP Server (src/mcp/server.ts)

  • Reads JSON-RPC 2.0 messages from stdin
  • Routes requests to appropriate handlers
  • Validates incoming requests
  • Writes responses to stdout
  • Handles errors gracefully

Tool Registry (src/tools/registry.ts)

  • Central registry of available tools
  • Provides tool list for discovery
  • Dispatches tool calls to appropriate handlers

Tool Handlers

Each tool has:

  • A Tool definition (name, description, input schema)
  • A ToolHandler function (async execution logic)

Troubleshooting

Server not starting

  • Ensure Node.js is installed: node --version
  • Check that dependencies are installed: npm install
  • Build the project: npm run build

Tools not visible in Claude

  • Verify the full path in claude_desktop_config.json is correct
  • Restart Claude Desktop after configuration changes
  • Check server logs for errors

Connection issues

  • Ensure the server process stays running
  • Check file permissions on the compiled files
  • Verify stdin/stdout are not being intercepted

License

MIT

References

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured