Integrations¶
Adapters that bridge Locus to external frameworks.
FastMCP¶
Expose a Locus agent (or any of its tools) as a Model Context Protocol
server, and consume MCP tools from any compliant client as native
Locus Tools.
LocusMCPServer ¶
Bases: BaseModel
Exposes a Locus Agent as an MCP server.
This allows Locus agents to be used by any MCP-compatible client.
Example
from locus import Agent from locus.integrations import LocusMCPServer
agent = Agent(model=model, tools=[...]) server = LocusMCPServer(agent=agent, name="my-agent") server.run() # Starts MCP server
run ¶
Run the MCP server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transport
|
Literal['stdio', 'http', 'sse', 'streamable-http']
|
Transport type ("stdio", "http", "sse", or "streamable-http"). |
'stdio'
|
Source code in src/locus/integrations/fastmcp.py
handle_request
async
¶
Handle a single MCP request (for testing).
Source code in src/locus/integrations/fastmcp.py
create_mcp_server ¶
create_mcp_server(agent: Agent, name: str = 'locus-agent', version: str = '1.0.0') -> LocusMCPServer
Create an MCP server from a Locus Agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Agent
|
Locus Agent instance |
required |
name
|
str
|
Server name |
'locus-agent'
|
version
|
str
|
Server version |
'1.0.0'
|
Returns:
| Type | Description |
|---|---|
LocusMCPServer
|
LocusMCPServer instance |
Example
server = create_mcp_server(agent, name="my-assistant") server.run()
Source code in src/locus/integrations/fastmcp.py
mcp_tool_to_locus ¶
mcp_tool_to_locus(name: str, description: str, func: Callable[..., Any], parameters: dict[str, Any] | None = None) -> Tool
Convert an MCP-style tool to a Locus Tool.
When parameters is provided, the JSON Schema is used as-is to
construct the Tool. This preserves the source tool's flat-field
schema end-to-end so the LLM sees the original argument shape
(e.g. {tenant_id, regex, limit}) instead of the generic
{kwargs: …} shape that the @tool decorator would otherwise
derive from the wrapper's **kwargs signature.
When parameters is omitted, falls back to the decorator-derived
schema (parameter-less tool) for backward compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Tool name |
required |
description
|
str
|
Tool description |
required |
func
|
Callable[..., Any]
|
The async function to call |
required |
parameters
|
dict[str, Any] | None
|
JSON Schema for parameters |
None
|
Returns:
| Type | Description |
|---|---|
Tool
|
Locus Tool instance |