Skip to content

Commit 810faf9

Browse files
committed
Document the uv-based MCP server launch and add PyPhi/GitHub install forms
The MCP how-to led with a bare `pyphi-mcp` command, which a client cannot find when the script lives in a project virtual environment (the client launches the server with its own PATH, not the shell's). Rework the Connect section to launch through `uvx --from "pyphi[mcp]" pyphi-mcp`, needing no activation or absolute path, and scope the absolute-path fallback to GUI clients like Claude Desktop that do not inherit the shell PATH. Show both the PyPI and GitHub install forms. Add a primer note steering the connected agent to the project's virtual environment (e.g. `uv run python`) rather than the bare system `python` when it runs PyPhi in a shell.
1 parent d95a26f commit 810faf9

2 files changed

Lines changed: 70 additions & 12 deletions

File tree

docs/howto/mcp-server.md

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@ exploring what Φ, distinctions, and relations actually mean.
1212

1313
## Install
1414

15+
Install PyPhi with the `mcp` extra. From PyPI:
16+
1517
```bash
1618
pip install "pyphi[mcp]"
1719
```
1820

21+
Or install the latest code straight from GitHub:
22+
23+
```bash
24+
pip install "pyphi[mcp] @ git+https://github.com/wmayner/pyphi.git"
25+
```
26+
1927
The IIT 3.0 formalism needs the earth-mover-distance backend, and plotting needs
20-
the visualization stack, so install those extras too if you want them:
28+
the visualization stack, so add those extras too if you want them:
2129

2230
```bash
2331
pip install "pyphi[mcp,emd,visualize]"
@@ -26,36 +34,81 @@ pip install "pyphi[mcp,emd,visualize]"
2634
## Connect it to a client
2735

2836
The server speaks MCP over stdio and is started by the `pyphi-mcp` console
29-
script (equivalently, `python -m pyphi.mcp`). Clients launch it for you; you
30-
rarely run it by hand.
37+
script (equivalently, `python -m pyphi.mcp`). Clients launch it as a subprocess;
38+
you rarely run it by hand.
39+
40+
A client launches that subprocess with its own environment rather than your
41+
shell's, so a bare `pyphi-mcp` is found only if it is on the client's `PATH`
42+
which a project virtual environment usually is not. Two ways to make the launch
43+
reliable without hardcoding a path:
44+
45+
- **Run it through `uv`** (recommended). `uvx` resolves an isolated environment
46+
and runs the entry point, so nothing needs to be installed or activated first.
47+
From PyPI the launch command is `uvx --from "pyphi[mcp]" pyphi-mcp`; from
48+
GitHub it is
49+
`uvx --from "pyphi[mcp] @ git+https://github.com/wmayner/pyphi.git" pyphi-mcp`.
50+
- **Install it as a tool** with `uv tool install "pyphi[mcp]"` (or
51+
`pipx install "pyphi[mcp]"`), which places `pyphi-mcp` on a stable `PATH`
52+
entry so the bare name works everywhere.
3153

32-
### Claude Desktop
54+
### Claude Code
3355

34-
Add it to `claude_desktop_config.json`:
56+
Add the server with `claude mcp add` — everything after `--` is the launch
57+
command. From PyPI:
58+
59+
```bash
60+
claude mcp add pyphi -- uvx --from "pyphi[mcp]" pyphi-mcp
61+
```
62+
63+
Or, for the latest code from GitHub:
64+
65+
```bash
66+
claude mcp add pyphi -- uvx --from "pyphi[mcp] @ git+https://github.com/wmayner/pyphi.git" pyphi-mcp
67+
```
68+
69+
This writes an entry to `.mcp.json` (or `~/.claude.json`), which you can also
70+
create by hand:
3571

3672
```json
3773
{
3874
"mcpServers": {
3975
"pyphi": {
40-
"command": "pyphi-mcp"
76+
"command": "uvx",
77+
"args": ["--from", "pyphi[mcp]", "pyphi-mcp"]
4178
}
4279
}
4380
}
4481
```
4582

46-
If `pyphi-mcp` is not on the client's `PATH`, use the absolute path to the
47-
executable in your environment (the one `which pyphi-mcp` prints inside your
48-
virtual environment).
83+
Claude Code inherits your shell's `PATH`, so as long as `uv` is on it this needs
84+
no absolute paths.
4985

50-
### Claude Code
86+
### Claude Desktop
87+
88+
Add it to `claude_desktop_config.json`:
89+
90+
```json
91+
{
92+
"mcpServers": {
93+
"pyphi": {
94+
"command": "uvx",
95+
"args": ["--from", "pyphi[mcp]", "pyphi-mcp"]
96+
}
97+
}
98+
}
99+
```
51100

52-
Add an `.mcp.json` to your project (or run `claude mcp add`):
101+
Claude Desktop is a GUI application and does not inherit your shell's `PATH`; it
102+
launches subprocesses with a minimal system `PATH`. If `uvx` (or `pyphi-mcp`) is
103+
not found there, give the absolute path to the executable — the one that
104+
`which uvx` prints in your shell:
53105

54106
```json
55107
{
56108
"mcpServers": {
57109
"pyphi": {
58-
"command": "pyphi-mcp"
110+
"command": "/Users/you/.local/bin/uvx",
111+
"args": ["--from", "pyphi[mcp]", "pyphi-mcp"]
59112
}
60113
}
61114
}

pyphi/mcp/content/primer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ reference.
4141
written against an older PyPhi? Read `get_iit_reference("migration")` first:
4242
2.0 renamed the core objects and has no compatibility shims.
4343

44+
When you run PyPhi in a shell rather than through these tools, use the project's
45+
virtual environment — `uv run python` if it is a uv project, otherwise the
46+
environment's own `python` — not the bare system `python`, which likely does not
47+
have PyPhi installed.
48+
4449
## Two things to keep straight from the start
4550

4651
- **States are little-endian.** The *first* node is the least-significant bit,

0 commit comments

Comments
 (0)