windlass.providers.mcp.fastmcp¶
fastmcp
¶
FastMCP client adapter, plus a dependency-free in-process client for tests.
Model Context Protocol servers expose tools, resources and prompts over stdio or HTTP. Once connected, their tools become ordinary Windlass tools — an agent binding a local Python function and a remote MCP tool cannot tell them apart, which is exactly the point.
Install with::
pip install "windlass[mcp]"
Example
from windlass import Windlass # doctest: +SKIP agent = Windlass.agent().mcp("filesystem", # doctest: +SKIP ... command="npx", args=["-y", "@modelcontextprotocol/server-filesystem", "."])
FastMCPClient
¶
FastMCPClient(
*,
server: str = "",
command: str | None = None,
args: list[str] | None = None,
url: str | None = None,
env: dict[str, str] | None = None,
config: dict[str, Any] | None = None,
namespace: bool = False,
timeout: float = 30.0,
**kwargs: Any
)
Bases: MCPClient
MCP client built on fastmcp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
str
|
Label for this server, used in logs and namespacing. |
''
|
command
|
str | None
|
Executable for a stdio server, e.g. |
None
|
args
|
list[str] | None
|
Arguments for |
None
|
url
|
str | None
|
HTTP or SSE endpoint, as an alternative to |
None
|
env
|
dict[str, str] | None
|
Extra environment variables for a stdio server. |
None
|
config
|
dict[str, Any] | None
|
A full FastMCP client configuration dict, for advanced setups. |
None
|
namespace
|
bool
|
Prefix remote tool names with the server label, so two servers
offering |
False
|
timeout
|
float
|
Per-call timeout in seconds. |
30.0
|
**kwargs
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
When |
ConfigurationError
|
When neither |
MCPError
|
When the server cannot be reached. |
Note
A stdio server is a subprocess this client starts and owns. Use it as an
async context manager, or call :meth:~windlass.interfaces.mcp.MCPClient.disconnect,
so the process is reaped.
Source code in src\windlass\providers\mcp\fastmcp.py
native
¶
aconnect
async
¶
Open the transport and enter the MCP session.
Idempotent: calling it twice does not start a second server.
Raises:
| Type | Description |
|---|---|
MCPError
|
When the server cannot be started or the handshake fails. |
Source code in src\windlass\providers\mcp\fastmcp.py
adisconnect
async
¶
Close the session and reap any subprocess.
Source code in src\windlass\providers\mcp\fastmcp.py
alist_tools
async
¶
Discover the server's tools.
Returns:
| Type | Description |
|---|---|
list[Tool]
|
class: |
list[Tool]
|
bind to an agent. |
Raises:
| Type | Description |
|---|---|
MCPError
|
When discovery fails. |
Source code in src\windlass\providers\mcp\fastmcp.py
acall_tool
async
¶
Invoke a remote tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Tool name, with any Windlass namespace prefix stripped. |
required |
arguments
|
dict[str, Any]
|
Arguments matching the remote schema. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The unwrapped result — plain text where the server returned text, |
Any
|
parsed JSON where it returned JSON, otherwise the raw payload. |
Raises:
| Type | Description |
|---|---|
MCPError
|
When the call fails. |
Source code in src\windlass\providers\mcp\fastmcp.py
alist_resources
async
¶
Discover the server's readable resources.
Source code in src\windlass\providers\mcp\fastmcp.py
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\providers\mcp\fastmcp.py
alist_prompts
async
¶
Discover the server's prompt templates.
Source code in src\windlass\providers\mcp\fastmcp.py
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. |
Source code in src\windlass\providers\mcp\fastmcp.py
StaticMCPClient
¶
StaticMCPClient(
*,
tools: dict[str, Callable[..., Any]] | None = None,
resources: dict[str, str] | None = None,
prompts: dict[str, str] | None = None,
server: str = "static",
namespace: bool = False,
**kwargs: Any
)
Bases: MCPClient
An MCP client backed by local Python callables.
Lets you exercise every MCP code path — discovery, namespacing, tool proxying, agent binding — without starting a subprocess or a server. That makes MCP integration testable in ordinary unit tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
|
dict[str, Callable[..., Any]] | None
|
Mapping of tool name to callable. |
None
|
resources
|
dict[str, str] | None
|
Mapping of URI to content. |
None
|
prompts
|
dict[str, str] | None
|
Mapping of prompt name to a template string, formatted with the supplied arguments. |
None
|
server
|
str
|
Server label. |
'static'
|
namespace
|
bool
|
Prefix tool names with the server label. |
False
|
**kwargs
|
Any
|
Forwarded to :class: |
{}
|
Example
client = StaticMCPClient( ... tools={"shout": lambda text: text.upper()}, ... resources={"file://greeting": "hello"}, ... ) client.connect() client.call_tool("shout", {"text": "hi"}) 'HI' client.read_resource("file://greeting") 'hello'
Source code in src\windlass\providers\mcp\fastmcp.py
aconnect
async
¶
alist_tools
async
¶
Return one tool per registered callable, with derived schemas.
Source code in src\windlass\providers\mcp\fastmcp.py
acall_tool
async
¶
Invoke a registered callable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Tool name, with any namespace prefix stripped. |
required |
arguments
|
dict[str, Any]
|
Keyword arguments. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The callable's return value. |
Raises:
| Type | Description |
|---|---|
MCPError
|
When no such tool is registered or the call fails. |
Source code in src\windlass\providers\mcp\fastmcp.py
alist_resources
async
¶
Return the registered resources.
aread_resource
async
¶
Return a registered resource's content.
Raises:
| Type | Description |
|---|---|
MCPError
|
When the URI is not registered. |
Source code in src\windlass\providers\mcp\fastmcp.py
alist_prompts
async
¶
aget_prompt
async
¶
Render a registered prompt template.
Raises:
| Type | Description |
|---|---|
MCPError
|
When the prompt is not registered or a placeholder is missing. |
Source code in src\windlass\providers\mcp\fastmcp.py
MultiMCPClient
¶
Bases: MCPClient
Aggregates several MCP servers behind one client.
Tool discovery unions every server's tools, and calls are routed back to
whichever server advertised the tool. Namespacing is forced on, because two
servers offering search is the normal case, not the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clients
|
list[MCPClient] | None
|
The servers to aggregate. |
None
|
server
|
str
|
Label for the aggregate. |
'multi'
|
**kwargs
|
Any
|
Forwarded to :class: |
{}
|
Example
a = StaticMCPClient(tools={"ping": lambda: "pong"}, server="alpha") b = StaticMCPClient(tools={"ping": lambda: "pong"}, server="beta") multi = MultiMCPClient(clients=[a, b]) sorted(t.name for t in multi.list_tools()) ['alpha_ping', 'beta_ping']
Source code in src\windlass\providers\mcp\fastmcp.py
add
¶
native
¶
aconnect
async
¶
Connect every server, tolerating individual failures.
Source code in src\windlass\providers\mcp\fastmcp.py
adisconnect
async
¶
alist_tools
async
¶
Union every server's tools, recording where each one came from.
Source code in src\windlass\providers\mcp\fastmcp.py
acall_tool
async
¶
Route a call to the server that advertised the tool.
Raises:
| Type | Description |
|---|---|
MCPError
|
When no server owns the tool. |
Source code in src\windlass\providers\mcp\fastmcp.py
alist_resources
async
¶
Union every server's resources.
Source code in src\windlass\providers\mcp\fastmcp.py
alist_prompts
async
¶
Union every server's prompts.