Reference · Tools for AI clients

mcp_tokens

signature
mcp_tokens(map | null=) -> list

What it does

The visitor's MCP tokens that are still good, oldest first. Those are the ones mcp_token made in this session, and those made for the user it is signed in as, so a new sign-in, or one after the first cookie has gone, lists them too. With { user } it lists every token made for that user, whichever session made it. Each is { id, user, made, expires }: the token's id, which revoke_mcp_token takes, who it is for, and when it was made and ends, in milliseconds as now() gives them. Never the token itself, which only its holder has.

Examples

in a program
route GET /settings/ai/tokens = mcp_tokens()

Signed in as ana with two tokens, one made with { max_age: 3600 }, the route answers:

[{"id":"e657b145d3fc8fe0","user":"ana","made":1794151725793,"expires":1796743725793}, {"id":"a3b4a2d9db86d934","user":"ana","made":1794151725799,"expires":1794155325799}]

Outside a request there is no session, and so no tokens:

print(mcp_tokens())print(mcp_tokens({ user: "ana" }))
output
[][]

Edge cases

Errors

An option other than user stops the program: `mcp_tokens` has no option `who`: it takes `user`. Tokens it could not read (the database failing) stop the request too, saying so.

this one fails
print(mcp_tokens({ who: 1 }))
output
line 1: `mcp_tokens` has no option `who`: it takes `user`

Chaining

in a program
route GET /settings/ai/count = len(mcp_tokens() | filter((t) => t.expires > now() + 86400 * 1000))

See also

mcp_token, revoke_mcp_token, end_session, Tools for AI clients

Thread
1Useful? Like it, or add to its thread below.

Thread 0 posts

On mcp_tokens(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo