Calculator MCP Server
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
FastMCP Calculator Example
English | 繁體中文
A small calculator MCP server built with FastMCP that shows how to expose an MCP server on a private network safely: API key or bearer token auth, Host / Origin / client IP allowlists (proxy-aware), and a JSONL audit log with a trace ID for every tool call. Includes client setup for Claude Desktop and Codex and an Nginx HTTPS reverse proxy example.
Tools:
add(a, b)subtract(a, b)get_server_status()
There is a single entry point: server.py.
Main files
server.py: starts the MCP HTTP servermcp_server/config.py: readsconfig.production.envmcp_server/security.py: checks the API key, Host, and client IPmcp_server/audit.py: writeslogs/tool_calls.jsonlmcp_server/tools.py: calculator toolsconfig.production.example.env: config templatenginx.conf: Ubuntu / Nginx HTTPS reverse proxy example
Related MCP server: Okta Calculator MCP Server
Install
Windows 11
In Anaconda Prompt or cmd:
conda create -n calculator python=3.11
conda activate calculator
pip install -r requirements.txt
mkdir logs
copy config.production.example.env config.production.envUbuntu
sudo apt update
conda create -n calculator python=3.11
conda activate calculator
pip install -r requirements.txt
mkdir -p logs
cp config.production.example.env config.production.envLocal setup and start
Edit config.production.env first. For local testing:
MCP_HOST=127.0.0.1
MCP_PORT=8000
MCP_PATH=/mcp
MCP_BEARER_TOKENS=test-token
MCP_API_KEYS=test-api-key
MCP_ALLOWED_HOSTS=localhost,127.0.0.1
MCP_ALLOWED_ORIGINS=
MCP_ALLOWED_CLIENT_CIDRS=127.0.0.1/32
MCP_TRUSTED_PROXY_CIDRS=127.0.0.1/32
MCP_AUDIT_LOG=./logs/tool_calls.jsonlconfig.production.env is in .gitignore. Change the token and API key for real use.
Start the server:
Windows cmd or PowerShell
python .\server.pyUbuntu
python server.pyserver.py reads config.production.env from the project folder automatically. Set MCP_CONFIG_FILE only if you want to use a different config file.
Default endpoint:
http://127.0.0.1:8000/mcpIf opening it in a browser shows:
{"error": "missing_or_invalid_token"}the server is running.
MCP client setup
These examples use the local server and X-API-Key: test-api-key.
Claude Desktop
{
"mcpServers": {
"calculator": {
"type": "http",
"url": "http://127.0.0.1:8000/mcp",
"headers": {
"X-API-Key": "test-api-key"
}
}
}
}Codex
~/.codex/config.toml
[mcp_servers.calculator]
url = "http://127.0.0.1:8000/mcp"
http_headers = { "X-API-Key" = "test-api-key" }or, for a remote server:
[mcp_servers.calculator]
url = "http://<server-ip>:8000/mcp"
http_headers = { "X-API-Key" = "test-api-key" }Once connected, the client should list:
addsubtractget_server_status
Using it on a private network
1. Direct connection test
To check that another computer can reach the server before setting up HTTPS or a reverse proxy, open port 8000 directly.
Change config.production.env to:
MCP_HOST=0.0.0.0
MCP_PORT=8000
MCP_PATH=/mcp
MCP_BEARER_TOKENS=
MCP_API_KEYS=test-api-key
MCP_ALLOWED_HOSTS=localhost,127.0.0.1,<server-tailscale-ip>
MCP_ALLOWED_ORIGINS=
MCP_ALLOWED_CLIENT_CIDRS=100.64.0.0/10,127.0.0.1/32,<client-tailscale-ip>/32,<client-ip>/32
MCP_TRUSTED_PROXY_CIDRS=127.0.0.1/32
MCP_AUDIT_LOG=./logs/tool_calls.jsonlTo allow only one computer, set MCP_ALLOWED_CLIENT_CIDRS to its actual IP and Tailscale IP with /32, for example:
MCP_ALLOWED_CLIENT_CIDRS=100.101.102.103/32,192.168.1.50/32,127.0.0.1/32Open the firewall on Windows:
New-NetFirewallRule -DisplayName "Calculator MCP 8000" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 8000Check the rule:
Get-NetFirewallRule -DisplayName "Calculator MCP 8000"On Ubuntu with ufw:
sudo ufw allow 8000/tcp
sudo ufw statusTest URL:
http://<server-tailscale-ip>:8000/mcpIf the browser shows:
{"error": "missing_or_invalid_token"}the network, Host, and client IP checks all pass.
2. Production deployment
For real use, don't expose port 8000 directly. Instead:
Set
MCP_HOST=127.0.0.1Let the app listen only on
127.0.0.1:8000Put an HTTPS reverse proxy in front of it
Expose:
https://mcp.intra.example.com/mcpOn Ubuntu, use nginx.conf as a starting point. On Windows, use IIS, Caddy, or Nginx for Windows.
You will also need:
Internal DNS
A TLS certificate
Port
443open in the firewallA real API key
Checks and troubleshooting
Is the config file being read?
Windows cmd, PowerShell, or Ubuntu:
python -c "from mcp_server.config import load_settings; s=load_settings(); print(s.host); print(s.allowed_hosts); print(s.allowed_client_cidrs)"Is the server listening on the network?
Windows:
netstat -ano | findstr :8000Ubuntu:
ss -ltnp | grep 8000For the direct connection test you should see:
0.0.0.0:8000If you see:
127.0.0.1:8000the server is bound to localhost only, and other computers can't reach it.
Minimal test with curl
The server uses MCP streamable HTTP, so curl must also send:
Accept: text/event-streamWindows PowerShell:
curl.exe -H "X-API-Key: test-api-key" -H "Accept: text/event-stream" http://<server-tailscale-ip>:8000/mcpUbuntu:
curl -H "X-API-Key: test-api-key" -H "Accept: text/event-stream" http://<server-tailscale-ip>:8000/mcpWithout Accept, the usual response is:
{"jsonrpc":"2.0","id":"server-error","error":{"code":-32600,"message":"Not Acceptable: Client must accept text/event-stream"}}The server isn't broken; the request just doesn't follow the MCP protocol.
Common mistakes
The config file is not in the project folder when you run
python .\server.pyorpython server.py. The program readsconfig.production.envfrom the project folder automatically. If you keep it somewhere else, setMCP_CONFIG_FILE.MCP_HOSTis still127.0.0.1. Only this computer can connect; other computers time out.MCP_ALLOWED_HOSTSdoesn't include the Host the client actually uses. For example, if the client connects tohttp://100.101.102.104:8000/mcp,MCP_ALLOWED_HOSTSmust include100.101.102.104.MCP_ALLOWED_CLIENT_CIDRSdoesn't include the client's real source IP. Over Tailscale, the server usually sees the client's100.x.x.xaddress, not192.168.x.x.The firewall is open, but the server still listens only on
127.0.0.1. Opening the firewall is not enough: setMCP_HOST=0.0.0.0and restart the server.An error from a browser or plain
curlis mistaken for a broken server.missing_or_invalid_tokenusually means the endpoint is reachable;Not Acceptable: Client must accept text/event-streamusually means both the endpoint and the API key work.
Common responses
missing_or_invalid_tokenThe endpoint is reachable, but there is no valid API key or bearer token.host_not_allowedMCP_ALLOWED_HOSTSdoesn't include the Host used.client_ip_not_allowedMCP_ALLOWED_CLIENT_CIDRSdoesn't include the client's source IP.origin_not_allowedThe client sent anOriginthat is not on the allowlist.TLS errors The certificate or trust chain isn't set up yet.
Tests
pip install pytest
python -m pytest -qtests/test_server.py starts a real server and connects with an MCP client to check: a missing or wrong key returns 401, a Host or Origin not on the allowlist returns 403, all three tools are listed, and after a call the audit log has an entry with the same trace ID. tests/test_config.py checks config loading. GitHub Actions runs them on every push.
What success looks like
logs/tool_calls.jsonlis created when the server startsThe MCP client sees the three calculator tools
After a tool call, the audit log records the tool name, trace ID, and result
Not done yet
No built-in way to run in the background. You start it by hand with
python server.py; there is no Windows service, systemd service, or other auto-start yet.No finished HTTPS reverse proxy setup. The repo has an
nginx.confexample, but the domain, certificate, DNS, and proxy deployment depend on your environment.No user roles or key management. Authentication is basic (
MCP_API_KEYS/MCP_BEARER_TOKENS); there is no fuller permission model, key rotation, or SSO.
License
Apache-2.0, see LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
MCP gateway: one connection for your AI apps, with tool policies, PII redaction and audit logs.
Zero-setup MCP gateway securely connecting AI to your tools with authentication and workflows
Find, vet, and run MCP tools through a secure audited gateway with prompt-injection risk scoring
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to discover and execute tools via a secure MCP server with JWT authentication, RBAC, rate limiting, and audit logging.1MIT
- AlicenseNot gradedqualityDmaintenanceExposes basic calculator tools (add, subtract, multiply, divide) and validates Okta access tokens on tool calls for secure access.MIT
- AlicenseNot gradedqualityCmaintenanceEnables production-hardened MCP tool serving with OAuth 2.1 audience-restricted tokens, purpose-bound tools, human-in-the-loop approvals, containment, and audit trails for AI agents.Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables LLM agents to access multiple stdio or Streamable HTTP MCP servers through one authenticated endpoint, enforcing OAuth bearer validation, per-client tool RBAC, rate limits, schema validation, audit logging, and tool-definition pinning.MIT