A Model Context Protocol (MCP) server providing AI assistants with access to IMAS (Integrated Modelling & Analysis Suite) data structures through natural language search and optimized path indexing.
IMAS Codex provides two MCP servers:
| Server | Command | Purpose |
|---|---|---|
| IMAS DD | imas-codex serve imas |
IMAS Data Dictionary knowledge, semantic search |
| Agents | imas-codex serve agents |
Remote facility exploration via subagents |
Select the setup method that matches your environment:
Choose hosted for instant access; choose a local option for customization or controlled resources.
| HTTP | UV | Docker | Slurm / HPC |
Connect to the public ITER Organization hosted server—no local install.
Ctrl+Shift+P → “MCP: Add Server”imashttps://imas-dd.iter.org/mcpWorkspace .vscode/mcp.json (or inside "mcp" in user settings):
{
"servers": {
"imas": { "type": "http", "url": "https://imas-dd.iter.org/mcp" }
}
}
Pick path for your OS:
Windows: %APPDATA%\\Claude\\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/claude/claude_desktop_config.json
{
"mcpServers": {
"imas-codex-hosted": {
"command": "npx",
"args": ["mcp-remote", "https://imas-dd.iter.org/mcp"]
}
}
}
Placeholder: clarify what “op” refers to (e.g. OpenAI, Operator) to add tailored instructions.
Install with uv:
# Standard installation (includes sentence-transformers)
uv tool install imas-codex
# Add to a project env
uv add imas-codex
The IMAS Data Dictionary version determines which schema definitions are used. The version is resolved in priority order:
| Priority | Source | Description |
|---|---|---|
| 1 | --dd-version CLI option |
Highest priority, explicit override |
| 2 | IMAS_DD_VERSION env var |
Environment-based override |
| 3 | pyproject.toml default |
Configured default from [tool.imas-codex].default-dd-version |
Configuration:
Set the default DD version in pyproject.toml:
[tool.imas-codex]
default-dd-version = "4.1.0"
Runtime Override:
# Via CLI option
imas-codex --dd-version 3.42.2
# Via environment variable
IMAS_DD_VERSION=3.42.2 imas-codex
# Docker build
docker build --build-arg IMAS_DD_VERSION=3.42.2 ...
Version Validation:
The server validates that the requested DD version does not exceed the maximum version available in the installed imas-data-dictionaries package. If you request a version that’s not available, you’ll see:
ValueError: Requested DD version 5.0.0 exceeds maximum available version 4.1.0.
Update imas-data-dictionaries dependency or use a lower version.
The IMAS Codex server uses sentence-transformers for generating embeddings:
Configuration:
The default embedding model is configured in pyproject.toml under [tool.imas-codex]:
[tool.imas-codex]
imas-embedding-model = "all-MiniLM-L6-v2" # For DD embeddings
Environment variables override pyproject.toml settings:
export IMAS_CODEX_EMBEDDING_MODEL="all-MiniLM-L6-v2"
Path Inclusion Settings:
Control which IMAS paths are indexed and searchable. These settings affect schema generation, embeddings, and semantic search:
| Setting | pyproject.toml | Environment Variable | Default | Description |
|---|---|---|---|---|
| Include GGD | include-ggd |
IMAS_CODEX_INCLUDE_GGD |
true |
Include Grid Geometry Description paths |
| Include Error Fields | include-error-fields |
IMAS_CODEX_INCLUDE_ERROR_FIELDS |
false |
Include uncertainty bound fields (_error_upper, _error_lower, etc.) |
Example pyproject.toml configuration:
[tool.imas-codex]
include-ggd = true
include-error-fields = false
Environment variable overrides:
export IMAS_CODEX_INCLUDE_GGD=false # Exclude GGD paths
export IMAS_CODEX_INCLUDE_ERROR_FIELDS=true # Include error fields
Error Handling:
If model loading fails, the system will fall back to the default all-MiniLM-L6-v2 model.
VS Code (.vscode/mcp.json):
{
"servers": {
"imas-codex-uv": {
"type": "stdio",
"command": "uv",
"args": ["run", "imas-codex", "serve", "imas", "--transport", "stdio"]
}
}
}
Claude Desktop:
{
"mcpServers": {
"imas-codex-uv": {
"command": "uv",
"args": ["run", "imas-codex", "serve", "imas", "--transport", "stdio"]
}
}
}
For exploring remote fusion facilities, run the Agents server locally:
VS Code (.vscode/mcp.json):
{
"servers": {
"imas-agents": {
"type": "stdio",
"command": "uv",
"args": ["run", "imas-codex", "serve", "agents"]
}
}
}
This provides the /explore prompt for LLM-driven exploration of remote facilities via SSH.
For fast repeated SSH connections during facility exploration, configure SSH ControlMaster. This keeps connections alive, reducing latency from ~1-2 seconds to ~100ms for subsequent commands.
# Create socket directory
mkdir -p ~/.ssh/sockets
chmod 700 ~/.ssh/sockets
Add to ~/.ssh/config:
# EPFL / Swiss Plasma Center
Host epfl
HostName spcepfl.epfl.ch
User your_username
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 600
# Add other facilities as needed
Host ipp
HostName gateway.ipp.mpg.de
User your_username
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 600
How it works:
ControlPersist 600: Keep connection alive for 10 minutes after last useVerify setup:
# Check if master connection is active
ssh -O check epfl
# Manually close master connection
ssh -O exit epfl
Once SSH is configured, explore facilities directly from the terminal:
# Execute commands on remote facility
uv run imas-codex epfl "python --version"
uv run imas-codex epfl "ls /common/tcv/codes"
# View session history
uv run imas-codex epfl --status
# Persist learnings when done
uv run imas-codex epfl --finish << 'EOF'
python:
version: "3.9.21"
tools:
rg: unavailable
paths:
codes: /common/tcv/codes
EOF
# Or discard session
uv run imas-codex epfl --discard
Run locally in a container (pre-built indexes included):
docker run -d \
--name imas-codex \
-p 8000:8000 \
ghcr.io/iterorganization/imas-codex:latest-streamable-http
# Optional: verify
docker ps --filter name=imas-codex --format "table \t"
VS Code (.vscode/mcp.json):
{
"servers": {
"imas-codex-docker": { "type": "http", "url": "http://localhost:8000/mcp" }
}
}
Claude Desktop:
{
"mcpServers": {
"imas-codex-docker": {
"command": "npx",
"args": ["mcp-remote", "http://localhost:8000/mcp"]
}
}
}
Helper script: scripts/imas_codex_slurm_stdio.sh
VS Code (.vscode/mcp.json, JSONC ok):
{
"servers": {
"imas-slurm-stdio": {
"type": "stdio",
"command": "scripts/imas_codex_slurm_stdio.sh"
}
}
}
Launch behavior:
SLURM_JOB_ID present → start inside current allocation.srun --pty then starts server (unbuffered stdio).Resource tuning (export before client starts):
| Variable | Purpose | Default |
|---|---|---|
IMAS_CODEX_SLURM_TIME |
Walltime | 08:00:00 |
IMAS_CODEX_SLURM_CPUS |
CPUs per task | 1 |
IMAS_CODEX_SLURM_MEM |
Memory (e.g. 4G) |
Slurm default |
IMAS_CODEX_SLURM_PARTITION |
Partition | Cluster default |
IMAS_CODEX_SLURM_ACCOUNT |
Account/project | User default |
IMAS_CODEX_SLURM_EXTRA |
Extra raw srun flags |
(empty) |
IMAS_CODEX_USE_ENTRYPOINT |
Use imas-codex entrypoint vs python -m |
0 |
Example:
export IMAS_CODEX_SLURM_TIME=02:00:00
export IMAS_CODEX_SLURM_CPUS=4
export IMAS_CODEX_SLURM_MEM=8G
export IMAS_CODEX_SLURM_PARTITION=compute
Direct CLI:
scripts/imas_codex_slurm_stdio.sh --ids-filter "core_profiles equilibrium"
Why STDIO? Avoids opening network ports; all traffic rides the existing srun pseudo-TTY.
Once you have the IMAS Codex server configured, you can interact with it using natural language queries. Use the @imas prefix to direct queries to the IMAS server:
Find data paths related to plasma temperature
Search for electron density measurements
What data is available for magnetic field analysis?
Show me core plasma profiles
Explain what equilibrium reconstruction means in plasma physics
What is the relationship between pressure and magnetic fields?
How do transport coefficients relate to plasma confinement?
Describe the physics behind current drive mechanisms
Analyze the structure of the core_profiles IDS
What are the relationships between equilibrium and core_profiles?
Show me identifier schemas for transport data
Export bulk data for equilibrium, core_profiles, and transport IDS
Find all paths containing temperature measurements across different IDS
What physics domains are covered in the IMAS data dictionary?
Show me measurement dependencies for fusion power calculations
Explore cross-domain relationships between heating and confinement
How do I access electron temperature profiles from IMAS data?
What's the recommended workflow for equilibrium analysis?
Show me the branching logic for diagnostic identifier schemas
Export physics domain data for comprehensive transport analysis
The IMAS Codex server provides 8 specialized tools for different types of queries:
The server includes integrated search for documentation libraries with IMAS-Python as the default indexed library. This feature enables AI assistants to search across documentation sources using natural language queries.
search_docs: Search any indexed documentation library
query (required), library (optional), limit (optional, 1-20), version (optional)search_imas_python_docs: Search specifically in IMAS-Python documentation
query (required), limit (optional), version (optional)list_docs: List all available documentation libraries or get versions for a specific library
library (optional)add-docs: Add new documentation libraries via command line
add-docs LIBRARY URL [OPTIONS]--ignore-errors flag (enabled by default) to handle problematic pages gracefully# Search IMAS-Python documentation
search_imas_python_docs "equilibrium calculations"
search_imas_python_docs "IDS data structures" limit=5
search_imas_python_docs "magnetic field" version="2.0.1"
# Search any documentation library
search_docs "neural networks" library="numpy"
search_docs "data visualization" library="matplotlib"
# List all available libraries
list_docs
# Get versions for specific library
list_docs "imas-python"
# Add new documentation using CLI
add-docs udunits https://docs.unidata.ucar.edu/udunits/current/
add-docs pandas https://pandas.pydata.org/docs/ --version 2.0.1 --max-pages 500
add-docs imas-python https://imas-python.readthedocs.io/en/stable/ --no-ignore-errors
docker-compose up --build
# Start IMAS Codex server
python -m imas_codex
For embedding generation capabilities (during build), you’ll need an OpenRouter API key:
For Local Development:
# Set up environment variables (create .env file from env.example)
cp env.example .env
# Edit .env with your OpenRouter API key
For CI/CD (GitHub Actions):
Settings → Secrets and variables → ActionsOPENAI_API_KEY📖 Detailed Setup Guide: See .github/SECRETS_SETUP.md for complete instructions on configuring GitHub repository secrets and troubleshooting.
Build Behavior:
Local Docker Build:
# Build with API key (for API-based embeddings)
docker build --build-arg OPENAI_API_KEY=your_key_here .
# Build without API key (uses local model)
docker build .
For local development and customization:
# Clone repository
git clone https://github.com/iterorganization/imas-codex.git
cd imas-codex
# Install development dependencies (search index build takes ~8 minutes first time)
uv sync --all-extras
This project requires additional dependencies during the build process that are not part of the runtime dependencies:
imas-data-dictionary - Git development package, required only during wheel building for parsing latest DD changesrich - Used for enhanced console output during build processesFor runtime: The imas-data-dictionaries PyPI package is now a core dependency and provides access to stable DD versions (e.g., 4.0.0). This eliminates the need for the git package at runtime and ensures reproducible builds.
For developers: Build-time dependencies are included in the [build-system.requires] section for wheel building. The git package is only needed when building wheels with latest DD changes.
# Regular development - uses imas-data-dictionaries (PyPI)
uv sync --all-extras
# Set DD version for building (defaults to 4.0.0)
export IMAS_DD_VERSION=4.0.0
uv run build-schemas
Location in configuration:
[build-system.requires] in pyproject.tomlimas-data-dictionaries>=4.0.0 in [project.dependencies]Note: The IMAS_DD_VERSION environment variable controls which DD version is used for building schemas and embeddings. Docker containers have this set to 4.0.0 by default.
# Run tests
uv run pytest
# Run linting and formatting
uv run ruff check .
uv run ruff format .
# Build schema data structures from IMAS data dictionary
uv run build-schemas
# Build document store and semantic search embeddings
uv run build-embeddings
# Run the IMAS DD server locally (default: streamable-http on port 8000)
uv run imas-codex serve imas
# Run with stdio transport for MCP clients
uv run imas-codex serve imas --transport stdio
# Run the Agents server for facility exploration
uv run imas-codex serve agents
The project includes two separate build scripts for creating the required data structures:
build-schemas - Creates schema data structures from IMAS XML data dictionary:
--ids-filter "core_profiles equilibrium" to build specific IDS--force to rebuild even if files existbuild-embeddings - Creates document store and semantic search embeddings:
--model-name "all-mpnet-base-v2" for different models--force to rebuild embeddings cache--no-normalize to disable embedding normalization--half-precision to reduce memory usage--similarity-threshold 0.1 to set similarity score thresholdsNote: The build hook creates JSON data. Build embeddings separately using build-embeddings for better control and performance.
The repository includes a .vscode/mcp.json file with pre-configured development server options. Use the imas-local-stdio configuration for local development.
Add to your config file:
{
"mcpServers": {
"imas-local-dev": {
"command": "uv",
"args": ["run", "imas-codex", "serve", "imas", "--transport", "stdio"],
"cwd": "/path/to/imas-codex"
},
"imas-agents-dev": {
"command": "uv",
"args": ["run", "imas-codex", "serve", "agents"],
"cwd": "/path/to/imas-codex"
}
}
}
imas_codex/resources/schemas/ (LLM-optimized structured data)The IMAS Codex server now includes imas-data-dictionaries as a core dependency, providing stable DD version access (default: 4.0.0). The git development package (imas-data-dictionary) is used during wheel building when parsing latest DD changes.
uv add imas-codex - Includes all transports (stdio, sse, streamable-http)uv add imas-codex - Recommended for all usersThe system uses composable accessors to access IMAS Data Dictionary version and metadata:
IMAS_DD_VERSION (highest priority) - Set to specify DD version (e.g., “4.0.0”)imas-data-dictionaries package (4.0.0)This design ensures the server can:
IMAS_DD_VERSIONimas-data-dictionaries PyPI packageimas-data-dictionary package to parse XML and create indexesThe search system is the core component that provides fast, flexible search capabilities over the IMAS Data Dictionary. It combines efficient indexing with IMAS-specific data processing and semantic search to enable different search modes:
Semantic Search (SearchMode.SEMANTIC):
Lexical Search (SearchMode.LEXICAL):
AND, OR, NOT)* and ? patterns)documentation:plasma ids:core_profiles)Hybrid Search (SearchMode.HYBRID):
Auto Search (SearchMode.AUTO):
We plan to implement MCP resources to provide efficient access to pre-computed IMAS data:
ids://catalog - Complete IDS catalog with metadataids://structure/{ids_name} - Detailed structure for specific IDSids://physics-domains - Physics domain mappings and relationshipsexamples://search-patterns - Common search patterns and workflowsSpecialized prompts for physics analysis and workflow automation:
physics-explain - Generate comprehensive physics explanationsmeasurement-workflow - Create measurement analysis workflowscross-ids-analysis - Analyze relationships between multiple IDSimas-python-code - Generate Python code for data analysisContinued optimization of search and tool performance:
Comprehensive testing strategy for all MCP components:
The server is available as a pre-built Docker container with the index already built:
# Pull and run the latest container
docker run -d -p 8000:8000 ghcr.io/iterorganization/imas-codex:latest
# Or use Docker Compose
docker-compose up -d
See DOCKER.md for detailed container usage, deployment options, and troubleshooting.