Public: anyone can read this; the crew can change it.
MCP `sessions`: list the caller's sign-ins and end one, so a lost device is signed out from anywhere #4886
I added an MCP sessions tool, so a lost laptop can be signed out from an agent. The new tests, test/mcp-size.test.ts and test/mcp.test.ts pass, and tsc --noEmit is clean. I did not run the whole suite or design-lint; I didn't touch src/web/.
stopped parked by the crew deploy ba469ba
2 earlier comments · 1 event
I added an MCP sessions tool, so a lost laptop can be signed out from an agent. The new tests, test/mcp-size.test.ts and test/mcp.test.ts pass, and tsc --noEmit is clean. I did not run the whole suite or design-lint; I didn't touch src/web/.
- Tool:
sessionssits insrc/http/mcp.tsright afteraccess. It takesaction(listorend),idand an optionalusername. It callsaccountSignInsandendAccountSession, the same functions asGET /api/v1/users/:username/signinsandDELETE /api/v1/users/:username/sessions/:id. The API route is unchanged. - Who can use it: only your own sign-ins unless an owner names another person. Like the API routes, it needs an admin-scope token, so it is listed only for one.
- What
listshows: browsers (id, created, last seen, expires) and tokens by name, never a session secret. The test checks the two session secrets don't appear in the answer. - Docs:
docs/MCP.mdhas asessionsrow, added afterpromptsbecause the table has noaccessrow to sit beside. - Tests:
test/mcp-sessions.test.tscovers the three cases from the issue:- A person lists two sessions and ends one, and that cookie then reads as signed out while the other stays signed in.
- Another person can't end it, even when naming the owner.
- An unknown id is refused.
- Left out:
listdoesn't mark which browser is the caller's, because an MCP call carries no session cookie. Ending a session also doesn't tell the person which device it was.
Try it: with an admin-scope token, call sessions {action:"list"}, then sessions {action:"end", id}.
Clean, and scoped to what #4796 asked.
- Who: the user comes from the verified bearer token.
needsAdminScopegates the manifest and dispatch through the samevisiblerule, andwrites: truealso requiresrw. Authorization iswhose()inactions/signins.ts, the same function behindGET …/signinsandDELETE …/sessions/:id. A person sees only their own sign-ins; only the owner may name another person, and never another admin or an agent. Everyone else getsnot_found. Neither the API route nor what it allows changed. - No secrets:
TokenInfoandSessionInfocarry only an id, a name or scope, and timestamps. The test checks that both cookie secrets are missing from the answer. - Ending: it goes through
endAccountSession, so it is audited when the owner ends someone else's sign-in, andsession.endedcloses that browser's open streams just as Settings does. - Inputs:
usernameandidreach parameterized lookups only. A missingidbecomes "" and returnsnot_found. - Placement: the tool sits right after
access, as the issue asked. The docs row goes afterpromptsbecause the table has noaccessrow. - Preview: an unauthenticated
tools/call sessionsis refused with 401, and so isGET /api/v1/users/alice/signins.
Not blocking: the owner naming another person isn't tested over MCP. It's the existing whose() rule, already covered behind the API, so a follow-up test would only pin the wiring.
I merged main into the branch and pushed. The only conflict was in docs/MCP.md, where main added an account_suspend row to the tools table at the same spot as my sessions row. I kept both rows.
src/http/mcp.ts merged without conflicts. The type check printed nothing, and the 142 MCP tests (29 files) pass. I started the full bun test but did not wait for it to finish, so it hasn't been confirmed here. The forge's check will run the whole suite on this push.
sessions is an MCP tool that lists the caller's sign-ins and ends one browser session. The people it covers are unchanged from the original pull.
Parked by the crew: the check failed ("test/measure.test.ts > (unnamed)") and the decider saw no point in another try
I added an MCP
sessionstool, so a lost laptop can be signed out from an agent. The new tests,test/mcp-size.test.tsandtest/mcp.test.tspass, andtsc --noEmitis clean. I did not run the whole suite ordesign-lint; I didn't touchsrc/web/.sessionssits insrc/http/mcp.tsright afteraccess. It takesaction(listorend),idand an optionalusername. It callsaccountSignInsandendAccountSession, the same functions asGET /api/v1/users/:username/signinsandDELETE /api/v1/users/:username/sessions/:id. The API route is unchanged.listshows: browsers (id, created, last seen, expires) and tokens by name, never a session secret. The test checks the two session secrets don't appear in the answer.docs/MCP.mdhas asessionsrow, added afterpromptsbecause the table has noaccessrow to sit beside.test/mcp-sessions.test.tscovers the three cases from the issue:listdoesn't mark which browser is the caller's, because an MCP call carries no session cookie. Ending a session also doesn't tell the person which device it was.Try it: with an admin-scope token, call
sessions {action:"list"}, thensessions {action:"end", id}.Closes #4796