Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Required MCP documentation updates are missing, and metadata tests do not assert the advertised scopes or supported bearer-token transport.
2 open issues
What changed in this PR
Adds OAuth discovery to the HTTP MCP server so clients can find the Writebook instance to sign in with. Full connector sign-in still requires Writebook-side OAuth support.
Changes:
- Adds two public resource-metadata routes while keeping
/mcptoken-protected. - Includes a discovery URL in 401 responses, using the request host and proxy-reported HTTPS scheme.
- Adds discovery integration tests and extracts a shared server-start helper.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
| File | Description |
|---|---|
tests/mcp.rs |
Tests discovery routes, the 401 challenge, and HTTPS metadata; shares server setup. |
src/mcp.rs |
Serves public OAuth metadata and adds discovery challenges to unauthenticated MCP responses. |
Review effort: Balanced
writebook mcp --serve publishes the protected resource metadata (RFC 9728) at /.well-known/oauth-protected-resource, naming the Writebook it serves as the authorization server, and a request without a token gets a 401 whose WWW-Authenticate points there. MCP clients that sign in with OAuth, like hosted connectors, can find where to sign the person in.
… say only /mcp needs a token
monorkin
force-pushed
the
mcp-oauth-discovery
branch
from
November 30, 2026 14:27
ca4b7e5 to
fc9d5da
Compare
…s it Writebook now has an admin scope for managing people and settings. The CLI's sign-in asks for read write admin, so an administrator's TUI keeps managing people; anyone else gets read write. A sign-in that lacks the scope gets an insufficient_scope 403, which the CLI now explains with a note to sign in again.
… by what the sign-in can do A Writebook without the admin scope refuses it as invalid_scope; the CLI then asks again for read write. An insufficient_scope 403 tells a read-only sign-in it's read-only, rather than to sign in as an administrator.
…sing scope, and add --public-url A client renews its token when it gets a 401, so the server now checks each token with Writebook before handling the request, and remembers accepted ones for a minute. A refusal names what's missing: a read-only connection is told to reconnect and choose read and change books, and a sign-in without admin to tick Manage people and settings. --public-url names the server's address for proxies that don't pass the original Host.
…d kamal-proxy, Caddy and Apache
…ronment variables, so it runs under ONCE ONCE can only pass environment variables to a container. WRITEBOOK_MCP_INSTANCE, WRITEBOOK_MCP_READ_ONLY and WRITEBOOK_MCP_PUBLIC_URL set the mcp options, and the image runs mcp --serve 0.0.0.0:80 unless given another command.
…he MCP environment variables through the CLI, check --public-url, drop narrating comments
…ndings writebook mcp serves stdio as before; writebook mcp serve serves one instance over HTTP, listening on 127.0.0.1:8080 unless --bind says otherwise. Its options belong to it, so the "only goes with --serve" checks are gone. The token check answers 502 when it can't reach Writebook, instead of letting the request through. Host is parsed before it goes into an address. Scope refusals name the profile's sign-in command and what to approve. The device sign-in reports an unreadable answer instead of a missing code. Tests no longer pick up WRITEBOOK_MCP_* from the environment, and cover the challenges sent without a Host. The skill says what the image runs and when to tick the admin box.
…n again, and trim the README to the commands
…nd help in plain sentences
--read-only is one flag for mcp and mcp serve, so mcp --read-only serve no longer drops it. A refusal for a WRITEBOOK_TOKEN says to use a token with the access, since signing in again wouldn't change it, and mcp serve words every scope refusal for a remote app. The server logs a warning when the instance uses http. New tests cover the 502, WRITEBOOK_MCP_BIND and each way to set read-only. The skill says only /mcp needs a token and mentions --public-url.
Writebook now issues MCP clients tokens bound to this server (RFC 8707) and refuses them anywhere else. mcp serve exchanges each one for a short-lived Writebook token (RFC 8693), authenticating with WRITEBOOK_MCP_SECRET, and gives that to the tools. Exchanged and refused tokens are remembered, so a client's token is exchanged once per short-lived token and junk tokens don't reach Writebook again for a minute. --public-url is now required, since the bound address has to match exactly, so the server no longer builds addresses from Host or X-Forwarded-Proto, and the root resource metadata path is gone. The server checks its secret with Writebook when it starts.
--public-url must be https unless it's this machine. An expiry Writebook can't mean is a failed exchange instead of a crash. The startup check says which host it couldn't reach, and a 401 names every cause Writebook has for it. An unreadable inventory no longer reads as a WRITEBOOK_TOKEN sign-in. New tests cover the http warning, exchanging a token again before it runs out, and the sign-in command a refusal names for a stored profile.
… a 401 Revoking an app's token revokes what the server exchanged it for, but the server kept reusing its copy, so tools failed inside 200 answers for up to five minutes and clients never renewed. Found by revoking a token against a real Writebook.
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.

This is the CLI part of letting MCP clients sign in to Writebook with OAuth. The Writebook part is basecamp/writebook#524.
mcp serveneeds a Writebook with #524. Signing in with the CLI still works with older Writebooks.Breaking change for the release notes:
--serveis replaced bymcp serve, and the server no longer accepts tokens pasted into an MCP client; agents sign in with OAuth instead.writebook mcp servewritebook mcp --serve <address>is nowwritebook mcp serve. It listens on127.0.0.1:8080by default, and--bindchanges the address.writebook mcpwithoutservestill uses stdio.--public-urlis required: the server's https address. The instance'sMCP_SERVER_URLis this address followed by/mcp.WRITEBOOK_MCP_SECRET, never a flag. The server checks it with Writebook when it starts and stops if Writebook refuses it.--instance,--bind,--public-urland--read-onlycan also be set withWRITEBOOK_MCP_INSTANCE,WRITEBOOK_MCP_BIND,WRITEBOOK_MCP_PUBLIC_URLandWRITEBOOK_MCP_READ_ONLY.mcp serve --bind 0.0.0.0:80by default, so it can be deployed with ONCE.GET /upreturns 200 without a token, for health checks.Sign-in and token exchange
GET /.well-known/oauth-protected-resource/mcpreturns the resource metadata (RFC 9728): the resource is<public url>/mcp, and the Writebook is the authorization server. Clients send that resource when they sign in, so Writebook binds their tokens to this server (RFC 8707)./mcpwithout a token gets a 401 withWWW-Authenticate: Bearer resource_metadata="…".error="invalid_token", so the client renews its token. If the exchange fails for another reason, the request gets a 502.Admin scope
read write admin. An administrator who ticks "Manage people and settings" on the approval page can manage people in the TUI. Other people getread write.invalid_scope. The CLI then asks again forread write.insufficient_scope, the error says which access is missing and gives the sign-in command for the profile in use. Through the MCP server, a read-only connection is told to reconnect and choose "Read and change books".Docs
doc/mcp-server.mdexplains how to run the server with ONCE, kamal-proxy, Caddy and Apache. The README links to it.Tests
--public-url, the environment variables, tools using the exchanged token, one exchange per token, remembered refusals, the 502, starting without a secret or with a wrong one, and the refusal messages.bin/dev test runandbin/dev code lintpass.