From f4aee82a826fe2c7a7c849eae276fc17ee704fa7 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Thu, 12 Nov 2026 20:54:55 +0800 Subject: [PATCH 1/9] docs/abc: Document Agentic Batch Changes over MCP --- docs/agentic-batch-changes/mcp.mdx | 431 +++++++++++++++++++++++++++++ docs/api/mcp/index.mdx | 11 +- src/data/navigation.ts | 4 + 3 files changed, 441 insertions(+), 5 deletions(-) create mode 100644 docs/agentic-batch-changes/mcp.mdx diff --git a/docs/agentic-batch-changes/mcp.mdx b/docs/agentic-batch-changes/mcp.mdx new file mode 100644 index 000000000..91d18063c --- /dev/null +++ b/docs/agentic-batch-changes/mcp.mdx @@ -0,0 +1,431 @@ +# Agentic Batch Changes over MCP + +

+ Start, follow, and steer agentic batch changes from an MCP client. +

+ + + Supported on [Enterprise](/pricing/plans/enterprise) plans. + + +An MCP client, such as Claude Code, Codex, or Cursor, can do what you do on the page of an [agentic batch change](/agentic-batch-changes): start an agent, follow its progress, answer its questions and publication approvals, send follow-up messages, review workspaces, patches, and logs, and stop it. The agent runs on your Sourcegraph instance as you, with your repository permissions and your Batch Changes credentials. The client only sends requests and reads results; it does not edit a local checkout. + +You can see and act only on agents you own. Agents shared with you do not appear. + +## Before you start + +- Agentic Batch Changes is available to you. The read tools need `Batch Changes: Read` and `Batch Changes: Agent Read`; tools that start or change an agent also need `Batch Changes: Write` and `Batch Changes: Agent Write`. See [Access](/agentic-batch-changes/configuration#access). +- MCP is enabled and you have the `MCP#ACCESS` permission. See [Availability and access control](/api/mcp#availability-and-access-control). +- The `abc-mcp` feature flag is on for you. A site admin creates it under **Administration > Configuration > Feature flags** and enables it for users or organizations. While it is off, the endpoint lists no tools and every call returns `FEATURE_DISABLED`. + + + The feature flag controls rollout, not access: users can add a feature flag + override for themselves. To keep a user from using these tools, remove their + Agentic Batch Changes permissions. + + +## Access tokens and scopes + +Tools that start or change an agent need a Sourcegraph access token with an agent scope. OAuth tokens cannot carry these scopes, so a client connected through OAuth gets the read tools only. + +| Scope | Tools on `/.api/mcp/abc` | +| ------------------------------------ | ------------------------------------------------ | +| `mcp` or `user:all` | Read tools only | +| `mcp:batch-change-agents` | All tools except `start_batch_change_unattended` | +| `mcp:batch-change-agents:unattended` | Read tools and `start_batch_change_unattended` | + +The read tools are `list_batch_changes`, `read_batch_change`, `list_batch_change_workspaces`, `read_batch_change_workspace_diff`, `read_batch_change_workspace_logs`, `read_batch_change_spec`, `read_batch_change_transcript`, and `list_batch_change_standing_approvals`. + +- The two agent scopes do not include each other. A pipeline that starts unattended agents and also answers or stops them needs both. +- The agent scopes work only on `/.api/mcp/abc`. Add `mcp` to the token if the same client also uses the [other MCP endpoints](/api/mcp#server-endpoints). +- A tool that needs an agent scope is listed only when the token has that scope and you have the write permissions. Calling it without the scope returns `INSUFFICIENT_SCOPE`, and the refusal is recorded in the audit log. + +To create a token: + +1. Open **Settings > Access tokens** and create a new token. +2. Enter a **Token description**. +3. Under **Token scope**, check `mcp:batch-change-agents`, `mcp:batch-change-agents:unattended`, or both. These checkboxes appear only while the `abc-mcp` flag is on for you. Checking one clears the default `user:all`, unless `site-admin:sudo` is checked. Leave `user:all` cleared: it adds nothing on this endpoint and grants full API access elsewhere. +4. Click **Generate token** and copy it. The page shows a `curl` command that lists the tools on `/.api/mcp/abc`. + +Creating a token with an agent scope fails while the `abc-mcp` flag is off for the token's user. A token created earlier keeps its scopes and works again when the flag is turned back on. + +Treat a token with `mcp:batch-change-agents:unattended` like a deploy key: it can open changesets as you without a person approving them. Create it only for pipelines that need it. + +## Connect a client + +The tools are only on this endpoint: + +``` +https://sourcegraph.example.com/.api/mcp/abc +``` + +A connection to `/.api/mcp` or `/.api/mcp/all` does not include them. Add a second server entry for this URL. + +In all examples, replace `sourcegraph.example.com` with your Sourcegraph instance URL and set `SOURCEGRAPH_ACCESS_TOKEN` in the client's environment. For other clients, follow [Client integrations](/api/mcp/client-integrations) with this URL and an access token header. + +### Claude Code + +```bash +claude mcp add --transport http sourcegraph-abc https://sourcegraph.example.com/.api/mcp/abc \ + --header "Authorization: token $SOURCEGRAPH_ACCESS_TOKEN" +``` + +### Codex + +Add the following to `~/.codex/config.toml`: + +```toml +[mcp_servers.sourcegraph-abc] +url = "https://sourcegraph.example.com/.api/mcp/abc" +bearer_token_env_var = "SOURCEGRAPH_ACCESS_TOKEN" +``` + +Five tools are marked destructive: `decide_batch_change_approval`, `message_batch_change`, `control_batch_change_turn`, `stop_batch_change`, and `revoke_batch_change_standing_approval`. Codex can ask for approval before calling them. With the approval policy `never`, as in `codex exec`, such a call fails with `MCP tool call requires approval`. To run a tool without asking, approve it: + +```toml +[mcp_servers.sourcegraph-abc.tools.decide_batch_change_approval] +approval_mode = "approve" + +[mcp_servers.sourcegraph-abc.tools.message_batch_change] +approval_mode = "approve" + +[mcp_servers.sourcegraph-abc.tools.control_batch_change_turn] +approval_mode = "approve" + +[mcp_servers.sourcegraph-abc.tools.stop_batch_change] +approval_mode = "approve" + +[mcp_servers.sourcegraph-abc.tools.revoke_batch_change_standing_approval] +approval_mode = "approve" +``` + +To approve every tool on this server instead, set `default_tools_approval_mode = "approve"` under `[mcp_servers.sourcegraph-abc]`. See the [Codex configuration reference](https://developers.openai.com/codex/config-reference). + +Codex can also start its own subagents in your local checkout. If you ask it to "start an agent", it may do that instead. Say that the agent should run through Sourcegraph, for example: "Start a batch change agent through Sourcegraph, not a local coding subagent, to ...". + +### Cursor + +Add the following to `~/.cursor/mcp.json`, or to `.cursor/mcp.json` for a project: + +```json +{ + "mcpServers": { + "sourcegraph-abc": { + "url": "https://sourcegraph.example.com/.api/mcp/abc", + "headers": { + "Authorization": "token ${env:SOURCEGRAPH_ACCESS_TOKEN}" + } + } + } +} +``` + +## Available tools + + + Every tool takes and returns IDs as strings. Each result stays under 36 KiB, + counting both the structured result and its text copy, so clients do not cut + it or save it to a file. Tools that page return `next_cursor`; pass it as + `after` until it is absent. Long text is shortened in the middle and marked + with `[truncated; see url]`. + + +Admins can disable any of these tools by name with [`mcp.tools.disabled`](/api/mcp#disabling-individual-tools). A disabled tool is not listed, and calls to it return `FEATURE_DISABLED`. + +### Start an agent + +#### `start_batch_change` + +
+Start an attended agent. It plans and makes the change; publishing waits for your approval. + +**Parameters:** + +- `message` - The change to make, with context, constraints, and what must not change (required, up to 32,768 characters) +- `repositories` - Full repository names such as `github.com/org/repo` (optional, up to 1,000). Omit to let the agent find repositories. +- `request_key` - A nonblank key you generate, such as a UUID (required, up to 200 characters). Reuse it with identical input on every retry; a retry returns the first agent instead of starting a second one. + +Names that do not exist or that you cannot see come back in `unresolved`. If none resolve, the call fails with `EMPTY_SCOPE`. + +
+ +#### `start_batch_change_unattended` + +
+Start an agent for a pipeline with no person present. You set the repositories and how far it may publish up front. + +**Parameters:** + +- `message` - The change to make, with everything the agent needs without a person present (required, up to 32,768 characters) +- `repositories` - Repository names (optional, up to 1,000) +- `query` - A Sourcegraph search whose matching repositories join the scope (optional, up to 32,768 characters) +- `mode` - How far the agent may publish without asking (required): `none` keeps edits in Sourcegraph, `branch` pushes branches, `draft` opens draft changesets, `ready` opens changesets ready for review +- `max_repositories` - Refuse to start if the resolved scope is larger (optional; no limit when omitted) +- `canary` - Run one repository before the rest (optional, default `true`) +- `ci_repair` - Fix failing checks on changesets this agent opened (optional, default `true`) +- `request_key` - As for `start_batch_change` (required) + +The scope is fixed at start. Publishing outside the scope or above `mode` is refused and shows up as a `refusal` item in `attention`. The agent uses only secrets already allowed in Sourcegraph. If it needs a decision it cannot make, it asks and waits for an answer. + +
+ +### Follow an agent + +#### `list_batch_changes` + +
+List agents you own, newest first, with their state and original request. + +**Parameters:** + +- `query` - Return agents whose title contains this text, ignoring case (optional) +- `first` - Agents to scan, 1 to 25 (optional, default 25) +- `after` - `next_cursor` from the previous page (optional) + +
+ +#### `read_batch_change` + +
+Read one agent: state, progress, items that need you, scope, and the latest answer. Optionally wait for a change. + +**Parameters:** + +- `agent_id` - The agent to read (required) +- `version` - The `version` object from your last read, to wait for a change (optional). See [Waiting for updates](#waiting-for-updates). +- `wait_seconds` - Longest wait when `version` is set, 0 to 50 (optional, default 25) +- `decision_id` - Return only this pending decision, in full (optional) +- `after` - With `decision_id`, the `next_cursor` from the previous page of that approval's repositories (optional) + +`state` is `working`, `awaiting_merge`, `stopping`, or `done`. `attention` lists what needs you: a `question` or `approval` with a `decision_id`, or a `refusal` or `failure` with a `reason` that says what to do. `publication_approval` shows what is already approved for publishing; pending requests are in `attention`. Counts cover the current plan and the repositories you can see. + +A regular read shows up to five repository names per approval and may leave out a question form to fit. Read a decision with `decision_id` before you answer it. If its `questions` are still absent, the form is too large for one response; ask the agent to ask fewer questions at a time, or answer on its page. + +
+ +### Answer questions and approvals + +#### `answer_batch_change_question` + +
+Answer every question in one decision. + +**Parameters:** + +- `agent_id` - (required) +- `decision_id` - From `read_batch_change` (required) +- `answers` - One entry per question, 1 to 100 (required). Each has `question_id`, and either `option_id` or `text`. Omit both to skip that question. + +Include every question ID, including skipped ones. After a timeout, repeat the call with identical answers in the same order; nothing is recorded twice. + +
+ +#### `decide_batch_change_approval` + +
+Allow a publication approval, or request changes. + +**Parameters:** + +- `agent_id` - (required) +- `decision_id` - From `read_batch_change` (required) +- `response` - One of the forms below (required) + +Read every repository page of the decision first. Then pass one of: + +- `{"decision":"allow"}` keeps the requested mode and the `this_agent` scope. +- `{"decision":"allow","publication":{"mode":"draft","scope":"this_agent"}}` sets both. `mode` must match the request, except that `ready` can be lowered to `draft`. +- With `"scope":"all_attended_agents"`, allowing also saves standing draft authority over the reviewed repositories for all your attended agents. +- `{"decision":"request_changes","note":"What to change"}` declines and gives the agent feedback. + +Allowing a secret approval returns `REFUSED`; decide those in Sourcegraph. Requesting changes on one works. + +
+ +#### `list_batch_change_standing_approvals` + +
+List your standing publication authority. + +Takes no parameters. Returns the authority's `id`, `mode`, and a sample of its repositories. + +
+ +#### `revoke_batch_change_standing_approval` + +
+Revoke your standing publication authority. + +**Parameters:** + +- `id` - `publication.id` from `list_batch_change_standing_approvals` (required) + +Approvals for a single agent and changesets already published stay in place. + +
+ +### Review the work + +#### `list_batch_change_workspaces` + +
+List workspaces in the agent's current plan with execution, publication, and check state, and their changesets. + +**Parameters:** + +- `agent_id` - (required) +- `status` - One publication status: `no_changeset`, `no_change`, `unpublished`, `branch`, `draft`, `open`, `merged`, or `closed` (optional) +- `checks` - Draft or open changesets with this check result: `none`, `pending`, `passed`, `failed`, or `unavailable` (optional) +- `repository` - Exact repository name (optional) +- `first` - Workspaces per page, 1 to 100 (optional, default 50) +- `after` - `next_cursor` from the previous page, with the same filters (optional) + +Workspaces in repositories you cannot see, or excluded by [context filters](/context-filters), are left out. When a changeset has `publication_failed`, open the agent's page to see why, fix the cause, and send a message to retry. + +
+ +#### `read_batch_change_workspace_diff` + +
+Read a workspace's patches, page by page. + +**Parameters:** + +- `agent_id` - (required) +- `workspace_id` - From `list_batch_change_workspaces` (required) +- `after` - `next_cursor` from the previous page (optional) + +File blocks excluded by context filters are left out. A patch over 1 MiB returns `REFUSED`; read it on the agent's page. + +
+ +#### `read_batch_change_workspace_logs` + +
+Read a workspace's latest execution logs, page by page. + +**Parameters:** + +- `agent_id` - (required) +- `workspace_id` - From `list_batch_change_workspaces` (required) +- `entry_key` - Read only this log entry, using a `key` from the returned `catalog` (optional) +- `after` - `next_cursor` from the previous page, with the same `entry_key` (optional) + +Without `entry_key`, setup and teardown entries that succeeded are left out. Logs are condensed as the agent reads them: structured events are summarized, embedded step diffs are left out, and long lines are shortened. Logs whose stored JSON is over 1 MiB return `REFUSED`; read them on the agent's page. + +
+ +#### `read_batch_change_spec` + +
+Read the agent's current batch spec, page by page. + +**Parameters:** + +- `agent_id` - (required) +- `after` - `next_cursor` from the previous page (optional) + +This is the batch spec the plan view shows. A plan the agent has proposed but not created yet is in the transcript instead. + +
+ +#### `read_batch_change_transcript` + +
+Read the agent's conversation, newest entry first, page by page. + +**Parameters:** + +- `agent_id` - (required) +- `after` - `next_cursor` from the previous page (optional) + +Each page holds one entry, or part of a long one: messages, thinking, tool calls and results, and the reason for each automatic resume. Only the agent's first thread is read, without attachments. + +
+ +### Steer and stop + +#### `message_batch_change` + +
+Send follow-up instructions. + +**Parameters:** + +- `agent_id` - (required) +- `text` - Instructions (required, up to 32,768 characters) +- `interrupt` - Cancel the message the agent is working on before sending (optional, default `false`) + +If the agent is answering a message and `interrupt` is not set, the call returns `AGENT_BUSY`. A message is not safe to retry blindly: after a timeout, read the agent and compare `latest_message_id` before you send again. + +
+ +#### `control_batch_change_turn` + +
+Cancel one specific message. + +**Parameters:** + +- `agent_id` - (required) +- `message_id` - From `read_batch_change`, `message_batch_change`, or `read_batch_change_transcript` (required) + +A different active message is left alone. + +
+ +#### `stop_batch_change` + +
+Stop the agent, and optionally close its changesets. + +**Parameters:** + +- `agent_id` - (required) +- `close_changesets` - Also queue closing its open changesets (optional, default `false`) + +Stopping can take several minutes. Success means cleanup is queued, not that every changeset is closed. Pushed branches stay on the code host. A stopped agent cannot continue; start a new one. + +
+ +## Waiting for updates + +To wait for a change instead of polling, pass the `version` object from your last `read_batch_change` response back unchanged. The call returns once something changed, or after `wait_seconds`. An unchanged `version` means nothing changed; call again with it. + +`wait_seconds` tops out at 50 so the reply arrives before the 60-second timeout most clients use; pass a smaller value if your client's tool timeout is shorter. Each Sourcegraph server holds up to four waiting reads per user; an extra one returns the current state within about 5 seconds. + +## Errors + +A failed call returns an MCP tool error whose text starts with a code, followed by what happened and what to do: + +``` +AGENT_BUSY: batch change agent has a running turn; read or wait, then decide whether to send or retry; do not interrupt automatically +``` + +These codes usually need a change outside the client: + +| Code | What to do | +| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | +| `FEATURE_DISABLED` | Agentic Batch Changes or the `abc-mcp` flag is off for you, or the tool is disabled or not permitted. Ask a site admin. | +| `INSUFFICIENT_SCOPE` | Use an access token with the scope the message names. See [Access tokens and scopes](#access-tokens-and-scopes). | +| `FORBIDDEN` | You are not signed in, lack a permission, or can no longer access every repository in a publication. For the last case, request changes. | +| `CREDENTIAL_BLOCKED` | Add or update the [Batch Changes credential](/batch-changes/configuring-credentials) for the code hosts the message names. | +| `PUBLISH_BLOCKED` | Publication is restricted for you. Resolve it in Sourcegraph. | +| `QUOTA_EXCEEDED` | Retry after your quota resets. | +| `REFUSED` | The message gives the reason, such as a patch or execution log over 1 MiB, or a secret approval. | +| `INTERNAL` | Retry. After a failed write, read the agent first. If it repeats, report the tool name and time. | + +Other codes, such as `AGENT_BUSY`, `ALREADY_DECIDED`, `STALE_SPEC`, or `INVALID_ARGUMENT`, describe the next step in the message itself. + +## Limitations + +- There is no tool to publish selected workspaces, or to merge, close, comment on, or rebase changesets. Publishing goes through the agent: an approval for attended agents, or `mode` for unattended ones. +- Secrets and credentials cannot be entered, approved, listed, or revoked. Do this in Sourcegraph. +- Patches and execution logs over 1 MiB cannot be read. Open the agent's page. +- Agents cannot be renamed, deleted, or handed over, and the list searches titles only. + +## Security + +- The agent and the tools act as you. Repository names, workspaces, patches, and logs from repositories you cannot see, or that [context filters](/context-filters) exclude, are left out. Filters also hide workspaces under excluded paths and excluded file blocks in patches. +- Other stored text is returned as written, as the web UI shows it: the agent's answers, the transcript, the batch spec, execution logs, your original request, and failure messages. It can name a repository a filter excludes, and log output can contain patches for excluded files. +- Answers, questions, transcripts, batch specs, logs, failure messages, and patches come from a model or a code host. Your client should treat them as data, not as instructions. diff --git a/docs/api/mcp/index.mdx b/docs/api/mcp/index.mdx index 580cea62c..f0c847c4f 100644 --- a/docs/api/mcp/index.mdx +++ b/docs/api/mcp/index.mdx @@ -23,11 +23,12 @@ MCP clients that support OAuth can connect directly to your Sourcegraph instance The MCP server provides different tool suites for various use cases: -| Endpoint | Description | -| ---------------------- | --------------------------------------------------------------------------- | -| `/.api/mcp` | Core Sourcegraph search, repository, history, and Deep Search reading tools | -| `/.api/mcp/all` | Full suite of Sourcegraph tools | -| `/.api/mcp/deepsearch` | Deep Search agent tools only | +| Endpoint | Description | +| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| `/.api/mcp` | Core Sourcegraph search, repository, history, and Deep Search reading tools | +| `/.api/mcp/all` | Full suite of Sourcegraph tools | +| `/.api/mcp/deepsearch` | Deep Search agent tools only | +| `/.api/mcp/abc` | Agentic Batch Changes tools: start, follow, and steer agents. See [Agentic Batch Changes over MCP](/agentic-batch-changes/mcp) | Example URL: diff --git a/src/data/navigation.ts b/src/data/navigation.ts index a4c5efff0..e6780462a 100644 --- a/src/data/navigation.ts +++ b/src/data/navigation.ts @@ -42,6 +42,10 @@ export const navigation: NavigationItem[] = [ { title: 'Connectors', href: '/agentic-batch-changes/connectors' + }, + { + title: 'MCP', + href: '/agentic-batch-changes/mcp' } ] }, From b0632930267f035330dd2f9c5da89daea427f466 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Fri, 13 Nov 2026 12:30:35 +0800 Subject: [PATCH 2/9] docs/abc: Drop file-path context filter claims --- docs/agentic-batch-changes/mcp.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/agentic-batch-changes/mcp.mdx b/docs/agentic-batch-changes/mcp.mdx index 91d18063c..5e3b4b66b 100644 --- a/docs/agentic-batch-changes/mcp.mdx +++ b/docs/agentic-batch-changes/mcp.mdx @@ -295,7 +295,7 @@ Workspaces in repositories you cannot see, or excluded by [context filters](/con - `workspace_id` - From `list_batch_change_workspaces` (required) - `after` - `next_cursor` from the previous page (optional) -File blocks excluded by context filters are left out. A patch over 1 MiB returns `REFUSED`; read it on the agent's page. +A patch over 1 MiB returns `REFUSED`; read it on the agent's page. @@ -426,6 +426,6 @@ Other codes, such as `AGENT_BUSY`, `ALREADY_DECIDED`, `STALE_SPEC`, or `INVALID_ ## Security -- The agent and the tools act as you. Repository names, workspaces, patches, and logs from repositories you cannot see, or that [context filters](/context-filters) exclude, are left out. Filters also hide workspaces under excluded paths and excluded file blocks in patches. -- Other stored text is returned as written, as the web UI shows it: the agent's answers, the transcript, the batch spec, execution logs, your original request, and failure messages. It can name a repository a filter excludes, and log output can contain patches for excluded files. +- The agent and the tools act as you. Repository names, workspaces, patches, and logs from repositories you cannot see, or that [context filters](/context-filters) exclude, are left out. +- Other stored text is returned as written, as the web UI shows it: the agent's answers, the transcript, the batch spec, execution logs, your original request, and failure messages. It can name a repository a filter excludes. - Answers, questions, transcripts, batch specs, logs, failure messages, and patches come from a model or a code host. Your client should treat them as data, not as instructions. From 8006a5662b93ec8cd04d35445debd87d6482e4b3 Mon Sep 17 00:00:00 2001 From: constantin-cyber Date: Wed, 18 Nov 2026 09:07:40 +0100 Subject: [PATCH 3/9] docs/abc: Clarify least-privilege token setup --- docs/agentic-batch-changes/mcp.mdx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/agentic-batch-changes/mcp.mdx b/docs/agentic-batch-changes/mcp.mdx index 5e3b4b66b..3b8d0632e 100644 --- a/docs/agentic-batch-changes/mcp.mdx +++ b/docs/agentic-batch-changes/mcp.mdx @@ -28,6 +28,8 @@ You can see and act only on agents you own. Agents shared with you do not appear Tools that start or change an agent need a Sourcegraph access token with an agent scope. OAuth tokens cannot carry these scopes, so a client connected through OAuth gets the read tools only. +Follow least privilege: select only the scopes needed for your client's workflow. + | Scope | Tools on `/.api/mcp/abc` | | ------------------------------------ | ------------------------------------------------ | | `mcp` or `user:all` | Read tools only | @@ -36,20 +38,26 @@ Tools that start or change an agent need a Sourcegraph access token with an agen The read tools are `list_batch_changes`, `read_batch_change`, `list_batch_change_workspaces`, `read_batch_change_workspace_diff`, `read_batch_change_workspace_logs`, `read_batch_change_spec`, `read_batch_change_transcript`, and `list_batch_change_standing_approvals`. -- The two agent scopes do not include each other. A pipeline that starts unattended agents and also answers or stops them needs both. -- The agent scopes work only on `/.api/mcp/abc`. Add `mcp` to the token if the same client also uses the [other MCP endpoints](/api/mcp#server-endpoints). +- For attended workflows, use `mcp:batch-change-agents`. Add `mcp:batch-change-agents:unattended` only if the client needs to start unattended agents. The two scopes do not include each other: a client that starts unattended agents and also answers or stops them needs both. +- One token can combine the scopes needed by the same client. The agent scopes work only on `/.api/mcp/abc`. Add `mcp` to that token if the client also uses the [other MCP endpoints](/api/mcp#server-endpoints). - A tool that needs an agent scope is listed only when the token has that scope and you have the write permissions. Calling it without the scope returns `INSUFFICIENT_SCOPE`, and the refusal is recorded in the audit log. +Token scopes cannot be edited. If an existing token lacks a required scope, create a replacement or an additional token with the scopes your client needs. + To create a token: 1. Open **Settings > Access tokens** and create a new token. 2. Enter a **Token description**. -3. Under **Token scope**, check `mcp:batch-change-agents`, `mcp:batch-change-agents:unattended`, or both. These checkboxes appear only while the `abc-mcp` flag is on for you. Checking one clears the default `user:all`, unless `site-admin:sudo` is checked. Leave `user:all` cleared: it adds nothing on this endpoint and grants full API access elsewhere. +3. Under **Token scope**, select the agent scopes for your workflow as described above. These checkboxes appear only while the `abc-mcp` flag is on for you. Checking one clears the default `user:all`, unless `site-admin:sudo` is checked. Leave `user:all` cleared: it adds nothing on this endpoint and grants full API access elsewhere. 4. Click **Generate token** and copy it. The page shows a `curl` command that lists the tools on `/.api/mcp/abc`. Creating a token with an agent scope fails while the `abc-mcp` flag is off for the token's user. A token created earlier keeps its scopes and works again when the flag is turned back on. -Treat a token with `mcp:batch-change-agents:unattended` like a deploy key: it can open changesets as you without a person approving them. Create it only for pipelines that need it. + + **Unattended access allows publication without another approval.** An agent + can push branches or open changesets within the repositories and publication + mode selected at start. + ## Connect a client From 02b569c221ec6a908ae8fa08ce6f56c2c1acbd9b Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Wed, 25 Nov 2026 09:05:10 +0800 Subject: [PATCH 4/9] docs/abc: Match ABC over MCP docs to the MCP permission model --- docs/agentic-batch-changes/mcp.mdx | 109 +++++++++++++++-------------- 1 file changed, 57 insertions(+), 52 deletions(-) diff --git a/docs/agentic-batch-changes/mcp.mdx b/docs/agentic-batch-changes/mcp.mdx index 3b8d0632e..f43d54358 100644 --- a/docs/agentic-batch-changes/mcp.mdx +++ b/docs/agentic-batch-changes/mcp.mdx @@ -10,53 +10,46 @@ An MCP client, such as Claude Code, Codex, or Cursor, can do what you do on the page of an [agentic batch change](/agentic-batch-changes): start an agent, follow its progress, answer its questions and publication approvals, send follow-up messages, review workspaces, patches, and logs, and stop it. The agent runs on your Sourcegraph instance as you, with your repository permissions and your Batch Changes credentials. The client only sends requests and reads results; it does not edit a local checkout. -You can see and act only on agents you own. Agents shared with you do not appear. +You can see and act only on agents you own. Agents that others share with you or invite you to collaborate on do not appear; open them in Sourcegraph. ## Before you start - Agentic Batch Changes is available to you. The read tools need `Batch Changes: Read` and `Batch Changes: Agent Read`; tools that start or change an agent also need `Batch Changes: Write` and `Batch Changes: Agent Write`. See [Access](/agentic-batch-changes/configuration#access). - MCP is enabled and you have the `MCP#ACCESS` permission. See [Availability and access control](/api/mcp#availability-and-access-control). -- The `abc-mcp` feature flag is on for you. A site admin creates it under **Administration > Configuration > Feature flags** and enables it for users or organizations. While it is off, the endpoint lists no tools and every call returns `FEATURE_DISABLED`. +- The `abc-mcp` feature flag is on for you. While it is off, the endpoint lists no tools and every call returns `FEATURE_DISABLED`. + - On self-hosted instances, a site admin creates it under **Administration > Configuration > Feature flags** and enables it for users or organizations. + - On Sourcegraph Cloud, Sourcegraph manages feature flags. Ask your account team to enable it. - The feature flag controls rollout, not access: users can add a feature flag - override for themselves. To keep a user from using these tools, remove their - Agentic Batch Changes permissions. + The feature flag controls rollout, not access: on self-hosted instances, + users can add a feature flag override for themselves. To keep a user from + using these tools, remove their Agentic Batch Changes permissions. -## Access tokens and scopes +## Authentication and tool access -Tools that start or change an agent need a Sourcegraph access token with an agent scope. OAuth tokens cannot carry these scopes, so a client connected through OAuth gets the read tools only. +The endpoint uses the same `mcp` permission as the other MCP endpoints. Sign in through OAuth, or use an access token with the `mcp` or `user:all` scope. See [MCP authentication](/api/mcp/authentication). -Follow least privilege: select only the scopes needed for your client's workflow. +Your permissions and the site configuration decide which tools the endpoint lists: -| Scope | Tools on `/.api/mcp/abc` | -| ------------------------------------ | ------------------------------------------------ | -| `mcp` or `user:all` | Read tools only | -| `mcp:batch-change-agents` | All tools except `start_batch_change_unattended` | -| `mcp:batch-change-agents:unattended` | Read tools and `start_batch_change_unattended` | +- The read tools need the read permissions above. They are `list_batch_changes`, `read_batch_change`, `list_batch_change_workspaces`, `read_batch_change_workspace_diff`, `read_batch_change_workspace_logs`, `read_batch_change_spec`, `read_batch_change_transcript`, and `list_batch_change_standing_approvals`. +- The tools that start or change an agent also need the write permissions. +- `start_batch_change_unattended` is listed only after a site admin enables unattended starts in site configuration. They are off by default: -The read tools are `list_batch_changes`, `read_batch_change`, `list_batch_change_workspaces`, `read_batch_change_workspace_diff`, `read_batch_change_workspace_logs`, `read_batch_change_spec`, `read_batch_change_transcript`, and `list_batch_change_standing_approvals`. - -- For attended workflows, use `mcp:batch-change-agents`. Add `mcp:batch-change-agents:unattended` only if the client needs to start unattended agents. The two scopes do not include each other: a client that starts unattended agents and also answers or stops them needs both. -- One token can combine the scopes needed by the same client. The agent scopes work only on `/.api/mcp/abc`. Add `mcp` to that token if the client also uses the [other MCP endpoints](/api/mcp#server-endpoints). -- A tool that needs an agent scope is listed only when the token has that scope and you have the write permissions. Calling it without the scope returns `INSUFFICIENT_SCOPE`, and the refusal is recorded in the audit log. - -Token scopes cannot be edited. If an existing token lacks a required scope, create a replacement or an additional token with the scopes your client needs. - -To create a token: - -1. Open **Settings > Access tokens** and create a new token. -2. Enter a **Token description**. -3. Under **Token scope**, select the agent scopes for your workflow as described above. These checkboxes appear only while the `abc-mcp` flag is on for you. Checking one clears the default `user:all`, unless `site-admin:sudo` is checked. Leave `user:all` cleared: it adds nothing on this endpoint and grants full API access elsewhere. -4. Click **Generate token** and copy it. The page shows a `curl` command that lists the tools on `/.api/mcp/abc`. +```json +{ + "batchChanges.agenticBatchChanges.unattended.enabled": true +} +``` -Creating a token with an agent scope fails while the `abc-mcp` flag is off for the token's user. A token created earlier keeps its scopes and works again when the flag is turned back on. +With every permission, the endpoint lists 15 tools, or 16 with unattended starts enabled. A tool in [`mcp.tools.disabled`](/api/mcp#disabling-individual-tools) is not listed, even with unattended starts enabled, and calls to it return `FEATURE_DISABLED`. - **Unattended access allows publication without another approval.** An agent - can push branches or open changesets within the repositories and publication - mode selected at start. + **Unattended agents publish without another approval.** An agent can push + branches or open changesets within the repositories and publication mode + selected at start. Turning unattended starts off blocks new starts; agents + already running keep publishing within their scope until their owner or a + site admin stops them. ## Connect a client @@ -69,15 +62,16 @@ https://sourcegraph.example.com/.api/mcp/abc A connection to `/.api/mcp` or `/.api/mcp/all` does not include them. Add a second server entry for this URL. -In all examples, replace `sourcegraph.example.com` with your Sourcegraph instance URL and set `SOURCEGRAPH_ACCESS_TOKEN` in the client's environment. For other clients, follow [Client integrations](/api/mcp/client-integrations) with this URL and an access token header. +In all examples, replace `sourcegraph.example.com` with your Sourcegraph instance URL. For other clients, or to use an access token, follow [Client integrations](/api/mcp/client-integrations) with this URL. ### Claude Code ```bash -claude mcp add --transport http sourcegraph-abc https://sourcegraph.example.com/.api/mcp/abc \ - --header "Authorization: token $SOURCEGRAPH_ACCESS_TOKEN" +claude mcp add --transport http sourcegraph-abc https://sourcegraph.example.com/.api/mcp/abc ``` +Then run `/mcp` in Claude Code and follow the browser authentication flow. + ### Codex Add the following to `~/.codex/config.toml`: @@ -85,9 +79,11 @@ Add the following to `~/.codex/config.toml`: ```toml [mcp_servers.sourcegraph-abc] url = "https://sourcegraph.example.com/.api/mcp/abc" -bearer_token_env_var = "SOURCEGRAPH_ACCESS_TOKEN" +scopes = ["mcp"] ``` +Then authenticate with `codex mcp login sourcegraph-abc`. + Five tools are marked destructive: `decide_batch_change_approval`, `message_batch_change`, `control_batch_change_turn`, `stop_batch_change`, and `revoke_batch_change_standing_approval`. Codex can ask for approval before calling them. With the approval policy `never`, as in `codex exec`, such a call fails with `MCP tool call requires approval`. To run a tool without asking, approve it: ```toml @@ -119,15 +115,14 @@ Add the following to `~/.cursor/mcp.json`, or to `.cursor/mcp.json` for a projec { "mcpServers": { "sourcegraph-abc": { - "url": "https://sourcegraph.example.com/.api/mcp/abc", - "headers": { - "Authorization": "token ${env:SOURCEGRAPH_ACCESS_TOKEN}" - } + "url": "https://sourcegraph.example.com/.api/mcp/abc" } } } ``` +Enable the server from **Cursor Settings > Tools & MCP** and follow the OAuth prompt. + ## Available tools @@ -138,23 +133,23 @@ Add the following to `~/.cursor/mcp.json`, or to `.cursor/mcp.json` for a projec with `[truncated; see url]`. -Admins can disable any of these tools by name with [`mcp.tools.disabled`](/api/mcp#disabling-individual-tools). A disabled tool is not listed, and calls to it return `FEATURE_DISABLED`. - ### Start an agent #### `start_batch_change`
-Start an attended agent. It plans and makes the change; publishing waits for your approval. +Start an attended agent. It plans and makes the change, and publishes only with an approval from you. **Parameters:** - `message` - The change to make, with context, constraints, and what must not change (required, up to 32,768 characters) - `repositories` - Full repository names such as `github.com/org/repo` (optional, up to 1,000). Omit to let the agent find repositories. -- `request_key` - A nonblank key you generate, such as a UUID (required, up to 200 characters). Reuse it with identical input on every retry; a retry returns the first agent instead of starting a second one. +- `request_key` - A key you generate, such as a UUID (required, up to 200 characters). Reuse it with identical input on every retry; a retry returns the first agent instead of starting a second one. Names that do not exist or that you cannot see come back in `unresolved`. If none resolve, the call fails with `EMPTY_SCOPE`. +The agent skips the approval when an approval you already gave covers the repositories and publication mode: an earlier one on the same agent, or a [standing approval](#list_batch_change_standing_approvals) for all your attended agents. +
#### `start_batch_change_unattended` @@ -165,7 +160,7 @@ Names that do not exist or that you cannot see come back in `unresolved`. If non **Parameters:** - `message` - The change to make, with everything the agent needs without a person present (required, up to 32,768 characters) -- `repositories` - Repository names (optional, up to 1,000) +- `repositories` - Full repository names (optional, up to 1,000) - `query` - A Sourcegraph search whose matching repositories join the scope (optional, up to 32,768 characters) - `mode` - How far the agent may publish without asking (required): `none` keeps edits in Sourcegraph, `branch` pushes branches, `draft` opens draft changesets, `ready` opens changesets ready for review - `max_repositories` - Refuse to start if the resolved scope is larger (optional; no limit when omitted) @@ -173,7 +168,9 @@ Names that do not exist or that you cannot see come back in `unresolved`. If non - `ci_repair` - Fix failing checks on changesets this agent opened (optional, default `true`) - `request_key` - As for `start_batch_change` (required) -The scope is fixed at start. Publishing outside the scope or above `mode` is refused and shows up as a `refusal` item in `attention`. The agent uses only secrets already allowed in Sourcegraph. If it needs a decision it cannot make, it asks and waits for an answer. +Pass `repositories`, `query`, or both. Their union must resolve to at least one repository you can see, or the call fails with `EMPTY_SCOPE`; unlike `start_batch_change`, this agent cannot find repositories on its own. + +The endpoint lists this tool only after a site admin enables unattended starts; see [Authentication and tool access](#authentication-and-tool-access). The scope is fixed at start. Publishing outside the scope or above `mode` is refused and shows up as a `refusal` item in `attention`. The agent uses only secrets already allowed in Sourcegraph. If it needs a decision it cannot make, it asks and waits for an answer. @@ -222,7 +219,11 @@ A regular read shows up to five repository names per approval and may leave out - `agent_id` - (required) - `decision_id` - From `read_batch_change` (required) -- `answers` - One entry per question, 1 to 100 (required). Each has `question_id`, and either `option_id` or `text`. Omit both to skip that question. +- `answers` - One entry per question, 1 to 100 (required). Each has `question_id` and one of these forms: + - `option_id` picks a choice. + - `option_id` with `text` picks a choice marked `freeform` and fills it in, for example `{"question_id":"q0","option_id":"other","text":"Only frontend repositories"}`. A freeform choice without `text` returns `INVALID_ANSWER`. + - `text` alone gives your own answer, also to a question with choices. + - Neither skips the question. Include every question ID, including skipped ones. After a timeout, repeat the call with identical answers in the same order; nothing is recorded twice. @@ -246,6 +247,8 @@ Read every repository page of the decision first. Then pass one of: - With `"scope":"all_attended_agents"`, allowing also saves standing draft authority over the reviewed repositories for all your attended agents. - `{"decision":"request_changes","note":"What to change"}` declines and gives the agent feedback. +After a timeout, repeat the call with identical fields. Adding a field you left out, even with its default value, can return `ALREADY_DECIDED`. + Allowing a secret approval returns `REFUSED`; decide those in Sourcegraph. Requesting changes on one works. @@ -288,7 +291,7 @@ Approvals for a single agent and changesets already published stay in place. - `first` - Workspaces per page, 1 to 100 (optional, default 50) - `after` - `next_cursor` from the previous page, with the same filters (optional) -Workspaces in repositories you cannot see, or excluded by [context filters](/context-filters), are left out. When a changeset has `publication_failed`, open the agent's page to see why, fix the cause, and send a message to retry. +Workspaces in repositories you cannot see, or excluded by [context filters](/context-filters), are left out. When a changeset has `publication_failed`, publishing, updating, or closing it failed. Open the agent's page to see why, fix the cause, and send a message to retry. A stopped agent does not retry; see [`stop_batch_change`](#stop_batch_change). @@ -303,6 +306,8 @@ Workspaces in repositories you cannot see, or excluded by [context filters](/con - `workspace_id` - From `list_batch_change_workspaces` (required) - `after` - `next_cursor` from the previous page (optional) +Pages walk every branch patch the workspace produced, and `changeset_spec_id` names the patch a page belongs to. A workspace with no current result can return its previous run's patches; those pages have `source: "previous_run"`. + A patch over 1 MiB returns `REFUSED`; read it on the agent's page. @@ -392,13 +397,13 @@ A different active message is left alone. - `agent_id` - (required) - `close_changesets` - Also queue closing its open changesets (optional, default `false`) -Stopping can take several minutes. Success means cleanup is queued, not that every changeset is closed. Pushed branches stay on the code host. A stopped agent cannot continue; start a new one. +Stopping can take several minutes. Success means cleanup is queued, not that every changeset is closed. If cleanup does not finish, the `read_batch_change` summary says so; fix the cause and call `stop_batch_change` again. On an agent that is already stopped, `close_changesets` set to `true` still queues closing its open changesets. Pushed branches stay on the code host. A stopped agent cannot continue; start a new one. ## Waiting for updates -To wait for a change instead of polling, pass the `version` object from your last `read_batch_change` response back unchanged. The call returns once something changed, or after `wait_seconds`. An unchanged `version` means nothing changed; call again with it. +To wait for a change instead of polling, pass the `version` object from your last `read_batch_change` response back unchanged. The call returns once something changed, or after `wait_seconds`. An unchanged `version` means nothing changed yet, not that the work is done; call again with it. After you start an agent or allow a publication, keep reading until the work succeeds, fails, or needs you. To confirm a publication and get pull request links, use `list_batch_change_workspaces`. `wait_seconds` tops out at 50 so the reply arrives before the 60-second timeout most clients use; pass a smaller value if your client's tool timeout is shorter. Each Sourcegraph server holds up to four waiting reads per user; an extra one returns the current state within about 5 seconds. @@ -414,8 +419,7 @@ These codes usually need a change outside the client: | Code | What to do | | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | -| `FEATURE_DISABLED` | Agentic Batch Changes or the `abc-mcp` flag is off for you, or the tool is disabled or not permitted. Ask a site admin. | -| `INSUFFICIENT_SCOPE` | Use an access token with the scope the message names. See [Access tokens and scopes](#access-tokens-and-scopes). | +| `FEATURE_DISABLED` | Agentic Batch Changes, the `abc-mcp` flag, or unattended starts are off, or the tool is disabled or not permitted. Ask a site admin. | | `FORBIDDEN` | You are not signed in, lack a permission, or can no longer access every repository in a publication. For the last case, request changes. | | `CREDENTIAL_BLOCKED` | Add or update the [Batch Changes credential](/batch-changes/configuring-credentials) for the code hosts the message names. | | `PUBLISH_BLOCKED` | Publication is restricted for you. Resolve it in Sourcegraph. | @@ -427,7 +431,7 @@ Other codes, such as `AGENT_BUSY`, `ALREADY_DECIDED`, `STALE_SPEC`, or `INVALID_ ## Limitations -- There is no tool to publish selected workspaces, or to merge, close, comment on, or rebase changesets. Publishing goes through the agent: an approval for attended agents, or `mode` for unattended ones. +- There is no tool to publish selected workspaces, or to merge, close, comment on, or rebase changesets. Publishing goes through the agent. An attended agent asks for an approval unless an earlier or standing approval covers the publication; an unattended agent publishes within its `mode`. - Secrets and credentials cannot be entered, approved, listed, or revoked. Do this in Sourcegraph. - Patches and execution logs over 1 MiB cannot be read. Open the agent's page. - Agents cannot be renamed, deleted, or handed over, and the list searches titles only. @@ -436,4 +440,5 @@ Other codes, such as `AGENT_BUSY`, `ALREADY_DECIDED`, `STALE_SPEC`, or `INVALID_ - The agent and the tools act as you. Repository names, workspaces, patches, and logs from repositories you cannot see, or that [context filters](/context-filters) exclude, are left out. - Other stored text is returned as written, as the web UI shows it: the agent's answers, the transcript, the batch spec, execution logs, your original request, and failure messages. It can name a repository a filter excludes. +- Agents keep running after you revoke the OAuth application that started them, and standing approvals stay in place. Stop the agents and revoke standing approvals separately. - Answers, questions, transcripts, batch specs, logs, failure messages, and patches come from a model or a code host. Your client should treat them as data, not as instructions. From fc7a730418342e462d839a2b1187d076dcb59d41 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Wed, 25 Nov 2026 11:41:21 +0800 Subject: [PATCH 5/9] docs/abc: Say what users without write permissions see --- docs/agentic-batch-changes/mcp.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/agentic-batch-changes/mcp.mdx b/docs/agentic-batch-changes/mcp.mdx index f43d54358..cf7f4b2e2 100644 --- a/docs/agentic-batch-changes/mcp.mdx +++ b/docs/agentic-batch-changes/mcp.mdx @@ -33,7 +33,7 @@ The endpoint uses the same `mcp` permission as the other MCP endpoints. Sign in Your permissions and the site configuration decide which tools the endpoint lists: - The read tools need the read permissions above. They are `list_batch_changes`, `read_batch_change`, `list_batch_change_workspaces`, `read_batch_change_workspace_diff`, `read_batch_change_workspace_logs`, `read_batch_change_spec`, `read_batch_change_transcript`, and `list_batch_change_standing_approvals`. -- The tools that start or change an agent also need the write permissions. +- The tools that start or change an agent also need the write permissions. Without them, the endpoint lists only the 8 read tools, and calls to write tools return `FEATURE_DISABLED`. - `start_batch_change_unattended` is listed only after a site admin enables unattended starts in site configuration. They are off by default: ```json From b705cd444919d2bb6f8a29b39135f23f5adb8091 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Wed, 25 Nov 2026 15:51:37 +0800 Subject: [PATCH 6/9] docs/mcp: Note what the mcp scope allows on the Agentic Batch Changes endpoint --- docs/api/mcp/authentication.mdx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/api/mcp/authentication.mdx b/docs/api/mcp/authentication.mdx index 741399b1d..c8cd93153 100644 --- a/docs/api/mcp/authentication.mdx +++ b/docs/api/mcp/authentication.mdx @@ -92,7 +92,15 @@ For clients that do not support OAuth, include a [Sourcegraph access token](/cli Authorization: token YOUR_ACCESS_TOKEN ``` -Access tokens can use the `mcp` scope to restrict access to MCP endpoints only. +Access tokens can use the `mcp` scope to restrict access to MCP endpoints only. That includes the Agentic Batch Changes tools below. + +## Agentic Batch Changes + +The `mcp` scope also covers the [Agentic Batch Changes MCP server](/agentic-batch-changes/mcp) at `/.api/mcp/abc`. A credential your client got for `/.api/mcp` works there too. Users with the Batch Changes and Agent write permissions can start agents and approve their publications through it. + +Unattended starts are off by default. Once a site admin sets `batchChanges.agenticBatchChanges.unattended.enabled` to `true`, those users can also start agents that publish without another approval. To keep a tool off, list it in [`mcp.tools.disabled`](/api/mcp#disabling-individual-tools). + +When you revoke an OAuth app or access token, the agents it started keep running and standing publication approvals stay. Stop the agents and revoke the approvals separately, as described in [Authentication and tool access](/agentic-batch-changes/mcp#authentication-and-tool-access). ## Troubleshooting From 38400f0a78d005169b6b2549380e9ef24f88acf5 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Wed, 25 Nov 2026 16:02:55 +0800 Subject: [PATCH 7/9] docs/abc: Tighten the ABC over MCP page and link instead of repeating facts --- docs/agentic-batch-changes/mcp.mdx | 98 +++++++++++++----------------- docs/api/mcp/authentication.mdx | 8 +-- docs/api/mcp/index.mdx | 2 + 3 files changed, 46 insertions(+), 62 deletions(-) diff --git a/docs/agentic-batch-changes/mcp.mdx b/docs/agentic-batch-changes/mcp.mdx index cf7f4b2e2..5f923c597 100644 --- a/docs/agentic-batch-changes/mcp.mdx +++ b/docs/agentic-batch-changes/mcp.mdx @@ -8,9 +8,9 @@ Supported on [Enterprise](/pricing/plans/enterprise) plans. -An MCP client, such as Claude Code, Codex, or Cursor, can do what you do on the page of an [agentic batch change](/agentic-batch-changes): start an agent, follow its progress, answer its questions and publication approvals, send follow-up messages, review workspaces, patches, and logs, and stop it. The agent runs on your Sourcegraph instance as you, with your repository permissions and your Batch Changes credentials. The client only sends requests and reads results; it does not edit a local checkout. +An MCP client, such as Claude Code, Codex, or Cursor, can do what you do on the page of an [agentic batch change](/agentic-batch-changes): start an agent, follow its progress, answer its questions and publication approvals, send follow-up messages, review workspaces, patches, and logs, and stop it. The agent runs on your Sourcegraph instance as you, with your repository permissions and your Batch Changes credentials. The client sends requests and reads results; all edits happen on Sourcegraph. -You can see and act only on agents you own. Agents that others share with you or invite you to collaborate on do not appear; open them in Sourcegraph. +You can see and act only on agents you own. Open agents others share with you or invite you to in Sourcegraph. ## Before you start @@ -21,19 +21,19 @@ You can see and act only on agents you own. Agents that others share with you or - On Sourcegraph Cloud, Sourcegraph manages feature flags. Ask your account team to enable it. - The feature flag controls rollout, not access: on self-hosted instances, - users can add a feature flag override for themselves. To keep a user from - using these tools, remove their Agentic Batch Changes permissions. + On self-hosted instances, users can turn the feature flag on for themselves. + To keep a user from using these tools, remove their Agentic Batch Changes + permissions. ## Authentication and tool access -The endpoint uses the same `mcp` permission as the other MCP endpoints. Sign in through OAuth, or use an access token with the `mcp` or `user:all` scope. See [MCP authentication](/api/mcp/authentication). +The endpoint uses the same `mcp` scope as the other MCP endpoints. Sign in through OAuth, or use an access token with the `mcp` or `user:all` scope. See [MCP authentication](/api/mcp/authentication). -Your permissions and the site configuration decide which tools the endpoint lists: +The endpoint lists tools based on your permissions and the site configuration: - The read tools need the read permissions above. They are `list_batch_changes`, `read_batch_change`, `list_batch_change_workspaces`, `read_batch_change_workspace_diff`, `read_batch_change_workspace_logs`, `read_batch_change_spec`, `read_batch_change_transcript`, and `list_batch_change_standing_approvals`. -- The tools that start or change an agent also need the write permissions. Without them, the endpoint lists only the 8 read tools, and calls to write tools return `FEATURE_DISABLED`. +- The tools that start or change an agent also need the write permissions. Without them, the endpoint lists only the read tools, and calls to write tools return `FEATURE_DISABLED`. - `start_batch_change_unattended` is listed only after a site admin enables unattended starts in site configuration. They are off by default: ```json @@ -42,7 +42,7 @@ Your permissions and the site configuration decide which tools the endpoint list } ``` -With every permission, the endpoint lists 15 tools, or 16 with unattended starts enabled. A tool in [`mcp.tools.disabled`](/api/mcp#disabling-individual-tools) is not listed, even with unattended starts enabled, and calls to it return `FEATURE_DISABLED`. +The endpoint hides tools in [`mcp.tools.disabled`](/api/mcp#disabling-individual-tools), even with unattended starts enabled, and calls to them return `FEATURE_DISABLED`. **Unattended agents publish without another approval.** An agent can push @@ -60,7 +60,7 @@ The tools are only on this endpoint: https://sourcegraph.example.com/.api/mcp/abc ``` -A connection to `/.api/mcp` or `/.api/mcp/all` does not include them. Add a second server entry for this URL. +If you already connect to `/.api/mcp` or `/.api/mcp/all`, add a second server entry for this URL. In all examples, replace `sourcegraph.example.com` with your Sourcegraph instance URL. For other clients, or to use an access token, follow [Client integrations](/api/mcp/client-integrations) with this URL. @@ -84,29 +84,15 @@ scopes = ["mcp"] Then authenticate with `codex mcp login sourcegraph-abc`. -Five tools are marked destructive: `decide_batch_change_approval`, `message_batch_change`, `control_batch_change_turn`, `stop_batch_change`, and `revoke_batch_change_standing_approval`. Codex can ask for approval before calling them. With the approval policy `never`, as in `codex exec`, such a call fails with `MCP tool call requires approval`. To run a tool without asking, approve it: +These tools are marked destructive: `decide_batch_change_approval`, `message_batch_change`, `control_batch_change_turn`, `stop_batch_change`, and `revoke_batch_change_standing_approval`. Codex can ask for approval before calling them. With the approval policy `never`, as in `codex exec`, such a call fails with `MCP tool call requires approval`. To skip the prompt, set `approval_mode` per tool, and repeat the table for each tool you want: ```toml [mcp_servers.sourcegraph-abc.tools.decide_batch_change_approval] approval_mode = "approve" - -[mcp_servers.sourcegraph-abc.tools.message_batch_change] -approval_mode = "approve" - -[mcp_servers.sourcegraph-abc.tools.control_batch_change_turn] -approval_mode = "approve" - -[mcp_servers.sourcegraph-abc.tools.stop_batch_change] -approval_mode = "approve" - -[mcp_servers.sourcegraph-abc.tools.revoke_batch_change_standing_approval] -approval_mode = "approve" ``` To approve every tool on this server instead, set `default_tools_approval_mode = "approve"` under `[mcp_servers.sourcegraph-abc]`. See the [Codex configuration reference](https://developers.openai.com/codex/config-reference). -Codex can also start its own subagents in your local checkout. If you ask it to "start an agent", it may do that instead. Say that the agent should run through Sourcegraph, for example: "Start a batch change agent through Sourcegraph, not a local coding subagent, to ...". - ### Cursor Add the following to `~/.cursor/mcp.json`, or to `.cursor/mcp.json` for a project: @@ -127,10 +113,10 @@ Enable the server from **Cursor Settings > Tools & MCP** and follow the OAuth pr Every tool takes and returns IDs as strings. Each result stays under 36 KiB, - counting both the structured result and its text copy, so clients do not cut - it or save it to a file. Tools that page return `next_cursor`; pass it as - `after` until it is absent. Long text is shortened in the middle and marked - with `[truncated; see url]`. + counting both the structured result and its text copy, so clients keep it + inline and whole. Tools that page return `next_cursor`; pass it as `after` + until it is absent. Long text is shortened in the middle and marked with + `[truncated; see url]`. ### Start an agent @@ -144,7 +130,7 @@ Enable the server from **Cursor Settings > Tools & MCP** and follow the OAuth pr - `message` - The change to make, with context, constraints, and what must not change (required, up to 32,768 characters) - `repositories` - Full repository names such as `github.com/org/repo` (optional, up to 1,000). Omit to let the agent find repositories. -- `request_key` - A key you generate, such as a UUID (required, up to 200 characters). Reuse it with identical input on every retry; a retry returns the first agent instead of starting a second one. +- `request_key` - A key you generate, such as a UUID (required, up to 200 characters). Reuse it with identical input on every retry; Sourcegraph then returns the first agent instead of starting a second one. Names that do not exist or that you cannot see come back in `unresolved`. If none resolve, the call fails with `EMPTY_SCOPE`. @@ -170,7 +156,7 @@ The agent skips the approval when an approval you already gave covers the reposi Pass `repositories`, `query`, or both. Their union must resolve to at least one repository you can see, or the call fails with `EMPTY_SCOPE`; unlike `start_batch_change`, this agent cannot find repositories on its own. -The endpoint lists this tool only after a site admin enables unattended starts; see [Authentication and tool access](#authentication-and-tool-access). The scope is fixed at start. Publishing outside the scope or above `mode` is refused and shows up as a `refusal` item in `attention`. The agent uses only secrets already allowed in Sourcegraph. If it needs a decision it cannot make, it asks and waits for an answer. +The endpoint lists this tool only after a site admin enables unattended starts; see [Authentication and tool access](#authentication-and-tool-access). The scope is fixed at start. Sourcegraph refuses publishing outside the scope or above `mode` and adds a `refusal` item to `attention`. The agent uses only secrets already allowed in Sourcegraph. If it needs a decision it cannot make, it asks and waits for an answer. @@ -217,7 +203,7 @@ A regular read shows up to five repository names per approval and may leave out **Parameters:** -- `agent_id` - (required) +- `agent_id` - The agent's ID, from `list_batch_changes` or a start tool (required) - `decision_id` - From `read_batch_change` (required) - `answers` - One entry per question, 1 to 100 (required). Each has `question_id` and one of these forms: - `option_id` picks a choice. @@ -225,7 +211,7 @@ A regular read shows up to five repository names per approval and may leave out - `text` alone gives your own answer, also to a question with choices. - Neither skips the question. -Include every question ID, including skipped ones. After a timeout, repeat the call with identical answers in the same order; nothing is recorded twice. +Include every question ID, including skipped ones. After a timeout, repeat the call with identical answers in the same order; Sourcegraph records them once. @@ -236,7 +222,7 @@ Include every question ID, including skipped ones. After a timeout, repeat the c **Parameters:** -- `agent_id` - (required) +- `agent_id` - The agent's ID, from `list_batch_changes` or a start tool (required) - `decision_id` - From `read_batch_change` (required) - `response` - One of the forms below (required) @@ -244,7 +230,7 @@ Read every repository page of the decision first. Then pass one of: - `{"decision":"allow"}` keeps the requested mode and the `this_agent` scope. - `{"decision":"allow","publication":{"mode":"draft","scope":"this_agent"}}` sets both. `mode` must match the request, except that `ready` can be lowered to `draft`. -- With `"scope":"all_attended_agents"`, allowing also saves standing draft authority over the reviewed repositories for all your attended agents. +- With `"scope":"all_attended_agents"`, allowing also saves standing draft approval for the reviewed repositories for all your attended agents. - `{"decision":"request_changes","note":"What to change"}` declines and gives the agent feedback. After a timeout, repeat the call with identical fields. Adding a field you left out, even with its default value, can return `ALREADY_DECIDED`. @@ -256,16 +242,16 @@ Allowing a secret approval returns `REFUSED`; decide those in Sourcegraph. Reque #### `list_batch_change_standing_approvals`
-List your standing publication authority. +List your standing approvals. -Takes no parameters. Returns the authority's `id`, `mode`, and a sample of its repositories. +Takes no parameters. Returns the approval's `id`, `mode`, and a sample of its repositories.
#### `revoke_batch_change_standing_approval`
-Revoke your standing publication authority. +Revoke your standing approval. **Parameters:** @@ -284,7 +270,7 @@ Approvals for a single agent and changesets already published stay in place. **Parameters:** -- `agent_id` - (required) +- `agent_id` - The agent's ID, from `list_batch_changes` or a start tool (required) - `status` - One publication status: `no_changeset`, `no_change`, `unpublished`, `branch`, `draft`, `open`, `merged`, or `closed` (optional) - `checks` - Draft or open changesets with this check result: `none`, `pending`, `passed`, `failed`, or `unavailable` (optional) - `repository` - Exact repository name (optional) @@ -302,11 +288,11 @@ Workspaces in repositories you cannot see, or excluded by [context filters](/con **Parameters:** -- `agent_id` - (required) +- `agent_id` - The agent's ID, from `list_batch_changes` or a start tool (required) - `workspace_id` - From `list_batch_change_workspaces` (required) - `after` - `next_cursor` from the previous page (optional) -Pages walk every branch patch the workspace produced, and `changeset_spec_id` names the patch a page belongs to. A workspace with no current result can return its previous run's patches; those pages have `source: "previous_run"`. +Pages cover every branch patch the workspace produced, and `changeset_spec_id` names the patch a page belongs to. A workspace with no current result can return its previous run's patches; those pages have `source: "previous_run"`. A patch over 1 MiB returns `REFUSED`; read it on the agent's page. @@ -319,12 +305,12 @@ A patch over 1 MiB returns `REFUSED`; read it on the agent's page. **Parameters:** -- `agent_id` - (required) +- `agent_id` - The agent's ID, from `list_batch_changes` or a start tool (required) - `workspace_id` - From `list_batch_change_workspaces` (required) - `entry_key` - Read only this log entry, using a `key` from the returned `catalog` (optional) - `after` - `next_cursor` from the previous page, with the same `entry_key` (optional) -Without `entry_key`, setup and teardown entries that succeeded are left out. Logs are condensed as the agent reads them: structured events are summarized, embedded step diffs are left out, and long lines are shortened. Logs whose stored JSON is over 1 MiB return `REFUSED`; read them on the agent's page. +Without `entry_key`, setup and teardown entries that succeeded are left out. Sourcegraph condenses logs as the agent reads them: it summarizes structured events, drops embedded step diffs, and shortens long lines. Logs whose stored JSON is over 1 MiB return `REFUSED`; read them on the agent's page.
@@ -335,10 +321,10 @@ Without `entry_key`, setup and teardown entries that succeeded are left out. Log **Parameters:** -- `agent_id` - (required) +- `agent_id` - The agent's ID, from `list_batch_changes` or a start tool (required) - `after` - `next_cursor` from the previous page (optional) -This is the batch spec the plan view shows. A plan the agent has proposed but not created yet is in the transcript instead. +The plan view shows the same spec. A plan the agent has proposed but not created yet is in the transcript instead. @@ -349,10 +335,10 @@ This is the batch spec the plan view shows. A plan the agent has proposed but no **Parameters:** -- `agent_id` - (required) +- `agent_id` - The agent's ID, from `list_batch_changes` or a start tool (required) - `after` - `next_cursor` from the previous page (optional) -Each page holds one entry, or part of a long one: messages, thinking, tool calls and results, and the reason for each automatic resume. Only the agent's first thread is read, without attachments. +Each page holds one entry, or part of a long one: messages, thinking, tool calls and results, and the reason for each automatic resume. The tool reads only the agent's first thread, without attachments. @@ -365,25 +351,25 @@ Each page holds one entry, or part of a long one: messages, thinking, tool calls **Parameters:** -- `agent_id` - (required) +- `agent_id` - The agent's ID, from `list_batch_changes` or a start tool (required) - `text` - Instructions (required, up to 32,768 characters) - `interrupt` - Cancel the message the agent is working on before sending (optional, default `false`) -If the agent is answering a message and `interrupt` is not set, the call returns `AGENT_BUSY`. A message is not safe to retry blindly: after a timeout, read the agent and compare `latest_message_id` before you send again. +If the agent is answering a message and `interrupt` is not set, the call returns `AGENT_BUSY`. Do not retry a message blindly: after a timeout, read the agent and compare `latest_message_id` before you send again. #### `control_batch_change_turn`
-Cancel one specific message. +Cancel one message. **Parameters:** -- `agent_id` - (required) +- `agent_id` - The agent's ID, from `list_batch_changes` or a start tool (required) - `message_id` - From `read_batch_change`, `message_batch_change`, or `read_batch_change_transcript` (required) -A different active message is left alone. +Other active messages keep running.
@@ -394,16 +380,16 @@ A different active message is left alone. **Parameters:** -- `agent_id` - (required) +- `agent_id` - The agent's ID, from `list_batch_changes` or a start tool (required) - `close_changesets` - Also queue closing its open changesets (optional, default `false`) -Stopping can take several minutes. Success means cleanup is queued, not that every changeset is closed. If cleanup does not finish, the `read_batch_change` summary says so; fix the cause and call `stop_batch_change` again. On an agent that is already stopped, `close_changesets` set to `true` still queues closing its open changesets. Pushed branches stay on the code host. A stopped agent cannot continue; start a new one. +Stopping can take several minutes. A successful call queues cleanup; some changesets may still be open. If cleanup does not finish, the `read_batch_change` summary says so; fix the cause and call `stop_batch_change` again. On an agent that is already stopped, `close_changesets` set to `true` still queues closing its open changesets. Pushed branches stay on the code host. A stopped agent cannot continue; start a new one. ## Waiting for updates -To wait for a change instead of polling, pass the `version` object from your last `read_batch_change` response back unchanged. The call returns once something changed, or after `wait_seconds`. An unchanged `version` means nothing changed yet, not that the work is done; call again with it. After you start an agent or allow a publication, keep reading until the work succeeds, fails, or needs you. To confirm a publication and get pull request links, use `list_batch_change_workspaces`. +To wait for a change instead of polling, pass the `version` object from your last `read_batch_change` response back unchanged. The call returns once something changed, or after `wait_seconds`. If `version` comes back unchanged, nothing changed yet; call again with it. After you start an agent or allow a publication, keep reading until the work succeeds, fails, or needs you. To confirm a publication and get pull request links, use `list_batch_change_workspaces`. `wait_seconds` tops out at 50 so the reply arrives before the 60-second timeout most clients use; pass a smaller value if your client's tool timeout is shorter. Each Sourcegraph server holds up to four waiting reads per user; an extra one returns the current state within about 5 seconds. @@ -431,7 +417,7 @@ Other codes, such as `AGENT_BUSY`, `ALREADY_DECIDED`, `STALE_SPEC`, or `INVALID_ ## Limitations -- There is no tool to publish selected workspaces, or to merge, close, comment on, or rebase changesets. Publishing goes through the agent. An attended agent asks for an approval unless an earlier or standing approval covers the publication; an unattended agent publishes within its `mode`. +- There is no tool to publish selected workspaces, or to merge, comment on, rebase, or close individual changesets (`stop_batch_change` can close all of them). Publishing goes through the agent. An attended agent asks for an approval unless an earlier or standing approval covers the publication; an unattended agent publishes within its `mode`. - Secrets and credentials cannot be entered, approved, listed, or revoked. Do this in Sourcegraph. - Patches and execution logs over 1 MiB cannot be read. Open the agent's page. - Agents cannot be renamed, deleted, or handed over, and the list searches titles only. diff --git a/docs/api/mcp/authentication.mdx b/docs/api/mcp/authentication.mdx index c8cd93153..d77512ed5 100644 --- a/docs/api/mcp/authentication.mdx +++ b/docs/api/mcp/authentication.mdx @@ -92,15 +92,11 @@ For clients that do not support OAuth, include a [Sourcegraph access token](/cli Authorization: token YOUR_ACCESS_TOKEN ``` -Access tokens can use the `mcp` scope to restrict access to MCP endpoints only. That includes the Agentic Batch Changes tools below. +Access tokens can use the `mcp` scope to restrict access to MCP endpoints only. ## Agentic Batch Changes -The `mcp` scope also covers the [Agentic Batch Changes MCP server](/agentic-batch-changes/mcp) at `/.api/mcp/abc`. A credential your client got for `/.api/mcp` works there too. Users with the Batch Changes and Agent write permissions can start agents and approve their publications through it. - -Unattended starts are off by default. Once a site admin sets `batchChanges.agenticBatchChanges.unattended.enabled` to `true`, those users can also start agents that publish without another approval. To keep a tool off, list it in [`mcp.tools.disabled`](/api/mcp#disabling-individual-tools). - -When you revoke an OAuth app or access token, the agents it started keep running and standing publication approvals stay. Stop the agents and revoke the approvals separately, as described in [Authentication and tool access](/agentic-batch-changes/mcp#authentication-and-tool-access). +The `mcp` scope also covers the [Agentic Batch Changes MCP server](/agentic-batch-changes/mcp) at `/.api/mcp/abc`. A credential your client got for `/.api/mcp` works there too. Users with the Batch Changes and Agent write permissions can start agents and approve their publications through it. For unattended starts and what revoking access leaves running, see [Authentication and tool access](/agentic-batch-changes/mcp#authentication-and-tool-access) and [Security](/agentic-batch-changes/mcp#security). ## Troubleshooting diff --git a/docs/api/mcp/index.mdx b/docs/api/mcp/index.mdx index f0c847c4f..dbe198b06 100644 --- a/docs/api/mcp/index.mdx +++ b/docs/api/mcp/index.mdx @@ -456,6 +456,8 @@ Use this matrix to choose the smallest endpoint that has the tools your MCP clie On `/.api/mcp`, `nls_search` is available as a fallback when `code_finder` is unavailable or disabled. +Agentic Batch Changes tools are only on `/.api/mcp/abc`. See [Agentic Batch Changes over MCP](/agentic-batch-changes/mcp#available-tools). + The default `/.api/mcp` endpoint can read existing Deep Search conversations with `deepsearch_read`, but it cannot create new Deep Search conversations. From 749a1f2ff77fab466826f31e4d48e5f4bfedbc12 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Thu, 26 Nov 2026 17:18:45 +0800 Subject: [PATCH 8/9] docs/abc: Document the mcp:write scope --- docs/admin/oauth-apps.mdx | 5 +++-- docs/agentic-batch-changes/mcp.mdx | 11 ++++----- docs/api/mcp/authentication.mdx | 36 +++++++++++++++++++++--------- docs/api/mcp/index.mdx | 4 ++-- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/docs/admin/oauth-apps.mdx b/docs/admin/oauth-apps.mdx index f8e8f96e9..69f477b5e 100644 --- a/docs/admin/oauth-apps.mdx +++ b/docs/admin/oauth-apps.mdx @@ -108,6 +108,7 @@ OAuth App can request only the scopes selected on that client. | `externalapi:read` | Read-only access to the [Sourcegraph API](/api) | | `externalapi:write` | Write access to the [Sourcegraph API](/api) | | `mcp` | Access to Model Context Protocol resources | +| `mcp:write` | Access to MCP endpoints, including write tools | The `user:all` scope is required for GraphQL API access with OAuth tokens. @@ -398,8 +399,8 @@ This endpoint can be disabled by setting either `mcp.enabled` or `auth.idpDynamicClientRegistrationEnabled` to `false`. Applications created through Dynamic Client Registration are limited to the -`mcp` scope. For general OAuth integrations that need scopes such as -`user:all`, `openid`, or `offline_access`, create an OAuth app manually. +`mcp` and `mcp:write` scopes. For general OAuth integrations that need +scopes such as `user:all`, create an OAuth app manually. To disable self-registration, set `auth.idpDynamicClientRegistrationEnabled` diff --git a/docs/agentic-batch-changes/mcp.mdx b/docs/agentic-batch-changes/mcp.mdx index 5f923c597..6de4a7b9c 100644 --- a/docs/agentic-batch-changes/mcp.mdx +++ b/docs/agentic-batch-changes/mcp.mdx @@ -28,12 +28,12 @@ You can see and act only on agents you own. Open agents others share with you or ## Authentication and tool access -The endpoint uses the same `mcp` scope as the other MCP endpoints. Sign in through OAuth, or use an access token with the `mcp` or `user:all` scope. See [MCP authentication](/api/mcp/authentication). +The read tools need the `mcp` scope, like the other MCP endpoints. The tools that start or change an agent also need `mcp:write`. OAuth clients request both scopes when they connect to this endpoint. For an access token, choose `mcp` and `mcp:write`, or `user:all`. See [MCP authentication](/api/mcp/authentication). The endpoint lists tools based on your permissions and the site configuration: - The read tools need the read permissions above. They are `list_batch_changes`, `read_batch_change`, `list_batch_change_workspaces`, `read_batch_change_workspace_diff`, `read_batch_change_workspace_logs`, `read_batch_change_spec`, `read_batch_change_transcript`, and `list_batch_change_standing_approvals`. -- The tools that start or change an agent also need the write permissions. Without them, the endpoint lists only the read tools, and calls to write tools return `FEATURE_DISABLED`. +- The tools that start or change an agent also need the write permissions and a credential with `mcp:write`. Without them, the endpoint lists only the read tools, and calls to write tools return `FEATURE_DISABLED`. - `start_batch_change_unattended` is listed only after a site admin enables unattended starts in site configuration. They are off by default: ```json @@ -42,7 +42,7 @@ The endpoint lists tools based on your permissions and the site configuration: } ``` -The endpoint hides tools in [`mcp.tools.disabled`](/api/mcp#disabling-individual-tools), even with unattended starts enabled, and calls to them return `FEATURE_DISABLED`. +The endpoint hides tools in [`mcp.tools.disabled`](/api/mcp#disabling-individual-tools), even with unattended starts enabled, and calls to them return `FEATURE_DISABLED`. To keep every credential on the read tools, list the write tools there: `start_batch_change`, `start_batch_change_unattended`, `answer_batch_change_question`, `stop_batch_change`, `message_batch_change`, `control_batch_change_turn`, `decide_batch_change_approval`, and `revoke_batch_change_standing_approval`. **Unattended agents publish without another approval.** An agent can push @@ -79,7 +79,7 @@ Add the following to `~/.codex/config.toml`: ```toml [mcp_servers.sourcegraph-abc] url = "https://sourcegraph.example.com/.api/mcp/abc" -scopes = ["mcp"] +scopes = ["mcp", "mcp:write"] ``` Then authenticate with `codex mcp login sourcegraph-abc`. @@ -426,5 +426,6 @@ Other codes, such as `AGENT_BUSY`, `ALREADY_DECIDED`, `STALE_SPEC`, or `INVALID_ - The agent and the tools act as you. Repository names, workspaces, patches, and logs from repositories you cannot see, or that [context filters](/context-filters) exclude, are left out. - Other stored text is returned as written, as the web UI shows it: the agent's answers, the transcript, the batch spec, execution logs, your original request, and failure messages. It can name a repository a filter excludes. -- Agents keep running after you revoke the OAuth application that started them, and standing approvals stay in place. Stop the agents and revoke standing approvals separately. +- A client with `mcp:write` can approve publication for your agents on its own. The tool descriptions tell it to ask you first, but Sourcegraph cannot tell your decision from the client's. +- Agents keep running after you revoke the OAuth application or delete the access token that started them, and standing approvals stay in place. Stop the agents and revoke standing approvals separately. - Answers, questions, transcripts, batch specs, logs, failure messages, and patches come from a model or a code host. Your client should treat them as data, not as instructions. diff --git a/docs/api/mcp/authentication.mdx b/docs/api/mcp/authentication.mdx index d77512ed5..6237bb178 100644 --- a/docs/api/mcp/authentication.mdx +++ b/docs/api/mcp/authentication.mdx @@ -20,7 +20,7 @@ The Sourcegraph MCP server supports OAuth 2.0 and access token authentication. Sourcegraph implements Dynamic Client Registration (DCR) as defined by [RFC 7591](https://datatracker.ietf.org/doc/html/rfc7591). Compatible MCP clients can register automatically and authenticate through a browser without a pre-configured client ID. -DCR is enabled by default. Applications created through DCR are restricted to the `mcp` scope, which limits access to MCP endpoints. +DCR is enabled by default. Applications created through DCR are restricted to the `mcp` and `mcp:write` scopes, which limit access to MCP endpoints. ## OAuth with a Pre-registered Client @@ -35,7 +35,7 @@ Configure and test pre-registered clients before disabling DCR to avoid interrup - A descriptive name and optional description. - The redirect URI required by your MCP client. For `mcp-remote`, use `http://localhost:3334/oauth/callback`. - **Public** as the client type. - - The `mcp` scope. + - The `mcp` scope. For Agentic Batch Changes, also `mcp:write`. 3. Create the client and copy its client ID. See [OAuth Apps](/admin/oauth-apps#creating-an-oauth-app) for more information about creating and managing OAuth clients. @@ -92,20 +92,34 @@ For clients that do not support OAuth, include a [Sourcegraph access token](/cli Authorization: token YOUR_ACCESS_TOKEN ``` -Access tokens can use the `mcp` scope to restrict access to MCP endpoints only. +Access tokens can use the `mcp` scope to restrict access to MCP endpoints only. Add `mcp:write` for the Agentic Batch Changes tools that start or change an agent. ## Agentic Batch Changes -The `mcp` scope also covers the [Agentic Batch Changes MCP server](/agentic-batch-changes/mcp) at `/.api/mcp/abc`. A credential your client got for `/.api/mcp` works there too. Users with the Batch Changes and Agent write permissions can start agents and approve their publications through it. For unattended starts and what revoking access leaves running, see [Authentication and tool access](/agentic-batch-changes/mcp#authentication-and-tool-access) and [Security](/agentic-batch-changes/mcp#security). +The [Agentic Batch Changes MCP server](/agentic-batch-changes/mcp) at `/.api/mcp/abc` lists its read tools with the `mcp` scope. Starting agents and approving their publications also needs `mcp:write`, plus the Batch Changes and Agent write permissions. OAuth clients request `mcp` and `mcp:write` when they connect to `/.api/mcp/abc`; the other MCP endpoints request only `mcp`. For unattended starts and what revoking access leaves running, see [Authentication and tool access](/agentic-batch-changes/mcp#authentication-and-tool-access) and [Security](/agentic-batch-changes/mcp#security). ## Troubleshooting Most MCP connection issues come from OAuth or access-control configuration rather than the MCP endpoint itself. -| If you see | Likely cause | What to check | -| ------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `invalid_scope` during OAuth sign-in | The OAuth client requested a scope it is not configured to use | For MCP-only connections, request the `mcp` scope. DCR clients cannot request general API scopes such as `user:all`. For an integration that also needs GraphQL access, create a pre-registered [OAuth App](/admin/oauth-apps) configured with both `mcp` and `user:all`. | -| `redirect_uri_mismatch` or a token exchange failure after browser authorization | The OAuth client is missing the callback URL expected by the MCP client | Register the exact redirect URI your client uses. For the `mcp-remote` configuration above, add `http://localhost:3334/oauth/callback` to the OAuth App. | -| `/.auth/idp/oauth/register` returns `404 not found` | Dynamic Client Registration is disabled | Confirm `mcp.enabled` and `auth.idpDynamicClientRegistrationEnabled` are both `true`. To keep MCP available without DCR, use a pre-registered OAuth client instead. | -| Users must sign in again frequently after the integration previously worked | The client is not refreshing tokens correctly | OAuth access tokens expire after one hour. Store the newest `refresh_token` returned by each refresh because refresh tokens are one-time use. M2M flows do not return refresh tokens; request a new access token when the current one expires. | -| `403 forbidden` from `/.api/mcp` | The token lacks the `mcp` scope or the user lacks MCP access | Confirm the OAuth client is configured with `mcp` and the user has the `MCP#ACCESS` permission. If MCP is disabled, the endpoint returns `404` instead. | +| If you see | Likely cause | What to check | +| ------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `invalid_scope` during OAuth sign-in | The OAuth client requested a scope it is not configured to use | For Agentic Batch Changes, see [Agentic Batch Changes sign-in fails with `invalid_scope`](#agentic-batch-changes-sign-in-fails-with-invalid_scope). For other MCP connections, request the `mcp` scope. DCR clients cannot request general API scopes such as `user:all`. For an integration that also needs GraphQL access, create a pre-registered [OAuth App](/admin/oauth-apps) configured with both `mcp` and `user:all`. | +| `redirect_uri_mismatch` or a token exchange failure after browser authorization | The OAuth client is missing the callback URL expected by the MCP client | Register the exact redirect URI your client uses. For the `mcp-remote` configuration above, add `http://localhost:3334/oauth/callback` to the OAuth App. | +| `/.auth/idp/oauth/register` returns `404 not found` | Dynamic Client Registration is disabled | Confirm `mcp.enabled` and `auth.idpDynamicClientRegistrationEnabled` are both `true`. To keep MCP available without DCR, use a pre-registered OAuth client instead. | +| Users must sign in again frequently after the integration previously worked | The client is not refreshing tokens correctly | OAuth access tokens expire after one hour. Store the newest `refresh_token` returned by each refresh because refresh tokens are one-time use. M2M flows do not return refresh tokens; request a new access token when the current one expires. | +| `403 forbidden` from `/.api/mcp` | The token lacks the `mcp` scope or the user lacks MCP access | Confirm the OAuth client is configured with `mcp` and the user has the `MCP#ACCESS` permission. If MCP is disabled, the endpoint returns `404` instead. | + +### Agentic Batch Changes sign-in fails with `invalid_scope` + +An OAuth client registered with only `mcp` fails when it asks for `mcp:write`. Until it signs in again, its cached `mcp` credential lists only the read tools. + +For Claude Code, log out before logging in again so it registers with both scopes: + +```shell +claude mcp logout && claude mcp login +``` + +A plain `claude mcp login ` can fail once with `invalid_scope`; run it again. + +For a pre-registered OAuth app, a site admin adds `mcp:write` to its scopes in **Administration > OAuth clients > Edit**. Users still approve write access on the consent screen. diff --git a/docs/api/mcp/index.mdx b/docs/api/mcp/index.mdx index dbe198b06..c60599f64 100644 --- a/docs/api/mcp/index.mdx +++ b/docs/api/mcp/index.mdx @@ -469,9 +469,9 @@ Agentic Batch Changes tools are only on `/.api/mcp/abc`. See [Agentic Batch Chan ### `invalid_scope` error during OAuth -If your MCP client's OAuth login fails with an `invalid_scope` error when connecting to `/.api/mcp`, the client requested a scope that the Sourcegraph identity provider does not allow for the MCP resource. MCP endpoints require the `mcp` scope. +If your MCP client's OAuth login fails with an `invalid_scope` error when connecting to `/.api/mcp`, the client requested a scope that the Sourcegraph identity provider does not allow for the MCP resource. MCP endpoints require the `mcp` scope, and `/.api/mcp/abc` also asks for `mcp:write`. -To fix this, pin `scopes = ["mcp"]` in your client's OAuth configuration so the client requests only the `mcp` scope during the OAuth flow. +To fix this, pin `scopes = ["mcp"]` in your client's OAuth configuration so the client requests only the `mcp` scope during the OAuth flow. For `/.api/mcp/abc`, pin `scopes = ["mcp", "mcp:write"]` instead; with `mcp` alone the client gets only the read tools. For OpenAI Codex specifically, set `scopes = ["mcp"]` in your `config.toml`. See the [Codex](/api/mcp/client-integrations#codex) section on the client integrations page for the full configuration. From 0277504781dd5b87ccac4c1b7911519dfdb99784 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Fri, 27 Nov 2026 14:10:19 +0800 Subject: [PATCH 9/9] docs/abc: List unattended starts as destructive --- docs/agentic-batch-changes/mcp.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/agentic-batch-changes/mcp.mdx b/docs/agentic-batch-changes/mcp.mdx index 6de4a7b9c..26fa64cff 100644 --- a/docs/agentic-batch-changes/mcp.mdx +++ b/docs/agentic-batch-changes/mcp.mdx @@ -84,7 +84,7 @@ scopes = ["mcp", "mcp:write"] Then authenticate with `codex mcp login sourcegraph-abc`. -These tools are marked destructive: `decide_batch_change_approval`, `message_batch_change`, `control_batch_change_turn`, `stop_batch_change`, and `revoke_batch_change_standing_approval`. Codex can ask for approval before calling them. With the approval policy `never`, as in `codex exec`, such a call fails with `MCP tool call requires approval`. To skip the prompt, set `approval_mode` per tool, and repeat the table for each tool you want: +These tools are marked destructive: `start_batch_change_unattended`, `decide_batch_change_approval`, `message_batch_change`, `control_batch_change_turn`, `stop_batch_change`, and `revoke_batch_change_standing_approval`. Codex can ask for approval before calling them. With the approval policy `never`, as in `codex exec`, such a call fails with `MCP tool call requires approval`. To skip the prompt, set `approval_mode` per tool, and repeat the table for each tool you want: ```toml [mcp_servers.sourcegraph-abc.tools.decide_batch_change_approval]