AI assistants (MCP)

nextpyp-mcp connects an AI assistant such as Cursor, Claude Desktop, or Claude Code to nextPYP through the Model Context Protocol (MCP). You ask in plain language, and the assistant works with your sessions and projects for you: it checks on runs, reads logs, changes block parameters, adds and runs blocks, and stops or cleans up work once you agree.

The assistant acts as you, through an app token that you approve on the website and can revoke at any time. It can only do what the token’s permissions allow.

Note

This needs a nextPYP website with API version 2.2.0 or later. If yours is older, the server says so when it starts.

What you need

  • A computer that runs your assistant and can reach the nextPYP website.

  • uv (recommended), or Python 3.10 or later and pip.

  • Your nextPYP user id.

Check that the server installs and runs:

uvx nextpyp-mcp --version

Without uv, run pip install nextpyp-mcp and use nextpyp-mcp in place of uvx nextpyp-mcp on this page.

Get an app token

  1. Request a token with the permissions you want to give the assistant. Replace the website address and user id with your own:

    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. Tools that need a missing permission say so instead of running. The snippet uses nextpyp-client, the Python library the assistant itself uses to talk to the website, and the same package a script can call on its own (Python client).

  2. Sign in to nextPYP, open Your Account from the account menu, and open the Apps tab. Approve the request with the id the command printed.

  3. Copy the token the website shows you.

Warning

Treat the token like a password: anyone who has it can act as you. Keep it out of shared files and repositories, and revoke it on the Apps tab if it leaks or you stop using it.

Connect your assistant

Add this to your global ~/.cursor/mcp.json, not a project’s .cursor/mcp.json, so the token never ends up in a repository:

{
  "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"
      }
    }
  }
}

Open Cursor Settings → MCP. nextpyp should be listed with a green dot and its tools. Ask your questions in the chat in Agent mode.

Add the same mcpServers entry as for Cursor to claude_desktop_config.json (Settings → Developer → Edit Config), then restart Claude Desktop.

claude mcp add nextpyp \
  -e NEXTPYP_URL=https://nextpyp.example.org \
  -e NEXTPYP_USER_ID=your-user-id \
  -e NEXTPYP_APP_TOKEN=paste-the-approved-token-here \
  -- uvx nextpyp-mcp

NEXTPYP_TIMEOUT_S (default 60) sets how many seconds to wait for each request to nextPYP.

Websites behind single sign-on

If you sign in to nextPYP through single sign-on (for example Shibboleth), requests from the assistant get the login page instead of nextPYP. Set NEXTPYP_URL to nextPYP’s own address behind the sign-on proxy, for example http://nextpyp-host.my.org:8080, and run the assistant on a machine that can reach it. Ask your administrator for the address. To check an address, this should print JSON with an apiVersion, not a web page:

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

What to ask

Name projects, sessions, and blocks as you see them on the website; the assistant looks up the ids.

What’s going on?

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

Why did it fail?

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

The assistant finds the failed cluster job and the micrographs or tilt-series that failed, and reads their logs.

Is the data any good?

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

Build part of a pipeline

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

Change parameters and rerun

Lower the particle radius in block 6 to 50 Å and rerun it.

Only that parameter changes; the block’s other parameters are kept.

Stop or clean up

Cancel the run that’s going in project my-project.

Nothing updates live: ask again (“how is it doing now?”) for fresh status. To work in a project that someone shared with you, say whose it is.

What needs your go-ahead

The assistant can read anything the token allows, and can change parameters and add blocks, without asking. These need you to agree first:

  • cancelling a run or a cluster job, and stopping or cancelling a session

  • rerunning blocks that already ran, because it replaces their outputs; the assistant first tells you which downstream blocks would become out of date (running blocks that have never run doesn’t need it)

  • deleting or wiping blocks, and clearing or deleting sessions

For these, the tool refuses the first time and explains what it would do, so the assistant has to check with you before calling it again.

Not supported yet: live updates, saving or deleting filters, exporting session data, and creating, deleting, or sharing projects. See the nextpyp-mcp README for the full list of tools.