sagemath-mcp: Instructions file for Claude Code

CLAUDE.md

sagemath-mcp CLAUDE.md is an instructions file for Claude Code from XBP-Europe/sagemath-mcp. It costs 2,439 tokens per session, scanned A, original, MIT.

A project guide for SageMath MCP, a server that lets language models run SageMath calculations while keeping variables between calls.

In plain words
What is it for?
Use it when developing, testing, linting, packaging, or running integration tests for the SageMath MCP server.
Why use it?
It gives the coding agent the repository’s setup, linting, testing, and build rules, including which tests need the SageMath runtime.

Instructions file for Claude Code

Written for Claude Code: the file is CLAUDE.md. Also seen: mentions CLAUDE.md; mentions Claude Code.

This is XBP-Europe/sagemath-mcp's own configuration. It tells Claude Code how to work on sagemath-mcp itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything sagemath-mcp configures →

Reuse

Borrowing it

Nothing to install: this file belongs to XBP-Europe/sagemath-mcp. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/XBP-Europe/sagemath-mcp/main/CLAUDE.md
Clone the repo
git clone --depth 1 https://github.com/XBP-Europe/sagemath-mcp

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for sagemath-mcp CLAUDE.md

README.md
[![agentmods](https://agentmods.dev/badge/instructions/xbp-europe/sagemath-mcp/claude-md/github.svg)](https://agentmods.dev/instructions/xbp-europe/sagemath-mcp/claude-md)
Your own site
<a href="https://agentmods.dev/instructions/xbp-europe/sagemath-mcp/claude-md"><img src="https://agentmods.dev/badge/instructions/xbp-europe/sagemath-mcp/claude-md/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for sagemath-mcp CLAUDE.md

Your own site · 80×15
<a href="https://agentmods.dev/instructions/xbp-europe/sagemath-mcp/claude-md"><img src="https://agentmods.dev/badge/instructions/xbp-europe/sagemath-mcp/claude-md.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 2,439 This file is loaded in full into every session.
When invoked 2,439 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.02439 $0.02439
Opus 5 $0.01220 $0.01220
Sonnet 5 $0.00488 $0.00488
Haiku 4.5 $0.00244 $0.00244

Measured 3d ago against content hash f57e7e974654, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

sagemath-mcp CLAUDE.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

CLAUDE.md · 109 lines

How it starts

The opening of the file, as written. The whole thing — 109 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project

SageMath MCP is a Model Context Protocol server exposing stateful SageMath computations to LLM clients via FastMCP. Each MCP session gets a dedicated Sage worker subprocess with persistent variable state across tool calls.

Commands

uv pip install -e .[dev]          # Install with dev extras
make lint                          # uv run ruff check
make test                          # uv run pytest (pure Python, no Sage needed)
make integration-test              # pytest inside Sage Docker container
make build                         # Build wheel + sdist via scripts/build_release.py
make sage-container                # Bootstrap the Sage Docker container
uv run pytest tests/test_server.py -k "test_name"  # Run a single test

Unit tests run with SAGEMATH_MCP_PURE_PYTHON=1 (uses Python math stdlib instead of Sage). Integration tests require docker exec sage-mcp and real Sage runtime.

Linting

Ruff with line-length 100, target Python 3.12. Rules: E, F, W, B, UP, ASYNC, RUF, I (import sorting). Run make lint before committing.

Testing

  • All async tests use @pytest.mark.asyncio (asyncio_mode is "auto")
  • Tests mirror source modules: test_server.py, test_session.py, test_security.py, test_config.py, etc.
  • test_integration.py, test_use_cases.py and most of test_math_coverage.py require the Sage container
  • Key fixtures: python_settings (injects force_python_worker=True), FakeContext (captures MCP context messages)

Architecture

Source lives in src/sagemath_mcp/:

  • server.py - Entry point: the /health route, main(), and the imports that register the tools. Re-exports the tool functions, so from sagemath_mcp import server keeps working.
  • app.py - The FastMCP object, instructions, lifespan and middleware. Owns mcp so tool modules can decorate against it without importing the module that imports them.
  • runtime.py - SETTINGS, SESSION_MANAGER and resolve_session(). Read the manager through this module (never from .runtime import SESSION_MANAGER) so tests can swap it.
  • codegen.py - Building the Sage snippets: prelude, literal encoding, the validation gates and the numeric guards. Any caller string reaching a template must pass a gate — generated code runs under trusted_policy(), which permits sage_eval.
  • tools/ - The 40 tools and 3 resources by domain: session, core, calculus, algebra, discrete, stats, plotting, diagnostics, verify. A module missing from tools/__init__.py registers nothing.
  • session.py - SageSessionManager (per-client session map with asyncio locks) and SageSession (spawns/manages _sage_worker.py subprocess via JSON stdin/stdout protocol).
  • _sage_worker.py - Subprocess worker that executes code in a persistent namespace. Handles execute/reset/shutdown commands. Validates AST before compilation.
  • security.py - AST validator enforcing SecurityPolicy. Caller code is deny-by-default: a name is refused unless the allowlist offers it or the caller's own code bound it. On top of that it blocks imports outright, eval/exec, dunder access, string-path attribute primitives (attrgetter and friends, which defeat every AST attribute rule), forbidden modules and known code-executing Sage helpers. Configurable via env vars.
  • allowlist.py - Generated, never hand-edited. The names caller code may read, produced from the installed Sage by scripts/generate_allowlist.py (make allowlist, which writes through a temp file because the generator imports the module it replaces). An integration test and a weekly job fail when it and the installed Sage disagree.
  • star_exports.py - Generated, never hand-edited. The curated from <module> import * exception to the import ban: internal SageMath modules whose public names are all ordinary mathematics, mapped to the exact names each star may bind. Produced by scripts/generate_star_exports.py, which screens each candidate module clean-as-a-whole with _star_export_screen (same danger basis as the namespace scrub). rewrite_permitted_imports expands a vetted star into these names before validation; nothing is added to the allowlist. test_the_star_exports_match_this_sage fails when a Sage upgrade makes a listed module dirty.
  • symbols.py - PREDEFINED_SYMBOLS, the one source of truth for x, y, z, t. Read by the worker, the generated prelude and the refusal message; a test asserts they agree, because them disagreeing is what made the tools and evaluate_sage accept different mathematics.
  • text.py - Strings shared between the tool modules and the app. They are part of the tool contract, so they live where both can reach them without a cycle.
  • config.py - SageSettings dataclass driven by SAGEMATH_MCP_* environment variables.
  • models.py - Pydantic models for results (EvaluateResult, SessionSnapshot, MonitoringSnapshot).
  • monitoring.py - Thread-safe EvaluationMetrics (counters, latency, error tracking).

Read the full file on GitHub · 109 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago Changed · +44 tokens per session f57e7e974654
  2. 11d ago First seen · 109 lines · 2,395 tokens per session scan A 284d662f1a5f

Subscribe to this mod's changes

sagemath-mcp CLAUDE.md is an instructions file published in the GitHub repository XBP-Europe/sagemath-mcp (14 stars, last pushed 3d ago), licensed MIT. It adds 2,439 tokens to every session, about $0.0122 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other instructions, from other repositories

next.js AGENTS.md

AGENTS.md instructions for vercel/next.js, covering next.js development guide, codebase structure, monorepo overview, core package: packages/next and other important packages.

vercel/next.js · 7,296 tokens

codex AGENTS.md

AGENTS.md instructions for openai/codex, covering rust/codex-rs, the codex-core crate, code review rules, crate api surface and model visible context.

openai/codex · 5,153 tokens

vscode buildNext.instructions.md

Working notes and architecture documentation for the new esbuild-based build system in build/next. Use when making changes to the new build pipeline (transpile/bundle commands, NLS plugin, source-map handling, resource copying, or self-hosting watch tasks).

microsoft/vscode · 6,785 tokens

spec-kit AGENTS.md

AGENTS.md instructions for github/spec-kit, covering agents.md, about spec kit and specify, quickstart — add a new integration in 5 steps, integration architecture and integrationmanifest — file tracking.

github/spec-kit · 7,104 tokens

langchain AGENTS.md

AGENTS.md instructions for langchain-ai/langchain, covering global development guidelines for the langchain monorepo, corridor security analysis, project architecture and context, monorepo structure and development tools & commands.

langchain-ai/langchain · 4,469 tokens

vscode oss-third-party-notices.instructions.md

Instructions for microsoft/vscode, covering vs code oss third-party-notices pipeline, architecture, pipeline flow in ci, applying the notice (cutover) and fallback chain (never fail the build).

microsoft/vscode · 5,001 tokens