ai.mcp.Connection

class in the ai package.

Reference version

Signature

class ai.mcp.Connection

Source:<builtin>/ai/ns_mcp/mcp.bamlbytes 10378476

Fields

server_name

string

p

baml.sys.Process

out

baml.sys.ReadPipeLines

timeout_ms

int

next_id

int

Static 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) -> void
function

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.