Skip to content

MCP Control of a Running Potato Task

The mcp block lets an agent query and change a live Potato server through tools you name, with a revocable token for each agent and an audit log.

Potato's mcp config block lets an agent read a running study's progress, add items, record annotations, and export results over the Model Context Protocol (MCP). MCP is an open protocol through which an AI application calls tools that another program exposes. Potato keeps the surface off until an admin enables the block and names every tool an agent may call, and Potato has no default set of tools. Each agent gets a separate token bound to a role, and Potato appends every call, granted or refused, to an audit log in the task directory. Potato 2.14.0 offers 17 tools, of which one destroys work and needs a second opt-in.

Two MCP servers in Potato

Potato has two MCP servers, and the mcp block configures only the second one. potato mcp serve is the first server and runs on your own machine while a study is being designed. The design-time server speaks MCP over stdio. It answers from Potato's registries and bundled examples, validates a config with Potato's own validator, and boots a temporary local copy of the task to return a screenshot with any browser errors. It never contacts a running server, and its file access is confined to the folder given by --root. Quick Start with a Coding Agent covers potato mcp serve. The second server is part of a running Potato task and answers on the task's own address, under /api/mcp/. The rest of this page covers the second server.

Configuration options

The block below turns the surface on for an agent that labels items as the annotator llm-annotator and checks the study's progress. Add the block to an existing config:

yaml
mcp:
  enabled: true
  tools:
    - get_status
    - get_progress
    - list_items
    - get_item
    - submit_annotation
  destructive: []
  scope:
    users: [llm-annotator]
  audit_log: mcp_audit.jsonl

The scope.users list keeps the agent from writing annotations for any annotator other than llm-annotator. Each option of the block and the option's default are listed below:

OptionDefaultWhat the option controls
enabledfalseRegisters the /api/mcp/ routes. While enabled is false, the routes do not exist and Potato skips every other check of the block.
toolsnoneThe tools an agent may call, by name. A tool left off the list is refused.
destructivenoneThe destructive tools an agent may call. A destructive tool has to appear in both tools and destructive.
scope.usersnoneThe annotators an agent may act on. With no list, or with an empty list, an agent may name any annotator.
audit_logmcp_audit.jsonlThe file Potato appends each call to. A relative path is read from task_dir.
auth.tokens_filemcp_tokens.jsonThe file that holds the token digests. A relative path is read from task_dir.
allow_debugfalseLets the surface run on a server with debug: true. Without the option, Potato refuses the combination.

Potato treats the block as a security allowlist and fails at startup on a mistake rather than logging a warning. With enabled: true, Potato rejects a config in which tools or destructive names a tool that does not exist, destructive lists a tool that destroys no work, or destructive lists a tool that tools leaves out. The error message names the unknown tool, such as a mistyped get_itme, and lists the 17 valid names. With a non-empty tools list, the validator also refuses debug: true written in the YAML unless allow_debug is set. Potato checks only that scope is a mapping. A misspelt sub-key such as scope: {usrs: [...]} therefore restricts nothing and raises no error. Granting an engine_ tool while the labeling engine is off produces a warning, because every call to the tool would then be refused.

Agent tokens

Each agent presents a token issued on the machine that holds the task's files. Three commands issue, list, and revoke tokens:

bash
potato mcp issue-token --config config.yaml --name ops-agent --role admin
potato mcp tokens --config config.yaml
potato mcp revoke-token --config config.yaml --name ops-agent

The first command prints the token once, and Potato never shows the token again. Potato stores only the token's SHA-256 digest in mcp_tokens.json under task_dir and sets the file's permissions to owner-only. Beside the digest, the file records the agent's name, the role, the creation time, and an optional --note. potato mcp tokens lists each token's name, role, creation time, and whether the token is active or revoked, and --json prints the same records as JSON. revoke-token revokes every token issued under the name. Potato reads the token file on every request. A revoked token therefore stops working at the agent's next call, with no restart.

The --role option takes admin, adjudicator, or annotator, and the default is annotator. A token's role grants the permissions of Potato's built-in role of the same name. Potato pins a token's own role to the built-in permissions, so custom roles in the rbac block do not change what the token role grants. A token whose name matches a user also gets that user's permissions. Potato looks the name up in rbac.user_role_assignments, in adjudication.adjudicator_users, and in the legacy user_roles map, and custom roles in rbac.roles do apply to a permission that comes through the name. The built-in roles reach the tools as follows:

Token rolePermissionsTools the role can call
adminall sevenevery tool
adjudicatoradjudicate, export_data, annotatesubmit_annotation, export_data, engine_certificate
annotatorannotatesubmit_annotation

The read tools need view_admin_dashboard, which only the admin role holds among the built-in roles. An agent that checks progress therefore needs an admin token, and scope.users is the setting that keeps an admin token from acting on every annotator.

Tools and permissions

Each tool declares the permission a token needs and whether the tool destroys work. Potato 2.14.0 has the 17 tools below:

ToolPermissionArgumentsWhat the tool does
get_statusview_admin_dashboardnoneReturns the task name, the number of items, and the number of annotators.
get_progressview_admin_dashboardnoneReturns the study's overall annotation progress.
list_annotatorsview_admin_dashboardnoneLists each annotator with the number of items assigned, the number annotated, and the current phase.
list_itemsview_admin_dashboardlimit (default 50), offset (default 0)Lists item IDs with the usernames of each item's annotators.
get_itemview_admin_dashboardinstance_idReturns one item's data and the usernames of the item's annotators.
get_agreementview_admin_dashboardnoneReturns the inter-annotator agreement that the admin dashboard reports.
get_configview_admin_dashboardnoneReturns the task's config with live secrets in plaintext. Only secret_key, admin_api_key, the mcp block, and top-level keys that start with _ are removed. See the warning below the table.
engine_statusview_admin_dashboardnoneReturns the labeling engine's predictions, requests, contracts, and spend.
engine_requestsview_admin_dashboardpurpose, status, limit (default 100, at most 1,000)Lists the labeling engine's requests for human labels.
add_itemsmanage_assignmentitemsAdds items, each carrying the task's id_key.
engine_runmanage_assignmentnoneRuns one pass of the labeling engine's planner.
engine_certifymanage_assignmentretest (default false)Evaluates every labeling-engine contract.
engine_certificateexport_dataformat (json, md, or html)Returns the labeling engine's quality certificate.
assign_itemsmanage_assignmentusername, max_instancesSets how many items an annotator may receive.
submit_annotationannotateusername, instance_id, annotations, span_annotations, behavioral_dataRecords an annotation as the named annotator.
export_dataexport_dataformat, output, optionsRuns a registered export format on the server.
delete_annotationsmanage_assignmentusername, instance_id, confirmClears one annotator's annotations for one item. Destructive.

Warning: get_config returns live secrets in plaintext. Potato expands ${ENV} references into the config when Potato loads the config, so moving a secret into an environment variable does not hide the secret from the agent. Potato removes only secret_key, admin_api_key, the mcp block, and top-level keys whose names start with _. The response therefore carries the credentials below:

  • the api_key of each ai_config block in ai_support, live_agent, live_coding_agent, solo_mode, labeling_engine, judge_calibration, agent_proxy, and chat_support
  • trace_ingestion.api_key and huggingface_backup.token
  • the tokens and S3 keys of backup sinks
  • each client_secret under authentication.providers
  • database_url
  • the Prolific, clickworker, and Sona credentials

Do not list get_config in mcp.tools for any agent you would not hand those credentials to.

The five engine_ tools answer 404 unless the study enables the labeling engine, and the labeling engine's CLI and API page covers the engine side.

Four write tools apply the rules below:

  • add_items records each item in <output_annotation_dir>/runtime_items.jsonl, and Potato loads the recorded items again after a restart. When max_annotations_per_user is set to anything but -1, the response carries a note that Potato assigns items added at runtime only while the cap is -1. A call that stops partway through the list with an error keeps the items added before the error.
  • assign_items never lowers an annotator's cap below the number of items the annotator has already annotated. A lower value is raised to the annotated count.
  • submit_annotation takes annotations as {scheme: {label: value}}, or as {scheme: label} for a scheme with one answer. A single answer to a scheme that declares labels has to name one of the labels. The named annotator has to exist and be in the annotation phase. For an annotator in any other phase, such as a consent page, the tool answers 409 and writes nothing. The tool does not check that instance_id names an existing item. A call that stops partway through with an error can leave the labels written before the error in place.
  • export_data writes under <output_annotation_dir>/exports/. The output argument names a folder inside the exports directory and defaults to the format name, and a path that leads outside the directory is refused. A failed export answers 500.

Order of checks on each call

Every call passes through one gate, and the gate stops the call at the first check that fails, with a message the agent can act on. Potato runs the checks in the order below:

CheckPasses whenAnswer on failure
Enabledmcp.enabled is true404, because the routes do not exist
Known toolthe URL names one of the 17 toolsFlask's plain 404, with no list of valid names and no audit line
Tokenthe request carries a valid token that has not been revoked401
Grantedthe tool appears in mcp.tools403, with the granted tools
Destructive opt-ina destructive tool also appears in mcp.destructive403
Confirmationa destructive call passes "confirm": true400
Permissionthe token's role carries the tool's permission403, naming the missing permission
Scopea call that names a username names one on mcp.scope.users, when the list is not empty403

Each of the 17 tools has a fixed route, and Flask answers a mistyped tool name before any check of the gate runs. Potato compares token digests in constant time across the whole token table, and the token check never consults debug mode. The shared admin key does not open the surface, because Potato reads tokens only from the Authorization: Bearer and X-Agent-Token headers and ignores X-API-Key.

HTTP endpoints and the stdio bridge

The surface speaks plain HTTP with JSON bodies. GET /api/mcp/manifest returns the task name, the agent's name and role, the granted tools with the arguments of each, the destructive tools enabled, and the scope. Each tool answers POST /api/mcp/tools/<tool>, with the tool's arguments as the JSON body. The request below lists the first ten items of a task running on port 8000:

bash
curl -X POST http://localhost:8000/api/mcp/tools/list_items \
  -H "Authorization: Bearer $POTATO_AGENT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"limit": 10}'

potato mcp connect bridges the HTTP surface to an MCP client that runs tool servers over standard input and output. pip install 'potato-annotation[mcp]' installs the MCP SDK that the bridge needs on the agent's machine. The token comes from --token or from the POTATO_AGENT_TOKEN environment variable:

bash
export POTATO_AGENT_TOKEN=...
potato mcp connect --url https://annotation.example.org

The bridge serves the local design-time tools and adds the remote tools with a live_ prefix, such as live_get_progress. The list of remote tools comes from the server's manifest. The manifest lists every tool in mcp.tools with no filtering by role, so an annotator token also sees read tools that answer the token with 403. A refused call comes back as a tool error carrying the server's message. Each request through the bridge times out after 30 seconds.

Audit log

Potato appends one JSON line to the audit log for every granted call and every refused attempt to call a tool. Each line records the time in UTC, the event, and the caller's IP address. A granted call writes a call line with the agent's name, the role, and the names of the arguments passed, without the argument values. A refused call writes one of auth_failed, not_granted, destructive_not_opted_in, destructive_unconfirmed, permission_denied, or out_of_scope. A mistyped tool name matches no route and writes no line. A tool that raises an exception adds an error line with the exception's text, and a tool that answers with an HTTP error adds a refused line with the status.

The write tools add a second line naming what changed:

  • items_added, with the number of items
  • annotation_submitted, with the annotator, the item, and the numbers of labels and spans written
  • assignment_changed, with the annotator and the new cap
  • exported, with the format and the output folder
  • annotations_deleted, with the annotator and the item
  • engine_run and engine_certify

The call line leaves out argument values, but other lines carry values, such as the target annotator, the instance_id, the export path, and the exception text. No setting turns the audit log off, and a blank audit_log falls back to mcp_audit.jsonl. A failed write to the log goes to the server log as a warning and never fails the call.

Safety on a live study

The surface gives an agent control of a study that people are working on, so grant the fewest tools the agent's job needs and the lowest role whose permissions cover the granted tools. Potato's own checks cover several failure modes, and the settings below cover the rest:

  • Debug mode. debug: true opens admin pages without a key to requests from the server's own machine, and a tunnel or reverse proxy on that machine can make every caller look local. Potato refuses mcp.enabled with debug mode in two places. The config validator refuses debug: true written in the YAML when mcp.tools is not empty. The --debug and --debug-phase command-line options take effect after validation. With either option, or with an empty tools list, the debug check runs only once, when Potato registers the routes. potato mcp issue-token never checks debug mode. mcp.allow_debug: true overrides both refusals, and the token check still applies.
  • Deleting annotations. delete_annotations clears every label and span that one annotator recorded on one item and saves the annotator's state, and the deletion cannot be undone. The annotator's span links, event annotations, and behavioral data for the item stay. In 2.14.0 the item still lists the annotator afterward and still counts the annotator toward the item's completion, and an unknown instance_id answers "status": "deleted" while deleting nothing. A change made after 2.14.0, in no release yet, removes the annotator from the item and stops an unknown instance_id from answering deleted. Span links, event annotations, and behavioral data stay after the change as well. Take a project snapshot before granting the tool.
  • Scope. scope.users applies only to the three tools that take a username (submit_annotation, assign_items, and delete_annotations). Tools such as list_annotators, get_item, and export_data still read every annotator's work. An empty scope.users list restricts nothing, and warning D020 fires only when the key is missing, so an empty list also passes potato deploy check. A string in place of the list becomes a substring match, and users: llm-annotator then admits llm and annotator as well.
  • Config contents. Potato expands ${ENV} references when Potato loads the config, and get_config returns the expanded credentials in plaintext. Moving a secret into an environment variable therefore does not hide the secret from an agent. Do not list get_config in mcp.tools for any agent you would not hand the config's credentials to. The warning under the tools table lists the credentials involved.
  • Rate limits. Potato 2.14.0 applies no rate limit to /api/mcp/. A reverse proxy in front of the server is the place to limit how often an agent can call.

potato deploy check config.yaml runs four MCP checks before you deploy. Errors D017 and D018 flag mcp.enabled on a server with debug: true and an enabled surface with no active token. Warnings D019 and D020 flag any tool in mcp.destructive and an active admin token with no scope.users list. The deployment guide covers the rest of potato deploy.

Further reading

For implementation details, see the source documentation.