Skip to main content

nextpyp-mcp

An MCP server for nextPYP. It lets an AI assistant (Cursor, Claude Desktop, Claude Code, …) work with your nextPYP sessions and projects: check on them, read logs, change parameters, add and run blocks, and stop or clean up work when you confirm.

It talks to nextPYP through nextpyp-client, using an app token that you approve on the nextPYP website and can revoke at any time.

Requirements

  • A nextPYP website with API v2.2.0 or later. That version adds the cluster-job log and project-block services this server uses. The server checks the version and explains what's wrong if it doesn't match.
  • uv (recommended), or Python 3.10+ and pip.

Install

Nothing to install by hand with uv: your assistant starts the server with uvx nextpyp-mcp (see Connect your assistant), which downloads it on first use. To check it works:

uvx nextpyp-mcp --version

Or install it with pip: pip install nextpyp-mcp, then use nextpyp-mcp as the command below.

Get an app token

Ask nextPYP for a token with the permissions you want, approve the request on the website (your account page), and copy the token it shows you.

uvx --from nextpyp-mcp python - <<'EOF'
from nextpyp.client import Client
client = Client("https://nextpyp.example.org", None)
request = client.services.apps.request_token("your-user-id", "nextpyp-mcp", [
    # read
    "project_list", "project_read", "session_list", "session_read", "group_list", "cluster_job_read",
    # change parameters, add blocks, create sessions
    "project_write", "session_write", "session_create",
    # run, start, stop, cancel
    "project_control", "session_control",
    # delete and wipe (leave these out if you don't want the assistant to have them)
    "project_delete", "session_delete",
])
print("approve request", request.request_id, "on the website")
EOF

Leave out any permission you don't want to grant; the tools that need it will report that it's missing. Treat the token like a password. It acts as you. Revoke it on your account page if it leaks.

Connect your assistant

Add this to your MCP host's configuration (eg Cursor's .cursor/mcp.json, or Claude Desktop's claude_desktop_config.json), with your own URL, user id, and token:

{
  "mcpServers": {
    "nextpyp": {
      "command": "uvx",
      "args": ["nextpyp-mcp"],
      "env": {
        "NEXTPYP_URL": "https://nextpyp.example.org",
        "NEXTPYP_USER_ID": "your-user-id",
        "NEXTPYP_APP_TOKEN": "paste-the-approved-token-here"
      }
    }
  }
}

For Claude Code:

claude mcp add nextpyp \
  -e NEXTPYP_URL=https://nextpyp.example.org -e NEXTPYP_USER_ID=your-user-id -e NEXTPYP_APP_TOKEN=… \
  -- uvx nextpyp-mcp

uvx uses the newest release; pin one with nextpyp-mcp==0.1.0 in place of nextpyp-mcp. If you installed with pip, use "command": "nextpyp-mcp" and no args (the full path to it if the host can't find it).

Optional: NEXTPYP_TIMEOUT_S (default 60) is how long to wait for each request to nextPYP.

If your website is behind single sign-on (eg Shibboleth in front of Apache), requests from this server get the login page instead of nextPYP. Point NEXTPYP_URL at nextPYP's own port behind the proxy instead, eg http://nextpyp-host.my.org:8080, from a machine that can reach it. If you're not sure, this should print JSON with an apiVersion, not HTML:

curl -s -X POST -H 'Content-Type: application/json' \
  --data '{"id":1,"method":"/kv/apps/version","params":[]}' "$NEXTPYP_URL/kv/apps/version"

Using it from Cursor

  1. Put the configuration above in your global ~/.cursor/mcp.json, not a project's .cursor/mcp.json, so the token never ends up in a repository.
  2. Open Cursor Settings → MCP (or Tools & Integrations). nextpyp should be listed with a green dot and its tools. If it shows an error, run uvx nextpyp-mcp --version in a terminal to see the message.
  3. In the chat, use Agent mode and ask in plain language. Cursor picks the tools and asks before running each one, unless you allow them automatically.

Some things to ask, and what happens:

What's going on?

Which of my nextPYP projects are running right now? For each, which blocks are still going and which failed?

The assistant calls list_running_projects, then list_runs for each project, and summarizes the block and cluster job statuses.

Why did it fail?

The last run of the Particle picking block in project test-frames failed. Show me why.

The assistant finds the block with list_jobs, the failed cluster job with list_runs, the failing micrographs or tilt-series with list_cluster_job_series (errors only), and reads their logs with get_cluster_job_log. Logs are trimmed to their last 20,000 characters, where errors usually are.

Is the data any good?

In session EMPIAR-11306, how fast is data coming in, and does the CTF fit of TS_01 look reasonable?

The assistant uses get_session_speeds and get_session_ctf, and reads the processing log for that tilt-series if something looks off.

Build part of a pipeline

In project test-mcp, add a pre-processing block after the raw data block. Use the same settings as block 2 in project test-frames, but with ctf_min_res = 25. Then run it.

The assistant reads block 2's parameters with get_job, looks up anything it's unsure of with get_block_args_schema, adds and connects the block with add_job, and runs it with run_jobs. A block that has never run starts right away.

Change parameters and rerun

Lower the particle radius in block 6 of test-frames to 50 Å and rerun it.

edit_job changes only that parameter and keeps the rest. Because block 6 already ran, run_jobs first reports which outputs would be replaced and which downstream blocks would become stale, and the assistant asks you before rerunning.

Stop or clean up

Cancel the run that's going in project MissAlign-validation-10164.

Delete the blocks I added to test-mcp today.

Cancelling, stopping, clearing, wiping, and deleting always need your go-ahead: the tools refuse until the assistant calls them again with confirm=true, so it has to check with you first.

Tips:

  • Name projects, sessions, and blocks as you see them on the website; the assistant looks up the ids.
  • To work in someone else's project that's shared with you, say whose it is (their user id).
  • Nothing updates live. Ask again ("how is it doing now?") to get fresh status.

Tools

Area Read Change Run / stop Delete
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*
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*
Cluster jobs get_cluster_job_log, list_cluster_job_elements, list_cluster_job_series, get_cluster_job_waiting_reason

* Needs confirm=true. Without it, the tool explains what it would do and asks the assistant to check with you first. run_jobs runs right away when it would only run blocks that haven't run yet. Rerunning a block replaces its outputs, so that needs confirmation, and the tool lists the downstream blocks that would become stale.

clear_session on the pre-processing daemon (Pypd) erases every pre-processed micrograph or tilt-series, CTF and motion results, saved filters, and particles; with delete_session_files it also deletes the processed files and logs on disk, keeping only the raw data.

Notes:

  • Edits change only what you name. nextPYP replaces all of a block's or session's parameters on every edit, so edit_job and edit_session read the newest values first and merge your changes into them.
  • Parameters are flat keys like ctf_min_res. get_block_args_schema (with search) finds them.
  • Long output is trimmed. Logs keep their last 20,000 characters (adjustable per call); long lists say how many items were left out.
  • Shared projects: project tools take an optional owner_id for projects other users shared with you.

Not yet supported: live (websocket) updates, so ask the assistant to check again instead; saving or deleting filters; session data export; creating, deleting, or sharing projects.

Source code

GitHub GitLab (where development happens)
This server https://github.com/nextpyp/nextpyp-mcp https://gitlab.cs.duke.edu/nextpyp/nextpyp-mcp
nextpyp-client https://github.com/nextpyp/nextpyp-client https://gitlab.cs.duke.edu/nextpyp/nextpyp-client

Development

Check out both projects side by side; uv sync uses the client checkout next to this one ([tool.uv.sources] in pyproject.toml), so you can change both at once:

git clone git@gitlab.cs.duke.edu:nextpyp/nextpyp-client.git
git clone git@gitlab.cs.duke.edu:nextpyp/nextpyp-mcp.git
cd nextpyp-mcp
uv sync
uv run pytest

To point your assistant at this checkout instead of the release, use "command": "uv", "args": ["run", "--directory", "/path/to/nextpyp-mcp", "nextpyp-mcp"].

Tests use a fake nextPYP client, so they don't need a website. When nextPYP's exported API changes, scripts/release-client.sh in the nextPYP repo regenerates the client; release the client first, then raise the nextpyp-client requirement in pyproject.toml if this server needs the new API.

Releasing

Bump version in pyproject.toml, commit, and push a tag v<version>. The tag's GitLab pipeline tests and builds the package; run its publish-testpypi job, check the TestPyPI install, then run publish-pypi.

Metadata

Release files for nextpyp-mcp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nextpyp-mcp 0.1.0
File Size Uploaded Provenance Actions
nextpyp_mcp-0.1.0.tar.gz 115.0 kB Without provenance Details for nextpyp_mcp-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nextpyp-mcp 0.1.0
File Interpreter ABI Platform Actions
nextpyp_mcp-0.1.0-py3-none-any.whl Python 3 none any Details for nextpyp_mcp-0.1.0-py3-none-any.whl

Total release size: 134.9 kB

Release files / nextpyp_mcp-0.1.0.tar.gz

Download URL nextpyp_mcp-0.1.0.tar.gz
Size 115.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d12bedc4f8e24addaad2cd472555f5d18ddd9d08afaacbfeea5da58323d6a453
BLAKE2b-256 checksum
How to use checksums
680f38aff3c45e1ab079848bc2518d8f0aadae51820b2ac816ec0fa4011f0324
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / nextpyp_mcp-0.1.0-py3-none-any.whl

Download URL nextpyp_mcp-0.1.0-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4da2bc8da10a12331f990b10d981f0da6e50fb0a0c7a1fd4a4d1c1d3c7d3c51c
BLAKE2b-256 checksum
How to use checksums
272677e7db50b606b5cd2bd2e445e7d5128150862307c580b6b1560fc7962b56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Security for nextpyp-mcp 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page