I am using python_a2a version 0.5.9, I am trying to use to_langchain_tool from python_a2a.langchain package but I am getting following error while trying to convert a MCP Server to langchain tool
code:
from python_a2a.langchain import to_langchain_tool
add = to_langchain_tool("http://localhost:8080/mcp", "add")
print(add)
Error:
MCPToolConversionError Traceback (most recent call last)
File ~/Documents/project/venv/lib/python3.12/site-packages/python_a2a/langchain/mcp.py:492, in to_langchain_tool(mcp_url, tool_name)
491 if tools_response.status_code != 200:
--> 492 raise MCPToolConversionError(f"Failed to get tools from MCP server: {tools_response.status_code}")
494 available_tools = tools_response.json()
MCPToolConversionError: Failed to get tools from MCP server: 404
During handling of the above exception, another exception occurred:
MCPToolConversionError Traceback (most recent call last)
Cell In[2], line 2
1 from python_a2a.langchain import to_langchain_tool
----> 2 add = to_langchain_tool("http://localhost:8080/mcp", "add")
3 print(add)
File ~/Documents/project/venv/lib/python3.12/site-packages/python_a2a/langchain/mcp.py:498, in to_langchain_tool(mcp_url, tool_name)
496 except Exception as e:
497 logger.error(f"Error getting tools from MCP server: {e}")
--> 498 raise MCPToolConversionError(f"Failed to get tools from MCP server: {str(e)}")
500 # Filter tools if a specific tool is requested
501 if tool_name is not None:
MCPToolConversionError: Failed to get tools from MCP server: Failed to get tools from MCP server: 404
which basically means that it's unable to find the MCP Server path
Following is my code for MCP Server:
add_mcp.py
from fastmcp import FastMCP
mcp = FastMCP("Demo", stateless_http=True)
@mcp.tool
def add(a: int, b:int) -> int:
print(a + b)
return a + b
if __name__ == "__main__":
mcp.run()
I am able to use fastmcp.client to call the MCP Server, here is the code for that
from fastmcp.client import Client
client = Client("http://localhost:8080/mcp")
async with client:
tools = await client.list_tools()
print(tools)
result = await client.call_tool("add", arguments={"a": 10, "b": 20})
print(result.content)
Am I making any mistake while using the python_a2a package for converting MCP Server to langchain tools ?
Following are the version details:
fastmcp==2.10.5
langchain==0.3.26
langchain-anthropic==0.3.17
langchain-core==0.3.69
langchain-mcp-adapters==0.1.9
langchain-ollama==0.3.5
langchain-tavily==0.2.10
langchain-text-splitters==0.3.8
python-a2a==0.5.9
I run your code and there are few mistakes.
Client has to be in async function and use asyncio.run(main())
.
Server needs transport=streamable-http
because it was using transport=stdio
. And this was giving error 404
.
But main problem is that to_langchain_tool()
works incorrectly.
When I use client.list_tools()
in normal Client then Server shows in terminal POST
requests
INFO: 127.0.0.1:43026 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 127.0.0.1:43026 - "POST /mcp/ HTTP/1.1" 200 OK
But if I use to_langchain_tool('http://localhost:8000/mcp', 'add')
to get tool add
or to_langchain_tool('http://localhost:8000/mcp')
to get list of all tools then Server shows GET
instead of POST
(but this time with code 406
)
INFO: 127.0.0.1:47460 - "GET /mcp/tools HTTP/1.1" 406 Not Acceptable
I found in source code that it uses
tools_response = requests.get(f"{mcp_url}/tools")
and this would need to change this code in to_langchain_tool()
to work correctly.
At this moment it seems it can't work.
Maybe you would have to send this problem to author(s) of python-a2a
EDIT:
For other people: problem is reported on python-a2a
repo: