ai.mcp.Connection
class in the ai package.
Reference version
Signature
class ai.mcp.ConnectionSource:<builtin>/ai/ns_mcp/mcp.bamlbytes 1037–8476
Fields
server_name
stringp
baml.sys.Processout
baml.sys.ReadPipeLinestimeout_ms
intnext_id
intStatic methods
function
connect
(name: string,
command: string,
args: string[],
timeout_ms: int = …
) -> ai.mcp.Connection throws baml.json.SerializationError | ai.errors.NetworkFailure
Spawn the server and perform the initialize handshake. The connection is live until close(); the caller owns the lifetime.
Instance methods
function
_request
(self,
method: string,
params: map<string, unknown>
) -> baml.json.json throws baml.json.SerializationError | ai.errors.NetworkFailure
(internal) One request/response round-trip. Server notifications and unrelated ids are skipped; a JSON-RPC error object throws.
function
call_tool
(self,
name: string,
args: map<string, unknown>
) -> string throws baml.errors.InvalidArgument | baml.json.SerializationError | ai.errors.NetworkFailure
One tools/call. Text content items join as the tool's result; an isError result throws, which the runner journals as ToolFailed.
function
close
(self) -> voidfunction
tools
(self
) -> ai.tools.Tool[] throws baml.errors.InvalidArgument | baml.json.SerializationError | ai.errors.NetworkFailure
The server's catalog as ordinary tools. Each tool's inputSchema is already JSON Schema, so it carries into Tool.input_schema unchanged; the handler proxies tools/call over this connection.