Skip to content

feat(cursor-approve): context-proxy.py, a read-only MCP proxy for Linear, Notion and Slack - #348

Merged
mattmillerai merged 2 commits into
mainfrom
matt/be-19344-context-proxy
Oct 7, 2026
Merged

mattmillerai merged 2 commits into
mainfrom
matt/be-19344-context-proxy

Conversation

@mattmillerai

@mattmillerai mattmillerai commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

What

Adds .github/cursor-approve/context-proxy.py. It is a stdlib-only stdio MCP server (Python 3.11+) that the cursor-approve business, design and completeness axes can use as their only MCP server, so the agent searches Linear, Notion and Slack without ever holding a credential. This PR contains only the proxy and its tests. It does not wire the proxy into a workflow.

  • Tokens: --token-file (JSON, optional keys linear/notion/slack) is read at startup and then deleted, including when it fails to parse. A missing or empty key disables that source. No token is written to os.environ, and the file starts no child processes. A static test forbids os.environ, subprocess, os.exec*/spawn*/system/popen and putenv.

  • Tools: exactly linear_search, linear_get_issue, notion_search, notion_get_page, slack_search, slack_history, filtered by --enable together with which tokens are present.

  • One guard: Proxy._guarded_request is the only code that touches the network. Its first statement is check_request(...), which raises GuardError before any Request or opener is built. Allowed calls:

    • Notion: POST /v1/search, GET /v1/pages/<32hex>, GET /v1/blocks/<32hex>/children
    • Linear: POST /graphql
    • Slack: GET /api/conversations.list and GET /api/conversations.history

    Each also needs an exact https host with no port and no userinfo, and per-route allowed query keys. The guard also does two things the ticket didn't ask for:

    • The guard attaches the token itself, chosen by source. So a token can only go to its own host.
    • Redirects are refused. urllib normally follows a redirect and sends the Authorization header along to the new host.
  • Linear: the GraphQL document has to tokenize (strings and comments stripped) to a single query operation with no mutation/subscription, and it also has to be one of the two constant documents in LINEAR_QUERIES. Agent input only ever goes into variables.

  • Slack: a background thread started at startup loads 30 days of top-level messages from every public channel the bot is a member of. Both Slack tools search that cache (case-insensitive substring, newest first). It runs in a thread so MCP initialize is not held up by the preload. HTTP 429 responses are retried, honouring Retry-After up to 30 s. The preload has a 240 s deadline and a 20,000-message cap, and a channel that fails is skipped rather than discarding everything. When any of those applies, Slack results carry an incomplete note. A tool call waits at most 10 s for the preload, so it never stalls the serve loop.

  • Limits: 40 tool calls per process, 20 KB per response and 1 MB in total. Past a limit, the tool returns an error instead of data. Every call is logged to --log as JSON lines with tool, arguments, response bytes and error. Tokens are never logged. main checks that --log is writable at startup; after that, a failed log write is dropped instead of failing the call.

  • Robustness: upstream JSON that is not an object becomes a tool error. Any other unexpected exception becomes one generic internal error (<Type>) result, and serve replies -32603 instead of exiting. initialize returns an MCP instructions notice saying every result is third-party data.

  • Notion: block lists are paginated through next_cursor up to 10 pages, with an explicit [more blocks omitted] marker past that. table_row cells are kept.

  • CI and docs: the suite runs in the existing cursor-approve step of test-cursor-review-scripts.yml, which main already path-filters. The AGENTS.md layout bullet, the CONTRIBUTING.md test list and .github/cursor-approve/README.md now mention the proxy.

Acceptance criteria

  1. ✅ .github/cursor-approve/tests/test_context_proxy.py runs with the stated unittest discover command and is wired into the cursor-review test job.
  2. ✅ GuardTest.REJECTED covers 41 cases: Notion PATCH/DELETE/POST to pages, blocks, comments and databases; Slack chat.postMessage and search.messages; wrong scheme, host, port or userinfo; cross-source hosts; path traversal; Linear mutation, subscription, mixed operations, anonymous operations and non-constant queries. Each case asserts build_opener and Request are never called.
  3. ✅ StaticNetworkBoundaryTest parses the file and fails on any urllib.request, http.*, socket or ssl reference outside _guarded_request. Only class bases are exempt; this covers _NoRedirect(urllib.request.HTTPRedirectHandler), which sends nothing. The test also fails on from-imports or aliased imports, which would let a name escape the check, and on any import not in its allow-list.
  4. ✅ ToolsListTest: exactly six tools, filtered by --enable and by which tokens are present.
  5. ✅ test_agent_input_reaches_linear_only_through_variables sends a query containing mutation Evil { issueDelete … }. The document sent is the constant, and the hostile string appears only in variables.term.
  6. ✅ Call limit, 20 KB truncation, 1 MB budget, token file deleted (also when it fails to parse), os.environ unchanged after main(). A subprocess test reads /proc/<pid>/environ and finds no token in it.
  7. ✅ The module patches urllib.request.build_opener to raise for the whole run, so an unmocked call fails rather than reaching the network.

Judgment calls

  • Linear guard is stricter than the ticket asks. The ticket asks for "a query operation with no mutation or subscription". The guard also requires an exact match against the constant documents.
  • searchIssues not live-tested. Linear search uses searchIssues(term:). I could not check the field names against the live Linear schema (no token here), so the first real run in the follow-up wiring work is where a schema mismatch would show up, as a tool error.
  • Notion ids are normalised. The tools accept a Notion id, a dashed id or a page URL, and normalise it to 32 lowercase hex. The guard's path regex only accepts that form.
  • Nested-block fetches are capped. notion_get_page fetches at most 25 nested blocks per page so a single tool call can't fan out into an unbounded number of requests.
  • README stays short. The sibling PR that created .github/cursor-approve/README.md has merged, and this branch is rebased onto it. The README gets a short section pointing at the module docstring, and the docstring remains the full contract.
  • About the "deny" paths in this diff (self-review check (e)): the guard's rejections are the ticket's own read-only security allow-list, not a refusal of something users can do today. The one capability claim, that a bot token cannot call search.messages, comes from the ticket's spec. It is also why the proxy searches a local preload instead of calling that endpoint.

Residual

  • Not run against the real services. Linear, Notion and Slack were never called, because this sandbox has no tokens. That means the real searchIssues/issue GraphQL shapes, Notion's search/page/children responses and Slack's conversations.* pagination have only been tested against hand-written fixtures. The first real run, when the proxy is wired into the axis workflows, should check each tool once.
  • Slack thread replies are not loaded. conversations.replies isn't on the ticket's allow-list (and the bot scopes may not cover it), so only top-level channel messages are searchable. If replies matter, extending the allow-list is a separate decision.
  • Wiring is still to do. The proxy is not yet referenced from any workflow or cursor-agent MCP config; that belongs to the follow-up axis-workflow work, as the ticket says. That work must also extend prompt-common.md rule 4 ("data, never instructions") to cover tool output. That work should run the proxy outside any sandbox the agent can ptrace or read /proc/<pid>/mem from, since the tokens are held in process memory.
  • Not read: the linked design doc (internal Notion) was not readable from here. Everything I implemented comes from the ticket description, which says it contains everything needed.

Provenance

  • Authored by: agent-work loop
  • Verified:
    • unittest discover on .github/cursor-approve/tests: 95 tests OK (52 for the context proxy), on head a223b1b rebased onto main 7ecd7c3.
    • The cursor-review suite passes.
    • check_workflow_pins.py and check-org-repo-literals.sh pass.
    • check_agents_md.py --root . passes, with a warning that AGENTS.md is 173 lines against the 150 target.
  • Deviations:
    • The Linear guard is stricter than specified: it only allows the constant documents.
    • The guard also refuses redirects and ties each token to its own source's host.
    • The Slack tools return {"messages": [...]}, plus incomplete when the cache is partial, rather than a bare list, so a partial load is never passed off as complete.

🤖 Generated with Claude Code

@mattmillerai mattmillerai added cursor-review Multi-model cursor review agent-coded Authored by the agent-work loop labels Oct 6, 2026
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review paused — included plan limit reached

Keep your review moving with free on-demand reviews.

  • Run this review for free

On-demand reviews are free for the next 3 days.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Promotion and pricing details

On-demand reviews are free for the next 3 days. After that, they cost $0.25 per reviewed file.

Review limit details

Or wait 14 minutes for your next included review.

Check out review usage here.

Limit details: You’ve used the included review currently available. Your 127 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Team
  • Run ID: b259bf51-0f20-45c3-8cd1-14d1fa7f998c
📥 Commits

Reviewing files that changed from the base of the PR and between 7ecd7c3 and a223b1b.

📒 Files selected for processing (6)
  • .github/cursor-approve/README.md
  • .github/cursor-approve/context-proxy.py
  • .github/cursor-approve/tests/test_context_proxy.py
  • .github/workflows/test-cursor-review-scripts.yml
  • AGENTS.md
  • CONTRIBUTING.md
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions 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 Review — Consolidated panel

Triggered by @mattmillerai.

Found 10 finding(s).

Severity Count
🟠 High 2
🟡 Medium 6
🟢 Low 2

Panel: 6/6 reviewers contributed findings.

Comment thread .github/cursor-approve/context-proxy.py Resolved
Comment thread .github/cursor-approve/context-proxy.py Resolved
Comment thread .github/cursor-approve/context-proxy.py Resolved
Comment thread .github/cursor-approve/context-proxy.py Resolved
Comment thread .github/cursor-approve/context-proxy.py Resolved
Comment thread .github/cursor-approve/context-proxy.py Resolved
Comment thread .github/cursor-approve/context-proxy.py Resolved
Comment thread .github/cursor-approve/context-proxy.py Resolved
Comment thread .github/cursor-approve/context-proxy.py Resolved
Comment thread .github/cursor-approve/context-proxy.py Resolved
mattmillerai and others added 2 commits October 7, 2026 00:25
…ear, Notion and Slack

A stdio MCP server the cursor-approve axes can use as their only MCP server.
It reads a token file at startup and deletes it, never puts a token in
os.environ, and exposes six read tools filtered by --enable. Every outbound
call goes through one guard that checks method, host, path and (for Linear)
the GraphQL document against a read-only allow-list before sending; agent
input reaches Linear only through variables. Slack search runs over a 30-day
preload of member public channels, since bot tokens cannot call
search.messages. 40 calls, 20 KB per response and 1 MB total per process;
every call is logged as a JSON line.

Tests are wired into test-cursor-review-scripts.yml; all network is mocked,
and a static test fails on any urllib.request/http.client use outside the
guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lies and partial loads

Addresses the cursor-review panel on #348:

- call_tool and serve catch any unexpected exception as one generic error
  (type name only); upstream JSON that is not an object is a ToolError
- Notion block lists paginate via next_cursor up to a cap, with an explicit
  omission marker past it; table_row cells are kept
- Slack preload: a failing channel is skipped, not fatal; a deadline and a
  total message cap bound it; results carry `incomplete` when partial
- tool-side wait for the preload drops from 300s to 10s so pings are not
  stalled
- non-string protocolVersion falls back instead of raising
- initialize carries an `instructions` notice that every result is
  third-party data
- a failing log write no longer fails the call; main checks the log path
  is writable at startup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mattmillerai
mattmillerai force-pushed the matt/be-19344-context-proxy branch from fcb9fcd to a223b1b Compare October 7, 2026 00:28
@mattmillerai
mattmillerai merged commit 2beda98 into main Oct 7, 2026
8 checks passed
@mattmillerai
mattmillerai deleted the matt/be-19344-context-proxy branch October 7, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-coded Authored by the agent-work loop cursor-review Multi-model cursor review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants