Claude Consultant
README.md
# Claude Consultant
An MCP server that proxies technical questions to Claude Sonnet (`claude-sonnet-4-6`),
acting as a senior network engineer / Linux / RouterOS 7 expert.
Before forwarding any request to the Claude API, the server automatically detects
and masks sensitive data (IP addresses, MAC addresses, WireGuard keys, passwords,
Bearer tokens, SSH private keys, hostnames, and secret file paths).
---
## Quick start
```bash
cd /home/mgrigorov/claude-consultant
cp .env.example .env
# Edit .env — set ANTHROPIC_API_KEY and CONSULTANT_API_TOKEN
sudo bash install.sh
```
---
## Manual setup (without systemd)
```bash
python3.12 -m venv venv
source venv/bin/activate
pip install -e .
pip install pytest pytest-asyncio httpx # for tests only
cp .env.example .env
# edit .env
# Run tests
pytest -v
# stdio MCP mode (for MCP clients like Claude Code)
source .env && claude-consultant
# HTTP mode (for testing with curl)
source .env && claude-consultant --http
```
---
## Project structure
```
claude-consultant/
├── src/claude_consultant/
│ ├── config.py # Env-var configuration
│ ├── sanitizer.py # Sanitization pipeline (zero external deps)
│ ├── claude_client.py # Anthropic SDK wrapper
│ └── server.py # Entrypoint: MCP stdio + HTTP modes
├── tests/
│ ├── test_sanitizer.py # Pattern tests + edge cases
│ ├── test_mcp_tool.py # MCP tool tests (mocked API)
│ └── test_http_endpoint.py # HTTP auth + request tests
├── logs/ # Created at runtime
├── .env.example
├── claude-consultant.service
├── install.sh
└── pyproject.toml
```
---
## Configuration
| Variable | Required | Default | Description |
|---|---|---|---|
| `ANTHROPIC_API_KEY` | Yes | — | Anthropic API key |
| `CONSULTANT_API_TOKEN` | HTTP mode | — | Bearer token for HTTP endpoint |
| `LOG_DIR` | No | `./logs` | Directory for log files |
| `MAX_TOKENS` | No | `2048` | Max tokens in Claude response |
| `LOG_LEVEL` | No | `INFO` | Logging level |
---
## MCP tool: `consult_claude`
**Input**
| Field | Type | Description |
|---|---|---|
| `problem` | `string` (required) | Description of the problem |
| `context` | `string` (optional) | Config snippets, error output, logs |
**Output** — Claude's response as plain text.
**Example (Claude Code)**
```
Use the consult_claude tool with problem="BGP session drops every 30 minutes" and context="<router logs here>"
```
---
## HTTP API
### `POST /consult`
Requires `Authorization: Bearer <CONSULTANT_API_TOKEN>` header.
```bash
curl -s -X POST http://localhost:8765/consult \
-H "Authorization: Bearer $CONSULTANT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"problem": "OSPF neighbour not forming", "context": "interface ether1 is up"}'
```
**Response**
```json
{
"answer": "Check that ...",
"sanitized_fields": 0
}
```
### `GET /health`
No auth required. Returns `{"status": "ok"}`.
---
## Sanitization pipeline
The following patterns are detected and replaced **before** any data leaves the host:
| Pattern | Token |
|---|---|
| IPv4 addresses | `<IPv4_ADDR_N>` |
| IPv6 addresses | `<IPv6_ADDR_N>` |
| MAC addresses | `<MAC_ADDR_N>` |
| WireGuard keys (44-char base64) | `<WG_KEY_N>` |
| SSH/PEM private key blocks | `<SSH_PRIVATE_KEY_N>` |
| Generic private keys (base64 40+) | `<PRIVATE_KEY_N>` |
| Passwords (`password=X`, `passwd: X`, …) | `<PASSWORD_N>` |
| Bearer / API tokens | `<API_TOKEN_N>` |
| `/etc/ssl/`, `/etc/wireguard/`, … paths | `<SECRET_PATH_N>` |
| FQDNs (3+ labels with alpha TLD) | `<HOSTNAME_N>` |
**Preserved:** VLAN IDs, port numbers, protocol names, CIDR masks (`/24`),
RFC 1918 example ranges (`192.168.x.x/24`), RouterOS commands, error messages.
Every substitution is logged to `logs/sanitization.log` with pattern type and
character position. The internal reverse mapping is never serialised or transmitted.
---
## Running tests
```bash
source venv/bin/activate
pytest -v
```
---
## systemd management
```bash
sudo systemctl status claude-consultant
sudo systemctl restart claude-consultant
sudo journalctl -u claude-consultant -f
```
---
## Security notes
- Secrets are loaded exclusively from environment variables / `.env` file.
- The `.env` file is read by systemd's `EnvironmentFile=` directive; never committed to git.
- HTTP mode enforces Bearer token authentication on every request.
- systemd unit runs with `NoNewPrivileges=yes`, `PrivateTmp=yes`, `ProtectSystem=strict`.
- The sanitization reverse mapping exists only in process memory and is discarded after
each request — it is never logged, returned, or persisted.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues