Files
PaperClipAI/server
DottaandClaude Opus 5.5 371ece9375 fix(tool-access): do not store provider-removed actions in the connection profile (#22908)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Connected apps give agents actions. A person reviews and turns on
each action on the Permissions page.
> - #22877 lets the review save when it contains an action that the
provider no longer lists (status `removed`, or `disabled` with
`quarantineReason: mcp_tool_removed`).
> - But the save still wrote that action to the connection profile as an
`include` entry.
> - When the provider lists the action again, the catalog refresh sets
the row back to `active`. The stored `include` then turns the action on
for agents with no new review.
> - The Permissions page does not send removed ids now, but a stale page
or a direct API call can still send them.
> - This pull request keeps provider-removed actions out of the profile
entries and the Ask first policies when the review is saved.
> - The benefit is that an action that comes back from the provider is
not offered to agents until a person turns it on again.

## Linked Issues or Issue Description

Refs #22877

**What happened?**
`finishGalleryAppConnection` accepted a provider-removed action in
`enabledCatalogEntryIds` or `askFirstCatalogEntryIds` and stored it as
an `include` profile entry (or an Ask first policy). When the provider
listed the action again, the refresh set the row to `active` and agents
got the action with no new review.

**What did you expect to happen?**
The save accepts the removed action, but does not store it. When the
provider lists the action again, the action is `active` in the catalog
but it is off for agents until a person turns it on.

**Steps to reproduce**
1. Connect Google Workspace and save a review.
2. Make Google stop listing `gmail__list_threads`. Refresh the catalog.
The row becomes `disabled` with `mcp_tool_removed`.
3. Save the review again with that row id in `enabledCatalogEntryIds`.
4. Make Google list the action again. Refresh the catalog.
5. Before this fix, the agent tool list contains `gmail__list_threads`.

## What Changed

- `server/src/services/tool-access.ts`: `finishGalleryAppConnection`
filters the enabled rows and the Ask first rows with
`isCatalogEntryOffered` before it builds the profile entries and the Ask
first policies. The validation is the same. A blocked action still gives
"Disabled actions cannot be enabled".
- `server/src/services/tool-access.ts`: when `preserveExistingAccess` is
true (OAuth completion and task setup use it), the save no longer copies
back a prior `include` entry whose catalog row is provider-removed. A
prior `exclude` entry is kept, so a saved exclusion still blocks the
action if it comes back.
- `server/src/__tests__/google-workspace-mcp-transport.test.ts`: the
test "saves the review when Google no longer offers actions that were
on…" now makes Google list the two removed actions again. It also saves
one removed action as Ask first and checks that no enabled
`require_approval` policy is made for it. It checks that the rows are
`active` and that the agent tool list does not contain them.
- New test "does not keep a removed action on when a save keeps the
existing access": a save with `preserveExistingAccess: true` does not
keep the old `include` for a removed action, and keeps an `exclude` for
a removed action.

What happens to a removed action that the provider lists again: the
refresh sets the row to `active` with no profile entry. The action is
off. A person must turn it on again on the Permissions page. It is not
held as `quarantined`, because the definition was already reviewed; only
the on/off choice is reset to off.

This applies to every connection kind that saves through
`finishGalleryAppConnection`. Remote MCP aggregators (Zapier, Arcade,
Composio, Executor) also stop storing a removed action when a review is
saved. This is the safe result for them too: an aggregator can list a
different tool under a reused name, so a returning action must not turn
on by itself. Their existing tests (`remote-mcp-connectors.test.ts`,
`tool-access-service.test.ts`) pass with no change.

Scope: this PR changes what a save stores. It does not change the
catalog refresh or a reconnect that keeps the profile unchanged
(`mcpPreserveAccess`). An `include` that was saved before the provider
removed the action, with no later save, stays in the profile as before.
A follow-up can decide if a refresh should drop it.

## Verification

- Red: with only the test change, the new assertion fails: `expected [
'docs__read_doc', …(8) ] to not include 'gmail__list_threads'`.
- Red: without the preserve-path filter, the preserve test fails
(`gmail__list_threads` is offered again). With the filter but without
the `include` check, the exclusion assertion fails (`expected [] to
deeply equal [ 'exclude' ]`). Without the Ask first filter, the policy
assertion fails.
- Green: with the fix, `google-workspace-mcp-transport.test.ts` and
`tool-access-service.test.ts` pass (547 tests).
- `remote-mcp-connectors.test.ts`,
`tool-profile-review-service.test.ts`, `app-permission-save.test.ts`,
`tool-connection-removal.test.ts`, `tool-gateway.test.ts` pass.
- `pnpm --filter @paperclipai/server typecheck` and `pnpm verify` run
locally. CI covers the full suite.

## Risks

- Low risk. A person who saved a removed action as on must turn it on
again if the provider lists it again. This is the intended result.
- A prior Ask first policy for a removed action can stay on the preserve
path (`disableStale` is false there). It only restricts an action. It
cannot turn an action on.
- No schema change. No migration.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, in Claude Code with
tool use and code execution.

## 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
- [x] 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>
2026-11-25 05:25:51 -06:00
..