Metadata-Version: 2.3
Name: joule-mcp
Version: 0.1.2
Summary: MCP server that lets AI agents inspect and manage Joule use cases through the Guardian REST API
License: MIT
Keywords: joule,mcp,model-context-protocol,streaming,ai-agents
Author: Fractalworks
Requires-Python: >=3.10
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Dist: mcp (>=2.3,<3.0)
Requires-Dist: pyyaml (>=6.0,<7.0)
Requires-Dist: requests (>=2.33.0,<3.0.0)
Project-URL: Documentation, https://docs.fractalworks.io/joule
Project-URL: Homepage, https://getjoule.io/
Project-URL: changelog, https://gitlab.com/joule-platform/joule-mcp/-/blob/main/CHANGELOG.md
Project-URL: issues, https://gitlab.com/joule-platform/joule-mcp/-/issues
Project-URL: source, https://gitlab.com/joule-platform/joule-mcp
Description-Content-Type: text/markdown

# joule-mcp

<!-- mcp-name: io.fractalworks/joule-mcp -->

An MCP server that lets an AI agent inspect a Joule installation. It calls the Guardian REST API
(`/joule/management/*`). It is independent of `joulectl` and Guardian.

By default the server is read-only. The change tools exist only when you set `JOULE_MCP_ALLOW_WRITE=1`.

## Install and connect

`joule-mcp` is a **local** program. Your AI client starts it when the client starts, and talks to it through standard input and
output. It does not listen on a network port. The server then calls the Joule Guardian REST API.

```
AI client  <--stdio-->  joule-mcp  <--HTTP, X-API-Key-->  Joule Guardian
```

### What you need

| Item | Detail |
|------|--------|
| Python | 3.10 or newer (not needed if you use `uvx`) |
| A Joule Guardian | A host and port that your machine can reach |
| An API key | From the Joule UI (API keys) or from `joulectl`. A `viewer` key is enough for the read tools |
| An AI client | One of the clients under "Connect your AI client" |

### Install the server

Pick **one** way.

#### Option A: pipx (recommended)

`pipx` puts the program in its own environment and on your PATH.

```bash
pipx install joule-mcp
which joule-mcp          # write this path down: you need it when you connect your client
joule-mcp < /dev/null && echo OK
```

The program has no `--help`. It is a server: it starts, waits for an AI client
on standard input, and stops when the input ends. The `< /dev/null` line gives
it no input, so it stops at once. `OK` means that it starts.

Install `pipx` first if you do not have it: `brew install pipx` on macOS, or
`python3 -m pip install --user pipx`.

#### Option B: uvx (nothing to install)

`uvx` is part of [uv](https://docs.astral.sh/uv/). It downloads and runs the
newest version when the client starts.

```bash
which uvx                # write this path down
uvx joule-mcp            # run it once to fill the cache. Stop it with Ctrl-C
```

Run it once in a terminal before you add it to a client. The first download
can be slower than the time a client waits.

#### Option C: pip in a virtual environment

```bash
python3 -m venv ~/.venvs/joule-mcp
~/.venvs/joule-mcp/bin/pip install joule-mcp
~/.venvs/joule-mcp/bin/joule-mcp < /dev/null && echo OK     # starts, sees no input, stops. This is the path to use when you connect your client
```

On Windows the program is `Scripts\joule-mcp.exe`.

#### Option D: from the source (developers)

```bash
git clone https://gitlab.com/joule-platform/joule-mcp.git
cd joule-mcp
poetry install                    # makes .venv with the test tools
.venv/bin/joule-mcp < /dev/null && echo OK
.venv/bin/python -m pytest        # the tests need no Guardian
```

Without Poetry: `python3 -m venv .venv && .venv/bin/pip install -e . pytest pytest-cov requests-mock pytest-html`.

The program is `<folder>/.venv/bin/joule-mcp`. A client that uses this path
runs your working copy, so a code change applies the next time the client
starts the server.

### Get an API key and keep it safe

Guardian refuses any request without a valid `X-API-Key`.

1. Make a key in the Joule UI (API keys) or with `joulectl`.
2. Put **only the key** in a file. Keep the file private:
   ```bash
   mkdir -p ~/.joule && printf '%s' 'PASTE_THE_KEY_HERE' > ~/.joule/mcp-api-key && chmod 600 ~/.joule/mcp-api-key
   ```
3. Use the **full path** of the file in the client settings. Many clients do
   not expand `~`.

If you already use `joulectl login` for the same host, you can skip the file.
The server reads the key that `joulectl` stored in
`~/.config/joule/config.json`.

| Key scope | What it allows |
|-----------|----------------|
| `*:read` (a `viewer` key) | All read tools and the resources |
| `usecases:write` (an `operator` key) | Also deploy, pause, resume and undeploy, when the change tools are on |

WARNING: Do not paste the key in a chat, a ticket or a file in a repository.
Do not set `JOULE_API_KEY` in a config file that you share. Use
`JOULE_API_KEY_FILE`.

### Reach the Guardian

The default address is `127.0.0.1:9080`. Set `JOULE_HOST` for another one.

| Where the Guardian runs | What to do |
|-------------------------|------------|
| Minikube or Kubernetes | Start a port-forward and leave it running: `kubectl --context minikube -n joule port-forward svc/guardian-service 9080:9080` |
| Another machine | Set `JOULE_HOST` to `host:port`, or `https://host:port` |
| HTTPS with a private CA | Also set `JOULE_CA_BUNDLE` to the CA file |

A key sent over plain HTTP to a host that is not your own machine is visible
on the network. Use HTTPS for a remote Guardian.

Check the Guardian answers before you start a client:

```bash
curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:9080/joule/management/apikeys/whoami
```

An answer of `200`, `401` or `403` means that the Guardian is there. `000`
means that nothing answers: start the port-forward.

### Connect your AI client

Every client needs the same three things: a **command**, its **arguments**,
and the **environment variables**.

| Setting | Value |
|---------|-------|
| Command | The full path from "Install the server" (for example `/Users/you/.local/bin/joule-mcp`), or the full path of `uvx` |
| Arguments | none, or `joule-mcp` when the command is `uvx` |
| `JOULE_API_KEY_FILE` | The full path of the key file |
| `JOULE_HOST` | Only if the Guardian is not at `127.0.0.1:9080` |

Windows and macOS apps (Claude Desktop, Cursor) do not use the PATH of your
terminal. Write the **full path** of the command.

The change tools are **off**. Add `JOULE_MCP_ALLOW_WRITE=1` only when you want
them (see "Turn on the change tools" below).

Clients change their settings files from time to time. If a path or a field
does not match your version, read the MCP page in the documentation of the
client. The command, arguments and environment stay the same.

#### Claude Desktop

1. Open the menu **Claude, Settings, Developer, Edit Config**. This opens the
   file `claude_desktop_config.json`:
   - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
   - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
2. Add the server. Keep any other servers that are already there:
   ```json
   {
     "mcpServers": {
       "joule": {
         "command": "/Users/you/.local/bin/joule-mcp",
         "args": [],
         "env": {
           "JOULE_API_KEY_FILE": "/Users/you/.joule/mcp-api-key"
         }
       }
     }
   }
   ```
   With uvx, use `"command": "/Users/you/.local/bin/uvx"` and
   `"args": ["joule-mcp"]`.
3. **Quit Claude Desktop fully** (Claude, Quit, not only the window) and
   start it again.
4. Open a new chat. The tools icon shows `joule`.

Log file on macOS: `~/Library/Logs/Claude/mcp-server-joule.log`.

#### Claude Code

```bash
claude mcp add --scope user joule -e JOULE_API_KEY_FILE=$HOME/.joule/mcp-api-key -- joule-mcp
# with uvx:
claude mcp add --scope user joule -e JOULE_API_KEY_FILE=$HOME/.joule/mcp-api-key -- uvx joule-mcp
claude mcp get joule            # shows the status
```

`--scope user` makes it available in every project. Use `--scope project` to
write a `.mcp.json` file for one repository. Do not put the key itself in a
`.mcp.json` file that you commit. Start a new session after the change.

#### Cursor

1. Open the file `~/.cursor/mcp.json` (for all projects) or
   `.cursor/mcp.json` in a project.
2. Add the same block as for Claude Desktop (the top key is `mcpServers`).
3. Open **Cursor Settings, MCP** (or Tools & MCP). Turn on `joule`. The
   status dot turns green when the server runs.

#### VS Code (GitHub Copilot, agent mode)

VS Code uses the key `servers`, and it needs `"type": "stdio"`. Save this as
`.vscode/mcp.json` in a project, or run the command **MCP: Open User
Configuration** for all projects:

```json
{
  "servers": {
    "joule": {
      "type": "stdio",
      "command": "/Users/you/.local/bin/joule-mcp",
      "env": { "JOULE_API_KEY_FILE": "/Users/you/.joule/mcp-api-key" }
    }
  }
}
```

Open the Chat view, choose **Agent** mode, and turn on the `joule` tools in
the tools list.

#### Windsurf

Add the Claude Desktop block to `~/.codeium/windsurf/mcp_config.json`
(top key `mcpServers`). Then refresh the list in **Cascade, MCP servers**.

#### Codex CLI

Add this to `~/.codex/config.toml`:

```toml
[mcp_servers.joule]
command = "/Users/you/.local/bin/joule-mcp"

[mcp_servers.joule.env]
JOULE_API_KEY_FILE = "/Users/you/.joule/mcp-api-key"
```

#### Gemini CLI

Add the Claude Desktop block to `~/.gemini/settings.json` (top key
`mcpServers`). Run `/mcp` in the CLI to see the status.

#### Any other client

Look for "MCP servers", "stdio" or "command" in its settings. Give it the
command, the arguments and the environment from the table above.

### Check that it works

Start a new chat or session. Then ask:

1. "Run the Joule `whoami` tool." The answer shows the owner, the scopes and
   the end date of the key. It never shows the key.
2. "List the Joule pods."
3. "List the Joule use cases and their status."
4. "Show the latest events of the use case `<name>`."

If step 1 works, the key, the Guardian and the client are all connected.

To test the server **without** an AI client, use the MCP Inspector (it needs
Node.js):

```bash
npx @modelcontextprotocol/inspector /Users/you/.local/bin/joule-mcp
```

Set the same environment variables in the Inspector window.

### Turn on the change tools (optional)

The change tools are `deploy_usecase`, `pause_usecase`, `resume_usecase` and
`undeploy_usecase`. They change a running Joule system.

WARNING: An AI agent can call these tools. Turn them on only for a person who
must make changes, and use a key with `usecases:write` for that person.

1. Add `"JOULE_MCP_ALLOW_WRITE": "1"` to the `env` block of the client (or
   `-e JOULE_MCP_ALLOW_WRITE=1` for Claude Code).
2. Restart the client fully.

Keep a separate entry, for example `joule-write`, if you want both modes.
`undeploy_usecase` needs the argument `confirm`. It refuses a use case that
shares a stream with another one, because that stops the other use case.

### Upgrade and remove

| Task | Command |
|------|---------|
| Upgrade (pipx) | `pipx upgrade joule-mcp` |
| Upgrade (pip) | `pip install --upgrade joule-mcp` |
| Upgrade (uvx) | `uvx --refresh joule-mcp`, or nothing: `uvx` fetches the newest version |
| Upgrade (source) | `git pull && poetry install` |
| Remove | `pipx uninstall joule-mcp`, and delete the `joule` entry from the client |
| Remove from Claude Code | `claude mcp remove joule -s user` |

Restart the client after an upgrade.

### Problems and fixes

| Symptom | Cause | Fix |
|---------|-------|-----|
| The server is not in the client | The client was not fully restarted, or the JSON is not valid | Quit the app fully and start it again. Check the JSON for a missing comma |
| `spawn joule-mcp ENOENT` or `spawn uvx ENOENT` | The client cannot find the command | Use the full path from `which joule-mcp` or `which uvx` |
| The server starts and stops at once | The key file cannot be read or the key is not valid | Read the log. The key must have 8 to 200 characters with no spaces or line breaks |
| `Cannot connect to Joule Guardian at ...` | Nothing listens on that address | Start the port-forward. Set `JOULE_HOST` |
| `Guardian requires an API key.` | No key is set | Set `JOULE_API_KEY_FILE`, or run `joulectl login` for this host. Restart the client |
| A message with `AUTH_INVALID`, `AUTH_EXPIRED` or `AUTH_REVOKED` | The key is not accepted | Make a new key. Restart the client |
| A message that names a missing scope | The key is too weak for that tool | Use a key with the scope that the message names |
| `TLS error talking to Joule Guardian` | A private CA | Set `JOULE_CA_BUNDLE` |
| The deploy and pause tools are missing | The change tools are off | See "Turn on the change tools" |
| A change reports "most likely failed" | Guardian answered with an empty reply | Run `list_usecases` to see the real state. Do not repeat the change blindly |
| Changes to the code do not apply | The client still runs an old process | Quit the client fully and start it again |

Find the server log here:

| Client | Log |
|--------|-----|
| Claude Desktop (macOS) | `~/Library/Logs/Claude/mcp-server-joule.log` |
| Claude Code | `claude mcp get joule`, and `claude --debug` |
| Cursor and VS Code | The **Output** panel, channel MCP |
| Any client | Run the command in a terminal. The server writes its log to stderr |

## Tools

| Tool | Guardian route | Same as |
|---|---|---|
| `list_pods` | `pods/list` | `joulectl ls pods` |
| `list_pod_members` | `pods/connected` | `joulectl ls members POD` |
| `list_usecases` | `usecase/list` | `joulectl ls usecases` |
| `list_transports` | `transports/list` | `joulectl ls transports` |
| `list_streams` | `stream/list` | `joulectl ls streams` |
| `usecase_status` | `usecase/status` | `joulectl status usecase NAME` |
| `usecase_events(name, pod, limit)` | `usecase/status` | `joulectl status usecase NAME --events` |
| `whoami` | `apikeys/whoami` | the Joule UI's "who am I" |
| `describe_usecase` | `usecase/list`, `usecase/detail`, `usecase/status` | `joulectl inspect usecase NAME` and `status` |

Every tool carries the `readOnlyHint` annotation.

`usecase_events` returns the latest events a use case emitted, parsed from JSON, for each running process (`limit` 1 to
100, default 10, newest last). Guardian keeps only a short sample in memory (`last_emitted_events`), so it is for
inspection, not a stream, and it is empty while a use case is paused or idle. The result gives `emitted_events` for
each process, so two calls show whether events are flowing.

## Change tools

Off unless `JOULE_MCP_ALLOW_WRITE=1` is set. Guardian needs the `usecases:write` scope on the key.
`pod` is always required, so no change reaches every pod by accident.

| Tool | Guardian route | Same as |
|---|---|---|
| `deploy_usecase(pod, specification)` | `POST usecase/deploy` | `joulectl deploy usecase` |
| `pause_usecase(name, pod)` | `PUT usecase/pause` | `joulectl process pause` |
| `resume_usecase(name, pod)` | `PUT usecase/resume` | `joulectl process resume` |
| `undeploy_usecase(name, pod, confirm)` | `DELETE usecase/undeploy` | `joulectl undeploy usecase` |

- `specification` is an object, or JSON or YAML text. It is parsed with a safe loader and sent as JSON.
  The root key is `use case`, and a use case needs at least one source and one sink. For example:
  `{"use case": {"name": "x", "stream name": "s", "sources": ["a"], "sinks": ["b"]}}`.
- Guardian answers HTTP 200 with an empty body for a deploy the daemons rejected (the reason is only in the Guardian
  log), for a duplicate deploy, and for pause, resume or undeploy of an unknown name. The server raises for a failure
  in the envelope, maps service codes (for example 653 to `UNKNOWN_POD`), and never treats an empty reply as proof of
  success.
- Before a change the server reads `usecase/list`. Deploy of a name already on the pod, and pause, resume or undeploy
  of a name that is not on it, fail at once and send nothing.
- After a deploy the result has `verified: true` or `false` and the listed `state`. If the use case is not listed,
  the note says the deployment most likely failed and points at the DSL schema and the daemon logs.
- Pause and resume return `state_before` and `state_after` from `usecase/list` (`RUNNING`, `SUSPENDED`), and the live
  status rows.
- `undeploy_usecase` removes the use case and cannot be undone. `confirm` must equal `name` exactly. If it does not,
  the error tells the agent to ask the user, and no request is sent. After the call the server checks `usecase/list`
  and returns `removed: true` or `false`.
- A change is never retried.
- Every change tool is annotated as not read-only. `undeploy_usecase` is annotated destructive; the others are not. `pause_usecase` and `resume_usecase` are idempotent.

## Resources

An agent should read these before it writes a use case specification.

| Resource | Guardian route | Content |
|---|---|---|
| `joule://dsl/schema` | `dsl/schema` | JSON Schema (2020-12) for the Joule DSL, as `application/schema+json` |
| `joule://dsl/catalogue` | `dsl/catalogue` | Every component with its key, properties and example, plus analytic and aggregate functions |
| `joule://dsl/component/{key}` | `dsl/catalogue` | One component by its DSL key (not case sensitive). Much smaller than the full catalogue |

The key needs the `dsl:read` scope. Guardian caches both routes for 5 minutes.

## API keys

The server follows the same rules as the Joule UI. Guardian refuses any request without a valid `X-API-Key`, so the server
needs a key unless Guardian runs with authentication off.

| Situation | What the server does |
|---|---|
| Key is malformed (not 8 to 200 printable characters, no spaces) | Stops at start-up with a message. The key is not repeated. |
| Guardian wants a key and none is set | Every tool and resource answers "Guardian requires an API key" with how to set one. Nothing else is sent. |
| Guardian rejects the key (`AUTH_INVALID`, `AUTH_EXPIRED`, `AUTH_REVOKED`) | Every call says so and tells you to get a new key and restart. |
| Key is valid but lacks a scope | The call is refused before it is sent, and the message names the scope and the key's owner. |
| Guardian uses no keys (its `apikeys/whoami` does not exist) | Calls go through. |
| Guardian cannot be reached | The call itself reports that. |

Each tool states the scope it needs, the same as its Guardian route: `pods:read`, `usecases:read`, `transports:read`,
`streams:read`, `usecases:write` (deploy, pause, resume, undeploy) and `dsl:read` (the resources). A higher level
covers a lower one, so `usecases:write` includes `usecases:read`. Guardian stays the authority. The server's check only
saves a request that Guardian would refuse, and it never grants anything.

Use the `whoami` tool first when a call is refused. It says whether Guardian wants a key, whether this key is accepted,
who owns it, its scopes and when it ends. It never returns the key.

Get a key from the Joule UI (API keys) or joulectl. A `viewer` key is enough for the read tools, and an `operator` key adds
the change tools. Put the key in a file, set `JOULE_API_KEY_FILE` to its path, and keep the file private (`chmod 600`).
The server reads the key when it starts, so restart it after you change the key.

## Settings

| Setting | Source, highest first |
|---|---|
| Guardian host | `JOULE_HOST`, `joule_host` in `~/.config/joule/config.json`, `127.0.0.1:9080` |
| API key | `JOULE_API_KEY_FILE`, `JOULE_API_KEY`, the key `joulectl` stored for that host |
| Change tools | `JOULE_MCP_ALLOW_WRITE=1` (default off) |
| Timeout | `JOULE_TIMEOUT`, default 30 seconds |
| Private CA | `JOULE_CA_BUNDLE` |

The key is sent as `X-API-Key`. It is never a tool argument, and it is not logged. Redirects are
refused so the key cannot be forwarded. A key with only `*:read` scopes keeps the agent read-only
at Guardian too.

## Known risk: shared streams

On the Joule 1.3 test install (2026-12-02), deploying a second use case on the same stream as a running one worked.
Undeploying it then shut down the shared stream processors (`cleanMarketData` and the select step). The first use
case stayed `RUNNING` and kept receiving events, but processed and emitted none, and Guardian reported no error.
`undeploy_usecase` now refuses when another use case on the pod uses the same stream, and `deploy_usecase` returns a
`warning` in that case. Treat this as a Joule platform issue to confirm, not as a rule.

## More information

- Release notes: [CHANGELOG.md](https://gitlab.com/joule-platform/joule-mcp/-/blob/main/CHANGELOG.md)
- Report a security problem: [SECURITY.md](https://gitlab.com/joule-platform/joule-mcp/-/blob/main/SECURITY.md)
- Issues: https://gitlab.com/joule-platform/joule-mcp/-/issues

