my-mcp-server
A Model Context Protocol (MCP) server implementation in Node.js/TypeScript. This project provides multiple server implementations for MCP, supporting user todos, log file reading, and prompt templates for AI applications.
Features
- Get and add user todos (dummy API)
- Read application log files as a resource
- Serve prompt templates for code explanation and git commit messages
- MCP-compliant server using
@modelcontextprotocol/sdk - Multiple server transports: stdio and HTTP streamable
Server Implementations
1. Stdio MCP Server (src/index.ts)
- Runs as a stdio-based MCP server (for CLI/desktop integrations)
- Supports todos, log reading, and prompt features
2. HTTP Streamable MCP Server (src/index-http-streamable-server.ts)
- Runs as an HTTP server (default port: 7171)
- Supports the same features as the stdio server
- Useful for integrations that require HTTP transport
3. Custom HTTP Server (src/server.ts)
- Implements a different set of features (see code for details)
- Runs as an HTTP server (default port: 7171)
Setup
- Install dependencies:
bash npm install - Build the project:
- Build all servers:bash npm run build
- Or build individually:bash npm run build:stdio # For stdio MCP server npm run build:http # For HTTP streamable MCP server npm run build:custom # For custom HTTP server
Running the Servers
Stdio MCP Server```bash
npm run start:stdio
### HTTP Streamable MCP Server```bash
npm run start:http
Custom HTTP Server```bash
npm run start:custom
> You can also use the corresponding `inspect`, `inspect:http`, and `inspect:custom` scripts for debugging with the Model Context Protocol inspector.
## Using MCP Servers in VS Code
Example `mcp.json` for stdio:```json
{
"servers": [
{
"name": "My MCP Stdio Server",
"transport": "stdio",
"command": "node",
"args": [
"/Users/sofikulmallick/Documents/pprojects/GenAI/my-mcp-server/build/index.js"
]
}
]
}
Example mcp.json for HTTP:```json
{
"inputs": [
{
"type": "promptString",
"id": "AUTHORIZATION_TOKEN",
"description": "MCP Server Authorization JWT",
"password": true
}
],
"servers": {
"my-mcp-server-d959f687": {
"transport": "http",
"url": "http://localhost:7171/mcp",
"headers": {
"Authorization": "Bearer ${input:AUTHORIZATION_TOKEN}"
}
}
}
}
## Using MCP Servers in Claude Desktop```json
{
"servers": [
{
"name": "My MCP Stdio Server",
"transport": "stdio",
"command": "node",
"args": [
"/Users/sofikulmallick/Documents/pprojects/GenAI/my-mcp-server/build/index.js"
]
}
]
}
Claude does not support HTTP Streamable MCP server yet.
Project Structure
src/- TypeScript source filesbuild/- Compiled JavaScript outputsample_logs.txt- Example log file for resource reading
API Overview
- Get User Todos: Uses dummyjson.com to fetch todos for a user
- Add User Todo: Uses dummyjson.com to add a todo for a user
- Calculate BMI: Calculates Body Mass Index given weight (kg) and height (m)
- Read Logs: Reads from
sample_logs.txt - Prompts: Provides prompt templates for code explanation and git commit messages
Testing MCP HTTP API with Postman
You can test the MCP HTTP API using Postman. A ready-to-import Postman collection is provided:
- File:
mcp-server-postman-collection.json
Steps:
- Import the collection into Postman.
- Get Token: Use the "Get Token" request to obtain a JWT.
- Initialize MCP Session: Use the "MCP HTTP Server Initialize" request. Replace `` with your JWT.
- Call Tools (e.g., Calculate BMI): Use the "Calculate BMI Tool" request. Replace
andwith your values from previous steps.
Example cURL commands
Get token:```bash
curl --location 'http://localhost:7171/login' \
--header 'Content-Type: application/json' \
--data '{"username":"user1","password":"password1"}'
MCP HTTP Server Initialize:```bash
curl --location 'http://localhost:7171/mcp' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json, text/event-stream' \
--header 'Authorization: Bearer <token>' \
--data '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": { "interactive": true },
"clientInfo": { "name": "example-client", "version": "1.0.0" }
}
}'
Calculate BMI tool:bash
curl --location 'http://localhost:7171/mcp' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json, text/event-stream' \
--header 'mcp-session-id: <session-id>' \
--header 'Authorization: Bearer <token>' \
--data '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "calculate-bmi",
"arguments": { "weightKg": 70, "heightM": 1.75 }
}
}'
