# cal-server-mcp **Repository Path**: donymh/cal-server-mcp ## Basic Information - **Project Name**: cal-server-mcp - **Description**: 用@modelcontextprotocol/sdk中的Typescript SDK实现一个满足计算器的MCP - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-19 - **Last Updated**: 2025-11-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## 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 ```bash # Development mode npm run dev:http # Production mode npm run start:http # With inspector for debugging npm run inspector:http ``` #### Using HTTP Mode The server runs on `http://localhost:3000/mcp` by default (port configurable via PORT environment variable). ```bash # 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 ```bash # Development mode npm run dev:stdio # Production mode npm run start:stdio # With inspector for debugging npm run inspector:stdio ``` #### Using Stdio Mode In stdio mode, the server reads JSON-RPC messages from standard input and writes responses to standard output: ```bash # 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:stdio ``` ## Available 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: 1. **HTTP Configuration** (good for web applications): ```json { "mcpServers": { "calculator": { "command": "node", "args": ["dist/index.js", "http"], "env": { "PORT": "3000" } } } } ``` 2. **Stdio Configuration** (standard MCP approach): ```json { "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: ```bash # These are equivalent npm start npm run start:http ``` Use the transport-specific scripts for explicit mode selection.