feat(mcp): expose session Ping on Client

Gateway supervisors need a cheap liveness probe to detect mid-flight
upstream death (crashed stdio child, restarted HTTP server). Client.Ping
forwards to the SDK session's MCP ping; a non-nil error means the
session is no longer usable.

Also moves examples/minimal's keep-import-live statement above the REPL
loop — it sat after an infinite for loop, tripping go vet's unreachable
code check.
This commit is contained in:
sausheong committed 2026-06-10 12:44:21 +08:00
1 parent 6f0040f606
commit cf47b2fca8
3 files changed
+32 -1

No files matched your search

+7
View File
@@ -125,6 +125,13 @@ func (c *Client) Tools() []tool.Tool { return c.tools }
// Name returns the configured server name.
func (c *Client) Name() string { return c.name }
// Ping verifies the session is alive by sending an MCP ping. A non-nil
// error means the session (and for stdio servers, likely the child
// process) is no longer usable.
func (c *Client) Ping(ctx context.Context) error {
return c.session.Ping(ctx, nil)
}
// Close releases the underlying MCP session. Safe to call multiple
// times — subsequent calls are no-ops.
func (c *Client) Close() error {