在 Cursor Settings 中找到 MCP。
点击右侧上方的 Add new global MCP server 按钮,便自动打开 .local 目录下的 mcp.json 文件。在这个json文件中,我们需要配置要运行的 MCP server 的信息。
MCP server
我们可以在网上找到各种 MCP server,并一键部署到项目中去。这里我们找到一个关于天气(weather)的 MCP server。
我们在右侧可以看到 MCP server 的json信息,这里可以选择各个平台的json信息,例如Claude、cursor、windsurf、vscode等,也可以选择mac/linux与Windows系统相关信息。
mcp.json
我使用的是mac系统,这里将相应json复制到 cursor 的 mcp.json 中去。
json内容如下:
代码语言:json
AI代码解释
{ "mcpServers": { "weather": { "command": "npx", "args": [ "-y", "@smithery/cli@latest", "run", "@turkyden/weather", "--key", "92c5301c-e29d-4d84-9985-5c6e44940934" ] } } }
从json文件中可以分析,这个 MCP server 是使用 nodejs 开发的,这里使用 npx 安装运行 weather 这个 MCP server,command 指定运行命令, args 负责构造运行参数,最后传入了调用天气接口需要的key参数。
在保存了mcp.json之后,Cursor Settings 中 MCP 配置页面就多aly.suankj.com11了一个名为 weather 的 MCP server。
从界面中可以看到 MCP Server 的信息, weather 一共定义了两个 tools:get_alerts 和 get_forecast。
调用 MCP server
配置完成之后,接下来就是在cursor中调用 weather 这个查询天气的 MCP server。在 CHAT 对话框中,选择 Agent 模式。
然后输入查询天气的需求。
如上图所示,调用了 get_alerts 查询天气情况。在 weather 中为了让天气更精准,又调用了 get_forecast 这个接口确定经纬度。
然后 weather 这个 MCP Server就被cursor调用成功,然后返回查询天气的结果。
结语
本篇文章主要讲述了如何在cursor中配置和调用 MCP Server,我们也可以尝试使用自定义的 MCP Server 进行配置调用。