MCP for AI coding agents
Give Claude Code, Cursor, or any MCP client read+write access to a single PyCorner project over a revocable bearer token.
PyCorner exposes each project as an MCP server, so an external AI coding agent (Claude Code, Cursor, Continue, Windsurf, …) can read and write that project’s files over a single revocable bearer token. Edits go through the same pipeline as the web editor — if you have the project open in a browser tab, the agent’s changes converge into it live.
The isolation primitive is the same one the tunnel agent uses: one token = one project. A token minted for project A cannot touch project B, even if you own both. No tool ever takes a project_id — the project is fixed by the URL and the token.
MCP comes with the Pro and Team plans. Free accounts can’t mint tokens (the API returns
402 pro_required).
TL;DR
# 1. Mint a token in the app (Editor → 🤖 MCP), then:
claude mcp add --transport http marimo-smoke \
https://app.pycorner.dev/mcp/projects/<PROJECT_ID>/ \
--header "Authorization: Bearer pyc_mcp_xxx"
# 2. Confirm it connected
claude mcp list
# marimo-smoke: https://app.pycorner.dev/mcp/projects/<id>/ (HTTP) - ✓ Connected
# 3. In a Claude Code session:
# "List the files in the marimo-smoke project and read app.py"
Mint a token
From the app (recommended)
- Open the project in the editor at app.pycorner.dev.
- Click the 🤖 MCP chip in the editor header.
- Fill in the Create token form:
- Name — anything memorable (
claude-laptop,ci-bot). - Scope —
Write(read + mutate) orRead-only. - Expiry —
7d/30d/90d/1 year. Tokens always expire; one year is the max.
- Name — anything memorable (
- Click Create. The raw token (
pyc_mcp_…) is shown exactly once — copy it now. The modal also gives you a ready-to-pasteclaude mcp addcommand and a.mcp.jsonblock.
From the REST API
POST /api/v1/projects/<PROJECT_ID>/access-tokens/ as the project owner (owner-only, Pro and Team):
curl -X POST https://app.pycorner.dev/api/v1/projects/<PROJECT_ID>/access-tokens/ \
-H "Content-Type: application/json" \
-b "$YOUR_SESSION_COOKIES" \
-d '{"name": "claude-laptop", "scope": "write", "expires_in_days": 90}'
{
"id": "9c2…",
"name": "claude-laptop",
"prefix": "pyc_mcp_beV",
"scope": "write",
"expires_at": "2026-09-08T12:00:00Z",
"is_active": true,
"token": "pyc_mcp_beV_zCz6s8WMlbfqYwGWzmZd5HkZOvYuUf0whVMlZD8"
}
token is only present in this response — it’s never returned again. scope defaults to write; expires_in_days defaults to 365 and is capped at 365.
Connect a client
The endpoint is always:
https://app.pycorner.dev/mcp/projects/<PROJECT_ID>/
…with Authorization: Bearer <token>.
Claude Code
# user scope = available in every directory; drop --scope user for project-local
claude mcp add --transport http --scope user marimo-smoke \
https://app.pycorner.dev/mcp/projects/<PROJECT_ID>/ \
--header "Authorization: Bearer pyc_mcp_xxx"
The 🤖 MCP modal gives you this exact command pre-filled with your token and project id — just copy, paste, run. (The URL is a positional argument in current Claude Code, not
--url.) Verify withclaude mcp list— you want a✓ Connected.
.mcp.json (Cursor, Continue, Windsurf, project-checked-in config)
{
"mcpServers": {
"marimo-smoke": {
"type": "http",
"url": "https://app.pycorner.dev/mcp/projects/<PROJECT_ID>/",
"headers": { "Authorization": "Bearer pyc_mcp_xxx" }
}
}
}
The tools
Nine tools. Six read, three write. Write tools require a write-scoped token — a read token calling them gets a ToolError.
| Tool | Scope | What it does |
|---|---|---|
list_files | read | All file paths + updated_at. |
read_file | read | One file’s content. |
list_versions | read | Git history (needs version history / git sync). |
read_version | read | A file’s content at a specific commit SHA. |
list_resources | read | The project’s data-proxy resources (DBs/APIs/tunnels), names only. |
get_preview_url | read | The browser URL where the live app can be opened. |
write_file | write | Create/overwrite a file (converges to open editors live). |
delete_file | write | Delete a file. |
restore_version | write | Restore a file to a past commit (no-op if unchanged). |
Driving the tools from your agent
In practice you just talk to your coding agent in natural language and it picks the tools:
List the files in the marimo-smoke project, then read app.py.
Add a marimo cell to app.py that plots a sine wave with matplotlib.
What versions of app.py exist? Show me the diff of the most recent one.
Restore app.py to the version before the "demo rewrite".
What data-proxy resources does this project have available at runtime?
Because write_file rides the editor pipeline, if you have the project open in a browser tab you’ll watch the cell appear as the agent writes it.
Calling the tools directly (curl)
The transport is stateless Streamable HTTP — each call is a self-contained JSON-RPC POST. Responses come back as a one-line SSE data: frame. A tiny helper:
PID=<PROJECT_ID>
TOK=pyc_mcp_xxx
mcp() { # mcp '<method>' '<json-params>'
curl -sS -X POST "https://app.pycorner.dev/mcp/projects/$PID/" \
-H "Authorization: Bearer $TOK" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"$1\",\"params\":$2}" \
| sed -n 's/^data: //p'
}
# Handshake + list the tools
mcp initialize '{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"curl","version":"0"}}'
mcp tools/list '{}'
# Read tools
mcp tools/call '{"name":"list_files","arguments":{}}'
mcp tools/call '{"name":"read_file","arguments":{"path":"app.py"}}'
mcp tools/call '{"name":"list_versions","arguments":{"path":"app.py"}}'
mcp tools/call '{"name":"read_version","arguments":{"sha":"<SHA>","path":"app.py"}}'
mcp tools/call '{"name":"list_resources","arguments":{}}'
mcp tools/call '{"name":"get_preview_url","arguments":{}}'
# Write tools (write-scoped token required)
mcp tools/call '{"name":"write_file","arguments":{"path":"hello.py","content":"print(\"hi\")\n"}}'
mcp tools/call '{"name":"delete_file","arguments":{"path":"hello.py"}}'
mcp tools/call '{"name":"restore_version","arguments":{"sha":"<SHA>","path":"app.py"}}'
Path safety is enforced server-side: absolute paths and .. traversal are rejected (write_file(path="../../etc/passwd") → ToolError).
Token lifecycle
List & revoke
# List a project's tokens (owner-only). Never returns raw values.
curl https://app.pycorner.dev/api/v1/projects/<PID>/access-tokens/ -b "$COOKIES"
# Revoke (immediate; the row stays for audit)
curl -X DELETE https://app.pycorner.dev/api/v1/projects/<PID>/access-tokens/<TOKEN_ID>/ -b "$COOKIES"
In the app, each active token in the 🤖 MCP modal has Rotate and Revoke buttons.
Rotate (owner, by id)
Rotation replaces the secret in place — same id, scope, and name; a new pyc_mcp_… value is returned once and the old one stops working immediately. Omit expires_in_days to keep the current expiry; pass it to set a new one (capped at 365).
# Keep the same expiry, just swap the secret
curl -X POST https://app.pycorner.dev/api/v1/projects/<PID>/access-tokens/<TOKEN_ID>/rotate/ \
-H "Content-Type: application/json" -b "$COOKIES" -d '{}'
# Rotate AND reset the clock to 30 days
curl -X POST https://app.pycorner.dev/api/v1/projects/<PID>/access-tokens/<TOKEN_ID>/rotate/ \
-H "Content-Type: application/json" -b "$COOKIES" -d '{"expires_in_days": 30}'
The Rotate button in the app does the keep-current-expiry variant and reveals the new secret once.
Self-exchange (rotate using the token itself)
For headless automation that holds only the secret (no dashboard login), the agent can rotate its own credential by presenting it. This endpoint lives on the MCP app and is authenticated by the bearer:
# Get a fresh secret, preserving the current expiry
curl -X POST https://app.pycorner.dev/mcp/projects/<PID>/rotate \
-H "Authorization: Bearer $CURRENT_TOKEN" \
-H "Content-Type: application/json" -d '{}'
{ "token": "pyc_mcp_…new…", "scope": "write", "prefix": "pyc_mcp_new", "expires_at": "2026-09-08T12:00:00Z" }
Pass {"expires_in_days": 90} to also extend it. An expired token can’t self-rotate (the bearer is rejected) — rotate from the dashboard instead. This /rotate route is intentionally not an MCP tool, so the model can’t casually rotate your credential; it’s an HTTP endpoint for scripts.
Live convergence
write_file, delete_file, and restore_version go through PyCorner’s canonical write path, the same one the web editor uses. When a write lands while you have the file open in a browser editor, the server pushes an authoritative reset of that file’s collaborative document, so the open tab converges to the new content. There’s no “reload to see the agent’s change” — it just appears.
Security model
- Hashed at rest. Only a SHA-256 of the token is stored; the raw
pyc_mcp_…is shown once at mint/rotate. - One token, one project. A token whose
project_iddoesn’t match the URL is rejected (403). - Access is re-checked at request time. If the minting user’s access to the project is revoked after the token is minted, the token stops working. Write tools additionally re-check that the creator still has write access.
- Always expires. Max lifetime is one year; there is no never-expiring token.
- Revocable + rotatable. Revoke kills a token immediately (row kept for audit); rotate swaps the secret in place.
Troubleshooting
| Symptom | Cause / fix |
|---|---|
claude mcp list shows the server not connected | Bad/typo’d token or URL; or the token expired/was revoked. Re-mint and re-add. |
402 pro_required when minting | The account is on Free: MCP needs Pro or Team. |
401 on a tool call | Token invalid, revoked, or expired. |
403 “Token does not match this project” | You used a token from another project against this URL. |
ToolError “read scope” on a write | Mint a write-scoped token (or rotate to one by minting fresh — scope is fixed per token). |
--url not recognized by claude mcp add | Pass the URL positionally: claude mcp add --transport http <name> <url> --header …. |