nextpyp-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ NEXTPYP_URL=https://nextpyp.example.org
2
+ NEXTPYP_USER_ID=your-user-id
3
+ NEXTPYP_APP_TOKEN=paste-the-approved-token-here
4
+ # optional, seconds to wait for each nextPYP request
5
+ NEXTPYP_TIMEOUT_S=60
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ .env
5
+ .pytest_cache/
@@ -0,0 +1,74 @@
1
+ image: python:3.11
2
+
3
+ stages:
4
+ - test
5
+ - build
6
+ - publish
7
+
8
+ # a release is a tag like v0.1.0, matching the version in pyproject.toml
9
+ .release-tag: &release-tag
10
+ if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/
11
+
12
+ test:
13
+ stage: test
14
+ variables:
15
+ # where to get the client from. Until nextpyp-client is on PyPI, set this CI/CD variable to a git URL,
16
+ # eg nextpyp-client @ git+https://gitlab.cs.duke.edu/nextpyp/nextpyp-client.git@main
17
+ NEXTPYP_CLIENT_SPEC: "nextpyp-client>=2.2,<3"
18
+ script:
19
+ # pip, not uv: [tool.uv.sources] points at a sibling checkout that CI doesn't have
20
+ - pip install "$NEXTPYP_CLIENT_SPEC"
21
+ - pip install -e . "pytest>=8" "pytest-asyncio>=0.23"
22
+ - pytest -q
23
+ rules:
24
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"
25
+ - if: $CI_COMMIT_BRANCH
26
+ - *release-tag
27
+
28
+ build:
29
+ stage: build
30
+ rules:
31
+ - *release-tag
32
+ script:
33
+ - pip install build twine toml
34
+ - VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
35
+ - |
36
+ if [ "v$VERSION" != "$CI_COMMIT_TAG" ]; then
37
+ echo "tag $CI_COMMIT_TAG doesn't match the version in pyproject.toml ($VERSION)"
38
+ exit 1
39
+ fi
40
+ - python -m build
41
+ - twine check --strict dist/*
42
+ artifacts:
43
+ paths:
44
+ - dist/
45
+
46
+ # Uploads need a person to press the button in the pipeline: TestPyPI first, check it, then PyPI.
47
+ # TEST_PYPI_TOKEN and PYPI_TOKEN are masked, protected CI/CD variables (project-scoped PyPI API tokens),
48
+ # and v* tags are protected, so only maintainers can run these.
49
+
50
+ publish-testpypi:
51
+ stage: publish
52
+ needs: [build]
53
+ rules:
54
+ - <<: *release-tag
55
+ when: manual
56
+ variables:
57
+ TWINE_USERNAME: __token__
58
+ TWINE_PASSWORD: $TEST_PYPI_TOKEN
59
+ script:
60
+ - pip install twine
61
+ - twine upload --non-interactive --repository-url https://test.pypi.org/legacy/ dist/*
62
+
63
+ publish-pypi:
64
+ stage: publish
65
+ needs: [build]
66
+ rules:
67
+ - <<: *release-tag
68
+ when: manual
69
+ variables:
70
+ TWINE_USERNAME: __token__
71
+ TWINE_PASSWORD: $PYPI_TOKEN
72
+ script:
73
+ - pip install twine
74
+ - twine upload --non-interactive dist/*
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, nextPYP
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,250 @@
1
+ Metadata-Version: 2.5
2
+ Name: nextpyp-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server for nextPYP: let AI assistants check, change, and run your cryo-EM/ET sessions and projects
5
+ Project-URL: Homepage, https://nextpyp.app
6
+ Project-URL: Source, https://gitlab.cs.duke.edu/nextpyp/nextpyp-mcp
7
+ Project-URL: Mirror, https://github.com/nextpyp/nextpyp-mcp
8
+ License: BSD-3-Clause
9
+ License-File: LICENSE
10
+ Keywords: ai-assistant,cryo-em,cryo-et,mcp,nextpyp
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: BSD License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: anyio>=4.5
22
+ Requires-Dist: mcp<2,>=1.10
23
+ Requires-Dist: nextpyp-client<3,>=2.2
24
+ Requires-Dist: requests>=2.31
25
+ Requires-Dist: toml>=0.10.2
26
+ Description-Content-Type: text/markdown
27
+
28
+ # nextpyp-mcp
29
+
30
+ An [MCP](https://modelcontextprotocol.io) server for [nextPYP](https://nextpyp.app). It lets an AI assistant
31
+ (Cursor, Claude Desktop, Claude Code, …) work with your nextPYP sessions and projects: check on them, read
32
+ logs, change parameters, add and run blocks, and stop or clean up work when you confirm.
33
+
34
+ It talks to nextPYP through [nextpyp-client](https://pypi.org/project/nextpyp-client/), using an
35
+ app token that you approve on the nextPYP website and can revoke at any time.
36
+
37
+ ## Requirements
38
+
39
+ - A nextPYP website with **API v2.2.0 or later**. That version adds the cluster-job log and project-block
40
+ services this server uses. The server checks the version and explains what's wrong if it doesn't match.
41
+ - [uv](https://docs.astral.sh/uv/) (recommended), or Python 3.10+ and pip.
42
+
43
+ ## Install
44
+
45
+ Nothing to install by hand with uv: your assistant starts the server with `uvx nextpyp-mcp` (see
46
+ [Connect your assistant](#connect-your-assistant)), which downloads it on first use. To check it works:
47
+
48
+ ```bash
49
+ uvx nextpyp-mcp --version
50
+ ```
51
+
52
+ Or install it with pip: `pip install nextpyp-mcp`, then use `nextpyp-mcp` as the command below.
53
+
54
+ ## Get an app token
55
+
56
+ Ask nextPYP for a token with the permissions you want, approve the request on the website (your account
57
+ page), and copy the token it shows you.
58
+
59
+ ```bash
60
+ uvx --from nextpyp-mcp python - <<'EOF'
61
+ from nextpyp.client import Client
62
+ client = Client("https://nextpyp.example.org", None)
63
+ request = client.services.apps.request_token("your-user-id", "nextpyp-mcp", [
64
+ # read
65
+ "project_list", "project_read", "session_list", "session_read", "group_list", "cluster_job_read",
66
+ # change parameters, add blocks, create sessions
67
+ "project_write", "session_write", "session_create",
68
+ # run, start, stop, cancel
69
+ "project_control", "session_control",
70
+ # delete and wipe (leave these out if you don't want the assistant to have them)
71
+ "project_delete", "session_delete",
72
+ ])
73
+ print("approve request", request.request_id, "on the website")
74
+ EOF
75
+ ```
76
+
77
+ Leave out any permission you don't want to grant; the tools that need it will report that it's missing.
78
+ **Treat the token like a password.** It acts as you. Revoke it on your account page if it leaks.
79
+
80
+ ## Connect your assistant
81
+
82
+ Add this to your MCP host's configuration (eg Cursor's `.cursor/mcp.json`, or Claude Desktop's
83
+ `claude_desktop_config.json`), with your own URL, user id, and token:
84
+
85
+ ```json
86
+ {
87
+ "mcpServers": {
88
+ "nextpyp": {
89
+ "command": "uvx",
90
+ "args": ["nextpyp-mcp"],
91
+ "env": {
92
+ "NEXTPYP_URL": "https://nextpyp.example.org",
93
+ "NEXTPYP_USER_ID": "your-user-id",
94
+ "NEXTPYP_APP_TOKEN": "paste-the-approved-token-here"
95
+ }
96
+ }
97
+ }
98
+ }
99
+ ```
100
+
101
+ For Claude Code:
102
+
103
+ ```bash
104
+ claude mcp add nextpyp \
105
+ -e NEXTPYP_URL=https://nextpyp.example.org -e NEXTPYP_USER_ID=your-user-id -e NEXTPYP_APP_TOKEN=… \
106
+ -- uvx nextpyp-mcp
107
+ ```
108
+
109
+ `uvx` uses the newest release; pin one with `nextpyp-mcp==0.1.0` in place of `nextpyp-mcp`. If you
110
+ installed with pip, use `"command": "nextpyp-mcp"` and no `args` (the full path to it if the host can't
111
+ find it).
112
+
113
+ Optional: `NEXTPYP_TIMEOUT_S` (default 60) is how long to wait for each request to nextPYP.
114
+
115
+ **If your website is behind single sign-on** (eg Shibboleth in front of Apache), requests from this server
116
+ get the login page instead of nextPYP. Point `NEXTPYP_URL` at nextPYP's own port behind the proxy instead,
117
+ eg `http://nextpyp-host.my.org:8080`, from a machine that can reach it. If you're not sure, this should print
118
+ JSON with an `apiVersion`, not HTML:
119
+
120
+ ```bash
121
+ curl -s -X POST -H 'Content-Type: application/json' \
122
+ --data '{"id":1,"method":"/kv/apps/version","params":[]}' "$NEXTPYP_URL/kv/apps/version"
123
+ ```
124
+
125
+ ## Using it from Cursor
126
+
127
+ 1. Put the configuration above in your **global** `~/.cursor/mcp.json`, not a project's `.cursor/mcp.json`,
128
+ so the token never ends up in a repository.
129
+ 2. Open **Cursor Settings → MCP** (or **Tools & Integrations**). `nextpyp` should be listed with a green
130
+ dot and its tools. If it shows an error, run `uvx nextpyp-mcp --version` in a terminal to see the
131
+ message.
132
+ 3. In the chat, use **Agent** mode and ask in plain language. Cursor picks the tools and asks before
133
+ running each one, unless you allow them automatically.
134
+
135
+ Some things to ask, and what happens:
136
+
137
+ **What's going on?**
138
+
139
+ > Which of my nextPYP projects are running right now? For each, which blocks are still going and which failed?
140
+
141
+ The assistant calls `list_running_projects`, then `list_runs` for each project, and summarizes the
142
+ block and cluster job statuses.
143
+
144
+ **Why did it fail?**
145
+
146
+ > The last run of the Particle picking block in project test-frames failed. Show me why.
147
+
148
+ The assistant finds the block with `list_jobs`, the failed cluster job with `list_runs`, the failing
149
+ micrographs or tilt-series with `list_cluster_job_series` (errors only), and reads their logs with
150
+ `get_cluster_job_log`. Logs are trimmed to their last 20,000 characters, where errors usually are.
151
+
152
+ **Is the data any good?**
153
+
154
+ > In session EMPIAR-11306, how fast is data coming in, and does the CTF fit of TS_01 look reasonable?
155
+
156
+ The assistant uses `get_session_speeds` and `get_session_ctf`, and reads the processing log for
157
+ that tilt-series if something looks off.
158
+
159
+ **Build part of a pipeline**
160
+
161
+ > In project test-mcp, add a pre-processing block after the raw data block. Use the same settings as
162
+ > block 2 in project test-frames, but with ctf_min_res = 25. Then run it.
163
+
164
+ The assistant reads block 2's parameters with `get_job`, looks up anything it's unsure of with
165
+ `get_block_args_schema`, adds and connects the block with `add_job`, and runs it with `run_jobs`. A block
166
+ that has never run starts right away.
167
+
168
+ **Change parameters and rerun**
169
+
170
+ > Lower the particle radius in block 6 of test-frames to 50 Å and rerun it.
171
+
172
+ `edit_job` changes only that parameter and keeps the rest. Because block 6 already ran, `run_jobs` first
173
+ reports which outputs would be replaced and which downstream blocks would become stale, and the
174
+ assistant asks you before rerunning.
175
+
176
+ **Stop or clean up**
177
+
178
+ > Cancel the run that's going in project MissAlign-validation-10164.
179
+
180
+ > Delete the blocks I added to test-mcp today.
181
+
182
+ Cancelling, stopping, clearing, wiping, and deleting always need your go-ahead: the tools refuse until
183
+ the assistant calls them again with `confirm=true`, so it has to check with you first.
184
+
185
+ Tips:
186
+
187
+ - Name projects, sessions, and blocks as you see them on the website; the assistant looks up the ids.
188
+ - To work in someone else's project that's shared with you, say whose it is (their user id).
189
+ - Nothing updates live. Ask again ("how is it doing now?") to get fresh status.
190
+
191
+ ## Tools
192
+
193
+ | Area | Read | Change | Run / stop | Delete |
194
+ |---|---|---|---|---|
195
+ | Sessions | `list_groups`, `list_sessions`, `get_session`, `list_running_sessions`, `is_session_running`, `get_session_speeds`, `get_session_log_index`, `get_session_cluster_jobs`, `get_session_data_log`, `get_session_ctf`, `get_session_motion`, `list_session_filters`, `get_session_filter` | `create_session`, `edit_session` | `start_session`, `restart_session`, `stop_session`\*, `cancel_session`\* | `clear_session`\*, `delete_session`\* |
196
+ | Projects | `list_projects`, `get_project`, `list_running_projects`, `get_project_stats`, `list_block_types`, `get_block_args_schema`, `list_jobs`, `get_job`, `get_job_stats`, `get_job_data_log`, `get_job_ctf`, `get_job_motion`, `list_runs`, `new_job_values` | `add_job`, `edit_job`, `rename_job` | `run_jobs`\*, `cancel_run`\*, `cancel_job`\* | `delete_jobs`\*, `wipe_job`\* |
197
+ | Cluster jobs | `get_cluster_job_log`, `list_cluster_job_elements`, `list_cluster_job_series`, `get_cluster_job_waiting_reason` | | | |
198
+
199
+ \* Needs `confirm=true`. Without it, the tool explains what it would do and asks the assistant to check with
200
+ you first. `run_jobs` runs right away when it would only run blocks that haven't run yet. Rerunning a block
201
+ replaces its outputs, so that needs confirmation, and the tool lists the downstream blocks that would
202
+ become stale.
203
+
204
+ `clear_session` on the pre-processing daemon (`Pypd`) erases every pre-processed micrograph or tilt-series,
205
+ CTF and motion results, saved filters, and particles; with `delete_session_files` it also deletes the
206
+ processed files and logs on disk, keeping only the raw data.
207
+
208
+ Notes:
209
+
210
+ - **Edits change only what you name.** nextPYP replaces all of a block's or session's parameters on every
211
+ edit, so `edit_job` and `edit_session` read the newest values first and merge your changes into them.
212
+ - **Parameters** are flat keys like `ctf_min_res`. `get_block_args_schema` (with `search`) finds them.
213
+ - **Long output is trimmed.** Logs keep their last 20,000 characters (adjustable per call); long lists
214
+ say how many items were left out.
215
+ - **Shared projects:** project tools take an optional `owner_id` for projects other users shared with you.
216
+
217
+ Not yet supported: live (websocket) updates, so ask the assistant to check again instead; saving or deleting
218
+ filters; session data export; creating, deleting, or sharing projects.
219
+
220
+ ## Source code
221
+
222
+ | | GitHub | GitLab (where development happens) |
223
+ |---|---|---|
224
+ | This server | https://github.com/nextpyp/nextpyp-mcp | https://gitlab.cs.duke.edu/nextpyp/nextpyp-mcp |
225
+ | [nextpyp-client](https://pypi.org/project/nextpyp-client/) | https://github.com/nextpyp/nextpyp-client | https://gitlab.cs.duke.edu/nextpyp/nextpyp-client |
226
+
227
+ ## Development
228
+
229
+ Check out both projects side by side; `uv sync` uses the client checkout next to this one
230
+ (`[tool.uv.sources]` in `pyproject.toml`), so you can change both at once:
231
+
232
+ ```bash
233
+ git clone git@gitlab.cs.duke.edu:nextpyp/nextpyp-client.git
234
+ git clone git@gitlab.cs.duke.edu:nextpyp/nextpyp-mcp.git
235
+ cd nextpyp-mcp
236
+ uv sync
237
+ uv run pytest
238
+ ```
239
+
240
+ To point your assistant at this checkout instead of the release, use
241
+ `"command": "uv", "args": ["run", "--directory", "/path/to/nextpyp-mcp", "nextpyp-mcp"]`.
242
+
243
+ Tests use a fake nextPYP client, so they don't need a website. When nextPYP's exported API changes,
244
+ `scripts/release-client.sh` in the nextPYP repo regenerates the client; release the client first, then
245
+ raise the `nextpyp-client` requirement in `pyproject.toml` if this server needs the new API.
246
+
247
+ ### Releasing
248
+
249
+ Bump `version` in `pyproject.toml`, commit, and push a tag `v<version>`. The tag's GitLab pipeline tests and
250
+ builds the package; run its `publish-testpypi` job, check the TestPyPI install, then run `publish-pypi`.
@@ -0,0 +1,223 @@
1
+ # nextpyp-mcp
2
+
3
+ An [MCP](https://modelcontextprotocol.io) server for [nextPYP](https://nextpyp.app). It lets an AI assistant
4
+ (Cursor, Claude Desktop, Claude Code, …) work with your nextPYP sessions and projects: check on them, read
5
+ logs, change parameters, add and run blocks, and stop or clean up work when you confirm.
6
+
7
+ It talks to nextPYP through [nextpyp-client](https://pypi.org/project/nextpyp-client/), using an
8
+ app token that you approve on the nextPYP website and can revoke at any time.
9
+
10
+ ## Requirements
11
+
12
+ - A nextPYP website with **API v2.2.0 or later**. That version adds the cluster-job log and project-block
13
+ services this server uses. The server checks the version and explains what's wrong if it doesn't match.
14
+ - [uv](https://docs.astral.sh/uv/) (recommended), or Python 3.10+ and pip.
15
+
16
+ ## Install
17
+
18
+ Nothing to install by hand with uv: your assistant starts the server with `uvx nextpyp-mcp` (see
19
+ [Connect your assistant](#connect-your-assistant)), which downloads it on first use. To check it works:
20
+
21
+ ```bash
22
+ uvx nextpyp-mcp --version
23
+ ```
24
+
25
+ Or install it with pip: `pip install nextpyp-mcp`, then use `nextpyp-mcp` as the command below.
26
+
27
+ ## Get an app token
28
+
29
+ Ask nextPYP for a token with the permissions you want, approve the request on the website (your account
30
+ page), and copy the token it shows you.
31
+
32
+ ```bash
33
+ uvx --from nextpyp-mcp python - <<'EOF'
34
+ from nextpyp.client import Client
35
+ client = Client("https://nextpyp.example.org", None)
36
+ request = client.services.apps.request_token("your-user-id", "nextpyp-mcp", [
37
+ # read
38
+ "project_list", "project_read", "session_list", "session_read", "group_list", "cluster_job_read",
39
+ # change parameters, add blocks, create sessions
40
+ "project_write", "session_write", "session_create",
41
+ # run, start, stop, cancel
42
+ "project_control", "session_control",
43
+ # delete and wipe (leave these out if you don't want the assistant to have them)
44
+ "project_delete", "session_delete",
45
+ ])
46
+ print("approve request", request.request_id, "on the website")
47
+ EOF
48
+ ```
49
+
50
+ Leave out any permission you don't want to grant; the tools that need it will report that it's missing.
51
+ **Treat the token like a password.** It acts as you. Revoke it on your account page if it leaks.
52
+
53
+ ## Connect your assistant
54
+
55
+ Add this to your MCP host's configuration (eg Cursor's `.cursor/mcp.json`, or Claude Desktop's
56
+ `claude_desktop_config.json`), with your own URL, user id, and token:
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "nextpyp": {
62
+ "command": "uvx",
63
+ "args": ["nextpyp-mcp"],
64
+ "env": {
65
+ "NEXTPYP_URL": "https://nextpyp.example.org",
66
+ "NEXTPYP_USER_ID": "your-user-id",
67
+ "NEXTPYP_APP_TOKEN": "paste-the-approved-token-here"
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ For Claude Code:
75
+
76
+ ```bash
77
+ claude mcp add nextpyp \
78
+ -e NEXTPYP_URL=https://nextpyp.example.org -e NEXTPYP_USER_ID=your-user-id -e NEXTPYP_APP_TOKEN=… \
79
+ -- uvx nextpyp-mcp
80
+ ```
81
+
82
+ `uvx` uses the newest release; pin one with `nextpyp-mcp==0.1.0` in place of `nextpyp-mcp`. If you
83
+ installed with pip, use `"command": "nextpyp-mcp"` and no `args` (the full path to it if the host can't
84
+ find it).
85
+
86
+ Optional: `NEXTPYP_TIMEOUT_S` (default 60) is how long to wait for each request to nextPYP.
87
+
88
+ **If your website is behind single sign-on** (eg Shibboleth in front of Apache), requests from this server
89
+ get the login page instead of nextPYP. Point `NEXTPYP_URL` at nextPYP's own port behind the proxy instead,
90
+ eg `http://nextpyp-host.my.org:8080`, from a machine that can reach it. If you're not sure, this should print
91
+ JSON with an `apiVersion`, not HTML:
92
+
93
+ ```bash
94
+ curl -s -X POST -H 'Content-Type: application/json' \
95
+ --data '{"id":1,"method":"/kv/apps/version","params":[]}' "$NEXTPYP_URL/kv/apps/version"
96
+ ```
97
+
98
+ ## Using it from Cursor
99
+
100
+ 1. Put the configuration above in your **global** `~/.cursor/mcp.json`, not a project's `.cursor/mcp.json`,
101
+ so the token never ends up in a repository.
102
+ 2. Open **Cursor Settings → MCP** (or **Tools & Integrations**). `nextpyp` should be listed with a green
103
+ dot and its tools. If it shows an error, run `uvx nextpyp-mcp --version` in a terminal to see the
104
+ message.
105
+ 3. In the chat, use **Agent** mode and ask in plain language. Cursor picks the tools and asks before
106
+ running each one, unless you allow them automatically.
107
+
108
+ Some things to ask, and what happens:
109
+
110
+ **What's going on?**
111
+
112
+ > Which of my nextPYP projects are running right now? For each, which blocks are still going and which failed?
113
+
114
+ The assistant calls `list_running_projects`, then `list_runs` for each project, and summarizes the
115
+ block and cluster job statuses.
116
+
117
+ **Why did it fail?**
118
+
119
+ > The last run of the Particle picking block in project test-frames failed. Show me why.
120
+
121
+ The assistant finds the block with `list_jobs`, the failed cluster job with `list_runs`, the failing
122
+ micrographs or tilt-series with `list_cluster_job_series` (errors only), and reads their logs with
123
+ `get_cluster_job_log`. Logs are trimmed to their last 20,000 characters, where errors usually are.
124
+
125
+ **Is the data any good?**
126
+
127
+ > In session EMPIAR-11306, how fast is data coming in, and does the CTF fit of TS_01 look reasonable?
128
+
129
+ The assistant uses `get_session_speeds` and `get_session_ctf`, and reads the processing log for
130
+ that tilt-series if something looks off.
131
+
132
+ **Build part of a pipeline**
133
+
134
+ > In project test-mcp, add a pre-processing block after the raw data block. Use the same settings as
135
+ > block 2 in project test-frames, but with ctf_min_res = 25. Then run it.
136
+
137
+ The assistant reads block 2's parameters with `get_job`, looks up anything it's unsure of with
138
+ `get_block_args_schema`, adds and connects the block with `add_job`, and runs it with `run_jobs`. A block
139
+ that has never run starts right away.
140
+
141
+ **Change parameters and rerun**
142
+
143
+ > Lower the particle radius in block 6 of test-frames to 50 Å and rerun it.
144
+
145
+ `edit_job` changes only that parameter and keeps the rest. Because block 6 already ran, `run_jobs` first
146
+ reports which outputs would be replaced and which downstream blocks would become stale, and the
147
+ assistant asks you before rerunning.
148
+
149
+ **Stop or clean up**
150
+
151
+ > Cancel the run that's going in project MissAlign-validation-10164.
152
+
153
+ > Delete the blocks I added to test-mcp today.
154
+
155
+ Cancelling, stopping, clearing, wiping, and deleting always need your go-ahead: the tools refuse until
156
+ the assistant calls them again with `confirm=true`, so it has to check with you first.
157
+
158
+ Tips:
159
+
160
+ - Name projects, sessions, and blocks as you see them on the website; the assistant looks up the ids.
161
+ - To work in someone else's project that's shared with you, say whose it is (their user id).
162
+ - Nothing updates live. Ask again ("how is it doing now?") to get fresh status.
163
+
164
+ ## Tools
165
+
166
+ | Area | Read | Change | Run / stop | Delete |
167
+ |---|---|---|---|---|
168
+ | Sessions | `list_groups`, `list_sessions`, `get_session`, `list_running_sessions`, `is_session_running`, `get_session_speeds`, `get_session_log_index`, `get_session_cluster_jobs`, `get_session_data_log`, `get_session_ctf`, `get_session_motion`, `list_session_filters`, `get_session_filter` | `create_session`, `edit_session` | `start_session`, `restart_session`, `stop_session`\*, `cancel_session`\* | `clear_session`\*, `delete_session`\* |
169
+ | Projects | `list_projects`, `get_project`, `list_running_projects`, `get_project_stats`, `list_block_types`, `get_block_args_schema`, `list_jobs`, `get_job`, `get_job_stats`, `get_job_data_log`, `get_job_ctf`, `get_job_motion`, `list_runs`, `new_job_values` | `add_job`, `edit_job`, `rename_job` | `run_jobs`\*, `cancel_run`\*, `cancel_job`\* | `delete_jobs`\*, `wipe_job`\* |
170
+ | Cluster jobs | `get_cluster_job_log`, `list_cluster_job_elements`, `list_cluster_job_series`, `get_cluster_job_waiting_reason` | | | |
171
+
172
+ \* Needs `confirm=true`. Without it, the tool explains what it would do and asks the assistant to check with
173
+ you first. `run_jobs` runs right away when it would only run blocks that haven't run yet. Rerunning a block
174
+ replaces its outputs, so that needs confirmation, and the tool lists the downstream blocks that would
175
+ become stale.
176
+
177
+ `clear_session` on the pre-processing daemon (`Pypd`) erases every pre-processed micrograph or tilt-series,
178
+ CTF and motion results, saved filters, and particles; with `delete_session_files` it also deletes the
179
+ processed files and logs on disk, keeping only the raw data.
180
+
181
+ Notes:
182
+
183
+ - **Edits change only what you name.** nextPYP replaces all of a block's or session's parameters on every
184
+ edit, so `edit_job` and `edit_session` read the newest values first and merge your changes into them.
185
+ - **Parameters** are flat keys like `ctf_min_res`. `get_block_args_schema` (with `search`) finds them.
186
+ - **Long output is trimmed.** Logs keep their last 20,000 characters (adjustable per call); long lists
187
+ say how many items were left out.
188
+ - **Shared projects:** project tools take an optional `owner_id` for projects other users shared with you.
189
+
190
+ Not yet supported: live (websocket) updates, so ask the assistant to check again instead; saving or deleting
191
+ filters; session data export; creating, deleting, or sharing projects.
192
+
193
+ ## Source code
194
+
195
+ | | GitHub | GitLab (where development happens) |
196
+ |---|---|---|
197
+ | This server | https://github.com/nextpyp/nextpyp-mcp | https://gitlab.cs.duke.edu/nextpyp/nextpyp-mcp |
198
+ | [nextpyp-client](https://pypi.org/project/nextpyp-client/) | https://github.com/nextpyp/nextpyp-client | https://gitlab.cs.duke.edu/nextpyp/nextpyp-client |
199
+
200
+ ## Development
201
+
202
+ Check out both projects side by side; `uv sync` uses the client checkout next to this one
203
+ (`[tool.uv.sources]` in `pyproject.toml`), so you can change both at once:
204
+
205
+ ```bash
206
+ git clone git@gitlab.cs.duke.edu:nextpyp/nextpyp-client.git
207
+ git clone git@gitlab.cs.duke.edu:nextpyp/nextpyp-mcp.git
208
+ cd nextpyp-mcp
209
+ uv sync
210
+ uv run pytest
211
+ ```
212
+
213
+ To point your assistant at this checkout instead of the release, use
214
+ `"command": "uv", "args": ["run", "--directory", "/path/to/nextpyp-mcp", "nextpyp-mcp"]`.
215
+
216
+ Tests use a fake nextPYP client, so they don't need a website. When nextPYP's exported API changes,
217
+ `scripts/release-client.sh` in the nextPYP repo regenerates the client; release the client first, then
218
+ raise the `nextpyp-client` requirement in `pyproject.toml` if this server needs the new API.
219
+
220
+ ### Releasing
221
+
222
+ Bump `version` in `pyproject.toml`, commit, and push a tag `v<version>`. The tag's GitLab pipeline tests and
223
+ builds the package; run its `publish-testpypi` job, check the TestPyPI install, then run `publish-pypi`.
@@ -0,0 +1,55 @@
1
+ [project]
2
+ name = "nextpyp-mcp"
3
+ version = "0.1.0"
4
+ description = "MCP server for nextPYP: let AI assistants check, change, and run your cryo-EM/ET sessions and projects"
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ license = { text = "BSD-3-Clause" }
8
+ keywords = ["mcp", "nextpyp", "cryo-em", "cryo-et", "ai-assistant"]
9
+ classifiers = [
10
+ "Development Status :: 3 - Alpha",
11
+ "Intended Audience :: Science/Research",
12
+ "Programming Language :: Python :: 3",
13
+ "Programming Language :: Python :: 3.10",
14
+ "Programming Language :: Python :: 3.11",
15
+ "Programming Language :: Python :: 3.12",
16
+ "License :: OSI Approved :: BSD License",
17
+ "Operating System :: OS Independent",
18
+ "Topic :: Scientific/Engineering :: Bio-Informatics",
19
+ ]
20
+ dependencies = [
21
+ "mcp>=1.10,<2",
22
+ "anyio>=4.5",
23
+ "requests>=2.31",
24
+ "toml>=0.10.2",
25
+ # client X.Y speaks nextPYP API X.Y; this server needs the 2.2 services (project blocks, cluster job logs)
26
+ "nextpyp-client>=2.2,<3",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://nextpyp.app"
31
+ Source = "https://gitlab.cs.duke.edu/nextpyp/nextpyp-mcp"
32
+ Mirror = "https://github.com/nextpyp/nextpyp-mcp"
33
+
34
+ [project.scripts]
35
+ nextpyp-mcp = "nextpyp_mcp.server:main"
36
+
37
+ [dependency-groups]
38
+ dev = ["pytest>=8", "pytest-asyncio>=0.23"]
39
+
40
+ [tool.uv.sources]
41
+ # for local development, use the client checkout next to this one.
42
+ # only uv reads this: the published package depends on nextpyp-client from PyPI (above).
43
+ nextpyp-client = { path = "../nextpyp-client", editable = true }
44
+
45
+ [build-system]
46
+ requires = ["hatchling"]
47
+ build-backend = "hatchling.build"
48
+
49
+ [tool.hatch.build.targets.wheel]
50
+ packages = ["src/nextpyp_mcp"]
51
+
52
+ [tool.pytest.ini_options]
53
+ asyncio_mode = "auto"
54
+ asyncio_default_fixture_loop_scope = "function"
55
+ testpaths = ["tests"]
@@ -0,0 +1,3 @@
1
+ """MCP server for nextPYP."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,3 @@
1
+ from .server import main
2
+
3
+ main()