spectra-mcp-server

spectra-mcp-server

MCP server that exposes cosmology tools to LLM agents, including CLASS matter power spectrum computation, eBOSS DR14 Lyman-α forest data retrieval, and plotting capabilities.

Category
访问服务器

README

spectra-mcp-server

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

Part 2, the multi-agent client that drives this server, lives in multiagent-client-demo. Setup instructions for both repos are in that repo's prep.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 CLASS call, matplotlib. It never imports MCP. The power-spectrum example lives in tools/spectra_tools.py; your own science goes in sibling modules.
  • mcp_server/ is a ~70-line generic wrapper. It reads one line of config from pyproject.toml, imports the science package, and registers every function listed in its __all__ as an MCP tool.
[tool.mcp-server]
tool_modules = ["tools"]

Your type hints, Pydantic Field constraints, and docstrings become the tool schema 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 functions in __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 from marius311/mpk_compilation (Chabanier, Millea & Palanque-Delabrouille 2019, arXiv:1905.08103): the z = 0 linear matter power spectrum inferred from the eBOSS DR14 Ly-α forest. Mind the file's mixed units — k is in 1/Mpc while P(k), σ are in (Mpc/h)³ (the source notebook plots errorbar(k/h, Pk)). tools/spectra_tools.py does the k/h conversion once, on load; read the file any other way and the data appears 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's context 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 Python client 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. Committed outputs let you read it without running anything.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选