Testing helpers¶
Stable
Covered by the 1.0 API freeze (proposal 0029): no breaking change before 2.0.
testing ¶
Test helpers for servers built with OunceMCP.
as_caller makes the code inside it run as if the transport had verified an access
token, so policies, cursors, caches and state tokens can be tested in-process::
with as_caller(subject="alice", tenant="acme", scopes=["tickets:read"]):
result = await server.call_tool("tickets.search", {"query": "refund"})
make_token ¶
make_token(*, subject: str | None = 'user', issuer: str | None = None, client_id: str = 'test-client', tenant: str | None = None, scopes: Sequence[str] = (), audience: str | Sequence[str] | None = None, token: str = 'test-inbound-token-0123456789', claims: dict[str, Any] | None = None) -> AccessToken
A FastMCP AccessToken as a token verifier would produce it.
as_caller ¶
Run the enclosed code as the caller of access_token (else make_token(**fields)).