Skip to content

feat(plugins): Add optional service accounts for plugins - #2245

Merged
dcramer merged 9 commits into
mainfrom
feat/mcp-service-account
Oct 27, 2026
Merged

dcramer merged 9 commits into
mainfrom
feat/mcp-service-account

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Refs #2233.

A plugin can now allow an optional service account. This is one install-wide provider account, often a bot, that Junior itself uses. Per-user OAuth stays the default, and a person's own connection always wins. A person who has not connected uses the service account, but only for the tools it lists. Other tools still ask them to connect.

The top-level accounts block says which accounts Junior may use:

accounts:
  user-oauth: true # default
  service-account:
    tools:
      - notion-search
      - notion-fetch

junior-notion turns this on for search and fetch. People can then read Notion without connecting their own account, and so can automations without a creator connection. The block has no effect until an admin connects the account.

Connecting. Admins connect, reconnect, and disconnect service accounts from a new Service accounts section on the dashboard Admin page, like the Google account. Every route, including the OAuth callback, requires a Junior admin. A pending sign-in is single-use and expires after 10 minutes. Only the admin who started it can finish it. junior service-account connect|status|disconnect stays as a CLI fallback.

Service account only. Set accounts.user-oauth: false to turn off per-user OAuth for a plugin. Junior then uses only the service account. It never sends a connect link, ignores existing personal connections, and hides the tools that the service account does not list. Until an admin connects the account, the plugin reports that it is not available. A deployment can turn this on for Notion with plugins.manifests: { notion: { accounts: { userOAuth: false } } }, with no repeated tool list.

Policy boundary. serviceAccountAllows and serviceAccountOnly in chat/credentials/service-account.ts are the one place that decides what the shared account may do. MCP calls run on the host, so the MCP tool manager enforces service-account.tools on each call. The accounts block rejects unknown keys, so a rule that nothing enforces fails at load time.

Shared tokens. Concurrent requests refresh the shared token under a lock. If the provider revokes the grant, Junior removes the account. With user OAuth on, Junior goes back to per-user OAuth. With it off, the plugin stays unavailable.

Scope. This covers MCP plugins that register their own OAuth client, such as Notion. Linear uses a hosted MCP server too, so it should only need a tools list. Not covered yet:

  • Regular oauth: plugins that go through the egress proxy. Only plugins with a grantForEgress hook (GitHub, Sentry, Google) name their egress grants. Plain oauth: plugins get one grant named default for every request, so a service account cannot list what they may use yet. The plan and its catches are in this comment on #2233.
  • MCP plugins with a fixed oauth-client.

Where to look.

  • Manifest parsing and checks: chat/plugins/manifest.ts, junior-plugin-api/src/manifest.ts
  • Policy and sign-in: chat/credentials/service-account.ts, chat/mcp/service-account.ts
  • Enforcement: chat/mcp/tool-manager.ts, chat/services/mcp-auth-orchestration.ts
  • Dashboard: api/service-accounts/routes.ts, ServiceAccountsSection.tsx

This is a draft because the Notion sign-in has not been tried against the live Notion MCP server.

via David Cramer.

--

View Junior Session [Sentry]

sentry-junior Bot and others added 5 commits October 26, 2026 22:06
Let an MCP plugin declare mcp.service-account with a read tool subset.
After an admin connects the account with junior service-account connect,
actors without their own connection use it for those tools, and other
tools still go through the actor's own OAuth. Enable it for Notion search
and fetch.

Refs #2233

Co-Authored-By: David Cramer <[email protected]>
Move the service account policy from mcp.service-account to a top-level
service-account block, so every provider uses the same model: per-user
OAuth by default, an optional admin-connected shared account, and a
policy that limits what that account may do.

Core owns the policy check in chat/credentials/service-account.ts. Each
request surface enforces its part where it sees the request. MCP checks
each tool call against service-account.mcp-tools on the host. The block
is strict, so a key that no surface enforces fails validation instead of
being ignored.

Refs #2233

Co-Authored-By: David Cramer <[email protected]>
Admins now connect, reconnect, and disconnect plugin service accounts from
the dashboard Admin page, the same way as the Google account. The CLI stays
as an out-of-band fallback.

The connect flow is split into start and finish steps so the deployed OAuth
callback can complete it. A pending sign-in is single-use, expires after 10
minutes, and finishes only for the Admin who started it. Every route,
including the callback, requires a Junior admin. The stored account records
which Admin connected it.

Refs #2233

Co-Authored-By: David Cramer <[email protected]>
A plugin's service-account policy can now set `mode: only`. Junior then
uses only the shared account. It ignores Actor connections and never sends
a connect link. Until an Admin connects the account, MCP activation fails
with a model-visible error that tells the person to ask an Admin. If the
provider revokes the grant, the plugin stays unavailable instead of falling
back to per-Actor OAuth.

The manifest loader requires the policy to cover every loaded MCP tool in
`only` mode, so no tool needs an Actor connection. Deployments can turn it
on for a packaged plugin through `plugins.manifests`. The dashboard Admin
page shows the mode.

Refs #2233

Co-Authored-By: David Cramer <[email protected]>
`mode: only` did not say what it turned off. The service-account policy
now uses a boolean, `user-oauth`, that defaults to true. Set it to false to
turn off per-Actor OAuth for the plugin. The status API reports
`userOAuth` instead of `mode`.

Refs #2233

Co-Authored-By: David Cramer <[email protected]>
@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Oct 27, 2026 4:27pm UTC

Request Review

Replace the top-level `service-account` block with `accounts`:

    accounts:
      user-oauth: true        # default
      service-account:
        tools: [notion-search, notion-fetch]

The service account lists exactly the MCP tools it may call. `user-oauth`
now sits beside it instead of inside it.

With `user-oauth: false`, Junior hides the tools that the service account
does not list instead of refusing to load the plugin. A deployment can
turn on shared-only with `accounts: { userOAuth: false }` and no
repeated tool list.

The dashboard status API reports `tools` instead of `mcpTools`.

Refs #2233

Co-Authored-By: David Cramer <[email protected]>
A declared service account that no admin has connected must not change
anything when per-user OAuth is on. Junior asks the actor to connect as
before.

Co-Authored-By: David Cramer <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

When the provider revoked the shared grant, the service account threw a
plain Error. That stopped the turn instead of falling back to per-user
OAuth, or telling people to ask an admin when user OAuth is off. Throw
McpAuthorizationRequiredError so the tool manager handles both cases.

A refresh that fails without a rejection, such as a token endpoint
outage, no longer deletes the account. A turn whose refresh token another
turn already replaced retries with the stored token. Writes to the
stored credentials now run under a lock, so a turn cannot write back an
older refresh token.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 823f4c4. Configure here.

@blacksmith-sh

This comment has been minimized.

After a rejected refresh, the service account threw
McpAuthorizationRequiredError even when another turn had already
replaced the refresh token. That sent the actor to connect, or reported
the plugin as unavailable, while the account still worked. Treat that
case like a failed refresh and keep the account.

The check and the delete now run under the same lock as token writes,
so a concurrent saveTokens cannot be deleted.
@dcramer
dcramer merged commit 7bcf3e7 into main Oct 27, 2026
44 checks passed
@dcramer
dcramer deleted the feat/mcp-service-account branch October 27, 2026 16:41
dcramer added a commit that referenced this pull request Oct 27, 2026
Refs #2233. Follows #2245.

Linear connects through its hosted MCP server, so it uses the same
service-account path as Notion. No core change is needed. The plugin now
declares:

```ts
accounts: {
  serviceAccount: { tools: [...LINEAR_SERVICE_ACCOUNT_TOOLS] },
}
```

The list holds Linear's 21 read tools: the `get_*` and `list_*` tools,
`extract_images`, and `search_documentation`. It leaves out every write
tool, such as `save_issue`, `save_comment`, `save_project`, `create_*`,
`update_document`, and `delete_*`.

**Behavior**

- The block has no effect until a Junior admin connects a Linear account
on the dashboard Admin page, or runs `junior service-account connect
linear`.
- After that, people who have not connected Linear read through the
shared account. So do automations without a creator connection.
- Writes still ask the person to connect their own Linear account. A
person's own connection always wins.
- Per-user OAuth stays on by default. A deployment can use only the
service account with `manifests: { linear: { accounts: { userOAuth:
false } } }`. Junior then hides the write tools.

**Tool names**

Linear's MCP tool list requires auth, so I could not read it from the
live server. The names come from a published catalog of Linear's
official MCP server (31 tools), and they match the tool names Junior
already uses (`get_issue`, `save_issue`). Linear loads without
`mcp.allowed-tools`, so a listed name that Linear removes has no effect.
A new Linear read tool will ask people to connect until it is added
here.

Linear also offers a `read` OAuth scope that blocks writes on Linear's
side. The service-account sign-in cannot request a scope yet, so that is
a possible follow-up.

**Tests**

`tests/component/plugins/linear-plugin.test.ts` checks that the shipped
manifest parses, keeps per-user OAuth on, lists only read tools, allows
`get_issue`, and refuses `save_issue`. The shared allow, deny, fallback,
and revocation behavior is already covered by
`tests/component/auth/mcp-service-account-auth.test.ts`.

**Docs**

`packages/junior-linear/README.md` and the Linear plugin docs page
describe setup, the read-only scope, and the service-account-only
option.

<!-- junior-request-attribution:start -->
via **David Cramer**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0B595QDZLL%3A1793050581.051809 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0B595QDZLL%3A1793050581.051809)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0B595QDZLL%3A1793050581.051809/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>
dcramer added a commit that referenced this pull request Oct 27, 2026
When several Watch Events arrive in one wait window, they already run in
one Turn. But the Turn input pasted each Event's full task text
together, so the Watch instructions repeated once per Event. The saved
conversation message also kept only the first Event's type and summary.
On #2245, an approval plus three Bugbot review comments reached the
model as about 16KB with the same ~800-character instructions four
times. The dashboard showed only "approved by dcramer".

Now each Event saves its task facts (label, instructions, guidance,
people, Done by, summary, details, external text) on its mailbox input.
The batch text is written when the Turn starts:

```
[task]

This is a task, not a message from a person.

You received 4 events.

About: GitHub PR #2245
People involved: <@u123>
Instructions: <once per Watch>

Additional guidance:
- pull_request.review_comment.created: <once per event type>

Event 1: pull_request.review.approved
Done by: <@u123>. ...
Trusted summary: ...

Event 2: pull_request.review_comment.created
...

About: Vercel deployment junior-prod
Instructions: <this Watch's instructions>

Event 3: deployment.succeeded
...
```

- Events are grouped by Watch, not by resource. Two Watches on the same
PR keep separate instructions.
- A single Event renders the same as before.
- Input without saved facts, such as child agent results or input queued
before this deploy, keeps its own text after the task block. It is not
counted.
- Root and child Conversations use the same batch input.
- The conversation message keeps `meta.eventType` (the first Event) for
existing readers and adds `meta.events[]` with one entry per counted
Event. The reporting API exposes it under the same payload rules as the
rest of the message.
- The dashboard heading reads "N events · <label>", with one row per
Event. The label shows only when every Event shares it. Messages without
`events` render as before. I checked it on `/dev/transcripts` with a new
fixture based on the #2245 batch.

Duplicate handling is unchanged. The inbound id is still
`event:<watchId>:<eventKey>`, so a repeated webhook delivery for the
same Watch is dropped. Event automations don't batch and are not
affected.

The conversation stats schemas moved to
`api/schema/conversation-stats.ts` so `api/schema/conversation.ts` stays
under the 1,000-line limit. Exports are unchanged.

Tests: the burst scenario in `event-wake-delay.test.ts` now goes through
`enqueueEventNotification`. It uses a GitHub PR Watch (with guidance,
people and Done by), a second Watch on the same PR, a Vercel deployment
Watch, and a repeated delivery. It checks for one Turn, "You received 4
events", three instruction groups, the `meta.events` list, and the
dropped duplicate. Removing the saved task facts now fails this test.
The `renderTaskBatchInput` unit snapshot covers the exact layout.

An adversarial review pass found a test-architecture lint failure, child
Conversations missing the batch input, a count mismatch with child
results, and the test gap above. All are fixed here.

Not in this PR:
- Fencing external text so a comment body can't imitate an `Event N:`
line. The old format had the same gap.
- Showing event times or arrival order across Watches. The README notes
that numbering follows Watch groups.
- Saying explicitly that Event text is not approval.
- Dropping Events that cancel out, like a check that fails and then
passes.
- Dropping the extra `review.commented` sent with an approval body.
- Nesting inline comments under their review.

<!-- junior-request-attribution:start -->
via **David Cramer**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0B595QDZLL%3A1793117408.011919 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0B595QDZLL%3A1793117408.011919)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0B595QDZLL%3A1793117408.011919/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 19101ee5 Deployed Oct 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant