An instance serves a Model Context Protocol server at /mcp. It gives an AI agent the same abilities as the HTTP API, as tools.
Connect
Add a remote MCP server to your agent:
| Setting | Value |
|---|---|
| URL | https://<instance>/mcp, for production https://scwrap.j4k4.dev/mcp |
| Header | Authorization: Bearer <run token> |
| Transport | Streamable HTTP, MCP protocol 2026-07-28 or 2025-11-25 |
A client on 2026-07-28 sends every request on its own, with no session. A client on 2025-11-25, such as one built on @modelcontextprotocol/sdk 1.x, starts with initialize and gets an Mcp-Session-Id, which it sends with every later request. A client that offers an older revision in initialize is answered with 2025-11-25. Give each instance its own server name, so an agent connected to two instances can tell them apart.
Tools
| Tool | Does | Read-only |
|---|---|---|
list_scrapers | Lists the installed Release identities and the generation. | Yes |
get_scraper | Returns what GET /scrapers/<id> does: one Release's identity, when it was deployed, the input, output and error JSON Schemas of its Definition, its grants and its maximum Run duration. | Yes |
run_scraper | Runs a Scraper and returns its result record with the first page of items. | No |
get_run | Returns a result record by resultId. | Yes |
list_runs | Lists one Scraper's result records, newest first, up to 50 per page. | Yes |
get_run_items | Returns one page of a finished result's items. | Yes |
A typical session
list_scrapersto see what is installed.get_scraperwith ascraperIdto learn the input the Scraper takes.run_scraperwith the input. The answer holds the result record and the first page of items.get_run_itemswith theresultIdand thenextCursorof the previous answer, untilnextCursorisnull.
A result of up to 100 items and 64 KiB is complete after step 3. An agent that already knows the input can start there.
run_scraper
| Parameter | Meaning |
|---|---|
scraperId | The Scraper's ID. |
input | The JSON input. |
limit | Optional. The most items in the first page, 1 to 100. Defaults to 100. |
idempotencyKey | Optional. Makes the call safe to retry, as the HTTP Idempotency-Key does. |
The Run continues on the instance whether or not the call stays connected. The call waits up to 20 seconds. A Run that ends by then returns the first page of the result:
{
"items": [{ "…": "…" }],
"nextCursor": "100",
"result": { "resultId": "…", "status": "completed", "count": 380, "…": "…" }
}A failed Run answers the same way, with status: "failed" in the record and the items checked before the failure. A longer Run returns its running record with no items and nextCursor: null: keep result.resultId, call get_run until status is completed or failed, then read the items with get_run_items.
Which Release ran. The call runs the installed Release, and the record's digest and revision name it.
Input that does not match. The input is checked against the Definition before anything runs. A mismatch fails with status 400, the reason and the Scraper's input JSON Schema under inputSchema, so the agent can correct the input without calling get_scraper. No Run is stored.
Retrying with an idempotencyKey. A repeat call with the same key and input within 24 hours returns the original Run, waiting and paging as the first call did, instead of starting another. The same key with another input fails with status 422; a key whose Run is still being handed to its owner fails with status 409, and the agent calls again with the same key. A key belongs to one run token name and one Scraper.
WARNING
There are no automatic retries. If the answer to a call without an idempotencyKey is lost, the Scraper may already have run. Do not call run_scraper again for the same purpose without checking.
list_runs
| Parameter | Meaning |
|---|---|
scraperId | The Scraper's ID. |
cursor | Optional. The nextCursor of the previous page. |
limit | Optional. The most Runs in the page, 1 to 50. Defaults to 50. |
Returns { runs, nextCursor }: the result records with status, count, startedAt and endedAt, newest first. nextCursor is null on the last page. Results are deleted when the instance's retention runs out, 30 days after they were written by default; the tool's description states the instance's value (Exporting results).
get_run_items
| Parameter | Meaning |
|---|---|
resultId | The result to read. |
cursor | Optional. The nextCursor of the previous page. Without it the first page is returned. |
limit | Optional. The most items in the page, 1 to 100. Defaults to 100. |
Returns one page, { items, nextCursor, result }, of a completed or failed result. A running result answers with an error that names the HTTP location of its item stream, GET /results/<resultId>/items.
Pages
run_scraper and get_run_items answer with the same shape.
| Field | Meaning |
|---|---|
items | The items of this page, in the order the Scraper produced them. |
nextCursor | The cursor for the next page, or null when this page is the last. |
result | The result record. Its count is the number of items in the whole result. |
A page holds at most 100 items and 64 KiB, whichever is reached first, and always at least one item: an item larger than 64 KiB is a page of its own. No item is skipped or cut.
A cursor is the number of items before the page, as a string. A stored result never changes, so a cursor stays valid, and reading a page twice returns the same items.
Errors
A tool that fails answers with an MCP error result, isError: true, whose content is { "_tag": "McpFailure", "code", "reason", "status" }. code and status are those of the HTTP API, plus result_running (409) from get_run_items on a running result, which also carries location. reason is the message. An input that does not match also carries the Scraper's inputSchema.
A request that never reaches a tool, such as one without a valid run token, answers with the HTTP error body.
What MCP cannot do
- Deploy on
/mcp. Deploying needs the deployer token, which/mcpdoes not accept: use the deployer server or thescwrapCLI. - Cancel a Run.
The run token can run every installed Scraper and read every result, but it cannot deploy: the deployment routes and /deploy-mcp refuse it (tokens). A named run token limited to some Scrapers sees only those: list_scrapers lists only them, and every tool answers any other Scraper, or a result of one, as unknown.
The deployer server
/deploy-mcp is a second MCP server for an agent that writes Scrapers. It takes the deployer token instead of the run token, and the same transports as /mcp:
| Setting | Value |
|---|---|
| URL | https://<instance>/deploy-mcp, for production https://scwrap.j4k4.dev/deploy-mcp |
| Header | Authorization: Bearer <deployer token> |
| Tool | Does | Read-only |
|---|---|---|
get_authoring_guide | Returns how to write a Scraper this instance builds: Scraper.make, Scraper.layer, Download, Deployment.worker with its revision and maxRunDuration, the proxy, browser and AI Capabilities with the grant each needs, the imports a file may use, how long builds take, and the hn-top.ts example. | Yes |
check_scraper | Typechecks and bundles a Scraper on the instance, without deploying it. | Yes |
deploy_build | Deploys a passed build by its buildId, through POST /builds/<buildId>/deploy, without building it again. | No, idempotent |
deploy_scraper | Builds a Scraper like check_scraper and deploys the Release it built. | No, idempotent |
get_build | Reads a build by buildId. | Yes |
remove_scraper | Removes an installed Release, as scwrap remove does. | No |
rollback_scraper | Reinstalls a replaced Release, the latest or the latest with a revision (Rolling back). | No |
list_deployments | Returns what GET /deployments?include=deployed,runs does: the generation, the installed Releases with when and by whom each was deployed, the pending deployment and the active Runs. | Yes |
get_deployment | Returns what GET /deployments/<deploymentId> does: one deployment's status. | Yes |
deployment_history | Returns what GET /deployments/history does: the retained platforms and Releases a rollback chooses from. | Yes |
Each tool calls the instance's deployer route in process and answers its body, so the answers, the checks and the guarantees are the same as for the CLI. remove_scraper and rollback_scraper read the generation and send the command to POST /deployments. The build tools call /builds and answer its build status:
| Parameter | Meaning |
|---|---|
files | The source, by relative .ts path: the Release file, whose default export is Deployment.worker({ ... }), and every local file it imports by relative path. Up to 100 files and 1 MiB. |
entry | The Release file. Optional for one file; needed for several. |
force | deploy_scraper, deploy_build, remove_scraper and rollback_scraper. true stops the instance's active Runs first (Forcing a deploy). |
scraperId | remove_scraper and rollback_scraper. The Scraper to remove or roll back. |
revision | rollback_scraper only. Optional. The revision to reinstall. |
deploymentId | remove_scraper and rollback_scraper. Optional. A repeated call with the same ID returns that deployment instead of sending the command again. Without it the tool derives one from the Scraper and the current generation, so a repeat after the command took effect is a new command. |
A build waits up to 20 seconds. A warm build takes about 10 seconds and a cold one up to a minute, so a cold build answers running. While its status is running, or a deployment is pending, call get_build with its buildId: a running deploying build deploys on the first get_build that sees it pass. A failed build carries the TypeScript diagnostics in diagnostics. Calling deploy_scraper again with the same files returns the same build and deploys it once. To deploy exactly what was checked, call deploy_build with the buildId of the passed check_scraper build.
A named deployer token limited to some Scrapers checks any source but deploys only its own Scrapers; another Scraper's deploy fails with status 403. A tool that fails answers isError: true with the same { "_tag": "McpFailure", "code", "reason", "status" } as /mcp: status and code are those of the route it called (Errors), such as not_found (404) for removing a Scraper that is not installed, and reason is that route's error. When the instance itself fails, code is unavailable (503) or instance_failure (502).
Keeping MCP in step with the HTTP API
The tests of both servers read the routes tables of the HTTP API and the deployment service and the tool tables on this page. A documented route that names no tool, or is not explicitly HTTP-only, fails them, and so does a served tool that this page does not list or lists with another read-only flag. The tool descriptions and schemas an MCP client sees come from the instance itself, so a client that discovers tools from tools/list needs no change when they change.
How it is built
The MCP server runs in the instance's Worker and calls the same handlers as the HTTP API, in process. It has no catalog or state of its own, so the two cannot disagree.
Authentication is checked on every request, and cross-origin browser requests are rejected.
A 2025-11-25 session keeps no state on the instance. Its Mcp-Session-Id holds the client's initialize parameters, and each request replays them into a fresh server before it is answered, so any Worker isolate can answer any request of the session. With no stored session, GET /mcp and DELETE /mcp answer 405: the server sends no notifications outside a request's own answer, a session cannot be ended and its ID never expires, and every request still needs a valid run token.
Source
- instance-mcp.ts:
/mcpand the transport both servers share - deploy-mcp.ts:
/deploy-mcp - instance-mcp.test.ts