nabadeep25/mcp-server-nodejs
If you are the rightful owner of mcp-server-nodejs 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.
A Model Context Protocol (MCP) server implementation with multiple tools for testing and demonstration purposes.
MCP Test Server
A Model Context Protocol (MCP) server implementation with multiple tools for testing and demonstration purposes.
Overview
This server provides three main tools:
- BMI Calculator: Calculate Body Mass Index from weight and height
- Weather Service: Get weather information for any city (with API key support)
- Echo Tool: Simple echo functionality for testing
Features
- Built with TypeScript and Express.js
- Streamable HTTP transport for MCP
- Environment-based configuration
- Hot reload development support
- Modular tool architecture
Prerequisites
- Node.js (v18 or higher)
- npm or yarn package manager
Installation
-
Clone or download this repository
-
Install dependencies:
npm install
-
Copy the environment example file:
cp .env.example .env
-
(Optional) Add your weather API key to
.env
:WEATHER_API_KEY=your_openweathermap_api_key_here
Build and Run
Development Mode
# Build and start with hot reload
npm run dev
Production Mode
# Build the project
npm run build
# Start the server
npm start
The server will start on http://localhost:3000
(or the port specified in your PORT
environment variable).
API Endpoint
The MCP server is accessible at:
POST http://localhost:3000/mcp
Available Tools
1. BMI Calculator (calculate-bmi
)
Calculate Body Mass Index from weight and height.
Parameters:
weightKg
(number): Weight in kilogramsheightM
(number): Height in meters
2. Weather Service (get-weather
)
Get current weather information for a city.
Parameters:
city
(string): City namecountry
(string, optional): Country code (e.g., "IN", "US")
3. Echo Tool (echo
)
Simple echo functionality for testing purposes.
Parameters:
message
(string): Message to echo back
Testing the Server
Using MCP Inspector
For a GUI interface to test MCP server:
-
Start server:
npm start
-
In another terminal, run the MCP inspector:
npm run inspector
VS Code Integration
If you're using VS Code with MCP support, add this server to your settings:
{
"mcp": {
"servers": {
"mcp-test-server": {
"url": "http://localhost:3000/mcp"
}
}
}
}
Project Structure
āāā src/
ā āāā index.ts # Main server file
ā āāā tools/ # Tool implementations
ā āāā bmi.ts # BMI calculator tool
ā āāā weather.ts # Weather service tool
ā āāā echo.ts # Echo tool
āāā build/ # Compiled JavaScript files
āāā package.json # Project configuration
āāā tsconfig.json # TypeScript configuration
āāā .env.example # Environment variables example
āāā README.md # This file
Development
Adding New Tools
-
Create a new tool file in
src/tools/
:import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; import { z } from 'zod'; export const myTool = { name: 'my-tool', schema: { param1: z.string(), param2: z.number(), }, handler: async ({ param1, param2 }: { param1: string; param2: number }): Promise<CallToolResult> => { return { content: [ { type: 'text', text: `Result: ${param1} - ${param2}`, }, ], }; }, };
-
Import and register it in
src/index.ts
:import { myTool } from './tools/my-tool.js'; // In the getServer() function: server.tool( myTool.name, 'Description of my tool', myTool.schema, myTool.handler );
Available Scripts
npm run build
- Compile TypeScript to JavaScriptnpm run watch
- Watch for changes and recompilenpm run dev
- Development mode with hot reloadnpm start
- Start the compiled servernpm run inspector
- Launch MCP inspector