## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents use apps through connections to remote MCP servers
> - Today an organization connection must sign in as a person (browser
sign-in) or use a static key
> - Service accounts and CI-style integrations have no person who can
sign in
> - The MCP OAuth Client Credentials extension (2026-07-28) defines
machine-to-machine sign-in for this case
> - This pull request adds "Machine sign-in" for organization
connections, with a Paperclip-held signing key (recommended) or a client
secret
> - The benefit is that organizations can connect automation-owned MCP
servers safely, with credentials only in the vault and bound to one
sign-in service
## Linked Issues or Issue Description
**Subsystem affected**
Connections: remote MCP OAuth (server `tool-access/oauth`, tool gateway
token refresh) and the custom MCP server setup flow in the UI.
**Problem or motivation**
Organization-owned automation (service accounts, CI integrations) cannot
connect an MCP server that requires OAuth, because no person can
complete a browser sign-in. The MCP OAuth Client Credentials extension
(`io.modelcontextprotocol/oauth-client-credentials`) solves this with
`grant_type=client_credentials` and RFC 7523 signed client assertions.
**Proposed solution**
Add machine sign-in for organization connections only. Paperclip creates
a keypair per connection, keeps the private key in the company vault,
and shows the public key (PEM and JWK) for the admin to register. A
client secret is also supported. The sign-in service (issuer and token
endpoint) is pinned at setup. Tokens use the existing organization grant
refresh path, so caching, concurrent dedupe and 401 re-request reuse the
existing lease and single flight.
**Alternatives considered**
Reuse the deployment-wide `PAPERCLIP_TOOL_OAUTH_*` client env path that
already sent `client_credentials`. Rejected: it is not per connection,
it keeps secrets in env, and it has no issuer pin. Route machine sign-in
through `connectGalleryApp`. Rejected: its rollback deletes the draft on
a failed test, which would lose a key the admin already registered.
**Roadmap alignment**
Phase 1 of the enterprise MCP plan (no enterprise single sign-on
needed). OIDC login and enterprise-managed authorization (ID-JAG) are
later phases.
## What Changed
- `oauth/client-credentials.ts`: keypair generation (RS256, or ES256
when the service requires it), RFC 7638 key IDs, and RFC 7523 assertions
(`iss` = `sub` = client ID, `aud` = token endpoint, 60 s `exp`, unique
`jti`) with Node `crypto` only.
- `oauth/client.ts`: the token exchange accepts a signed assertion and
then sends only `client_assertion_type` and `client_assertion` (no
`client_id` or secret), as the extension specifies.
- `oauth/client-credentials-service.ts`: discovery of the sign-in
service (protected-resource metadata, then RFC 8414/OIDC metadata with
issuer check, or a token URL entered directly), issuer pinning,
vault-only key and secret handling, draft creation, test-and-activate,
and no-downtime rotation (test the new secret first; stage a new key and
switch only after the provider accepts it).
- `oauth/grant-refresh.ts` and `oauth/connection-refresh.ts`: machine
sign-in requests a new access token with the connection's own
credentials instead of needing a refresh token. It never falls back to
deployment-wide OAuth clients.
- `catalog/discovery.ts`: a rejected token on a machine sign-in
connection never re-runs discovery or rewrites the pinned endpoints.
- `mcp-http.ts` and the tool gateway: declare
`io.modelcontextprotocol/oauth-client-credentials` in client
capabilities only for connections that use it.
- Routes (with OpenAPI and activity logging): `POST
/companies/{companyId}/tools/machine-sign-in`, `GET|POST
/tool-connections/{id}/machine-sign-in[/test|/rotate|/rotate/complete]`.
Removal activity now records `machineSignIn: true`. The runner API
treats these routes as sensitive.
- Shared validators and types for machine sign-in.
- UI: "Machine sign-in" under Advanced authentication in the custom MCP
server flow (organization connections only), `MachineSignInSetup`
(choose Paperclip key or client secret, register the public key, test),
and Storybook stories for each setup state.
- Docs: `doc/connections/MCP-CLIENT-CREDENTIALS.md`, linked from
`doc/connections/README.md` and `GENERIC-REMOTE-MCP.md`.
## Verification
- `server/src/__tests__/tool-access-client-credentials.test.ts`: 16/16
pass. It uses a fake sign-in service that verifies real signatures
against registered keys, and a fake MCP server. It covers RS256 and
ES256 assertion claims and signatures, assertion-only client
authentication, the secret flow (`client_secret_basic`), discovery and
direct token URL, issuer pinning (refuses a different sign-in service
and sends it nothing), the pinned endpoint surviving a hostile
challenge, the token cache (0 token requests while live), concurrent
dedupe (5 callers on 2 service instances produce 1 token request), 401
re-request, key and secret rotation, a refused personal connection,
secret redaction in responses, rows and activity, and vault cleanup on
removal.
- Red/green: with the grant-refresh machine sign-in branch and the
discovery pin guard disabled, 5 runtime tests fail (pin, cache/dedupe,
401 re-request, both rotations). Restored: 16/16 pass. The other tests
cover new routes and services that do not exist on `master`.
- `ui/src/features/connections/MachineSignInSetup.test.tsx`: 3/3.
`ConnectionSetupFlow.architecture` and `.oauth` tests: 19/19.
- `openapi-routes.test.ts`: 51/51. `runner-api.test.ts`: 2153/2153.
`mcp-http.test.ts`: 9/9. Existing `tool-access-service.test.ts` refresh
and legacy client-credentials tests: 54/54 (filtered).
- Server package `tsc --noEmit`: clean. UI `tsc`: clean except the
pre-existing generated Storybook catalog imports.
- Not run locally (machine under heavy load): full suites, repo-wide
typecheck, browser check of the live app. CI covers breadth.
## Risks
- No migration. New config lives in `config.oauth` (`grantType:
"client_credentials"` plus `clientAuth`). Older env-configured
client-credentials connections have no `clientAuth` and keep their
original path.
- The capability declaration adds one extension key only for machine
sign-in connections. Other requests are unchanged.
- Rotation has no settings-page control yet; it is available through the
API. This is a follow-up.
- Low risk to agent boot and time to first token: a live token is read
exactly like a browser sign-in token.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, via Claude Code with
tool use (shell, file edits, test runs).
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [ ] I will address all Greptile and reviewer comments before
requesting merge
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
6.8 KiB
Machine sign-in (MCP OAuth client credentials)
Machine sign-in connects an organization-owned remote MCP server where no
person signs in: service accounts, CI-style integrations, internal automation.
Paperclip signs in as a client the provider registered for it, using the
MCP OAuth Client Credentials extension
(io.modelcontextprotocol/oauth-client-credentials, revision 2026-07-28),
which builds on RFC 6749 §4.4
and RFC 7523.
It works the same on Paperclip Cloud and self-hosted instances.
Setting it up
Apps → Connect an app → Connect your own MCP server, paste the address, press Change beside the sign-in line and choose Machine sign-in. The option appears only when the connection is shared with the organization; personal connections sign in as the person.
- Sign-in service. Leave it blank and Paperclip asks the server where it signs in (its protected-resource metadata, then that service's metadata). Otherwise enter the sign-in service's address, or its token URL when the provider publishes no metadata.
- How Paperclip proves who it is.
- Paperclip key (recommended). Press Create key. Paperclip creates a signing key, keeps the private half in the company vault, and shows the public key as PEM and as JSON. Register it with the provider for the Paperclip client. The public key isn't secret.
- Client secret. For providers that only issue secrets. The secret goes straight into the vault and is never shown again.
- Client ID and scopes. Enter the client ID the provider shows for the Paperclip client, and any scopes its docs list (space separated).
- Test connection. Paperclip asks the sign-in service for a token, then lists the server's tools with it. Success turns the connection on and goes to the normal review step. A failed test keeps the draft and its key, so you can fix the provider side and test again.
Errors say what to change: an unaccepted key or secret, refused scopes, a provider that doesn't accept keys (choose Client secret) or secrets (choose Paperclip key), or a sign-in service Paperclip couldn't find.
How tokens are requested
grant_type=client_credentials, withscopeand the RFC 8707resource(the MCP server address) on every request.- Paperclip key:
private_key_jwt. Each request carries a fresh assertion signed with RS256 (or ES256 when the service accepts only that):iss=sub= client ID,aud= the token endpoint,exp60 seconds afteriat, a uniquejti, andkid= the key's RFC 7638 thumbprint. Per the extension, noclient_idor secret is sent alongside it. - Client secret:
client_secret_basic, orclient_secret_postwhen that is all the service advertises. - Requests that carry a 2026-07-28 client capability object declare
io.modelcontextprotocol/oauth-client-credentialsfor these connections only.
Tokens live in the vault on the connection's organization grant, like any
other OAuth token, and are reused until a minute before they expire. There is
no refresh token: Paperclip asks for a new access token. The existing grant
refresh lease and in-process single flight mean concurrent agents, across
server processes, share one token request. A 401 from the server requests a
new token once; a second 401 reports the problem without touching the
pinned settings. Agent boot and time to first token do not change: a live
token is read the same way as for browser sign-in connections.
The sign-in service is pinned
The connection records the sign-in service's issuer and token endpoint at setup. Credentials and assertions go only to that token endpoint, never to a deployment-wide OAuth client and never to a different service the server later advertises:
- Test and rotation check the server's protected-resource metadata; if it now lists other sign-in services and not the pinned one, Paperclip refuses and asks you to set up machine sign-in again.
- A rejected token at runtime never re-runs discovery or rewrites the connection's endpoints.
When you enter a token URL directly there is no issuer to compare; the token URL itself is the pin.
Rotation without downtime
- New client secret: enter it; Paperclip tests it against the sign-in service first and only then replaces the stored secret (a new version of the same vault entry). A wrong secret changes nothing.
- New key: start a key rotation; Paperclip creates a replacement key and shows its public key while the current key keeps working. Register the new public key with the provider, then complete the rotation: Paperclip tests the new key and only then switches to it and deletes the old one.
API: POST /api/tool-connections/{id}/machine-sign-in/rotate with
{ "method": "client_secret", "clientSecret": "…" } or
{ "method": "paperclip_key" }, then
POST /api/tool-connections/{id}/machine-sign-in/rotate/complete for a key.
Security
- Private keys and client secrets exist only in the company vault
(
oauth.client_private_key,oauth.client_private_key_next,oauth.client_secret). Config, API responses, activity and logs carry only the public key, key ID, issuer, method and scope count. - Company scoped. Only connection managers can set it up, and only for organization connections; the service refuses personal connections.
- Activity:
tool_connection.machine_sign_in_created,…_verified,…_rotation_started,…_rotated, and removal astool_connection.archivedwithmachineSignIn: true. Removal destroys the vault entries the connection owned.
API
| Route | Use |
|---|---|
POST /api/companies/{companyId}/tools/machine-sign-in |
Create the draft (finds and pins the sign-in service, creates the key or stores the secret). |
GET /api/tool-connections/{id}/machine-sign-in |
Settings and public keys. |
POST /api/tool-connections/{id}/machine-sign-in/test |
Test with an optional client ID, scopes or secret; turns the connection on. |
POST /api/tool-connections/{id}/machine-sign-in/rotate |
Rotate the secret, or stage a new key. |
POST /api/tool-connections/{id}/machine-sign-in/rotate/complete |
Switch to the staged key. |
Code: server/src/services/tool-access/oauth/client-credentials.ts (keys and
assertions), client-credentials-service.ts (setup, pinning, token requests),
the machine sign-in branch in grant-refresh.ts, and
ui/src/features/connections/MachineSignInSetup.tsx. Tests:
server/src/__tests__/tool-access-client-credentials.test.ts.
Not yet covered
- A settings-page control for rotation (rotation is API-only today).
- Enterprise single sign-on and enterprise-managed authorization (ID-JAG) are later phases.