McpConnection
Represents an active connection to an MCP server. This class wraps a transport and provides high-level methods for interacting with the MCP server (tools, resources, etc.).
McpConnection::__construct()
public function __construct(string $name, Milpa\McpClient\Contracts\TransportInterface $transport):Parameters
| Name | Type | Description |
|---|---|---|
| $name | string | |
| $transport | Milpa\McpClient\Contracts\TransportInterface |
McpConnection::getName()
public function getName(): stringGet connection name.
McpConnection::connect()
public function connect(): voidConnect and initialize the MCP server.
McpConnection::disconnect()
public function disconnect(): voidDisconnect from the MCP server.
McpConnection::isConnected()
public function isConnected(): boolCheck if connection is active.
McpConnection::getCapabilities()
public function getCapabilities(): ?Milpa\McpClient\Contracts\McpCapabilitiesGet server capabilities.
McpConnection::listTools()
public function listTools(): arrayList available tools from this server.
McpConnection::getTool()
public function getTool(string $name): ?Milpa\McpClient\Contracts\McpToolGet a specific tool by name.
Parameters
| Name | Type | Description |
|---|---|---|
| $name | string |
McpConnection::callTool()
public function callTool(string $toolName, array $arguments = []): arrayCall a tool on this MCP server.
Parameters
| Name | Type | Description |
|---|---|---|
| $toolName | string | Name of the tool to call |
| $arguments | array<string, mixed> | Tool arguments |
Returns
Tool result
Throws
McpToolException If tool execution fails
McpConnection::listResources()
public function listResources(): arrayList available resources from this server.
McpConnection::readResource()
public function readResource(string $uri): arrayRead a resource by URI.
Parameters
| Name | Type | Description |
|---|---|---|
| $uri | string | Resource URI |
Returns
Resource content
McpConnection::refresh()
public function refresh(): voidRefresh tool and resource lists from server.
McpConnection::getTransport()
public function getTransport(): Milpa\McpClient\Contracts\TransportInterfaceGet raw transport for advanced operations.