McpServer.Create, without dependency injection, pass its McpServerOptions to AgentCatSdk.Track() before you call McpServer.Create. Servers that AddMcpServer() builds, which includes every ASP.NET Core HTTP server, use WithAgentCat() instead.
The requirements are those of ASP.NET Core and the generic host.
Track the options before McpServer.Create
- Before
McpServer.Create. The server reads the filters of its options when it is created, so aTrack()call afterMcpServer.Createdoes not reach that server. - The project ID.
nullreads it from theAGENTCAT_PROJECT_IDenvironment variable. An empty string, or no project ID at all, tracks the server but sends no events to AgentCat: your exporters still get them. - Options. The third argument is an
AgentCatOptionsobject with the same properties as forWithAgentCat(). AgentCat reads it once, during the call: later changes have no effect. - It never throws.
Track()returns the sameMcpServerOptions. When AgentCat cannot track the server, it returns them unchanged and the server runs untracked. - Tracking again changes nothing. A second
Track()on the same options installs nothing, and the first call’s project ID and options stay.
Custom events
Pass theMcpServer that McpServer.Create returned, or, in a tool, the McpServer that the tool receives:
SessionId in its CustomEventData has no session. Custom Events has the fields and the session-string form.
Shutdown
AgentCat sends events from a process-wide queue in the background, and you call nothing at shutdown.Track() sends the queued events when the process ends: at process exit, and, on .NET 8 and later, on SIGTERM and SIGINT. A stop sends the events for at most 5 seconds, then the last diagnostics batch for at most 1 second.
- Allow 6 seconds. Set the grace period of your container above the time that your server needs to stop, plus 6 seconds.
- The signal handlers never cancel the signal, so the process ends with its usual exit code. They do nothing when a .NET host in the same process cancelled the signal first.
- To wait for the events in your own code, call
await AgentCatSdk.FlushAsync(TimeSpan.FromSeconds(5)). It returnstruewhen nothing is left to send.AgentCatSdk.ShutdownAsync()also closes the queue: call it once, when your own code ends the process. DisableShutdownHandlers = trueon the first install of the process turns these handlers off. Then callFlushAsyncorShutdownAsyncbefore the process ends, or the queued events are lost.