HEP-KE

spectra-mcp-server

Community HEP-KE
Updated

spectra-mcp-server

Part 1 of the client-server agent tutorial. An MCP server that exposescosmology tools — CLASS matter power spectra compared against eBOSS DR14Lyman-α forest data — to any LLM agent.

Part 2, the multi-agent client that drives this server, lives inmultiagent-client-demo.Setup instructions for both repos are in that repo'sprep.md.

The one idea this repo teaches

The science code stays normal Python. The MCP wrapper only publishes it.

  • tools/ is an ordinary science package: parameter dictionaries, a CLASScall, matplotlib. It never imports MCP. The power-spectrum example lives intools/spectra_tools.py; your own science goes in sibling modules.
  • mcp_server/ is a ~70-line generic wrapper. It reads one line of config frompyproject.toml, imports the science package, and registers every functionlisted in its __all__ as an MCP tool.
[tool.mcp-server]
tool_modules = ["tools"]

Your type hints, Pydantic Field constraints, and docstrings become the toolschema agents see. To build your own server: drop your modules into tools/(or point that one config line at your own package), list the public functionsin __all__, done.

Layout

data/DR14_pm3d_19kbins.txt        eBOSS DR14 Ly-α P(k): 19 bins of (k, P, σ)
tools/
  cosmology.py                    CLASS parameter sets (Planck 2018) + run_class()
  spectra_tools.py                the 4 tool functions + ArtifactResult contract
  __init__.py                     __all__ — ONLY these names become tools
mcp_server/                       generic drop-in wrapper (FastMCP)
notebooks/01_manual_pipeline.ipynb  the walkthrough: science → tools → server
tests/test_tools.py               tools tested as plain Python, no MCP needed

About the data file

DR14_pm3d_19kbins.txt is taken verbatim frommarius311/mpk_compilation(Chabanier, Millea & Palanque-Delabrouille 2019,arXiv:1905.08103): the z = 0 linearmatter power spectrum inferred from the eBOSS DR14 Ly-α forest. Mind thefile's mixed units — k is in 1/Mpc while P(k), σ are in (Mpc/h)³ (thesource notebook plots errorbar(k/h, Pk)). tools/spectra_tools.py does thek/h conversion once, on load; read the file any other way and the dataappears offset from theory by a factor ~2.

Tools

tool what it does
get_eboss_data() return the 19 observed (k, P(k), σ) bins
list_cosmology_models() valid model names (lcdm, nu_mass, wcdm) + tunables
compute_power_spectrum(model, output_dir, ...) run CLASS, write pk_<model>.csv
plot_power_spectra(spectrum_files, output_dir, ...) two-panel figure: P(k) + data, ratio panel

Two conventions worth copying into any science MCP server:

  1. Every tool returns {status, files, message, metadata} (ArtifactResult).
  2. Arrays move between tools as file paths, never through the agent'scontext window.

Install

conda create -n spectra-tutorial python=3.12 -y
conda activate spectra-tutorial
pip install -e ".[dev]"       # classy compiles from source; see prep.md if it fails
pytest                        # 7 tests, no server or API key needed

Run the server

Streamable HTTP — the server is a visible process with a URL:

python -m mcp_server --transport streamable-http --port 8000
# clients connect to http://127.0.0.1:8000/mcp

stdio — do not start it yourself; the client spawns it as a subprocess:

{"spectra": {"transport": "stdio", "command": "python",
             "args": ["-m", "mcp_server"], "cwd": "<this repo>"}}

Spelling tripwire: this CLI says streamable-http (hyphen); most Pythonclient configs say streamable_http (underscore).

Start with the notebook

notebooks/01_manual_pipeline.ipynb builds everything up in order: the data,the science by hand, the same science as tools, then the server. Committedoutputs let you read it without running anything.

MCP Server · Populars

MCP Server · New

    atilaahmettaner

    TradingMCP: Market Data & Technical Analysis for AI Assistants

    MCP server for market analysis in AI assistants: screeners, multi-timeframe technical analysis, backtests and sentiment for crypto, stocks, forex and futures. 39 tools. Self-host free, or use the hosted version, TradingMCP.

    Community atilaahmettaner
    lifan-builds

    Faster Mac Use (fmu)

    Background-first, multi-cursor browser and native macOS computer-use engine for AI agents

    Community lifan-builds
    agent360dev

    Agent360 Browser MCP

    The browser tool that can stop and ask you. A 2FA code, a CAPTCHA, a choice only you can make: it asks on your screen, then carries on in the same signed-in Chrome. 41 tools, MCP clients that run local servers, MIT.

    Community agent360dev
    robinAKL

    Agent Room

    Put Claude Code, Cursor, Codex, Gemini & Antigravity in one room — real-time multi-agent AI collaboration over MCP for distributed dev, code review, PR handoff & frontend↔backend integration. Free, self-hostable, MCP-native.

    Community robinAKL
    blen-labs

    Capture MCP

    AI-native Model Context Protocol (MCP) server that integrates SAM.gov, USASpending.gov, and Tango APIs to capture and analyze federal procurement and spending data through natural language queries. Responses include both human-readable text and structured JSON so MCP-compatible clients can consume the data programmatically.

    Community blen-labs