Skip to main content
Glama
README.md
# cootmcp

An MCP (Model Context Protocol) server that lets Claude control [Coot](https://www2.mrc-lmb.cam.ac.uk/personal/pemsley/coot/) — the macromolecular graphics program — interactively.

Claude can load structures and maps, navigate the view, run refinement, validate geometry, and see the live Coot window via screenshots, creating a feedback loop between Claude's reasoning and what you see on screen.

![demo](/images/demo1.png)

---

## How it works

```
Claude (MCP client)
    │  stdio JSON-RPC
    ▼
server.py  (MCP server)
    │                │
    │ XML-RPC       │ screencapture
    │ port 40000     │
    ▼               ▼
Coot 1.x        macOS window
(coot-1)        → PNG → Claude sees it
```

1. `server.py` runs as an MCP server 
2. It connects to a running Coot session via Coot's built-in XML-RPC interface (enabled by `coot_startup.py`)
3. The `screenshot_coot` tool captures the native Coot window and returns it as an inline image Claude can see

---

## Requirements

- macOS (uses `screencapture` and AppleScript for window capture)
- [CCP4 9](https://www.ccp4.ac.uk) with Coot 1.x installed at `/Applications/ccp4-9/`
- Python 3.9+

Install Python dependencies:

```bash
pip install -r requirements.txt
```

---

## Setup

### 1. Register the MCP server with Claude

Tip: If you have any trouble with the following steps, ask Claude Code for help!

Add to your Claude Desktop config at `~/Library/Application Support/Claude/claude_desktop_config.json`:

```json
{
    "mcpServers": {
        "coot": {
            "command": "python",
            "args": ["/Users/yourname/Claude/cootmcp/server.py"]
        }
    }
}
```

Or for the `claude` CLI, add to `~/.config/claude/mcp.json`:

```json
{
    "coot": {
        "command": "python",
        "args": ["/Users/yourname/Claude/cootmcp/server.py"]
    }
}
```

### 2. Restart Claude Desktop (or reload the CLI)

The `coot` MCP server will appear in your tools list.

---

## Usage

Tip: I have found running the tool through Claude Code to be the most reliable method for getting started as opposed to Claude Chat. This also permits editing cootmcp if bugs are encountered along the way!

Once registered, Claude has access to tools such as:

| Tool | What it does |
|------|-------------|
| `launch_coot` | Start Coot 1.x and enable XML-RPC; run this first |
| `screenshot_coot` | Capture the live Coot window — Claude sees the image |
| `get_status` | Check connection and list loaded molecules |
| `load_structure` | Load a PDB or mmCIF file |
| `load_map` | Load an MTZ map (specify F and PHI column labels) |
| `list_molecules` | List all loaded molecules and maps with their numbers |
| `go_to_residue` | Navigate to a specific chain/residue |
| `set_map_sigma` | Adjust map contour level (in sigma units) |
| `refine_residues` | Run real-space refinement on residues |
| `validate_geometry` | Check Ramachandran and rotamer scores |
| `get_lessons` | Load accumulated tips and lessons from past sessions |
| `save_lesson` | Save a new lesson or finding for future sessions |
| `run_coot_python` | Execute arbitrary Python in Coot (escape hatch) |

### Example conversation

```
You: Load 1abc.pdb and show me what it looks like.

Claude: [calls launch_coot, load_structure, screenshot_coot]
        Here's the structure loaded in Coot — I can see a well-ordered
        protein chain. The map appears...

You: Navigate to residue A45 and check the fit.

Claude: [calls go_to_residue, screenshot_coot]
        Residue A45 (Lys) looks like it may have a rotamer issue —
        the sidechain is reaching outside the density. Want me to refine it?
```

---

## How Coot's XML-RPC server works

`coot_startup.py` is passed to Coot at launch via `--script`. It starts a Python `SimpleXMLRPCServer` on port 40000 (localhost only), polled via a GLib timer on Coot's main thread. The server dispatches method calls directly to Coot's Python API, so almost every `coot.*` function is callable remotely. A special `eval` method handles arbitrary Python expressions and multi-statement blocks.

To start Coot manually with XML-RPC enabled:

```bash
/Applications/ccp4-9/libexec/coot-1 --script /path/to/cootmcp/coot_startup.py
```

---

## Configuration

| Environment variable | Default | Description |
|---------------------|---------|-------------|
| `COOT_XMLRPC_PORT` | `40000` | Port for Coot XML-RPC server |
| `COOT_BINARY` | `/Applications/ccp4-9/libexec/coot-1` | Path to the `coot-1` executable |


---

## Project structure

```
cootmcp/
├── server.py          # MCP server — all tool definitions and handlers
├── coot_client.py     # XML-RPC client wrapper and Coot launcher
├── coot_startup.py    # Script passed to Coot to enable XML-RPC
├── screenshot.py      # macOS window capture (screencapture + AppleScript)
├── coot_memory.json   # Persistent lessons accumulated across sessions
├── requirements.txt   # Python dependencies
└── README.md
```

---

## Persistent memory

The server maintains a `coot_memory.json` file that accumulates lessons across sessions, such as Coot API quirks, map loading gotchas, and refinement workflows that work well.

Think of it like a real crystallographer, it gets better with experience! (but less tired)

At the start of a session, call `get_lessons` (optionally filtered by category) to load relevant context. When something non-obvious is discovered during a session, call `save_lesson` to persist it. Available categories: `maps`, `refinement`, `validation`, `file-formats`, `rotamers`, `api`.

This memory is shared across all clients using the same server install, therefore any crystallographer using the tool benefits from lessons learned by others.

---

## Notes & limitations

- **macOS only** — screenshot capture uses `screencapture` and `osascript`
- **Coot must be visible** for window-specific capture; the tool falls back to a full-screen capture if the window ID can't be determined
- **XML-RPC method availability** depends on what Coot's internal Python exposes; the `run_coot_python` tool provides a fallback for anything not directly supported
- Screenshots are resized to max 1280px wide to keep token usage reasonable (requires Pillow)

---

## License

MIT

## Work Cited

@Article{emsley2010:coot,
  author =    {Paul Emsley and Bernhard Lohkamp and William G. Scott and Kevin Cowtan},
  title =     {Features and Development of Coot},
  journal =   {Acta Crystallographica Section D - Biological Crystallography},
  year =      2010,
  volume =    66,
  pages  =    486-501
}

## Citation

@misc{cootmcp,
  author = {Kody A. Klupt},
  title = {cootmcp: An MCP server for controlling Coot},
  year = {2026},
  url = {https://github.com/kodyklupt/cootmcp},
}

## Use of AI 

This project was developed with the assistance of Claude Code, an AI coding agent, and is intended to be used as a tool for crystallographers to assist in their work! Enjoy and make it your own!