windlass.interfaces.mcp¶
mcp
¶
The Model Context Protocol (MCP) interface.
MCP servers expose three things: tools an agent can call, resources it can read, and prompts it can instantiate. Windlass treats an MCP server as one more source of tools — after connecting, its tools appear alongside your local Python functions and the agent cannot tell them apart.
Implementers override :meth:MCPClient.aconnect, :meth:MCPClient.alist_tools
and :meth:MCPClient.acall_tool; resources and prompts are optional.
Example
from windlass.providers.mcp.fastmcp import StaticMCPClient client = StaticMCPClient(tools={"echo": lambda text: text}) client.connect() [t.name for t in client.list_tools()]['echo']
MCPResource
¶
Bases: WindlassModel
A readable resource advertised by an MCP server.
Attributes:
| Name | Type | Description |
|---|---|---|
uri |
str
|
Resource identifier, e.g. |
name |
str
|
Human readable name. |
description |
str
|
What the resource contains. |
mimetype |
str | None
|
Content type, when the server declares one. |
server |
str
|
Which server advertised it. |
MCPPrompt
¶
Bases: WindlassModel
A parameterised prompt template advertised by an MCP server.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Prompt identifier. |
description |
str
|
What the prompt is for. |
arguments |
list[dict[str, Any]]
|
Declared arguments, each a dict with |
server |
str
|
Which server advertised it. |
MCPToolProxy
¶
MCPToolProxy(
client: MCPClient,
*,
name: str,
description: str = "",
parameters: dict[str, Any] | None = None,
server: str = "",
**config: Any
)
Bases: Tool
A local :class:~windlass.interfaces.tool.Tool backed by a remote MCP tool.
Created by :meth:MCPClient.alist_tools. Calling it forwards to the server
and returns whatever comes back, so agents bind it exactly like a local
function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
MCPClient
|
The MCP client that owns the connection. |
required |
name
|
str
|
Remote tool name. |
required |
description
|
str
|
Remote tool description. |
''
|
parameters
|
dict[str, Any] | None
|
Remote JSON Schema for the arguments. |
None
|
server
|
str
|
Server label, kept in metadata and used to disambiguate same-named tools across servers. |
''
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Source code in src\windlass\interfaces\mcp.py
acall
async
¶
Forward the call to the MCP server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Arguments matching the remote schema. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The server's result. |
Raises:
| Type | Description |
|---|---|
MCPError
|
When the call fails or the server is unreachable. |
Source code in src\windlass\interfaces\mcp.py
MCPClient
¶
MCPClient(
*,
server: str = "",
namespace: bool = False,
timeout: float = 30.0,
name: str | None = None,
**config: Any
)
Bases: Component
Abstract MCP client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
str
|
Server label used in logs and to namespace tools. |
''
|
namespace
|
bool
|
When True, remote tools are exposed as |
False
|
timeout
|
float
|
Per-call timeout in seconds. |
30.0
|
name
|
str | None
|
Component name. |
None
|
**config
|
Any
|
Transport-specific options (command, args, url, env, ...). |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
connected |
Whether the transport is currently open. |
Example
Implementing a client means three methods::
class MyClient(MCPClient):
provider_name = "mine"
async def aconnect(self): ...
async def alist_tools(self): ...
async def acall_tool(self, name, arguments): ...
Source code in src\windlass\interfaces\mcp.py
aconnect
abstractmethod
async
¶
Open the transport and perform the MCP handshake.
Must be idempotent — calling it twice should not open two sessions.
Raises:
| Type | Description |
|---|---|
MCPError
|
When the server cannot be reached or the handshake fails. |
Source code in src\windlass\interfaces\mcp.py
alist_tools
abstractmethod
async
¶
acall_tool
abstractmethod
async
¶
Invoke a remote tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Tool name as advertised by the server (without any namespace prefix Windlass may have added). |
required |
arguments
|
dict[str, Any]
|
Arguments matching the remote schema. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The server's result, unwrapped from the MCP content envelope. |
Raises:
| Type | Description |
|---|---|
MCPError
|
When the call fails. |
Source code in src\windlass\interfaces\mcp.py
alist_resources
async
¶
aread_resource
async
¶
Read a resource's contents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
The resource identifier. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The resource body as text. |
Raises:
| Type | Description |
|---|---|
MCPError
|
When the resource cannot be read. |
Source code in src\windlass\interfaces\mcp.py
alist_prompts
async
¶
aget_prompt
async
¶
Instantiate a prompt template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Prompt name. |
required |
arguments
|
dict[str, Any] | None
|
Template arguments. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered prompt text. |
Raises:
| Type | Description |
|---|---|
MCPError
|
When the prompt cannot be rendered. |