fits-mcp
README.md
# fits-mcp
**More scientific context. Less code.**
A lightweight, scientifically aware MCP server for exploring FITS files with AI agents.
Modern AI agents are already pretty good at writing Python. But do they really need to write a new script every time they encounter a FITS file?
fits-mcp gives agents a compact, meaningful view of scientific data, helping them understand what is inside a file before deciding what to do with it.
Generic by design, scientifically aware by convention.
## What can it do?
- Explore FITS images, cubes, tables, and multi-extension files.
- Recognize FITS, WCS, ESO, and NASA/OGIP conventions.
- Inspect headers, columns, axes, units, and scientific metadata.
- Read selected data and compute descriptive statistics.
- Select data using supported physical coordinates.
- Combine related operations and follow explicit companion-file references.
Everything is read-only, bounded, and designed to avoid unnecessary data loading.
No fitting, no data reduction, no instrument-specific dependencies. Just scientific context.
## Getting started
Requires Python 3.10+ and Astropy.
```sh
pip install .
```
For Codex, add the following to `~/.codex/config.toml`:
```toml
[mcp_servers.fits]
command = "/absolute/path/to/fits-mcp"
args = ["--allow-root", "/absolute/path/to/data"]
```
Use `command -v fits-mcp` to locate the executable. Additional directories can be authorized by repeating `--allow-root`.
The server uses standard MCP over stdio and works with compatible clients.
## Six tools, one purpose
| Tool | What it does |
|---|---|
| `inspect_file` | Get a meaningful snapshot of a FITS file. |
| `inspect_hdu` | Explore an individual extension. |
| `read_header` | Retrieve original FITS metadata. |
| `read_data` | Access selected scientific values. |
| `summarize_data` | Understand the contents of a dataset. |
| `read_batch` | Combine related operations in one call. |
See the [tool contracts](docs/tool-contracts.md) for the details.
## Is it actually faster?
That was one of the first questions we asked ourselves. And initially, the answer was not particularly encouraging!
After several iterations, fits-mcp achieved promising results against direct Python/Astropy using GPT-6.2-Sol in Codex.

Both approaches correctly completed all four benchmark tasks. While fits-mcp used more total tokens, it reduced latency, uncached input, and generated output.
Cached tokens are considerably cheaper than fresh input, so total token counts alone can be misleading. The estimated cost advantage remains sensitive to cache behavior.
These are preliminary benchmarks, not universal performance guarantees.
## Less is more
One interesting lesson from building fits-mcp is that exposing too many granular operations can actually make an agent less efficient.
Frontier models have little trouble writing a few lines of Astropy code. Making them replace that code with a long sequence of tool calls is not particularly helpful.
What made the difference was providing richer, compact context in fewer interactions.
This is a small, practical example of the challenges discussed in Anthropic's [Writing effective tools for AI agents](https://www.anthropic.com/research/writing-tools-for-agents) and [Code execution with MCP](https://www.anthropic.com/research/code-execution-with-mcp).
We also experimented with TOON serialization. Somewhat surprisingly, compact JSON consistently performed better in our tests, using 19% fewer tokens across 24 paired responses. JSON is therefore the default, with TOON still available.
## Tested on real scientific data
The first release has undergone extensive testing for a project of its size:
- Around 50 automated tests.
- Eight types of real astronomical FITS products, from spectral cubes to XSPEC table models.
- Hundreds of coordinate-selection checks.
- Validation against Astropy and NumPy.
- End-to-end MCP and agent integration tests.
## A work in progress
fits-mcp is a working tool built for everyday scientific workflows, and there is certainly room to make it better.
If you work with FITS files, scientific agents, or MCP servers, contributions and feedback are very welcome.
It would be particularly interesting to explore how far we can improve efficiency and how useful this approach might become for smaller, locally hosted agents.
Built for science, with curiosity.This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessOutdated data