# mcp_helpers

Shared library imported by the MCP servers. Provides two helpers.

```python
from mcp_helpers import SignedTool, signed, add_code_updater
```

## `signed` — Ed25519-signed tools

Gate an MCP tool behind a signature so only authorized callers can invoke it.

```python
# at startup:
SignedTool.load_keys({"alice": "<base64 ed25519 public key>"})

@signed("alice")
async def update_code(path: str, content: str) -> str:
    ...
```

The decorator adds `timestamp` and `signature` parameters, verifies a time window
(default ±5 min) and the Ed25519 signature, then calls your function without them.
Signed message: `"{tool_name}:{timestamp}:{sha256(json(args))}"` (deterministic JSON,
`sort_keys=True`, no spaces).

## `add_code_updater` — MCP self-edit

```python
from fastmcp import FastMCP

mcp = FastMCP("my_server")
add_code_updater(mcp, __file__)
```

Registers two tools on the server:

- `readCode()` — returns the server's own source.
- `updateCode(new_code)` — shows a diff, asks for confirmation in the server console,
  then overwrites the file and restarts the server (clients must reconnect).

## Requirements

`cryptography>=42.0.0`.
