cal-server-mcp
v1.0.0
Published
Calculator MCP server using TypeScript and Express
Downloads
4
Maintainers
Readme
Calculator MCP Server Usage Guide
This MCP server supports both HTTP and stdio transport modes for maximum flexibility.
Transport Modes
1. HTTP Transport (REST API)
The HTTP mode exposes the MCP server as a RESTful API endpoint that you can interact with using HTTP requests.
Starting HTTP Mode
# Development mode
npm run dev:http
# Production mode
npm run start:http
# With inspector for debugging
npm run inspector:httpUsing HTTP Mode
The server runs on http://localhost:3000/mcp by default (port configurable via PORT environment variable).
# List available tools
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
# Call the add tool
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"add","arguments":{"a":5,"b":3}}}'Important: HTTP requests must include both Accept: application/json and Accept: text/event-stream headers for the MCP server to accept the request.
2. Stdio Transport (Command Line Interface)
The stdio mode uses standard input/output for communication, which is the standard way MCP clients interact with servers.
Starting Stdio Mode
# Development mode
npm run dev:stdio
# Production mode
npm run start:stdio
# With inspector for debugging
npm run inspector:stdioUsing Stdio Mode
In stdio mode, the server reads JSON-RPC messages from standard input and writes responses to standard output:
# List available tools
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | npm run start:stdio
# Call the add tool
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"add","arguments":{"a":5,"b":3}}}' | npm run start:stdioAvailable Tools
The calculator MCP server provides these mathematical operations:
- add: Add two numbers (a + b)
- subtract: Subtract two numbers (a - b)
- multiply: Multiply two numbers (a * b)
- divide: Divide two numbers (a / b)
All tools require two numeric parameters: a and b.
Client Configuration
For MCP Client Configuration
When configuring MCP clients that support both transports, you can choose:
- HTTP Configuration (good for web applications):
{
"mcpServers": {
"calculator": {
"command": "node",
"args": ["dist/index.js", "http"],
"env": {
"PORT": "3000"
}
}
}
}- Stdio Configuration (standard MCP approach):
{
"mcpServers": {
"calculator": {
"command": "node",
"args": ["dist/index.js", "stdio"]
}
}
}Environment Variables
PORT: HTTP server port (default: 3000, only applies to HTTP mode)
Development
The server defaults to HTTP mode if no transport argument is provided:
# These are equivalent
npm start
npm run start:httpUse the transport-specific scripts for explicit mode selection.
