Skip to main content
Glama
FastMCP Science Demo

FastMCP Science Demo

by HEP-KE

Science MCP Server Starter

CI tutorial · part of the HEP-KE MCP server library

Minimal starter code for wrapping science functions as MCP tools. It is the smallest complete instance of the HEP-KE MCP server standard: copy it to start a new server. The science code stays normal Python; the generic MCP wrapper (mcp_server/) only imports the public tool functions listed in pyproject.toml and exposes them through FastMCP, together with the server-side skills in skills/.

This repo only defines the MCP server. Agent code lives in the client repo that connects to it.

At a glance

Category

tutorial

Domain

none (demo functions)

HPC dispatch

no (see Add HPC dispatch later)

Skill prefix

demo (list_demo_skills, load_demo_skill)

Default port

8000 (streamable-http)

Hosted endpoint

none

Related MCP server: math-anchor

Connect Science Code

The whole loop for a new server is: write a function in tools/, list the module in pyproject.toml, add a skill .md, run the tests.

pyproject.toml            [tool.mcp-server]: name, skill prefix, port, tool modules
mcp_server/               generic wrapper (copied from the standard, never edited)
mcp_server/INSTRUCTIONS.md   what your server does - the one per-server file in mcp_server/
tools/common.py           ArtifactResult, ok(), output helpers
tools/meta/               generic: list_<prefix>_skills / load_<prefix>_skill
tools/demo/               your science code: one sub-package per tool family
skills/*.md               recipes that chain your tools (also served as MCP prompts)
tests/                    test_contract.py + smoke_server.py (generic), test_demo.py (yours)
  1. Create normal Python functions in a tool family under tools/ (this repo uses tools/demo/). Validate arguments with Pydantic, say in the docstring when to use the tool, write files to output_dir, and return ok(...):

from typing import Annotated
from pydantic import Field, validate_call
from ..common import ArtifactResult, ok, resolve_outdir

@validate_call
def plot_sine_wave(
    output_dir: Annotated[str, Field(min_length=1, description="Directory for output files.")],
    num_points: Annotated[int, Field(ge=2, le=1000, description="Number of samples.")] = 200,
) -> ArtifactResult:
    """Plot one period of sin(x) and save it as a PNG in output_dir.

    Use this tool when a workflow needs a simple generated plot artifact.
    """
    outdir = resolve_outdir(output_dir)
    ...
    return ok("Generated sine wave plot.", [plot_path], num_points=num_points)
  1. Export only the MCP tools from the family's __init__.py.

from .science_tools import generate_random_points, plot_points, plot_sine_wave

__all__ = ["generate_random_points", "plot_sine_wave", "plot_points"]

Only names in __all__ become MCP tools. Helper functions stay private. This starter does not scan a repo for functions.

  1. List the module in pyproject.toml (tools.meta stays first).

dependencies = [
    "mcp[cli]>=1.27,<2",
    "pydantic>=2,<3",
]

[tool.mcp-server]
name = "Science MCP Server"
skill_prefix = "demo"
port = 8000
hpc = false
tags = ["tutorial"]
instructions_file = "mcp_server/INSTRUCTIONS.md"
tool_modules = ["tools.meta", "tools.demo"]
  1. Add a skill: a markdown file in skills/ whose frontmatter name equals the file stem. Every server ships <prefix>-tour.md plus at least one science recipe.

---
name: random-points-scatter
description: Recipe - generate a reproducible random-point dataset and scatter-plot it
---
1. generate_random_points(output_dir, count, seed) ...
  1. Run the tests (tests/test_contract.py checks all of the above).

uv sync --extra dev
uv run pytest -m "not network and not slow"
uv run python tests/smoke_server.py

To start your own server from this one: copy the repo, rename tools/demo/, change [tool.mcp-server] (name, skill_prefix, a free port, tags) and mcp_server/INSTRUCTIONS.md, rename skills/demo-tour.md to skills/<prefix>-tour.md, and update .mcp.json. Keep the generic files untouched so _standard/sync.py can update them.

Tools

tool

what it does

list_demo_skills / load_demo_skill

server-side skills (also served as MCP prompts)

generate_random_points

write a deterministic CSV of (x, y) points in the unit square

plot_points

scatter-plot the x, y columns of a CSV (e.g. the one above) to a PNG

plot_sine_wave

plot one period of sin(x) to a PNG

Demo Tools

The demo science package exposes:

generate_random_points(output_dir: str, count: int = 30, seed: int = 42) -> ArtifactResult
plot_sine_wave(output_dir: str, num_points: int = 200) -> ArtifactResult
plot_points(csv_path: str, output_dir: str) -> ArtifactResult

The type hints, docstrings, and Pydantic constraints become the MCP tool schema that external agents see.

Successful artifact tools return:

{"status": "success", "files": ["..."], "message": "...", "metadata": {}}

Tools pass data to each other as file paths: plot_points takes the CSV that generate_random_points wrote, not the numbers.

Skills

skill

use it to

demo-tour

a one-minute guided run through every tool

random-points-scatter

make a reproducible random-point dataset, sanity-check it, and plot it

Install and run

git clone https://github.com/HEP-KE/science-starter-server.git && cd science-starter-server
uv sync                                  # creates this server's own .venv from uv.lock
./run_server.sh                          # stdio (what agent clients launch)
./run_server.sh --transport streamable-http --port 8000   # URL endpoint at http://127.0.0.1:8000/mcp

Without uv: python3.12 -m venv .venv && .venv/bin/pip install -e ..

Connect a client

Connect an agent with one transport.

Use stdio for a local MCP server that the agent's MCP client starts for you. Do not start the stdio server in a separate terminal. Configure the client with the command and arguments to launch. Claude Code picks up .mcp.json from the repo directory automatically, or:

claude mcp add demo -- /path/to/science-starter-server/run_server.sh

A generic client config:

{
  "demo": {
    "transport": "stdio",
    "command": "/path/to/science-starter-server/run_server.sh",
    "args": ["--transport", "stdio"]
  }
}

Use streamable-http when the agent connects to an already running server. Start the server in a terminal:

./run_server.sh --transport streamable-http --host 127.0.0.1 --port 8000

Then point the agent at:

http://127.0.0.1:8000/mcp

Claude Desktop, Codex, ChatGPT, Antigravity and hep-genesis-agent: see the library site.

demo-notebooks/demo_remote_database_search_mcp.ipynb is a self-contained walk-through of MCP tool design (a read-only remote-database search server) driven from LangGraph and Archi.

Add HPC dispatch later

This starter has hpc = false. When a tool becomes heavy enough to run on ALCF / NERSC, follow the "HPC dispatch" section of _standard/STANDARD.md in the MCPs_servers library (reference implementation: supernova-data-server):

  1. Set hpc = true in [tool.mcp-server] and append "mcp_server.dispatch" last to tool_modules.

  2. Copy the generic mcp_server/dispatch.py (_standard/sync.py <dir> does it once hpc = true). It adds set_dispatch, get_dispatch, auth_status and export_dispatch_pack.

  3. Move the compute into tools/<family>/kernels.py: pure functions, JSON-safe arguments in, a JSON-safe dict out, files written to the working directory, importing only numpy/scipy/astropy and declared pip_deps.

  4. Declare them in the family's __init__.py as DISPATCH_KERNELS = {key: {"function": "<family>.kernels.<fn>", "args_shape", "pip_deps", "duration_hint_s", "returns"}}, and make the heavy tool branch on remote_site() (run_kernel(...) when a site is set, the same kernel locally otherwise). Mark it fn.weight = "heavy".

  5. Add skills/hpc-dispatch-handoff.md. The contract tests then check the dispatch tools, the pack and the kernels.

Development and tests

uv sync --extra dev
uv run ruff check .
uv run pytest -m "not network and not slow"   # contract + science tests (what CI runs)
uv run pytest -m network                       # tests that download public data (none here)
uv run python tests/smoke_server.py            # live stdio server: lists tools and prompts

The generic files (mcp_server/ except INSTRUCTIONS.md, tools/meta/, tests/test_contract.py, tests/smoke_server.py, .github/workflows/ci.yml, run_server.sh) come from the HEP-KE MCP server standard; do not edit them per server.

Limitations

The demo tools are deliberately trivial (random points, a sine wave); they exist to show the structure, not to do science. No HPC dispatch, no data registry, no hosted endpoint.

Citation and license

MIT License, see LICENSE. Part of the HEP-KE MCP server library.

Available Tools

2 tools
generate_random_pointsA

Generate random point data and save it as a CSV in output_dir.

Use this tool when a workflow needs a small deterministic dataset for
downstream analysis or visualization.

Args:
    output_dir: Directory where the CSV should be written.
    count: Number of point rows to generate. Must be at least 1.
    seed: Seed for deterministic random data.

Inputs: output_dir (required), seed, count. Returns: Success result returned by artifact-producing MCP tools.

plot_sine_waveA

Plot a sine wave and save it as a PNG in output_dir.

Use this tool when a workflow needs a simple generated plot artifact for
downstream inspection or reporting.

Args:
    output_dir: Directory where the PNG should be written.
    num_points: Number of samples to plot. Must be at least 2.

Inputs: output_dir (required), num_points. Returns: Success result returned by artifact-producing MCP tools.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 2 tools

    Disambiguation5/5

    The two tools have clearly distinct purposes: one generates random point data, the other plots a sine wave. There is no overlap or ambiguity.

    Naming Consistency5/5

    Both tools follow a consistent verb_noun pattern: generate_random_points and plot_sine_wave. The naming is clear and predictable.

    Tool Count3/5

    With only 2 tools, the server feels minimal for a science demo. While it might be intentionally lightweight, it is on the low end of reasonable scope.

    Completeness2/5

    The tool set lacks integration between the two capabilities. There is no tool to visualize the random points or generate data for the sine wave plot, leaving a gap in typical scientific workflows.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Provides a safe scientific runtime for agents with typed math operations including calculus, algebra, statistics, unit conversion, and more via MCP tools.
      4
      Apache 2.0
    • F
      license
      A
      quality
      D
      maintenance
      Enables exposing custom tools such as dice rolling and integer addition as MCP servers over stdio and HTTP transports.
      2
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables turning any Python function into an auto-registered MCP tool and serving them over a FastMCP server with auto-discovery, optional auth, and request context.
      MIT