mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 05:47:10 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Agents use Google Workspace through Paperclip's own REST tools for Gmail, Drive, Docs, Sheets, Slides and Calendar (#22634). > - In a live test on staging, an agent called `gmail__list_threads` with `query` and `q`. The tool did not have these arguments. > - The tool ignored them and returned threads that did not match. The agent read mail that it did not ask for. > - Google reviews this connector for restricted scopes. A tool that ignores a filter and reads too much data is a data-minimisation defect. > - This pull request makes every tool refuse an argument that is not in its input schema, before it sends a request to Google. It also adds `query` to `list_threads`. > - The benefit is that a filter can never be ignored. An agent gets a clear error that names the bad argument and lists the correct arguments. ## Linked Issues or Issue Description Refs #22634 **What happened?** On staging, against real Google, an agent called `gmail__list_threads` with `query` (and `q`) to list only threads with a marker. These arguments are not in the tool's input schema. The tool dropped them and returned unfiltered threads (5 shown, estimate 201). **What did you expect to happen?** The tool refuses an argument that it does not know, names it, and sends nothing to Google. `list_threads` accepts a Gmail search query, as `search_threads` does. **Steps to reproduce** 1. Connect Google Workspace with Gmail read access. 2. Call `gmail__list_threads` with `{ "query": "subject:marker" }`. 3. See that the result contains threads that do not match the query. ## What Changed - `defineTool` in `server/src/google-workspace-rest-tools/tool.ts` checks the arguments of all 36 tools against the advertised input schema before the zod parse. It checks the top level and structured inputs (for example `attendees[0]`, `writeControl`). An unknown argument gives a tool error and no request goes to Google. Example: `Invalid arguments for list_threads: unknown argument "q". Accepted arguments: pageSize, pageToken, query, labelIds, includeTrash, view. Nothing was sent to Google.` - `defineTool` sets `additionalProperties: false` on each object in the advertised input schema that lists `properties`. Agents get the schema from code, so existing connections see it with no reconnect and no refresh. - Google's batchUpdate request objects stay pass-through: `docs__update_doc`, `slides__update_presentation` and `sheets__update_spreadsheet` `requests[]`. The request-kind checks stay the same. - `gmail__list_threads` has a new optional `query`. It goes to Gmail as `q`, with the same name and meaning as in `search_threads`. It works together with `labelIds`. The draft and spam exclusions use the same shared function (`queryWithExclusions`) as `search_threads`. The page size stays default 20, maximum 50. - The README has a new "Unknown arguments" section, a new row in the input-differences table, a "Filters on list tools" decision list (`search_messages` and `list_drafts` already have `query`; `list_labels`, `list_calendars` have no REST filter; `list_events` uses `fullText`; Drive `list_recent_files` stays without `query`, and `search_files` is the Drive filter tool), and an updated `list_threads` design note. - `sheets/get-values.test.ts` expected that an unknown `valueRenderOption` was ignored. It now expects a refusal. ## Verification - `cd server && npx vitest run src/google-workspace-rest-tools` passes: 55 files, 1,400+ tests. - New `strict-arguments.test.ts` makes one case for each of the 36 tools from the tool list. Each case calls the tool with an unknown argument and expects the exact error and zero HTTP requests. It also checks `additionalProperties: false` on each closed object, the exact list of pass-through paths, and that the zod schema of each tool validates the same fields as its JSON schema. Red first: with the old `tool.ts`, 39 of 42 cases failed. - `gmail/list-threads.test.ts`: `{ query: "x" }` reaches Google as `q=(x) -in:draft`; `{ q: "marker" }` is refused with zero requests. - `src/__tests__/google-workspace-rest-transport.test.ts` (embedded Postgres, `executeTool` path): a connection with an older saved `list_threads` schema (no `query`, no `additionalProperties`) gets the new schema with no refresh and no Google request. A `query` call sends the right `q`. A `q` call fails as `tool_error` with the readable message, makes no Google request, and is recorded as a failed invocation and one `call_failed` audit event. - All Google-related server test files pass: 61 files, 1,542 tests. The allowlist and boundary tests pass. - `pnpm verify` exited 2 (the README is a broad input). Required CI gives the broad coverage. - Not checked against Google's servers. No request was sent to staging, production or Google. ## Risks - An agent that sent extra arguments before now gets an error, not a silent drop. This is the intended change. The error lists the accepted arguments, so the agent can correct the call at once. - If a tool's JSON schema and zod schema do not agree, a valid argument could be refused. A new test checks that they agree for all 36 tools. - What Google's own MCP servers do with unknown arguments is not recorded. We chose to refuse. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), through Claude Code, with tool use (shell, file edits) and extended thinking. ## 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>