Commit Graph
8 Commits
Author SHA1 Message Date
DottaandClaude Opus 5.5 56023fe80f feat(google-workspace): gateway sets the REST tool result size limit for all six services; update connector docs (#22050)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents read Gmail, Calendar, Drive, Docs, Sheets and Slides through
the built-in Google Workspace connection
> - Paperclip now has its own REST-backed Google tools in
`server/src/google-workspace-rest-tools/`. No service uses them yet
> - That folder guessed a result size limit of 250,000 bytes. It applied
the limit only to Drive, Docs, Sheets and Slides. Gmail and Calendar had
no limit
> - The guess was wrong in both directions. It refused documents that
Paperclip can deliver, and the folder should not know Paperclip's limits
> - This pull request makes the limit a number that the gateway gives.
The folder applies it to every tool in all six services through one
check. It also brings three Google planning docs up to date
> - The benefit is that a REST result is refused only when the gateway
would also refuse the same result from Google's own MCP server

## Linked Issues or Issue Description

Refs #22027, #22028, #22029, #22026

**Is your feature request related to a problem?**
The REST tools refused results over a size the folder chose itself
(250,000 bytes). Paperclip can deliver larger results: the runner saves
a large result as an artifact and gives the agent a pointer. Gmail and
Calendar results had no limit at all.

**Describe the solution you'd like**
The gateway gives the limit. The folder applies the given number to the
final serialized result of every tool, with one helper. A result over
the limit is an error that says how to ask for less. It is never cut
short.

**Describe alternatives you've considered**
A larger number chosen from the runner's 1 GiB capture limit. Google's
own transfer limit (20 MB per response) and memory use make that a poor
choice. Also, results would then differ between the REST path and
Google's MCP path.

### Limits a tool result passes on the way to an agent

| Point | Limit | What happens over it |
| --- | --- | --- |
| Google response read by `google-http.ts` | 20 MB
(`MAX_RESPONSE_BYTES`) | Tool error. Nothing returned |
| REST folder result (new) | the number the gateway passes: 999,885
bytes | Tool error with "read less" advice. The gateway returns
`tool_error` (502) |
| Gateway read of a remote MCP response (`MAX_REMOTE_MCP_RESPONSE_BYTES`
in `tool-gateway.ts`) | 1,000,000 bytes per JSON body or event-stream
message | `mcp_remote_response_too_large` (502). This is the "1,000,000
bytes are rejected" statement in `doc/prompt-injection-prevention.md`.
It applies to the Google MCP path only; the REST path has no HTTP read |
| Injection screening model check | 256 KiB model request | Not a
delivery limit. A larger result is checked by the built-in patterns only
|
| Gateway HTTP route (`POST /tool-gateway/.../tools/call`) | none in
Paperclip | `res.json(result)` |
| Runner (`captureRunnerToolResult`) | 500,000 bytes
(`RUNNER_TOOL_RESULT_MAX_BYTES`) | Saved as an artifact. The agent gets
a pointer and reads it with `read_tool_result` |
| Runner capture | 1 GiB (`RUNNER_API_RESPONSE_MAX_BYTES`) |
`SemanticToolOutcomeUnknownError` |

The gateway wraps the result as `{ content, data: { content,
structuredContent, ... } }`, so the payload occurs again. Measured: a
Gmail result of 676,459 bytes from the folder became 1,017,386 bytes
delivered (ratio 1.50). The ratio cannot be more than 2.

### The budget

`GOOGLE_WORKSPACE_REST_MAX_RESULT_BYTES` in `tool-gateway.ts` =
`MAX_REMOTE_MCP_RESPONSE_BYTES` less the JSON-RPC envelope and
event-stream framing (`event: message\ndata:
{"jsonrpc":"2.0","id":"paperclip-tool-<uuid>-version","result":...}`) =
**999,885 bytes**. A result that Google's MCP server could deliver
through the gateway is also delivered over REST, and the reverse. With
the wrapper, the largest delivered result is less than 2 MB. The runner
saves it as an artifact (far below 1 GiB). So the folder never refuses a
result that the runner can give as a pointer.

Practical limits at that budget (plain ASCII; escaped and non-ASCII
characters count more):

| Tool | Largest content |
| --- | --- |
| Gmail `get_message` | about 500 KB plain body, or about 250 KB each
for plain plus HTML |
| Calendar `get_event` | about 500 KB description |
| Drive `read_file_content` | about 500 KB text |
| Drive `download_file_content` | about 375 KB file bytes |
| Docs `read_doc` | about 240 KB document text |
| Slides `read_presentation` | about 250 KB text |
| Sheets `get_values` | about 500 KB cell text, at most 50,000 cells |

## What Changed

- `tool.ts`: `defineTool` takes `whenTooLarge` advice per read tool
(required for reads, refused for writes) and a `ToolLimits` argument. It
measures the final `CallToolResult` once (`withinResultBudget`) and
replaces an oversized result with a `too_large` tool error.
`FALLBACK_MAX_RESULT_BYTES` (250,000) applies only when a direct caller
gives no limit.
- `callGoogleWorkspaceRestTool` and `createGoogleWorkspaceRestServer`
take `maxResultBytes`. A value that is not a positive integer is refused
before any request.
- All 23 read tools state their advice: a smaller `pageSize` for list
tools, `messageFormat` or `view` for Gmail, a narrower range for Sheets,
`fields` for Slides. Write tools are not checked: a completed write is
never reported as an error, so an agent is not led to repeat it.
- Drive, Docs, Slides and Sheets no longer have their own byte checks
(`boundedStructuredResult`, `boundedResult`, `sizedResult`,
`MAX_CONTENT_BYTES` removed). Drive downloads stop reading at the given
limit. The Sheets 50,000-cell limit stays.
- Two Drive tool descriptions no longer state a fixed number.
- Adapter `google-workspace-rest-dispatch.ts`: `maxResultBytes` is a
required input and is passed through.
- `tool-gateway.ts`: new `GOOGLE_WORKSPACE_REST_MAX_RESULT_BYTES`,
passed on the REST branch.
- Folder README: new "Result size" section with the limits and costs;
old 250,000-byte text replaced.
- Docs: `doc/memory/google-connector-memory.md`, the production
checklist and the code-fix plan now list #22026 to #22029, the REST
status (36 of 36, none switched on), the November 17 decisions, the
known differences from Google's tools, open risks and next steps.

## Verification

- `cd server && npx vitest run src/google-workspace-rest-tools` passes
(53 files, 1,361 tests with the adapter test).
- New `result-budget.test.ts`: for Gmail (read, list), Calendar (list,
read), Drive, Docs, Slides and Sheets, a result just under a given
budget is returned and one just over is refused with the tool's advice.
Without a budget, the fallback applies; with a larger budget, the same
result is returned. Drive downloads use the given cap. A Gmail list
tells the caller to lower `pageSize`. A Gmail draft result over the
budget is still returned, not an error. `defineTool` refuses a read tool
without advice and a write tool with it.
- `npx vitest run src/services/google-workspace-rest-dispatch.test.ts`:
the adapter passes the gateway's number, and the folder applies exactly
that number.
- `npx vitest run src/__tests__/google-workspace-rest-transport.test.ts`
(24 tests): with Gmail on REST, a 330 KB email passes the gateway with
screening, is more than 500,000 bytes delivered, and
`captureRunnerToolResult` turns it into a `read_tool_result` pointer. A
520 KB email is refused with `tool_error` and the advice, after one
Google request.
- `npx tsc --noEmit -p server/tsconfig.json`: no errors.
- `pnpm verify --explain`: broader verification required (a doc under
`doc/` is a global CI input). CI supplies that coverage.
- Time per call: the check is one `JSON.stringify` of the result. About
5 µs for a 4 KB result, 18 µs for 42 KB, 0.24 ms for 700 KB. Drive,
Docs, Sheets and Slides had the same pass before, so they add nothing.
Gmail and Calendar add this one pass.

## Risks

- Gmail and Calendar results now have a limit. Direct callers that pass
no limit get the 250,000-byte fallback. The gateway always passes its
number.
- Drive, Docs, Slides and Sheets accept results up to about 4 times
larger than before through the gateway. Large results reach agents as
artifact pointers.
- Error text for oversized results changed to one shared form.
- No service is switched to REST, so users see no change today.

## Model Used

Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used in Claude Code with
tool use (shell, file edits, GitHub CLI) and extended reasoning.

## 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-17 13:05:13 -06:00
DottaandClaude Opus 5.5 ceaf574421 feat(google-workspace): REST-backed Drive tools in server/src/google-workspace-rest-tools (#22028)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents use Google Workspace through the tool gateway, and Paperclip
is replacing Google's preview MCP servers with its own tools over
Google's REST APIs (`server/src/google-workspace-rest-tools/`)
> - Gmail and Calendar are done there. Drive has no REST tools yet, so
Drive cannot switch to the REST transport
> - Drive is the hard service: file content must be exported or
downloaded, kept under a size cap, and never sent to another host;
search needs a safe query; writes run under the narrow `drive.file`
scope
> - This pull request adds the eight allowlisted Drive tools, with the
same names, inputs and result shapes as Google's Drive MCP tools
> - The benefit is that Drive can switch to `paperclip_rest` once the
switch is approved, with no broader scope and no new dependency

## Linked Issues or Issue Description

Refs #22000, #22014, #22016, #22017 (earlier parts of the same REST tool
set). Related open PRs in the same folder: #22027 (Sheets).

**What problem does this solve?**
The REST tool set has no Drive tools.
`googleWorkspaceRestTransportGaps()` blocks a Drive switch while any
allowlisted Drive tool is missing.

**Proposed solution**
Add `drive/` with the eight tools on the allowlist (`toolScopes.drive`),
a Drive probe, and the Drive paths in `google-http.ts`.

**Alternatives considered**
Converting PDFs and Office files to Google Docs to extract text. That is
a write, so the read tool does not do it.

## What Changed

- `drive/`: `search_files`, `list_recent_files`, `get_file_metadata`,
`get_file_permissions`, `read_file_content`, `download_file_content`
(reads, `drive.readonly`), `create_file`, `copy_file` (writes,
`drive.file`). One file per tool, pure request and result functions,
table-driven tests with synthetic fixtures.
- `drive/query.ts`: parses Google's MCP search syntax into a tree,
checks terms and operators, and writes a new Drive `q` string with every
value re-escaped. Adds `trashed = false` unless the query uses
`trashed`. Unsupported terms are errors, not ignored.
- Content: Google Docs are exported as Markdown (read) or plain text
(download), Sheets as CSV of the first sheet (the read text says so),
Slides as plain text. Binary files are downloaded and base64 encoded.
Every Drive read result is bounded after serialization to 250,000 bytes
(the payload is carried twice, in text and structured content); a larger
result is an error that says how to read less, never cut-short content.
`exportMimeType` must be a format Google lists for the file type, and
every request uses the caller's `fileId`. `create_file` and `copy_file`
are annotated as non-idempotent writes; an annotations test checks all
eight tools.
- `google-http.ts`: per-host path prefix lists, required for every host
(`www.googleapis.com` → `/calendar/v3/`, `/drive/v3/`,
`/upload/drive/v3/`; `sheets.googleapis.com` → `/v4/spreadsheets/`;
`gmail.googleapis.com` → `/gmail/v1/users/me/`, which had no prefix
before, so any path was accepted on that host); a bounded `download()`
for raw bytes; raw upload bodies for multipart uploads; `redirect:
"manual"` with any 3xx turned into a tool error; Drive error reasons
`exportSizeLimitExceeded` and `appNotAuthorizedToFile` mapped to clear
messages.
- `google-http.test.ts`: the host and path allowlist test is now one
table with Sheets rows (allows `/v4/spreadsheets/{id}` and
`/v4/spreadsheets/{id}:batchUpdate`; rejects `/v4/spreadsheets`,
`/v4/other`, `/v4/spreadsheets/../other`, and the Sheets path on
`www.googleapis.com`) and a structural check that every host in
`GOOGLE_API_HOSTS` has at least one allowed and one rejected row.
- `errors.ts`: new `too_large` kind. `probe.ts`: Drive probe
(`about.get`, `fields=kind`), allowed by `drive.readonly` or
`drive.file`.
- `allowlist.test.ts`: Drive 8 of 8; only `create_file` and `copy_file`
write; no update, delete, trash, move or share tool.
- README: Drive section with an endpoint-and-scope table (one Google
reference URL per row), content formats, size caps, requests per call,
and differences from Google's tools.
- Outside the folder, one line:
`server/src/services/google-workspace-rest-dispatch.test.ts` used
`drive` as its example of an unimplemented service. It now uses `chat`.
After merging master (#22026), this file and
`google-workspace-rest-transport.test.ts` pass with Drive added; no
other change was needed.

## Verification

- `cd server && npx vitest run src/google-workspace-rest-tools`: 46
files with the dispatch and transport tests (after merging master with
Sheets), 992 tests pass.
- `cd server && npx tsc --noEmit -p .`: no errors in the folder.
- `pnpm verify`: exit 2 (README is a broad input); required CI supplies
the broad checks.
- Not run: live calls to Google. All tests use synthetic responses.

## Risks

- `copy_file` under `drive.file`: Google does not document whether a
token with `drive.readonly` + `drive.file` can copy a file the app never
created or opened. If not, the tool returns a clear error and nothing is
copied. A live check on the test account is needed before the switch.
- `google-http.ts` now uses `redirect: "manual"` for every request. A
redirect from Gmail or Calendar was a retried network error before and
is now a clear tool error. Google's APIs do not redirect these calls.
- Drive stays on `google_mcp`; nothing calls these tools until the
switch is flipped.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, via Claude Code with
tool use (shell, file edits, web fetch of Google's public docs).

## 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-17 12:06:00 -06:00
DottaandClaude Opus 5.5 f61b919701 feat(google-workspace): REST-backed Docs and Slides tools; mark Calendar update_event destructive (#22029)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The Google Workspace connector gives agents Google tools through the
tool gateway
> - Google's hosted Workspace MCP servers are a Developer Preview, so
Paperclip launches on its own tools over Google's REST APIs, in
`server/src/google-workspace-rest-tools/`
> - Gmail and Calendar are done there; Docs and Slides have no tools yet
> - This pull request adds `read_doc`, `update_doc`, `read_presentation`
and `update_presentation` with the same names and inputs as Google's MCP
tools
> - The benefit is that the Docs and Slides services can switch to
`paperclip_rest` once their API is enabled, and reviewers see a full
document in Paperclip

## Linked Issues or Issue Description

**Subsystem affected**
Google Workspace REST tool set
(`server/src/google-workspace-rest-tools/`), Docs and Slides services.

**Problem or motivation**
The REST tool set has no Docs or Slides tools. The allowlist
(`toolScopes.docs`, `toolScopes.slides`) names two tools for each
service. A service cannot switch to `paperclip_rest` until all of its
allowlisted tools exist.

**Proposed solution**
Add the four tools in new `docs/` and `slides/` folders. Each tool makes
exactly one REST call. The read tools return the whole file as
Markdown-style text plus an index structure for edits. The update tools
post `batchUpdate` requests in order and require the revision ID that
the caller read.

**Alternatives considered**
Return the raw `documents.get` JSON. It is 10 to 20 times larger than
the text, so ordinary documents go over the result size limit, and it is
hard to compare with Google Docs. Reorder edit requests by index. That
changes what dependent requests do, and Google's tool does not do it.

Refs #22000, #22014, #22017

## What Changed

- `docs/`: `read_doc` (`documents.get` with `includeTabsContent=true`)
and `update_doc` (`documents.batchUpdate`), a renderer for every tab,
child tab, heading, list (real numbering), table, link, header, footer,
footnote, chip, suggestion and comment, and an index structure where
each paragraph's `text.length` equals `endIndex - startIndex`.
- `slides/`: `read_presentation` (`presentations.get`; with `fields` it
returns Google's resource as is) and `update_presentation`
(`presentations.batchUpdate`), a renderer for every slide's text,
tables, groups, media and speaker notes.
- `documents-shared.ts`: the 250,000-byte limit on the final serialized
result (an error, never a cut-short result), the revision-conflict
error, comment rendering, and argument checks.
- Update tools require `writeControl.requiredRevisionId` and refuse
`targetRevisionId`. A revision conflict returns "nothing was changed;
read it again". Writes are never retried.
- `google-http.ts`: allows `docs.googleapis.com` only under
`/v1/documents/` and `slides.googleapis.com` only under
`/v1/presentations/`.
- `tools.ts`, `probe.ts`: register the services. Docs and Slides have no
network probe, because every read needs a file ID.
- Update tools accept only a closed list of batch request kinds
(`docs/request-kinds.ts`, `slides/request-kinds.ts`). Kinds and forms
that read another file are refused by name: `insertRichLink`, the Sheets
chart kinds, `importSlides`, `createAudio`, Drive videos, and images
from Drive or Docs links. Unknown kinds are refused too.
- `read_doc` always requests `SUGGESTIONS_INLINE` and falls back to an
explicit `PREVIEW_WITHOUT_SUGGESTIONS` read for view-only users; the
result says which view it used.
- Tables with merged cells are placed on the full grid; covered cells
read `(merged left)` or `(merged up)`.
- Revision conflicts are recognized from Google's `error.status` and
`error.details` first, with the message as a fallback.
- Annotations: `update_doc` and `update_presentation` are destructive
and not idempotent. **Calendar `update_event` is now also marked
destructive** (it overwrites fields, removes attendees and replaces
reminders). Google's references mark both non-destructive; the README
records this.
- `README.md`: endpoint and scope table with Google's documentation
links, the result format, what cannot be shown, update order and
revision rules, and every difference from Google's tools.

## Verification

- `cd server && npx vitest run src/google-workspace-rest-tools`: 33
files, 573 tests pass (169 new in `docs/` and `slides/`, plus host,
probe and allowlist tests).
- `cd server && pnpm typecheck`: passes.
- `pnpm verify`: exit 2 (README is a broad input), so required CI
supplies broad coverage.
- `src/services/google-workspace-rest-dispatch.test.ts` fails the same
way on `master` (it still expects Gmail to be incomplete after #22014).
This PR does not touch it.

## Risks

- Low risk. Nothing calls these tools until the Docs or Slides transport
is set to `paperclip_rest`; both stay `google_mcp`.
- The inner format of `content` differs from Google's tool, which Google
does not publish. The README lists this.
- Revision-conflict detection matches Google's 400 message on
"revision". Any 400 rejects the whole batch, so nothing changes in
either case.

## 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-17 17:28:13 +00:00
DottaandClaude Opus 5.5 c366a606b1 feat(google-workspace): REST-backed Sheets tools in server/src/google-workspace-rest-tools (#22027)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents reach Google Workspace through the built-in Google connector
and its tool gateway
> - Google's hosted Workspace MCP servers are a Developer Preview, so
Paperclip will launch on its own tools over Google's REST APIs
(`server/src/google-workspace-rest-tools/`)
> - Gmail and Calendar are there; Sheets has no REST tools yet, so a
Sheets grant has no tools when the connector runs on REST
> - This pull request adds the six Sheets tools that `toolScopes.sheets`
allows, with the same names, inputs and result shapes as Google's Sheets
MCP tools
> - The benefit is that Sheets can switch to `paperclip_rest`, and later
back to Google's MCP servers, without a rewrite

## Linked Issues or Issue Description

Refs #22000
Refs #22017

**Subsystem affected**
Google Workspace REST tool set,
`server/src/google-workspace-rest-tools/`.

**Problem or motivation**
The REST tool set has no Sheets tools. Agents with a Sheets grant cannot
read or write spreadsheets when the connector runs on REST.

**Proposed solution**
One file per tool under `sheets/`, with pure argument-to-request and
response-to-result functions. Names, fields and annotations come from
Google's Sheets MCP reference
(https://developers.google.com/workspace/sheets/api/reference/mcp). Each
tool uses only the scopes its allowlist entry permits. The README lists
the endpoint, scope and Google documentation URL for each tool, the
value handling, the bounds, and every difference from Google's tools.

**Alternatives considered**
Reuse `packages/google-sheets-mcp-server`. It has its own tool names and
shapes, and the folder's boundary test forbids the import.

## What Changed

- `sheets/get-values.ts`: `get_values` over `spreadsheets.values.get`,
formatted values, rows first (the REST defaults, sent explicitly).
Google's answer is returned unchanged (`range`, `values`).
- `sheets/get-spreadsheet.ts`: `get_spreadsheet` over `spreadsheets.get`
with `includeGridData`, `ranges` and `fields`. `commentsIncluded: true`
is refused because REST cannot return comments.
- `sheets/update-values.ts` and `sheets/update-formulas.ts`:
`spreadsheets.values.update` with `valueInputOption` `RAW` and
`USER_ENTERED`. Each description names its option.
- `sheets/insert-dimension.ts`: one `insertDimension` request through
`spreadsheets.batchUpdate`.
- `sheets/update-spreadsheet.ts`: `spreadsheets.batchUpdate` with the 64
request types Google documents that REST supports. Comment and data
source requests, unknown request types and `writeControl` are refused
before sending. The tool is marked `destructiveHint: true` because
Google's list includes `deleteSheet`, `deleteDimension`, `deleteRange`
and other removing operations.
- `sheets/range.ts`: A1 and R1C1 range validation, sheet-name quoting,
and range descriptions for write results.
- Bounds: at most 50,000 cells read or written per call and 450,000
characters per read result (under the gateway's 1 MB limit). Over a
limit, the tool returns an error that asks for a narrower range. It
never returns a cut-off result.
- Write results: Google's REST response under `content`, plus a `status`
sentence that names the changed ranges and the number of cells.
- `google-http.ts`: allows `sheets.googleapis.com` only under
`/v4/spreadsheets/`.
- `probe.ts`: Sheets has no probe, because every Sheets read needs a
spreadsheet ID.
- `tools.ts`, `allowlist.test.ts`, `README.md`: register the service,
check Sheets 6 of 6, and document the tools.

## Verification

- `cd server && npx vitest run src/google-workspace-rest-tools`: 34
files, 647 tests pass. The Sheets tests use synthetic fixtures and a
fake fetch. There is no network and no real spreadsheet.
- Table-driven tests cover ranges (accepted and refused, quoting round
trips), request building for each tool, result shapes, cell and size
bounds, the uncertain-outcome warning on failed writes without a retry,
the host path restriction, the absent probe, and each tool's scopes.
- `npx tsc --noEmit -p server`: no errors in
`server/src/google-workspace-rest-tools/`. Other errors in this local
run come from workspace packages that were not built.
- `pnpm verify`: exit 2 (the README is a broad input). Required CI
supplies the broad coverage.

## Risks

- Low risk. Nothing calls these tools until Sheets is set to
`paperclip_rest` in `GOOGLE_WORKSPACE_TOOL_TRANSPORT`. That setting
stays `google_mcp`.
- Google's reference does not name the value input option of
`update_values` or the render option of `get_values`. This PR uses `RAW`
and formatted values. A recorded comparison on Google's servers can
confirm both. The README lists this.
- `update_spreadsheet` accepts the removing operations that Google
documents, such as `deleteSheet`. Approval and audit stay with the
gateway.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, through Claude Code
with tool use (shell, file edits, web fetch).

## 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-17 10:59:22 -06:00
DottaandClaude Opus 5.5 1d3b4201e3 feat(google-workspace): remaining Gmail read tools in the REST tool set (#22014)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents use Gmail through the built-in Google Workspace connector
> - Google's hosted Gmail MCP server is a Developer Preview, so
Paperclip launches on its own REST-backed tool set in
`server/src/google-workspace-rest-tools/` (#22000)
> - That folder has 3 of the 9 Gmail tools on the reviewed allowlist
(`toolScopes.gmail`)
> - Agents cannot read a whole thread, list drafts, list labels or
search single messages
> - This pull request adds the 6 missing read tools, with the same
names, inputs and results as Google's MCP tools where Google documents
them
> - The benefit is that Gmail is complete on the REST transport, and a
message looks the same from every tool

## Linked Issues or Issue Description

Refs #22000

**Problem**
The REST-backed Gmail tool set implements only `get_message`,
`search_threads` and `create_draft`. The allowlist also names
`get_thread`, `get_draft`, `list_drafts`, `list_labels`, `list_threads`
and `search_messages`.

**Proposed solution**
Implement the 6 read tools in the folder. Follow the existing patterns:
one file per tool, pure request and result functions, synthetic unit
tests.

**Why it matters**
Google's reviewers compare an email in Paperclip with the same email in
Gmail. Full threads and drafts must show complete bodies.

## What Changed

- Add `get_thread`, `list_drafts` and `list_labels`. Their schemas come
from Google's Gmail MCP reference.
- Add `get_draft`, `list_threads` and `search_messages`. Google's
reference does not list them, so their schemas copy the sibling tools.
The README lists them under "Not verified against Google's servers".
- Move separately stored body reads from `get_message` into
`readMessageBodies` in `gmail/message.ts`. All tools that return bodies
use it. A body that cannot be read fails the call with "Could not read
the full body of this message".
- Add `gmail/parallel.ts`: a 10-at-a-time read pool that stops after the
first failure, and a helper that skips items deleted between list and
get.
- Cap page sizes (50 for threads, messages and drafts; 500 for labels,
which Gmail returns in one request). The README has a table of Google
requests per call at the maximum page size.
- Update descriptions: `search_threads` now points to `get_thread` and
`list_labels`. The `label:` search operator takes label names (spaces as
hyphens), not IDs. This corrects the wording in the original tools.
Google's MCP reference says IDs; the README records the difference, and
a test prevents drift.
- Cap separately stored body reads at 20 per call. The README lists
requests and quota units per call at the maximum page size.
- `allowlist.test.ts` now asserts that Gmail implements all 9
allowlisted tools and that only `create_draft` writes.

## Verification

- `cd server && npx vitest run src/google-workspace-rest-tools`: 15
files, 156 tests pass. Tests use synthetic fixtures and a fake `fetch`
only.
- `cd server && npx tsc --noEmit -p .`: passes.
- `pnpm verify`: exit 2 (the README is a broad input). Required CI
supplies the broad coverage.
- Tests prove: each tool maps messages exactly as `get_message` does;
separately stored bodies are fetched; a failed body read is an explicit
error; request counts at the maximum page size (51); invalid IDs send no
request; caller cancellation stops the call.

## Risks

- Low risk. Nothing outside the folder imports it yet
(`boundary.test.ts`).
- `get_draft`, `list_threads` and `search_messages` have no Google
schema. A switch back to Google's MCP servers would drop them unless
Google adds them.
- `list_labels` leaves out `threadsTotal` and `threadsUnread`: REST
returns them only with one request per label.
- One call reads at most 20 separately stored bodies. Beyond that it
returns an explicit "Could not read the full body of every message"
error and fetches none. The worst single call is 71 requests and 3,405
Gmail quota units (per-user limit: 6,000 per minute). A second maximal
call in the same minute can get a `rate_limited` tool error.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, via Claude Code with
tool use (file edits, shell, web fetch of Google's public reference).

## 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-17 09:51:17 -06:00
DottaandClaude Opus 5.5 c652c813bc feat(google-workspace): per-service transport switch for REST-backed tools (off by default) (#22016)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents use Google Workspace through one built-in `google-workspace`
connection and the tool gateway
> - Today every Google tool call goes to Google's hosted Workspace MCP
servers, which are a Developer Preview and cannot be offered to the
public
> - #22000 added Paperclip's own Gmail tools over Google's REST APIs in
`server/src/google-workspace-rest-tools/`, but nothing calls them yet
> - This pull request adds one per-service transport switch and connects
the gateway to the REST tools behind it. Every service stays on Google's
MCP servers, so production behavior does not change
> - The benefit is that a service moves to the REST tools with a
one-line, reviewed change once all its tools exist, and moves back the
same way

## Linked Issues or Issue Description

Refs #22000

**Subsystem affected**
Tool gateway and catalog discovery for the built-in Google Workspace
connection.

**Problem or motivation**
Google's Workspace MCP servers are a Developer Preview. Paperclip
launches on its own tools over Google's REST APIs. The REST tools exist
(#22000), but the gateway cannot call them, and there is no way to
choose them per service.

**Proposed solution**
Add a per-service transport setting (`google_mcp` or `paperclip_rest`)
in the shared Google Workspace module. Add one server adapter that is
the only importer of the REST folder. When a service is set to
`paperclip_rest`, the gateway call path and discovery use the adapter in
process. All gateway controls stay the same.

**Alternatives considered**
A loopback or hosted MCP endpoint for the REST tools. It adds a
connection, JSON-RPC framing and the protocol probe to every call, and
authenticated public deployments refuse loopback addresses. An
environment variable or instance setting. A plain constant keeps every
flip a reviewed code change.

## What Changed

- `packages/shared/src/google-workspace-connectors.ts`: adds
`GOOGLE_WORKSPACE_TOOL_TRANSPORT` (every service is `google_mcp`),
`transport` on the result of `googleWorkspaceToolTarget`, and
`googleWorkspaceServiceToolNames`.
- New `server/src/services/google-workspace-rest-dispatch.ts`: the only
importer of the REST folder. It keeps only the bearer token from the
gateway's credential headers, passes the gateway's egress-guarded fetch
and cancellation signal, and returns either the MCP result or a token
problem. `googleWorkspaceRestTransportGaps()` lists allowlisted tools
that a `paperclip_rest` service does not implement. Today Calendar is
eligible (9 of 9) and Gmail is not (3 of 9); nothing is flipped.
- `server/src/services/tool-gateway.ts` (`executeRemoteHttpTool`): for a
`paperclip_rest` tool, the gateway rechecks the current grant, calls the
adapter, and returns through the same result handling as the MCP path.
Google's insufficient-scope answer maps to `oauth_insufficient_scope`. A
rejected token forces a refresh and returns
`oauth_refreshed_retry_required` without a replay. A passed deadline
returns `tool_timeout`. The audit record names the protocol `Google
Workspace REST`. The grant recheck is now one shared helper for both
paths. A timed-out Google Workspace write, on either transport, now
returns `tool_timeout` with a warning that the change may or may not
have been made; a timed-out read keeps the plain timeout message.
- `server/src/services/tool-access/catalog/discovery.ts`: for a
`paperclip_rest` service, discovery and health run one REST probe with
the caller's token, then list the REST tools under the same names and
scope filter. A 401 refreshes and probes again. A second 401 on a
managed grant marks it `needs_reauthorization`. Any other probe failure
makes only that service unavailable.
- `server/src/google-workspace-rest-tools/`: adds `probe.ts` and its
export. Each service has an ordered list of cheap reads with the scopes
that allow each (Gmail: `users.getProfile`; Calendar: one calendar list
entry, one primary-calendar event, or one minute of free/busy). The
probe uses the first read the grant allows. A grant that allows none is
listed without a probe, and an insufficient-scope answer never drops a
service. It also and lets `boundary.test.ts` allow exactly the adapter
as the importer. The README now describes the implemented seam, how to
flip a service, and the removal procedure.
- `doc/connections/GOOGLE-WORKSPACE.md`: describes the transport
setting.
- `tests/runner-e2e/source-sdk-public-inputs.json`: refreshed pins for
the changed shared files.

## Verification

- `cd server && npx vitest run
src/__tests__/google-workspace-rest-transport.test.ts`: 15 tests. They
were red before the gateway and discovery changes (10 failed), and green
after. With Gmail set to `paperclip_rest` through a test-only change of
the map, the tests use the real managed setup, discovery, gateway,
policy and screening with a fake Google fetch. They prove: discovery
lists the same tool names filtered by scopes after one probe; a read
runs with the caller's token and is audited; a draft waits for approval
and then runs; a tool outside the grant and a narrowed grant are refused
before any Google request; Google's insufficient scope maps to
`oauth_insufficient_scope`; a 401 refreshes the token, is not replayed,
and the retry uses the new token; an injected email is blocked; a passed
deadline aborts the Google request and returns `tool_timeout`; the
experimental-feature gate stops calls and discovery; a failed Gmail
probe leaves Docs usable and Gmail comes back; a lasting 401 asks for
reconnection. A timed-out draft carries the uncertain-write warning in
the error, the invocation record and the audit entry on both transports,
and an approved REST draft whose request was lost returns the warning.
With the default map, a call goes to `gmailmcp.googleapis.com` and the
adapter is never called.
- `cd server && npx vitest run
src/services/google-workspace-rest-dispatch.test.ts
src/google-workspace-rest-tools`: eligibility (no partial flip),
bearer-only forwarding, signal and fetch pass-through, token outcome
mapping, probe, boundary.
- `cd packages/shared && npx vitest run
src/google-workspace-connectors.test.ts`: every service defaults to
`google_mcp`.
- Existing Google tests are unchanged and pass:
`google-workspace-injection-screening.test.ts`, the Google cases in
`tool-gateway-service.test.ts` and `tool-access-service.test.ts` (142
Workspace/Google/Gmail cases).
- `npx tsc --noEmit` for `packages/shared` and `server`: clean.
- `pnpm verify`: exit 2 (a doc under `doc/` is a global CI input), so
required CI supplies broad coverage.
- Speed, stubbed fetch, 300 calls after warm-up: the adapter adds about
15 µs per call. A full `gmail__get_message` through `executeTool` took a
median of 18.2 ms on REST and 18.3 ms on MCP (p90 21.6 ms and 22.3 ms).
The REST path adds no waits, no extra round trips and no dynamic
imports.

## Risks

- Low risk for production: every service stays on `google_mcp`, and the
default-map test proves the adapter is not called.
- The server now loads the REST folder at start. It uses only modules
the server already loads (MCP SDK, zod).
- A later flip must add a probe and the API host for each new REST
service. The `Record` type of the probe table makes typecheck fail when
a REST service has no probe.
- On `paperclip_rest`, MCP resources, MCP Tasks and elicitation do not
exist for that service.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, through 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
- [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-17 09:49:49 -06:00
DottaandClaude Opus 5.5 c41ca4a992 feat(google-workspace): REST-backed Calendar tools in server/src/google-workspace-rest-tools (#22017)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents use Google Workspace through the built-in Google connector
and its tool gateway
> - Google's hosted Workspace MCP servers are a Developer Preview, so
Paperclip launches on its own tools over Google's REST APIs
(`server/src/google-workspace-rest-tools/`, added in #22000 with three
Gmail tools)
> - Calendar has nine allowlisted tools and none of them exist in the
REST tool set yet
> - The tools must keep Google's MCP names, inputs and results, so
Paperclip can switch back to Google's servers later
> - This pull request adds the nine Calendar tools, and the HTTP support
they need, inside the isolated folder
> - The benefit is that agents can read and change calendars with
exactly the scopes the allowlist grants

## Linked Issues or Issue Description

Refs #22000

**Feature description**
Add the nine Calendar tools that `toolScopes.calendar` allows to the
REST-backed Google Workspace tool set: `list_calendars`, `get_event`,
`list_events`, `search_events`, `suggest_time`, `create_event`,
`update_event`, `delete_event` and `respond_to_event`.

**Problem it solves**
The REST tool set has only Gmail tools. A Calendar grant has no tools
when the connector runs on REST.

**Proposed solution**
One file per tool under `calendar/`, with pure argument-to-request and
response-to-result functions. Names, fields and annotations come from
Google's Calendar MCP reference. Each tool uses only the scopes its
allowlist entry permits. The README lists the endpoint and scope for
each tool, the time rules, the notification defaults, the `suggest_time`
algorithm, and every difference from Google's tools.

## What Changed

- `calendar/`: nine tools, shared event mapping (`event.ts`), input
building (`event-input.ts`), JSON schemas, synthetic fixtures, and
`probeCalendar()` (one `calendarList.list` with `maxResults=1`) for a
health check.
- `calendar/time.ts`: time zone arithmetic with `Intl` only. It reads
offset-less times in a given IANA zone, handles DST gaps and repeated
hours (Temporal `compatible` rule), and never guesses a zone.
- `google-http.ts`: adds `www.googleapis.com` to the allowed hosts, but
only under `/calendar/v3/` (checked after URL normalization). Adds
PATCH, PUT and DELETE. All are writes: never retried, and failures after
dispatch carry the uncertain-outcome warning. A POST marked `readOnly`
(free/busy) is a read. Adds `If-Match`. Maps 412 to "nothing was
changed" and 410 to not found.
- `tools.ts`: registers the `calendar` service.
- `allowlist.test.ts`: asserts Calendar is fully implemented (9 of 9).
- `README.md`: Calendar section (endpoints and scopes, time handling,
notifications, `suggest_time`, differences) and two open questions.

## Verification

- `cd server && npx vitest run src/google-workspace-rest-tools`: 19
files, 330 tests pass. Of these, about 210 are new Calendar tests in 11
files, plus new `google-http` tests for PATCH, PUT, DELETE, read-only
POST, `If-Match`, 410, 412 and the path restriction, and the 9-of-9
allowlist assertion. Table-driven tests cover all-day versus timed
events, IANA zones with 30-minute and half-hour offsets, DST gaps and
repeated hours in New York, London and Lord Howe, recurring series and
single occurrences, pagination (including `startTimeDesc` paging),
free/busy fallback, notification mapping, and write failures (no retry,
uncertain-outcome warning). All fixtures are synthetic; no network.
- `cd server && npx tsc --noEmit -p .`: passes.
- `pnpm verify`: exit 2 (the README is a broad input), so required CI
supplies broad coverage.

## Risks

- Low risk. Nothing outside the folder imports it yet, so no runtime
path changes until the gateway wiring lands.
- Write tools follow Google's documented notification defaults:
`create_event`, `update_event` and `delete_event` email all attendees by
default; `respond_to_event` emails external attendees by default. Tool
descriptions say this, and `NONE` sends nothing.
- `freeBusy.query` does not accept `calendar.events`. A read and write
grant has no free/busy scope, so `suggest_time` falls back to reading
each attendee's calendar. That fallback cannot see coworkers who share
only free/busy. The README proposes adding `calendar.events.freebusy` to
the `calendar.write` profile.
- `delete_event` refuses a whole recurring series on purpose: it deletes
single events and single occurrences only, and sends no delete for a
series ID. This differs from REST and from Google's tool. `update_event`
and `respond_to_event` on a series ID change the whole series; their
descriptions say so, and the result shows series (`recurrence`) or
occurrence (`recurringEventId`).
- `list_events` page tokens carry the first page's time range, so later
pages stay consistent.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, in Claude Code with
tool use (shell, file edits, web fetch of Google's public reference
pages).

## 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-17 15:01:29 +00:00
DottaandClaude Opus 5.5 a29658b5b7 feat(google-workspace): REST-backed Gmail tools in server/src/google-workspace-rest-tools (#22000)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents use Google Workspace through the built-in Google Workspace
connector
> - Today the connector sends each tool call to Google's hosted
Workspace MCP servers
> - Those servers are a Developer Preview, so we cannot offer them to
the public
> - The owner decided to launch on our own tools over Google's GA REST
APIs, with the same tool names, inputs and results, in one folder that
we can delete later
> - This pull request adds that folder inside the server, with its first
three Gmail tools, and a written trace of where it will plug in
> - The benefit is a public-ready Gmail path that we can switch back to
Google's MCP servers with one setting, with no new package to publish

## Linked Issues or Issue Description

Refs #21996 (plan and working memory for the Google Workspace connector,
section 9)
Refs #15412 (an earlier community Gmail REST MCP server; this code
follows Google's MCP tool contract instead)

**Subsystem affected**
Connections: the Google Workspace connector and the tool gateway.

**Problem or motivation**
Google's Workspace MCP servers are a Developer Preview. We cannot launch
the Google Workspace connector to the public on them.

**Proposed solution**
Add `server/src/google-workspace-rest-tools/`. It exposes the same tools
as Google's MCP servers over the GA REST APIs. It knows nothing about
Paperclip. A later pull request selects it per service with one switch.

**Alternatives considered**
A separate npm package (it would have to be published, because the
server is published) and a loopback or hosted HTTP MCP endpoint. The
README explains why an in-process call is better: speed, token handling,
and the egress guard, which refuses loopback addresses on public
deployments.

## What Changed

- New folder `server/src/google-workspace-rest-tools/` inside the
existing server package. No new npm package, no new dependency, no
workspace, Docker, lockfile or release change. Every changed file is in
this folder.
- `index.ts` is the only entry point. `boundary.test.ts` enforces that
the folder imports only its own files, Node built-ins,
`@modelcontextprotocol/sdk` and `zod` (both existing server
dependencies; tests may also import `vitest` and `@paperclipai/shared`),
and that no other server code imports the folder yet.
- `google-http.ts` is the only code that calls `googleapis.com`. It sets
the bearer header, allows only listed hosts, has a 20 s deadline and a
20 MB response limit, and retries a read once. It never retries a write.
Every write that fails after it is sent says that the change may or may
not have been made.
- Token errors are thrown as `GoogleWorkspaceAuthError` (an `McpError`).
401 gives `unauthenticated`. 403 insufficient scope gives
`insufficient_scope`, the code the gateway already recognizes. Other
Google errors become tool error results.
- Gmail tools `get_message`, `search_threads` and `create_draft`. Names,
fields, types and enums follow Google's Gmail MCP reference.
`create_draft` calls only `drafts.create`. There is no send tool.
- `get_message` reads bodies that Gmail stores as attachments, and
returns an explicit error, never a body-less `FULL_CONTENT` result.
Address lists are parsed by a single-pass RFC 5322 tokenizer
(`gmail/address.ts`, table-driven tests including IPv6 domain literals
and malformed input); quoted search text and long draft headers are
handled.
- `server.ts`: a thin MCP server (`tools/list`, `tools/call`).
`callGoogleWorkspaceRestTool()` is the in-process equivalent.
- `allowlist.test.ts` fails if a tool is not in `toolScopes` in
`packages/shared/src/google-workspace-connectors.ts`, if its read-only
hint disagrees with the allowlist, or if a description names a tool the
folder does not list.
- `README.md`: purpose, boundary rules, the dispatch trace, the
recommended in-process seam and the files the switch PR touches, known
differences from Google's tools, and the removal procedure (delete the
folder, set the switch to `google_mcp`).
- No code comments. Explanations are in the README.

## Verification

- `cd server && npx vitest run src/google-workspace-rest-tools`: 8
files, 98 tests pass. Tests use synthetic REST fixtures and a fake
fetch. No network.
- Each review fix has a test that fails on the revision before it (10
tests red on `d65b51d245`, 3 more red on `5d7d52ec86`). The boundary
test fails when a probe file in the folder imports `../errors.js`.
- `tsc --noEmit` with the server's `tsconfig.json` settings over the
folder passes.
- `pnpm check:module-boundaries` passes.
- `pnpm verify` exits 2 because a new file under `server/src` is a broad
input. Required CI supplies the broad coverage.
- Local timing probe with a stubbed fetch: about 13 µs overhead per
call.

## Risks

- Low risk. Nothing imports the folder yet, so runtime behavior does not
change.
- The tool descriptions are our own wording. A contract test against a
recorded `tools/list` from Google's servers comes in a later pull
request.
- The allowlist names three Gmail tools (`get_draft`, `list_threads`,
`search_messages`) that Google's published Gmail MCP reference does not
list. The README flags this.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use
(shell, file edits, web fetch of Google's public reference pages).

## 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
- [x] All Paperclip CI gates are green
- [x] 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-17 08:13:01 -06:00