Ver Fonte

Merge pull request #124 from yzy-fulture/uvx_content

uvx_content
jjyaoao há 7 meses atrás
pai
commit
e60c86ba63

+ 1 - 0
code/chapter13/helloagents-trip-planner/backend/requirements.txt

@@ -22,6 +22,7 @@ loguru>=0.7.0
 
 # MCP相关
 fastmcp>=2.0.0
+uv>=0.8.0
 
 # 其他工具
 python-dateutil>=2.8.2

+ 2 - 0
docs/chapter13/Chapter13-Intelligent-Travel-Assistant.md

@@ -706,6 +706,8 @@ mcp_tool = MCPTool(
 
 What does this code do? First, `command` and `args` specify how to start the MCP server. `npx -y @sugarforever/amap-mcp-server` will download and run the `amap-mcp-server` package from the npm repository. The `env` parameter passes environment variables, here we pass the Amap API key.
 
+**Note:** Some examples in this document use `npx` to launch MCP (Model Context Protocol) services. However,in the code repository corresponding to this section of content, we actually use `uvx`. It’s important to note that `npx` and `uvx` share nearly identical design principles—the only difference lies in their ecosystems: `npx` targets JavaScript/Node.js (packages from npm), while `uvx` targets Python (packages from PyPI).There is no superiority or inferiority between the two methods. Please choose according to your needs when using them.
+
 When we create the `MCPTool` object, it will start the MCP server process in the background and communicate with the server through standard input/output (stdin/stdout). This is a feature of the MCP protocol: using inter-process communication instead of HTTP, which is more efficient and easier to manage.
 
 The most critical parameter is `auto_expand=True`. When set to True, `MCPTool` will automatically query what tools the MCP server provides, and then create an independent Tool object for each tool. This is why we only created one `MCPTool`, but the Agent got 16 tools. Let's see this process:

+ 2 - 0
docs/chapter13/第十三章 智能旅行助手.md

@@ -708,6 +708,8 @@ mcp_tool = MCPTool(
 
 这段代码做了什么呢?首先,`command`和`args`指定了如何启动 MCP 服务器。`npx -y @sugarforever/amap-mcp-server`会从 npm 仓库下载并运行`amap-mcp-server`这个包。`env`参数传递了环境变量,这里我们传递了高德地图的 API 密钥。
 
+**注意:**本文档中部分示例使用 `npx` 启动 MCP(Model Context Protocol)服务。而在本节代码仓中,我们实际采用的是 `uvx` 方式。需要说明的是,`npx` 和 `uvx` 在设计理念上高度一致,区别仅在于所处的生态系统,`npx` 面向 JavaScript/Node.js(包来自 npm),而`uvx` 面向 Python(包来自 PyPI)。两种方式并无优劣之分,请大家在使用时按需进行选择。
+
 当我们创建`MCPTool`对象时,它会在后台启动 MCP 服务器进程,并通过标准输入输出(stdin/stdout)与服务器通信。这是 MCP 协议的一个特点:使用进程间通信而不是 HTTP,这样更高效,也更容易管理。
 
 最关键的是`auto_expand=True`这个参数。当设置为 True 时,`MCPTool`会自动查询 MCP 服务器提供了哪些工具,然后为每个工具创建一个独立的 Tool 对象。这就是为什么我们只创建了一个`MCPTool`,但 Agent 却获得了 16 个工具。让我们看看这个过程: