Repository navigation
feat(mcp): an MCP server for agents to search, read and cite the archive - #43
Conversation
/mcp speaks Streamable HTTP without sessions, in both protocol eras (the initialize handshake and 2026-07-28's per-request envelope). Agents sign in with Lens's OAuth (the 401 names /.well-known/oauth-protected-resource/mcp, which asks for read only) or an API token, and read what the person can through the API's own checks. Read-only tools: search, list_namespaces, list_recordings, list_speakers, get_recording, get_transcript, fetch, cite, list_entities, get_entity, explore_graph and find_path; moments carry links that open the recording there in the web app. The web app proxies /mcp. Tested with the official MCP SDK client in both eras. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TUqMhwUCvF9dsP5JzVvMJf
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TUqMhwUCvF9dsP5JzVvMJf
|
CI is red on every check (FastAPI embedded, FastAPI SurrealDB server, Next.js, pre-commit, Conventional Commit title), but the failures don't come from this PR. Each job fails 2 to 3 seconds after it is queued, before checkout, and leaves no log or output. The same thing happens on Locally, on this head (93f8a7a), everything the CI jobs run passes:
I'll re-check once the runners are back. Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SNbRrpHTCqLewRKdkmd45X
Requested by Adeel · project thread
Description
Before: agents had no way into Lens. MCP clients could sign in through the OAuth provider from #18, but there was no MCP server for them to use.
After: add
https://<your Lens>/mcpto Claude, Cursor, VS Code or any other MCP client. The client sends you to Lens's consent page, asks for read access only, and the agent then sees exactly what you see: your namespaces, the collections you were given a role on, and the graphs those open.The tools are read-only:
search: moments that were said, shown on screen or written, each with a link to that moment.list_namespaces,list_recordings,list_speakers.get_recording: summary, chapters, top entities and keywords.get_transcript: paged by line or by time window.fetch: the whole text at once.cite: the quote, who said it, the recording, the date, the time and a link, also as Markdown.list_entities,get_entity,explore_graph,find_path: entities and the knowledge graph.Links open the recording at that moment in the web app (
/resources/<id>?t=), on whatever address the client used. Clients that can't sign in can send an API token instead. Seedocs/mcp.md.How it works:
app/api/mcp.pyimplements Streamable HTTP without sessions and serves both protocol eras:initializehandshake (2024-11-05 to 2025-11-25, including batches);params._meta, theMCP-Protocol-Version/Mcp-Method/Mcp-Nameheader checks,server/discover,resultType, -32020/-32022 errors with their HTTP statuses.app/api/mcp_tools.pyread only through the API's own route functions andAccesschecks, so permissions match the REST API. That covers partial (collection-role) users and isolated graphs./mcppoints at/.well-known/oauth-protected-resource/mcp, which advertisesscopes_supported: ["read"].CORS_ORIGINS./mcp(app/mcp/route.ts), and auth middleware skips it.mcp(the official SDK) is a dev dependency only, used to test against. Nothing new at runtime.Motivation and Context
This is the MCP server item from the backlog. Semantic search isn't on main yet, so
searchis full-text for now. It can gain a mode once semantic search lands.Steps to reproduce (if appropriate):
Tested end to end on SurrealDB 3.2.4 (server, surrealkv), with the API under uvicorn and the Next.js web app proxying:
http://localhost:3000/mcp: 401, protected-resource metadata, dynamic registration, consent, PKCE token, then tools. This worked inautomode (which settles on 2026-07-28) and inlegacymode (2025-11-25). The consent page showedscope: read.get_transcriptusing an API token.tests/api/test_mcp.pyalso passes against the SurrealDB 3.2.4 server (LENS_TEST_SURREAL_URL).Types of changes
!in the title)Checklist:
tests/api/test_mcp.pycovers auth, the transport, both eras, every tool, access limits and the official SDK client in both eras.docs/accordingly (docs/mcp.md, plus api, authentication, README and mkdocs nav).## UnreleasedinCHANGELOG.md.🤖 Generated with Claude Code
https://claude.ai/code/session_01TUqMhwUCvF9dsP5JzVvMJf
Generated by Claude Code