File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 31
31
uv add fastapi-mcp
32
32
```
33
33
34
- 或者,您可以使用pip安装 :
34
+ 或者,您可以使用 pip 安装 :
35
35
36
36
``` bash
37
37
pip install fastapi-mcp
@@ -62,7 +62,7 @@ mcp.mount()
62
62
63
63
就是这样!您的自动生成的 MCP 服务器现在可以在 ` https://app.base.url/mcp ` 访问。
64
64
65
- > ** 关于` base_url ` 的注意事项** :虽然` base_url ` 是可选的,但强烈建议您明确提供它。` base_url ` 告诉 MCP 服务器在调用工具时向何处发送 API 请求。如果不提供,库将尝试自动确定URL ,这在部署环境中内部和外部 URL 不同时可能无法正确工作。
65
+ > ** 关于` base_url ` 的注意事项** :虽然` base_url ` 是可选的,但强烈建议您明确提供它。` base_url ` 告诉 MCP 服务器在调用工具时向何处发送 API 请求。如果不提供,库将尝试自动确定 URL ,这在部署环境中内部和外部 URL 不同时可能无法正确工作。
66
66
67
67
## 工具命名
68
68
@@ -76,15 +76,15 @@ FastAPI-MCP 使用 FastAPI 路由中的`operation_id`作为 MCP 工具的名称
76
76
async def read_user (user_id : int ):
77
77
return {" user_id" : user_id}
78
78
79
- # 显式operation_id (工具将被命名为 "get_user_info")
79
+ # 显式 operation_id (工具将被命名为 "get_user_info")
80
80
@app.get (" /users/{user_id} " , operation_id = " get_user_info" )
81
81
async def read_user (user_id : int ):
82
82
return {" user_id" : user_id}
83
83
```
84
84
85
85
为了获得更清晰、更直观的工具名称,我们建议在 FastAPI 路由定义中添加显式的` operation_id ` 参数。
86
86
87
- 要了解更多信息,请阅读 FastAPI 官方文档中关于 [ 路径操作的高级配置] ( https://fastapi.tiangolo.com/advanced/path-operation-advanced-configuration/ ) 的部分。
87
+ 要了解更多信息,请阅读 FastAPI 官方文档中关于 [ 路径操作的高级配置] ( https://fastapi.tiangolo.com/advanced/path-operation-advanced-configuration/ ) 的部分。
88
88
89
89
## 高级用法
90
90
@@ -179,7 +179,7 @@ mcp_app = FastAPI()
179
179
# 从 API 应用创建 MCP 服务器
180
180
mcp = FastApiMCP(
181
181
api_app,
182
- base_url = " http://api-host:8001" , # API应用将运行的URL
182
+ base_url = " http://api-host:8001" , # API 应用将运行的 URL
183
183
)
184
184
185
185
# 将 MCP 服务器挂载到单独的应用
You can’t perform that action at this time.
0 commit comments