輕松配置Cursor玩轉(zhuǎn)MCP,你學(xué)會了嗎?
我們來看如何配置 Cursor。需要注意,低版本 Cursor 也支持 MCP 服務(wù),我用的是 0.48.7 版本。在 Cursor 設(shè)置中,先將版本切換到 Early Access(搶先體驗(yàn))。
圖片
然后點(diǎn)擊 Check for Updates,將 Cursor 升級到最新版(版本號會變化,這里不再具體說明)。
圖片
圖片
圖片
最新版 Cursor 支持全新的 MCP 配置方式。本文重點(diǎn)介紹這種新方法。在 Cursor 設(shè)置左側(cè),找到 MCP 配置選項(xiàng)。現(xiàn)在的 MCP 配置是通過文件方式實(shí)現(xiàn)的:
圖片
在項(xiàng)目根目錄下新建一個(gè)名為 .cursor 的文件夾:
圖片
圖片
在 .cursor 文件夾內(nèi),右鍵選擇 New File,新建 mcp.json 文件:
圖片
接下來,把之前在 Cline 配置的內(nèi)容完整復(fù)制到 mcp.json 文件中:
{
"mcpServers": {
"github.com/modelcontextprotocol/servers/tree/main/src/github": {
"command": "cmd",
"args": [
"/c",
"npx",
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "已脫敏"
},
"disabled": false,
"autoApprove": []
}
}
}
圖片
粘貼完成后,左下角會彈出 New MCP server detected(檢測到新的 MCP 服務(wù)器)提示,點(diǎn)擊 Enable 啟用:
圖片
然后打開 Cursor 的 MCP 選項(xiàng)卡,檢查 MCP Server 狀態(tài),確認(rèn)變?yōu)榫G色:
圖片
:warning: 注意:如果彈出黑色窗口,不要關(guān)閉,只要 MCP Server 顯示綠色即可。
到這里,Cursor 配置就完成了,說明當(dāng)前 Cursor 配置和 Cline 設(shè)置一致。
接下來演示如何添加另一種 MCP Server。前往 MCP Servers GitHub 頁面,找到官方的自定義 Server。這里以 file system(文件系統(tǒng)) Server 為例:
圖片
點(diǎn)擊鏈接后,向下滾動頁面,看到 npx 安裝方式:
圖片
將 file system 的配置添加到 Cursor 的 mcp.json 文件。復(fù)制如下配置段落:
圖片
在 mcp.json 文件中加一個(gè)逗號,把復(fù)制的內(nèi)容粘貼到逗號后,確保逗號在上一段最后一行末尾:
圖片
{
"mcpServers": {
"github.com/modelcontextprotocol/servers/tree/main/src/github": {
"command": "cmd",
"args": [
"/c",
"npx",
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "已脫敏"
},
"disabled": false,
"autoApprove": []
},
+ "filesystem": {
+ "command": "npx",
+ "args": [
+ "-y",
+ "@modelcontextprotocol/server-filesystem",
+ "/Users/username/Desktop",
+ "/path/to/other/allowed/dir"
+ ]
+ }
}
}
圖片
Mac 系統(tǒng)配置到這里就可以了;Windows 系統(tǒng)需要把 npx 移到 args 數(shù)組里,同時(shí)把 command 改為 cmd,并加一行 /c。
調(diào)整 文件系統(tǒng)配置如下:
圖片
這里定義了 file system 可操作的目錄。我把桌面目錄添加進(jìn)列表。Windows 路徑要用雙反斜杠 \\
,如:C:\\Users\\Public\\Desktop
。
圖片
注意:請刪除不需要的配置。
圖片
添加 MCP 后,保存并回到 Cursor 設(shè)置,進(jìn)入 MCP 選項(xiàng)卡,啟用 file system MCP Server。當(dāng)前顯示為 Disabled(禁用),點(diǎn)擊后變?yōu)?nbsp;Enable(啟用):
圖片
圖片
啟用后,點(diǎn)擊 Refresh(刷新):
圖片
此時(shí)可以看到 file system MCP Server 已變?yōu)榫G色:
圖片
如果彈出新的命令行窗口,不用管它,只要 MCP Server 是綠色就行。
最后,測試一下 file system MCP Server。在 Cursor 的 AI 對話框,一定要切換到 Agent 模式:
圖片
在該模式下,我提問:
C:\Users\Public\Desktop 這個(gè)文件夾里面有什么?
也就是想查看桌面上有哪些文件。回車后,Cursor 會用 MCP 工具,點(diǎn)擊 Run Command:
圖片
Cursor 說輸出有點(diǎn)亂碼,建議換種方式查看,繼續(xù)點(diǎn)擊 Run Command:
圖片
最終,成功列出了目錄內(nèi)容:
圖片
圖片
順便說下,如果想讓 Cursor 自動用 MCP 工具,無需每次授權(quán),可以在 Cursor 設(shè)置的 Features 選項(xiàng)卡勾選 Enable auto-run mode:
圖片
這樣用 MCP 時(shí)就不用再確認(rèn)授權(quán)了。你也可以直接把這個(gè)配置文件復(fù)制到 Cline,讓 Cline 也能用 file system MCP Server。
復(fù)制 Cursor 的 mcp.json
內(nèi)容,切換到 Cline,進(jìn)入 MCP Servers,點(diǎn) Installed,選擇 Configure MCP Server:
圖片
直接粘貼內(nèi)容:
圖片
保存后,可以看到 file system MCP Server 也變?yōu)榫G色:
圖片
這樣,無論在 Cursor 還是 Cline,file system MCP Server 都能正常使用,兩個(gè)工具的配置是互通的。
本文主要講了基于 Node.js 的 MCP Server 配置,其實(shí) MCP 生態(tài)遠(yuǎn)不止這些。