Skip to content

Give MCP clients the URL of a document - #9

Merged
afternoon merged 1 commit into
mainfrom
claude/mcp-document-url-qg4bc8
Sep 1, 2026
Merged

afternoon merged 1 commit into
mainfrom
claude/mcp-document-url-qg4bc8

Conversation

@afternoon

Copy link
Copy Markdown
Owner

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 url beside id:

  • create_document returns the link to what it just wrote.
  • get_document returns it alongside the HTML and CSS.
  • list_documents carries 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.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 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 remaining info is pre-existing, in sanitize.test.ts).
  • bun run test:unit — 447 passing, including four new cases in mcpServer.test.ts: the URL on create, on read, one per listed document, and no doubled slash when BETTER_AUTH_URL is 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

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
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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
afternoon marked this pull request as ready for review September 1, 2026 08:02
@afternoon
afternoon merged commit fd62009 into main Sep 1, 2026
2 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