8000 fix(mcp): check the token's audience, cap body reads and batches by adeelahmad · Pull Request #45 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content

fix(mcp): check the token's audience, cap body reads and batches - #45

Merged
adeelahmad merged 1 commit into
mainfrom
claude/mcp-server-au1poj
Oct 2, 2026
Merged

adeelahmad merged 1 commit into
mainfrom
claude/mcp-server-au1poj

Conversation

@adeelahmad
Copy link
Copy Markdown
Owner

Requested by Adeel · project thread

Follow-up to #43 from its review.

Before: an app could name the server it wanted a token for (resource, RFC 8707), but that was dropped once the code was swapped for tokens, so /mcp accepted a token asked for any server. /mcp also read the whole body before checking its size, took batches of any length, and get_entity's mentions_offset had no upper bound.

After: the token keeps its resource through every renewal, and /mcp refuses one that names another server with a 401 that points the app at where to sign in for this one. A token for Lens or its /mcp, on any address Lens is reached at, still works. Bodies over 1 MB get a 413 from Content-Length, or once the stream passes the limit, and are never held whole. Batches hold 20 messages at most, and mentions_offset stops at 10000 like search's offset.

How: resource goes from the oauth_code onto the grant and both token rows in _issue. refresh passes it on, and token_account returns it on the Principal. The check, _audience_ok, and the capped read, _read, are in app/api/mcp.py. The REST API doesn't check the audience, as before.

Validation: GitHub-hosted runners aren't available, so this was checked locally. Ruff, ruff format and mypy are clean, and the full backend suite ran on embedded SurrealDB and on a SurrealDB 3.2.4 server. New tests cover the audience across renewals, the batch cap, oversized bodies (with and without Content-Length) and the offset maximum.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TUqMhwUCvF9dsP5JzVvMJf


Generated by Claude Code

- Carry an app's RFC 8707 resource from the code onto its grant and its
  access and refresh tokens (renewals keep it), and expose it on the
  Principal. /mcp refuses an lo_ token whose resource names another
  server (Lens and its /mcp, on any address Lens is reached at, pass).
- Check Content-Length and read the body as a capped stream, so a
  message over MAX_BODY is never held whole.
- Cap JSON-RPC batches at 20 messages.
- get_entity's mentions_offset gets search's 10000 maximum.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TUqMhwUCvF9dsP5JzVvMJf
Copy link
Copy Markdown
Owner Author

All five checks failed within seconds of starting on 90e9783: Conventional Commit title, pre-commit, Next.js, and FastAPI on both embedded SurrealDB and the SurrealDB server. That matches main and every other open PR today. The GitHub-hosted runners aren't starting jobs at all (no logs), and #27 moves CI onto the self-hosted runner. Nothing here is this PR's failure.

The title is Conventional (fix(mcp): …). Adeel approved merging on clean local checks while Actions can't run, so this merges once the full local backend suite passes on both engines. Ruff, ruff format and mypy are already clean.


Generated by Claude Code

@adeelahmad
adeelahmad merged commit 1573faa into main Oct 2, 2026
0 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0