node-mcp-server

my-mcp-hub/node-mcp-server

3.2

If you are the rightful owner of node-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This Node.js MCP Server Template provides a robust foundation for building Model Context Protocol (MCP) servers with support for multiple transport protocols.

Node.js MCP Server Template

A Model Context Protocol (MCP) server template for Node.js applications. This template provides a foundation for building MCP-compatible servers with support for multiple transport protocols.

Features

  • Multiple Transport Protocols :

    • Standard I/O (stdio) for command-line interfaces
    • HTTP Streamable transport for web applications
    • Server-Sent Events (SSE) for real-time updates
  • TypeScript Support : Built with TypeScript for type safety and better developer experience

  • Development Tools :

    • Hot reloading during development
    • Integration with MCP Inspector for debugging
    • ESLint and Prettier for code quality
    • Husky and lint-staged for Git hooks
  • Extensible Tool System : Easy registration of custom MCP tools

Prerequisites

  • Node.js (latest LTS version recommended)
  • npm or yarn

Installation

npm install

Development

# Start development server with stdio transport
npm run dev

# Start development server with web transport
npm run dev:web

When using dev:web , the server will be available at:

Building

npm run build

The build output will be in the build directory.

Usage

Command Line

# Start with stdio transport (default)
node build/index.js

# Start with web transport
node build/index.js web --port 8401

Adding Custom Tools

Custom tools can be added in the src/tools/index.ts file:

server.registerTool(
  'YourToolName',
  {
    title: 'Your Tool Name',
    description: 'Tool description',
    inputSchema: {
      param1: z.string().describe('Parameter description'),
    },
  },
  ({ param1 }) => {
    // Implement tool logic
    return {
      content: [
        {
          type: 'text',
          text: `Your tool response: ${param1}`,
        },
      ],
    }
  },
)

Environment Variables

  • PORT : Specify the port for web transport (default: 8401)
  • NODE_ENV : Set to production for production builds or local for development

License