---
title: "Let a coding agent test its own pull request"
description: "A coding agent deploys the pull request it opened over MCP, opens the running app and tests its change. Then a person reviews the same stagelet."
url: https://stagely.dev/docs/guides/coding-agents
---

A coding agent can write a change and open a pull request. Before a person reviews it, the agent must show that the change works in the running app. With Stagely, the agent deploys its pull request as a stagelet over MCP, opens the stagelet and tests it. Then a person reviews the same stagelet.

## The loop

1. The agent opens a pull request. When the project deploys on push, the default, this starts a deploy, unless the pull request comes from a fork. The agent can also call `deploy_pull_request`.
2. The agent calls `get_stagelet` until the state is `running` and `ready` is true. While it waits, `get_operation` shows the steps and the log.
3. When a deploy fails, `get_operation` gives the failed step, its error and the last 200 log lines. The agent fixes the change and pushes again.
4. `open_stagelet` gives the agent a URL that works once, within 30 seconds. The agent tests the app at that URL.
5. A person opens the same stagelet from its page in the console. The pull request's commit status links to that page.

## A session

This session is shortened. The agent gets one request in plain words:

```text
> List my Stagely projects. Deploy pull request 1 of acme/web.
> Wait until the stagelet is ready, then open it.

list_projects
  "name": "acme/web"
deploy_pull_request {"repository":"acme/web","pull_request":1}
  "state": "deploying"
  "ready": true
get_operation {"stagelet_id":"f543a41f9949"}
  "[start stderr]  Container stagelet-web-1 Recreate"
get_stagelet {"stagelet_id":"f543a41f9949"}
  "state": "running"
  "outcome": "applied"
open_stagelet {"stagelet_id":"f543a41f9949"}
  "expires_in_seconds": 30
  "url": "https://f543a41f9949.stagelets.acme.dev/_stagely/handoff?token=‹redacted›"
```

Here, `ready` is true right after the deploy starts, because the previous revision still serves. So the agent also waits until the requested revision's outcome is `applied`. Only then does the new commit serve.

## What the agent can do

- The agent signs in with OAuth through a consent page. It acts as you, in the one account that you choose, with your role in that account.
- Its token works only at the MCP endpoint, never at the API. Access tokens last 15 minutes. A grant lasts at most one hour.
- A stagelet session that the agent opens never outlives its grant.
- To end the agent's access, open **Settings**, then **Access**. Under **Connected apps**, click **Revoke**. The stagelet sessions that the agent opened stop within about 50 seconds.

## Connect Claude Code

```sh
claude mcp add --transport http \
  stagely https://app.stagely.dev/mcp
claude mcp login stagely
```

Other MCP clients connect the same way: Stagely's endpoint uses Streamable HTTP and OAuth with PKCE.

## Start

1. Set up Stagely once with the [Quickstart](https://stagely.dev/docs/setup.md).
2. [Connect a coding agent](https://stagely.dev/docs/agents.md). That page lists every tool.
3. Show reviewers how to [review a stagelet](https://stagely.dev/docs/review.md).
