- Home
- MCP servers
- Calculator
Calculator
- python
0
GitHub Stars
python
Language
7 months ago
First Indexed
3 months ago
Catalog Refreshed
Documentation & install
Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.
You can run a streamable MCP server that exposes an HTTP endpoint and local STDIO runtimes to perform tools-backed computations, such as a calculator, via the MCP protocol. This server lets you initialize sessions, list available tools, and call specific tools like add in a structured, streaming MCP workflow. It is useful for interactive clients that need to discover capabilities and execute them in real time.
How to use
To use the calculator MCP server, you start by establishing a session with the MCP endpoint. Once your session is open, you can request the list of available tools, then invoke a tool by name with the required arguments. The flow supports initializing the session, opening a session, sending a notification that you are initialized, listing tools, and calling the add tool to perform arithmetic. The server communicates over the MCP protocol and supports streaming responses for interactive tool results.
How to install
Prerequisites: you need Python 3 and optionally Node.js if you want to use the Node-based tooling. You will also use a virtual environment to isolate dependencies.
Step by step commands you should run:
# create a Python virtual environment
python3 -m venv .venv
# activate the virtual environment
source .venv/bin/activate
# install dependencies for MCP server tooling
uv add mcp
uv add 'mcp[cli]'
# start the MCP server in development mode
uv run mcp dev server.py
# alternative runtime options shown in some setups
npx @modelcontextprotocol/inspector python server.py
python3 server.py
Additional content
Test workflow and tooling: you can initialize a session and then call the add tool to compute 1 + 1. The server will return the result through the MCP channel as a structured response. To interact, you typically start the server, initialize a session, and then list and invoke tools.
Notes on usage and security: keep the MCP endpoint reachable on the expected host and port (default is http://localhost:8000/mcp in examples). Use proper client headers for MCP protocol version negotiation and session management. If you rotate credentials or session IDs, ensure your client updates the session context accordingly.
Examples and quick-start commands
Below are representative commands shown for interacting with the MCP server. These illustrate the HTTP initialization flow, opening sessions, and invoking the add tool in a typical session.
curl -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2025-06-18" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{"tools":{}},"clientInfo":{"name":"test-client","version":"1.0.0"}}}'
Available tools
initialize
Start an MCP session by sending an initialize request with protocolVersion and client information.
sessions_open
Open a new MCP session to establish a session context for subsequent tool calls.
notifications/initialized
Notify the server that the client has finished initialization, establishing a session-wide state.
tools/list
Query the server for the list of available tools that can be invoked within the current session.
tools/call
Invoke a specific tool by name (for example, add) with the provided arguments to obtain a result.