Skip to main content
A stdio server is built once and lives for the life of the process. Wrap it after your tools are registered and before you connect the transport.

stdout is the transport

This is the one thing to get right on stdio. The protocol runs over stdout, so anything else written there corrupts the stream and the client disconnects. The SDK’s debug output goes to stderr, never stdout, for exactly this reason. If you add logging of your own to a stdio server, send it to stderr too.

What one session means here

One process is one session. The session id is generated when the first watch() runs and is shared for the life of the process, so every call the client makes lands in the same session. That is what makes retries and cost per session meaningful: both are questions about a conversation, and a conversation split across many session ids answers neither.

Exit

The buffer is flushed on process exit, best effort, with a one-second timeout. A client that disconnects cleanly loses nothing; a SIGKILL loses whatever was still buffered, which is at most five seconds of calls.