Repository navigation
Give MCP clients the URL of a document - #9
Merged
Merged
Conversation
An agent that writes a document is usually about to tell a person where it is, and until now it had only an id — so the link it offered was one it composed itself, from a path and an origin it had to guess at. Every MCP result that names a document now carries `url` beside `id`: `create_document` returns the link to what it just wrote, `get_document` returns it, and `list_documents` carries one per entry. A field rather than a seventh tool, so it costs no round trip and an agent cannot hold an id without the URL for it. The URL is built in the new `appUrl.ts` from `BETTER_AUTH_URL` — the origin the OAuth issuer and the MCP resource identifier already derive from — and not from the request's own Host, which is whatever hostname the call arrived at rather than the one a person can open. `mcpResource` now shares that origin helper, so the trailing-slash trim has one definition. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Se7Fqaji347cKa4spizoib
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
htmlcsspdf | 6ae7f78 | Commit Preview URL Branch Preview URL |
Aug 31 2026, 11:20 PM |
afternoon
marked this pull request as ready for review
September 1, 2026 08:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An agent that writes a document is usually about to tell a person where it is, and until now it had only an id — so any link it offered was one it composed itself, from a path and an origin it had to guess at.
What changed
Every MCP result that names a document now carries
urlbesideid:create_documentreturns the link to what it just wrote.get_documentreturns it alongside the HTML and CSS.list_documentscarries one per entry.A field rather than a seventh tool, so it costs no extra round trip and an agent cannot end up holding an id without the URL for it. Tool descriptions say so, so a client knows the URL is there without calling first.
The URL is built in a new
src/server/appUrl.tsfromBETTER_AUTH_URL— the origin the OAuth issuer and the MCP resource identifier already derive from — and not from the request's ownHost, which is whatever hostname the call happened to arrive at rather than the one a person can open.mcpResource()now shares that origin helper, so the trailing-slash trim has one definition instead of two.Nothing else moved: the tools are still thin calls into
documents.ts, with the same ownership clause in every query and the same 404 for somebody else's document.Testing
bun run check— clean (the one remaininginfois pre-existing, insanitize.test.ts).bun run test:unit— 447 passing, including four new cases inmcpServer.test.ts: the URL on create, on read, one per listed document, and no doubled slash whenBETTER_AUTH_URLis configured with a trailing one.bun run test:e2e— 16 passing against the real server; the end-to-end flow now asserts the URL is the app's actual origin rather than one a unit test handed it.Generated by Claude Code