> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Basic Calculator MCP Server

> Learn how to build a simple calculator MCP server that provides basic math operations using FastMCP.

Let's create a simple calculator MCP server that provides basic math operations.

```python server.py expandable lines theme={"dark"}
from fastmcp import FastMCP

mcp = FastMCP("Calculator MCP Server")

@mcp.tool
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b

@mcp.tool
def subtract(a: int, b: int) -> int:
    """Subtract two numbers"""
    return a - b

@mcp.tool
def multiply(a: int, b: int) -> int:
    """Multiply two numbers"""
    return a * b

@mcp.tool
def divide(a: float, b: float) -> float:
    """Divide two numbers"""
    if b == 0:
        raise ValueError("Cannot divide by zero")
    return a / b

@mcp.tool
def power(a: int, b: int) -> int:
    """Raise a number to the power of another number"""
    return a ** b

if __name__ == "__main__":
    mcp.run(transport="http", host="0.0.0.0", port=8000, path="/mcp")
```

```txt requirements.txt lines theme={"dark"}
fastmcp>=2.10.4
requests>=2.31.0
```

## Run Locally

```bash lines theme={"dark"}
# Install dependencies
pip install -r requirements.txt

# Run the server
python server.py
```

Your MCP server will be available at `http://localhost:8000/mcp`.

> [!TIP]
>
> We have already added this code to a Github Repo and deployed it on our live demo link:
>
> `Repository:` You can find the complete example code at: [Calculator MCP Server](https://github.com/truefoundry/mcp-servers/tree/main/simple-calculator-mcp)
>
> `Deployment:` You can find the live demo link at: [Calculator MCP Server Deployment](https://platform.live-demo.truefoundry.cloud/deployments/cmcnc0pml0q2x01qs4hiwh6fb?tab=pods)
>
> `Server Endpoint:` The MCP server can be accessed at this endpoint: [https://calculator-mcp-server.apps.live-demo.truefoundry.cloud](https://calculator-mcp-server.apps.live-demo.truefoundry.cloud)

## Register in TrueFoundry

To add this MCP server, follow [Getting Started](https://www.truefoundry.com/docs/ai-gateway/mcp/mcp-server-getting-started.md). Example values:

| Field | Value |
| - | - |
| **Name** | `calculator-mcp-server` |
| **Display Name** | Calculator |
| **Endpoint URL** | `https://calculator-mcp-server.apps.live-demo.truefoundry.cloud/mcp` |
| **Description** | A simple calculator MCP server |
| **Authentication** | No Auth |

To protect the server with OAuth, register it in [Okta](https://www.truefoundry.com/docs/ai-gateway/mcp/okta-app-setup.md) or [Microsoft Entra](https://www.truefoundry.com/docs/ai-gateway/mcp/entra-app-setup.md), then follow [Okta OAuth MCP server](https://www.truefoundry.com/docs/ai-gateway/mcp/mcp-server-oauth-okta.md) or [Microsoft Entra OAuth](https://www.truefoundry.com/docs/ai-gateway/mcp/mcp-server-oauth-azure.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.