You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用python_a2a的to_langchain_tool转换MCP Server为LangChain工具时触发404错误的问题咨询

使用python_a2a的to_langchain_tool转换MCP Server为LangChain工具时触发404错误的问题咨询

问题背景

我目前在使用python_a2a版本0.5.9,尝试从python_a2a.langchain包导入to_langchain_tool工具,把本地的MCP Server转换为LangChain可用的工具,但一直触发404错误。奇怪的是,用fastmcp.client却能正常和这个MCP Server交互,这让我很困惑,想请教下我哪里操作出错了?

触发错误的代码

from python_a2a.langchain import to_langchain_tool
add = to_langchain_tool("http://localhost:8080/mcp", "add")
print(add)

完整错误日志

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)}")

MCPToolConversionError: Failed to get tools from MCP server: Failed to get tools from MCP server: 404

我的MCP Server代码(可正常被fastmcp.client调用)

# 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()

可正常运行的fastmcp.client调用代码

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)

环境依赖版本

  • 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

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 03:10:24