Notes MCP server
This example is an MCP server protected by mcpauth, with the tensile-auth OAuth provider that issues its tokens in the same binary. It shows the whole loop: an MCP client connects, you approve it on a consent page, it calls tools, every call lands in the audit log, and revoking the connection stops the next call.
The sign-in is a demo that signs in anyone by name. Don't deploy this server.
What it serves
| Path |
What it is |
/mcp |
The MCP endpoint, with the tools notes_list (scope notes:read) and notes_add (scope notes:write) |
/.well-known/oauth-protected-resource/mcp |
Protected Resource Metadata (RFC 9728) |
/.well-known/oauth-authorization-server |
Authorization server metadata (RFC 8414), also at /.well-known/openid-configuration |
/login |
The demo sign-in |
/consent |
The consent page |
/connections |
Each connected client, with a button to revoke it |
/audit |
Your consents, tool calls, and revocations |
Connect Claude Code
-
Start the server:
go run ./examples/mcpserver
It listens on localhost:8080 and uses http://localhost:8080 as its issuer. The provider accepts http only for localhost.
-
Add the server to Claude Code:
claude mcp add --transport http notes http://localhost:8080/mcp
-
In Claude Code, run /mcp, choose notes, and choose to authenticate. Claude Code reads the Protected Resource Metadata from the 401 challenge, finds the authorization server, and identifies itself with its client ID metadata document, https://claude.ai/oauth/claude-code-client-metadata. The default CIMD allowlist admits claude.ai, so the server fetches that document and needs no registration.
-
Your browser opens the sign-in page. Sign in with any name.
-
The consent page shows:
- the client's name, Claude Code, which is its own claim, and its verified host,
claude.ai;
- the host the approval goes to,
localhost, with a warning, because any program on your computer can listen on a loopback address;
- the resource, Notes at
http://localhost:8080/mcp;
- the scopes,
notes:read and notes:write.
Choose Allow. Every approval is recorded before the code is issued, and a loopback redirect never skips this page.
-
Ask Claude Code to add a note and list your notes. It calls notes_add and notes_list with a token whose audience is http://localhost:8080/mcp. That token works nowhere else: not at another MCP server, and not at the provider's userinfo endpoint.
-
Open http://localhost:8080/audit. Each tool call is a tool_called event with the tool, the decision, and a hash of the arguments, never the arguments themselves.
-
Open http://localhost:8080/connections and choose Revoke. The next tool call from Claude Code gets 401 with error="invalid_token", at once, because the token is a session that the server checks on every request.
Run it behind your own login
Most applications already sign people in. Start the server with -own-login to play one:
go run ./examples/mcpserver -own-login
In this mode, /login is the application's own login. It sets its own session cookie, __Host-notes-app, and tensile-auth never starts a session from it directly. Instead, authhttp.Bridge wraps the provider's authorization endpoint, the consent page, and the other pages:
bridge, err := authhttp.Bridge(svc, authhttp.BridgeConfig{
User: func(r *http.Request) (authhttp.AppUser, bool) {
// Read the application's own session.
return authhttp.AppUser{ID: user, AuthenticatedAt: signedIn, Scopes: Scopes}, ok
},
})
provider.Register(mux, bridge)
On each request, the bridge asks the application who is signed in and keeps one short-lived tensile-auth session for that sign-in, in the __Host-bridge cookie. The connection flow is the same as in Connect Claude Code, with these differences:
- The consent page appears exactly as before. The bridge never skips it.
- Approving needs a sign-in to the application in the last 10 minutes, because the bridged session keeps the application's sign-in time. After that, the consent page sends you to
/login again.
- When someone else signs in on the same browser, or you choose Sign out on the home page, the bridge revokes the old session before anything else, so it can never approve for the wrong person.
- The bridged session can approve connections, but it can't create personal access tokens or agents.
The browser client at /client works the same way in this mode.
Other clients
- ChatGPT uses
https://chatgpt.com/oauth/client.json, which the default allowlist admits. ChatGPT reaches the server only over public HTTPS, so run it behind a tunnel or a proxy and set -issuer to the public URL.
- Codex uses
https://chatgpt.com/oauth/codex/client.json, which the default allowlist admits, and returns to a loopback address on any port. Codex CLI 0.154.0 signed in to this server and was approved on its consent page on 4 December 2026.
- Grok Build, formerly Cursor, uses dynamic client registration. Start the server with
-register to turn it on.
- Any other client can be configured in
Config.Clients, as the test does.
Files
| Name |
What it holds |
main.go |
The server: the provider, the protector, the tools, and the pages |
ownlogin.go |
The application's own login, which -own-login bridges to the provider with authhttp.Bridge |
client.go, client.html, client.js |
The browser MCP client at /client, which -client serves, on by default |
Test
go test ./examples/mcpserver/
TestConnectCallAuditRevoke runs steps 4 to 8 in process, with a configured client in place of Claude Code. TestOwnLoginBridgesTheConsent runs the same flow with -own-login, then signs in as another person and signs out.