MCP System Tools Server
by B-DINESH9
README.md
# MCP System Tools Server
A Python **Model Context Protocol (MCP)** server built with **FastMCP** that exposes host system monitoring and safe arithmetic calculation tools to AI agents and MCP clients over **Server-Sent Events (SSE)**.
## Prerequisites
- **Python 3.10+** (required for local execution)
- **Docker & Docker Compose** (optional, for containerized execution)
- **Node.js / npm** (optional, required only for running the MCP Inspector via `npx`)
## Project Structure
```text
mcp-system-tools/
├── mcp_server.py # FastMCP server, tool definitions, and FastAPI app definition
├── test_client.py # Async Python test client for verifying SSE tool discovery & calls
├── requirements.txt # Python dependencies (fastapi, uvicorn, fastmcp, psutil)
├── Dockerfile # Python 3.10-slim container setup
├── docker-compose.yml # Docker Compose service configuration on port 8000
└── README.md # Project documentation
```
## Included Tools
### 1. `get_system_stats`
Retrieves live CPU and memory usage metrics from the host machine using `psutil`.
- **Parameters:** None (`{}`)
- **Returns (`dict`):**
- `cpu_usage_percent` (`float`): CPU utilization percentage sampled over a 1-second interval.
- `memory_usage_percent` (`float`): Percentage of system virtual memory currently in use.
- `memory_available_mb` (`float`): Available physical memory in megabytes.
**Example Output:**
```json
{
"cpu_usage_percent": 14.5,
"memory_usage_percent": 62.3,
"memory_available_mb": 6124.82
}
```
### 2. `calculate_expression`
Evaluates a basic arithmetic expression after validating it against a strict character allowlist (`0-9`, `+`, `-`, `*`, `/`, `(`, `)`, `.`, and whitespace).
- **Parameters:**
- `expression` (`string`, required): Arithmetic expression to evaluate (e.g., `"(12 + 8) * 3 / 2"`).
- **Returns (`float`):** Evaluated numeric result. Raises `ValueError` if disallowed characters or invalid syntax are provided.
## Getting Started
### 1. Clone the Repository
```bash
git clone https://github.com/B-DINESH9/mcp-system-tools.git
cd mcp-system-tools
```
### 2. Run Locally (Python)
1. Install dependencies (using a virtual environment is recommended):
```bash
pip install -r requirements.txt
```
2. Start the MCP server:
```bash
python mcp_server.py
```
The server starts with **SSE** transport and listens at:
`http://127.0.0.1:8000/sse`
> **Note on FastAPI `/health`:** `mcp_server.py` also defines a FastAPI `app` instance with a `GET /health` endpoint, while the `__main__` entrypoint runs `mcp.run(transport="sse")` directly.
### 3. Run with Docker
Spin up the container using Docker Compose:
```bash
docker compose up --build -d
```
*(If using Docker Compose v1, run `docker-compose up --build -d`.)*
This exposes port `8000` and mounts `./mcp_server.py` into `/app/mcp_server.py` inside the container (`mcp_tool_server`).
## Testing the Server
Make sure the server is running first (`python mcp_server.py`), then verify it using either option below.
### Option A: Python Test Client
Run the included `test_client.py` script in a new terminal:
```bash
python test_client.py
```
This connects to `http://127.0.0.1:8000/sse`, lists discovered tools, and executes `get_system_stats`.
### Option B: MCP Inspector (Web UI)
Launch the official MCP Inspector:
```bash
npx -y @modelcontextprotocol/inspector
```
In the Inspector UI:
1. Select **SSE** as the transport type.
2. Enter `http://127.0.0.1:8000/sse` as the URL.
3. Click **Connect** to browse schemas and test tools interactively.
## Connecting to Claude Desktop
Because `mcp_server.py` runs using **SSE transport** (`mcp.run(transport="sse")`), you have two ways to connect it to stdio-based clients like Claude Desktop (`claude_desktop_config.json`):
- **Keep SSE mode (with `mcp-remote` bridge):** Start `python mcp_server.py` first, then configure:
```json
{
"mcpServers": {
"system-tools": {
"command": "npx",
"args": [
"-y",
"mcp-remote",
"http://127.0.0.1:8000/sse"
]
}
}
}
```
- **Direct Python subprocess (stdio mode):** Update the last line of `mcp_server.py` from `mcp.run(transport="sse")` to `mcp.run()`, then configure:
```json
{
"mcpServers": {
"system-tools": {
"command": "python",
"args": [
"/absolute/path/to/mcp_server.py"
]
}
}
}
```
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues