MCP 伺服器
概覽
Model-Context-Protocol (MCP) 為大型語言模型(LLM)提供了一種呼叫 API 並以明確定義的方式訪問外部系統的方法。
Prisma 提供了兩個 MCP 伺服器:一個本地伺服器和一個遠端伺服器。有關每個伺服器的具體資訊,請參閱下文。
如果您是開發人員,在本地機器上工作,並希望您的 AI 代理協助您的資料庫工作流,請使用本地 MCP 伺服器。
如果您正在構建一個“AI 平臺”,並希望為您的使用者提供管理資料庫的能力,請使用遠端 MCP 伺服器。
遠端 MCP 伺服器
您可以按如下方式啟動遠端 MCP 伺服器
npx -y mcp-remote https://mcp.prisma.io/mcp
工具
工具代表了 MCP 伺服器的功能。以下是遠端 MCP 伺服器公開的工具列表:
CreateBackupTool: 建立新的託管 Prisma Postgres 備份。CreateConnectionStringTool: 為給定 ID 的 Prisma Postgres 資料庫建立新的連線字串。CreateRecoveryTool: 將 Prisma Postgres 資料庫恢復到具有給定備份 ID 的新資料庫。DeleteConnectionStringTool: 刪除具有給定連線字串 ID 的連線字串。DeleteDatabaseTool: 刪除具有給定 ID 的 Prisma Postgres 資料庫。ListBackupsTool: 獲取給定資料庫 ID 和環境 ID 的可用 Prisma Postgres 備份列表。ListConnectionStringsTool: 獲取給定資料庫 ID 和環境 ID 的可用 Prisma Postgres 資料庫連線字串列表。ListDatabasesTool: 獲取使用者工作區中可用 Prisma Postgres 資料庫的列表。ExecuteSqlQueryTool: 在給定 ID 的 Prisma Postgres 資料庫上執行 SQL 查詢。IntrospectSchemaTool: 內省具有給定 ID 的 Prisma Postgres 資料庫的模式。
連線到遠端 MCP 伺服器後,您還可以隨時提示您的 AI 代理“列出 Prisma 工具”,以獲取最新支援工具的完整概覽。
用法
遠端 Prisma MCP 伺服器遵循 MCP 伺服器的標準 JSON 配置。如下所示:
{
"mcpServers": {
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
}
}
}
如果您想嘗試遠端 MCP 伺服器並探索其功能,我們推薦使用 Cloudflare 的 AI Playground。將 https://mcp.prisma.io/mcp URL 新增到帶有Enter MCP server URL佔位符的文字欄位中,點選連線,然後使用在彈出的視窗中進行身份驗證。連線後,您可以向 Playground 傳送提示,並檢視 LLM 根據您的提示選擇的 MCP 工具。
示例提示
- “顯示我賬戶中所有資料庫的列表。”
- “在美國區域為我建立一個新資料庫。”
- “用看起來真實的資料填充我的資料庫,但事先建立一個備份。”
- “顯示我資料庫的所有可用備份。”
- “顯示所有客戶並對他們的訂單進行分析。”
本地 MCP 伺服器
您可以按如下方式啟動本地 MCP 伺服器
npx -y prisma mcp
如果您使用的是 VS Code,您可以使用 VS Code 代理模式直接在聊天中輸入“建立 Postgres 資料庫”或“應用模式遷移”等提示。VS Code 代理會自動處理所有底層的 Prisma CLI 呼叫和 API 呼叫。有關更多詳細資訊,請參閱我們的 VS Code 代理文件。
工具
工具代表了 MCP 伺服器的功能。以下是本地 MCP 伺服器公開的工具列表:
migrate-status: 透過prisma migrate status命令檢查您的遷移狀態。migrate-dev: 透過prisma migrate dev --name <name>命令建立並執行遷移。LLM 將提供<name>選項。migrate-reset: 透過prisma migrate reset --force命令重置您的資料庫。Prisma-Postgres-account-status: 檢查您與透過platform auth show --early-access命令的身份驗證狀態。Create-Prisma-Postgres-Database: 透過'init --db --name' <name> '--region' <region> '--non-interactive'命令建立新的 Prisma Postgres 資料庫。LLM 將提供<name>和<region>選項。Prisma-Login: 使用透過platform auth login --early-access命令進行身份驗證。Prisma-Studio: 透過prisma studio命令開啟 Prisma Studio。
用法
本地 Prisma MCP 伺服器遵循 MCP 伺服器的標準 JSON 配置。如下所示:
{
"mcpServers": {
"Prisma-Local": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
}
}
}
示例提示
以下是一些當 MCP 伺服器執行時您可以使用的示例提示:
- “將我登入到 Prisma 控制檯。”
- “在美國區域建立一個數據庫。”
- “在我的資料庫中建立一個新的
Product表。”
整合到 AI 工具中
AI 工具整合 MCP 伺服器的方式各不相同。在大多數情況下,都有專用的配置檔案,您可以在其中新增上述 JSON 配置。該配置包含一個啟動伺服器的命令,該命令將由相應的工具執行,以便伺服器可供其 LLM 使用。
在本節中,我們將介紹最流行的 AI 工具的配置格式。
Cursor
要了解有關 Cursor MCP 整合的更多資訊,請查閱 Cursor MCP 文件。
透過一鍵安裝新增
您可以透過點選以下連結,使用 一鍵安裝將 Prisma MCP 伺服器新增到 Cursor:
這將提示您在瀏覽器中開啟 Cursor 應用。開啟後,您將被引導將 Prisma MCP 伺服器直接安裝到您的 Cursor 配置中。
透過 Cursor 設定 UI 新增
開啟 Cursor 設定時,您可以按如下方式新增 Prisma MCP 伺服器:
- 在設定側邊導航欄中選擇 MCP
- 點選 + 新增新的全域性 MCP 伺服器
- 將
Prisma片段新增到mcpServersJSON 物件中{
"mcpServers": {
"Prisma-Local": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
}
}
}
全域性配置
透過 Cursor 設定新增將修改全域性 ~/.cursor/mcp.json 配置檔案。在這種情況下,Prisma MCP 伺服器將在您的所有 Cursor 專案中可用:
{
"mcpServers": {
"Prisma-Local": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
},
// other MCP servers
}
}
專案配置
如果您希望 Prisma MCP 伺服器僅在特定的 Cursor 專案中可用,請將其新增到專案根目錄中 .cursor 資料夾內的相應專案的 Cursor 配置中:
{
"mcpServers": {
"Prisma-Local": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
}
// other MCP servers
}
}
Windsurf
要了解有關 Windsurf MCP 整合的更多資訊,請查閱 Windsurf MCP 文件。
透過 Windsurf MCP 外掛商店新增(推薦)
使用 Windsurf MCP 外掛商店中的 Prisma MCP 外掛。按照 此處的步驟在 Windsurf 中新增 Prisma MCP 外掛。這是將 Prisma MCP 伺服器新增到 Windsurf 最簡單和推薦的方式。
透過 Windsurf 設定 UI 新增
開啟 Windsurf 設定(透過 Windsurf - 設定 > 高階設定或命令面板 > 開啟 Windsurf 設定頁面)時,您可以按如下方式新增 Prisma MCP 伺服器:
- 在設定側邊導航欄中選擇 Cascade
- 點選 新增伺服器
- 將
Prisma-Local和/或Prisma-Remote片段新增到mcpServersJSON 物件中{
"mcpServers": {
"Prisma-Local": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
}
}
}
全域性配置
透過 Windsurf 設定新增將修改全域性 ~/.codeium/windsurf/mcp_config.json 配置檔案。或者,您也可以手動將其新增到該檔案中:
{
"mcpServers": {
"Prisma-Local": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
},
// other MCP servers
}
}
Warp
您可以將 Prisma MCP 作為全域性可用工具新增到 Warp。首先,訪問您的 MCP 設定並點選 + 新增。在此處,您可以將 Prisma MCP 伺服器配置為 JSON。使用 command 和 args 屬性將 Prisma MCP 伺服器作為設定命令啟動。您可以選擇配置 Prisma 在啟動時啟用,使用 start_on_launch 標誌:
{
"Prisma": {
"command": "npx",
"args": [
"-y",
"prisma",
"mcp"
],
"env": {},
"working_directory": null,
"start_on_launch": true
}
}
點選儲存並確保 MCP 伺服器在您的 MCP 設定面板中執行。然後,開啟一個新的終端視窗並要求 Warp 管理您的 Prisma 資料庫。它應該會自動連線到 Prisma MCP 伺服器。
要了解有關 Warp MCP 整合的更多資訊,請訪問 Warp MCP 文件。
Claude Code
Claude Code 是一個基於終端的 AI 工具,您可以使用 claud mcp add 命令為本地 MCP 伺服器新增 MCP 伺服器:
claude mcp add prisma-local npx prisma mcp
或為遠端 MCP 伺服器新增:
claude mcp add prisma-remote npx mcp-remote https://mcp.prisma.io/mcp
在 Claude Code MCP 文件中瞭解更多資訊。
Claude Desktop
按照 Claude Desktop MCP 文件中的說明建立所需的配置檔案:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
然後將 JSON 片段新增到該配置檔案中:
{
"mcpServers": {
"Prisma-Local": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
},
// other MCP servers
}
}
OpenAI Agents SDK
以下是一個透過 OpenAI Agents SDK 在 Python 指令碼中使用 Prisma MCP 伺服器的示例:
from openai import AsyncOpenAI
from openai.types.beta import Assistant
from openai.beta import AsyncAssistantExecutor
from openai.experimental.mcp import MCPServerStdio
from openai.types.beta.threads import Message, Thread
from openai.types.beta.tools import ToolCall
import asyncio
async def main():
# Launch both MCP servers concurrently
async with MCPServerStdio(
params={
"command": "npx",
"args": ["-y", "prisma", "mcp"]
}
) as local_server, MCPServerStdio(
params={
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
}
) as remote_server:
# Optional: list tools from both servers
local_tools = await local_server.list_tools()
remote_tools = await remote_server.list_tools()
print("Local server tools:", [tool.name for tool in local_tools])
print("Remote server tools:", [tool.name for tool in remote_tools])
# Set up the assistant with both MCP servers
agent = Assistant(
name="Prisma Assistant",
instructions="Use the Prisma tools to help the user with database tasks.",
mcp_servers=[local_server, remote_server],
)
executor = AsyncAssistantExecutor(agent=agent)
# Create a thread and send a message
thread = Thread(messages=[Message(role="user", content="Create a new user in the database")])
response = await executor.run(thread=thread)
print("Agent response:")
for message in response.thread.messages:
print(f"{message.role}: {message.content}")
# Run the async main function
asyncio.run(main())