Metadata-Version: 2.4
Name: sionna-mcp
Version: 0.1.0
Summary: MCP server that lets AI agents drive NVIDIA Sionna RT ray tracing and build wireless channel (CIR/CFR/CSI) datasets
Author: Alexli18
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/Alexli18/sionna-mcp
Project-URL: Issues, https://github.com/Alexli18/sionna-mcp/issues
Project-URL: Changelog, https://github.com/Alexli18/sionna-mcp/blob/main/CHANGELOG.md
Keywords: mcp,model-context-protocol,sionna,ray-tracing,wireless,csi,drone,ai-agents
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Communications
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mcp[cli]<2,>=1.0
Requires-Dist: sionna>=1.0
Requires-Dist: pydantic>=2.0
Requires-Dist: numpy>=1.24
Provides-Extra: dev
Requires-Dist: pytest>=7.4; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
Requires-Dist: pytest-cov>=4.1; extra == "dev"
Requires-Dist: ruff>=0.5; extra == "dev"
Dynamic: license-file

# sionna-mcp

[![CI](https://github.com/Alexli18/sionna-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/Alexli18/sionna-mcp/actions/workflows/ci.yml)
[![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)

An [MCP](https://modelcontextprotocol.io) server that lets AI agents (Claude Code, Claude Desktop, Cursor, any MCP
client) drive [NVIDIA Sionna RT](https://nvlabs.github.io/sionna/rt/) ray tracing: load a scene, place transmitters,
receivers and drones, trace the radio paths, and export channel data (CIR, CFR, CSI) as ready-to-train datasets.

The agent calls 16 typed tools instead of writing Sionna scripts, so scenes stay valid, runs stay bounded and
results stay reproducible.

```text
"Load Munich at 3.5 GHz, put a base station on a rooftop, fly a drone along 50 points at 60 m,
 and give me a CSI dataset with 64 subcarriers and 20 dB SNR."
        │
        ▼
load_scene → add_transmitter → add_drone_receiver → run_trajectory → export_dataset → inject_noise
        │
        ▼
~/.sionna-mcp/artifacts/export/ds_….npz          one CSI array per position, + ds_…_labels.json
```

## What it does

- **Scenes**: Sionna's built-in scenes (Munich, Étoile, Florence, San Francisco, …) or your own Mitsuba XML.
- **Nodes**: transmitters, receivers and drone receivers (velocity, antenna offset), planar antenna arrays.
- **Ray tracing**: line of sight, reflection, diffraction and scattering, with a depth limit and a runtime timeout.
- **Channel data**: CIR `(a, τ)`, CFR and CSI in one fixed shape, saved as `.npy`/`.npz` artifacts.
- **Drone datasets**: a whole trajectory in one call, optionally with rotating propellers (micro-Doppler).
- **Sim-to-real**: white Gaussian noise at a set SNR and phase jitter on any CSI artifact or dataset.

## Requirements

- Python 3.10+
- [Sionna](https://nvlabs.github.io/sionna/) 1.x (tested with 1.2.2) and PyTorch
- GPU optional. With NVIDIA OptiX (x86_64 drivers) the CUDA backend is used; without it (NVIDIA Jetson, macOS,
  CPU-only Linux) the server uses Mitsuba's LLVM CPU backend automatically. That needs an LLVM shared library
  (`apt install llvm` on Debian/Ubuntu).

## Install

```bash
pip install "git+https://github.com/Alexli18/sionna-mcp"
```

or from a checkout, for development:

```bash
git clone https://github.com/Alexli18/sionna-mcp
cd sionna-mcp
pip install -e ".[dev]"
```

Check it starts (it waits for an MCP client on stdin; stop it with Ctrl-C):

```bash
sionna-mcp            # or: python -m sionna_mcp
```

## Connect it to an agent

The server speaks MCP over stdio: the client starts it as a subprocess. Use the absolute path of the `sionna-mcp`
command (`which sionna-mcp`) if the client does not inherit your shell's `PATH`, for example with a virtualenv.

### Claude Code

```bash
claude mcp add sionna -- sionna-mcp
```

With your own folders:

```bash
claude mcp add sionna \
  -e SIONNA_SCENES_ROOT=/path/to/scenes \
  -e SIONNA_ARTIFACTS_ROOT=/path/to/artifacts \
  -- sionna-mcp
```

To share it with a team, put the same in `.mcp.json` at the project root:

```json
{
  "mcpServers": {
    "sionna": {
      "command": "sionna-mcp",
      "env": {
        "SIONNA_SCENES_ROOT": "/path/to/scenes",
        "SIONNA_ARTIFACTS_ROOT": "/path/to/artifacts"
      }
    }
  }
}
```

Check it with `/mcp` inside Claude Code.

### Claude Desktop

Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or
`%APPDATA%\Claude\claude_desktop_config.json` (Windows):

```json
{
  "mcpServers": {
    "sionna": {
      "command": "/absolute/path/to/sionna-mcp"
    }
  }
}
```

Restart Claude Desktop.

### Cursor

`~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` (one project), same format as the Claude Desktop block.

### Remote GPU machine

The server runs where Sionna runs. To use a GPU box (or a Jetson) from a laptop, let the client start it over SSH:

```json
{
  "mcpServers": {
    "sionna": {
      "command": "ssh",
      "args": ["-T", "user@gpu-box", "/home/user/.venv/bin/sionna-mcp"]
    }
  }
}
```

Artifacts are then written on the remote machine; `get_artifact` returns their remote paths.

## Using it

Ask in plain language; the agent picks the tools and chains the IDs (`scene_id`, `job_id`, `sionna://` URIs).

> Check that Sionna and CUDA are available.

> Load the Munich scene at 3.5 GHz, put a 2×2 transmitter at [0, 0, 30] and a receiver at [50, 0, 1.5], trace with
> up to 3 reflections and give me the CSI with 64 subcarriers.

> Fly a drone in 20 steps from [0, 0, 50] to [95, 0, 50] past a base station at [0, 0, 25], with 2-blade propellers at
> 6000 rpm, export the dataset, then make a copy at 15 dB SNR.

Typical sequences:

```text
single link   sionna_status → load_scene → set_antenna_array → add_transmitter → add_receiver
              → compute_paths → extract_csi_tool → get_artifact

drone dataset load_scene → add_transmitter → add_drone_receiver → run_trajectory → export_dataset
              → inject_noise → get_artifact
```

`examples/` has both as JSON tool-call scripts. Every parameter of every tool: [docs/tools.md](docs/tools.md).

### Tools

| group | tools |
|---|---|
| environment and scenes | `sionna_status`, `load_scene`, `inspect_scene` |
| nodes | `add_transmitter`, `add_receiver`, `add_drone_receiver`, `update_node_pose` |
| antenna arrays | `set_antenna_array` |
| ray tracing and channels | `compute_paths`, `extract_cir_tool`, `extract_cfr_tool`, `extract_csi_tool` |
| datasets | `run_trajectory`, `export_dataset`, `get_artifact` |
| sim-to-real | `inject_noise` |

### Built-in scenes

Pass `"builtin:<name>"` (or just the name) as `scene_path`:

| name | scene |
|---|---|
| `etoile` | Paris, Étoile roundabout (urban macro) |
| `munich` | Munich city block |
| `florence` | Florence street |
| `san_francisco` | San Francisco, urban |
| `simple_street_canyon` | two buildings |
| `simple_reflector` | one flat reflector |

Your own scenes: put the Mitsuba `.xml` (with its meshes) under `SIONNA_SCENES_ROOT` and pass its path relative to
that folder. Paths that leave the folder are refused.

### CSI shape

CSI is complex64 with shape `[N_tx, N_rx, N_sub, N_ant]`: transmitters, receivers, subcarriers, and
`N_ant = N_tx_ant × N_rx_ant` antenna pairs.

### Micro-Doppler

`run_trajectory` rotates the scene objects named in `propeller_ids` by
`2π · num_blades · rpm / 60 · step · trajectory_dt_s` before each step. If the blade rate is above the Nyquist limit
of the time step, the propellers are not rotated (macro-Doppler only) and the result's `micro_doppler` block says
so, with the highest safe rpm; at 10 ms and 2 blades that is 1500 rpm.

### Reproducibility

Pass `seed` to `compute_paths` and keep `diffraction=False`. The CUDA backend then gives identical results run to
run; the LLVM backend agrees to within 1e-6 per element.

## Configuration

| variable | default | meaning |
|---|---|---|
| `SIONNA_SCENES_ROOT` | `~/.sionna-mcp/scenes` | folder for your scene XML files |
| `SIONNA_ARTIFACTS_ROOT` | `~/.sionna-mcp/artifacts` | where results are written |
| `SIONNA_MAX_DEPTH` | `8` | largest `max_depth` a call may ask for |
| `SIONNA_MAX_SUBCARRIERS` | `4096` | largest `num_subcarriers` |
| `SIONNA_MAX_TRAJECTORY` | `1000` | most positions in one `run_trajectory` |
| `SIONNA_MCP_DEBUG` | `0` | `1`: write tracebacks of errors to `artifacts/logs/` |
| `SIONNA_MCP_VARIANT` | auto | Mitsuba variant, e.g. `llvm_ad_mono_polarized` (CPU) or `cuda_ad_mono_polarized`; auto = CUDA if OptiX is found, else CPU |

## Errors

A failed call returns `{"status": "error", "error_code": …, "message": …}`; unexpected exceptions also get a
`log_file` with the traceback.

| code | meaning |
|---|---|
| `SCENE_NOT_LOADED`, `JOB_NOT_FOUND`, `DATASET_NOT_FOUND` | unknown `scene_id` / `job_id` / `dataset_id` |
| `NODE_NOT_FOUND`, `DRONE_NOT_FOUND`, `TX_NOT_FOUND`, `RX_NOT_FOUND` | unknown node IDs |
| `DUPLICATE_TX_ID`, `DUPLICATE_RX_ID` | the ID is already used in the scene |
| `INVALID_POSITION` | NaN or infinity in a position or orientation |
| `UNSUPPORTED_PATTERN` | antenna pattern other than `iso`, `dipole`, `hw_dipole`, `tr38901` |
| `DEPTH_LIMIT_EXCEEDED`, `SUBCARRIER_LIMIT_EXCEEDED`, `TRAJECTORY_LIMIT_EXCEEDED` | above the configured limits |
| `RUNTIME_LIMIT_EXCEEDED` | ray tracing took longer than `max_runtime_seconds` |
| `PATH_TRAVERSAL_DENIED`, `INVALID_URI` | a scene path or `sionna://` URI outside its folder |
| `ARTIFACT_NOT_FOUND` | the artifact is not on disk |
| `INVALID_NOISE_PARAMS` | bad `snr_db` or negative `phase_jitter_deg` |
| `SIONNA_NOT_AVAILABLE`, `SIONNA_INTERNAL_ERROR`, `INTERNAL_ERROR` | Sionna missing or failing |

## Development

```bash
pip install -e ".[dev]"
ruff check .
pytest tests/unit           # no Sionna needed
pytest tests/integration    # needs Sionna; uses the LLVM backend without a GPU
python scripts/gen_tool_docs.py   # after changing a tool's signature or docstring
```

How it is built: [docs/architecture.md](docs/architecture.md). Contributions: [CONTRIBUTING.md](CONTRIBUTING.md).

## License

Apache-2.0, see [LICENSE](LICENSE). Sionna is © NVIDIA and licensed separately (Apache-2.0).
