Hi,
I would like to know if the prebuilt create_swarm supports mcp tools ?
My code looks like below:
async def swarm():
# get MCP tools
mcp_client = MultiServerMCPClient(
{
"math_tools":{
"url": "http://localhost:8000/sse",
"transport": "sse"
},
}
)
mcp_tools = await mcp_client.get_tools()
alice = create_react_agent(
model,
[mcp_tools, create_handoff_tool(agent_name="Bob")],
prompt="You are Alice, an math expert.",
name="Alice",
)
bob = create_react_agent(
model,
[create_handoff_tool(agent_name="Alice", description="Transfer to Alice, she can help with math")],
prompt="You are Bob, you speak like a pirate.",
name="Bob",
)
workflow = create_swarm(
[alice, bob],
default_active_agent="Alice"
)
return await workflow.compile()
where one the tool looks like this:
@mcp.tool()
async def multiply(a: int, b: int) -> int:
"""multiply 2 numbers
Args:
a (int): the first number to multiply
b (int): the second number to multiply
Returns:
int: the multiplication of a and b
"""
print(colored("multiplication tool", "cyan"))
print(colored(f"{a=}, {b=}", "cyan"))
return a*b
if __name__ == "__main__":
print(colored("starting math mcp server ...", "cyan"))
mcp.run(transport="sse")
When running langgraph dev, I got the following error:
ValueError: The first argument must be a string or a callable with a name for tool decorator. Got <class ‘list’>
Is there a conflict between the create_handoff_tool and those from the mcp server ?
thanks,
Jonathan