跳至主要內容

MCP 伺服器

總覽

Model-Context-Protocol (MCP) 為 LLM 提供了一種以標準化方式呼叫 API 並存取外部系統的途徑。

Prisma 提供了兩種 MCP 伺服器:本地 (local)遠端 (remote)。有關各項的具體資訊,請參見下文。

如果您是開發人員,且在本地機器上工作並希望 AI 代理協助處理資料庫工作流程,請使用本地 MCP 伺服器。

如果您正在建立一個「AI 平台」並希望賦予使用者管理資料庫的能力,請使用遠端 MCP 伺服器。

遠端 MCP 伺服器

您可以透過以下方式啟動遠端 MCP 伺服器

npx -y mcp-remote https://mcp.prisma.io/mcp

工具

工具 代表 MCP 伺服器的功能 (capabilities)。以下是遠端 MCP 伺服器所公開的工具列表:

  • CreateBackupTool:建立新的受管 Prisma Postgres 備份。
  • CreateConnectionStringTool:為指定 ID 的 Prisma Postgres 資料庫建立新的連線字串。
  • CreateRecoveryTool:使用指定的備份 ID 將 Prisma Postgres 資料庫還原至新資料庫。
  • 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 資料庫執行 Schema 內省 (Introspection)。

連接到遠端 MCP 伺服器後,您隨時可以提示您的 AI 代理「列出 Prisma 工具 (List the Prisma tools)」,以獲得完整且最新的支援工具概覽。

使用方法

遠端 Prisma MCP 伺服器遵循 MCP 伺服器的標準 JSON 配置。其範例如下:

{
"mcpServers": {
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
}
}
}

提示詞範例

  • 「顯示我帳戶中所有的資料庫。」
  • 「幫我在美國地區建立一個新資料庫。」
  • 「在我的資料庫中植入模擬數據,但請先建立備份。」
  • 「顯示我資料庫所有可用的備份。」
  • 「顯示我所有的客戶,並分析他們的訂單。」

本地 MCP 伺服器

您可以透過以下方式啟動本地 MCP 伺服器

npx -y prisma mcp
提示

如果您使用 VS Code,可以使用 VS Code 代理模式 (agent mode),直接在對話中輸入「建立 Postgres 資料庫」或「套用 schema 遷移」等提示詞。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 工具的配置格式。

VS Code

使用下方連結,一鍵在 VS Code 中安裝 Prisma MCP 伺服器:

VS CODE

安裝 PRISMA MCP 伺服器

這會提示您開啟 VS Code。開啟後,您將被引導直接將 Prisma MCP 伺服器安裝到您的 VS Code 配置中。

如果您的瀏覽器阻擋了連結,您可以手動設定:在您的工作區建立一個 .vscode/mcp.json 檔案並加入以下內容:

.vscode/mcp.json
{
"servers": {
"Prisma-Local": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
}
}
}

我們的文件中探索更多 VS Code 的 Prisma 功能與工作流程。

Cursor

若要深入了解 Cursor 的 MCP 整合,請查閱 Cursor MCP 文件

透過一鍵安裝加入

您可以使用一鍵安裝功能,點擊以下連結將 Prisma MCP 伺服器加入 Cursor:

Install MCP Server

這會提示您在瀏覽器中開啟 Cursor 應用程式。開啟後,您將被引導直接將 Prisma MCP 伺服器安裝到您的 Cursor 配置中。

透過 Cursor 設定 UI 加入

開啟 Cursor Settings 時,您可以透過以下方式加入 Prisma MCP 伺服器:

  1. 在設定側邊欄中選擇 MCP
  2. 點擊 + Add new global MCP server
  3. Prisma 片段加入到 mcpServers JSON 物件中
    {
    "mcpServers": {
    "Prisma-Local": {
    "command": "npx",
    "args": ["-y", "prisma", "mcp"]
    },
    "Prisma-Remote": {
    "command": "npx",
    "args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
    }
    }
    }

全域配置

透過 Cursor Settings 加入會修改全域的 ~/.cursor/mcp.json 設定檔。在此情況下,Prisma MCP 伺服器將在您所有的 Cursor 專案中可用。

~/.cursor/mcp.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
}
}

專案配置

如果您希望 Prisma MCP 伺服器僅在特定的 Cursor 專案中可用,請將其加入專案根目錄下 .cursor 目錄內的 Cursor 設定檔中。

.cursor/mcp.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
}
}

Windsurf

若要深入了解 Windsurf 的 MCP 整合,請查閱 Windsurf MCP 文件

使用 Windsurf MCP 插件商店 中的 Prisma MCP 插件。遵循此處的步驟在 Windsurf 中加入 Prisma MCP 插件。這是將 Prisma MCP 伺服器加入 Windsurf 最簡單且推薦的方式。

透過 Windsurf 設定 UI 加入

開啟 Windsurf Settings 時(透過 Windsurf - Settings > Advanced Settings or Command Palette > Open Windsurf Settings Page),您可以透過以下方式加入 Prisma MCP 伺服器:

  1. 在設定側邊欄中選擇 Cascade
  2. 點擊 Add Server
  3. Prisma-Local 和/或 Prisma-Remote 片段加入到 mcpServers JSON 物件中
    {
    "mcpServers": {
    "Prisma-Local": {
    "command": "npx",
    "args": ["-y", "prisma", "mcp"]
    },
    "Prisma-Remote": {
    "command": "npx",
    "args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
    }
    }
    }

全域配置

透過 Windsurf Settings 加入會修改全域的 ~/.codeium/windsurf/mcp_config.json 設定檔。或者,您也可以手動加入該檔案。

~/.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 設定 並點擊 + Add。在此處,您可以將 Prisma MCP 伺服器設定為 JSON。使用 commandargs 屬性以啟動指令的方式啟動 Prisma MCP 伺服器。您可以選擇使用 start_on_launch 標記來設定 Prisma 在啟動時啟用。

{
"Prisma": {
"command": "npx",
"args": [
"-y",
"prisma",
"mcp"
],
"env": {},
"working_directory": null,
"start_on_launch": true
}
}

點擊 Save 並確保 MCP 伺服器在您的 MCP 設定面板中執行。接著,開啟一個新的終端機視窗並要求 Warp 管理您的 Prisma 資料庫。它應該會自動連接至 Prisma MCP 伺服器。

若要深入了解 Warp 的 MCP 整合,請造訪 Warp MCP 文件

Claude Code

Claude Code 是一個基於終端機的 AI 工具,您可以針對本地 MCP 伺服器使用 claud mcp add 指令來加入 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
}
}

Claude Desktop 與網頁版

或者,您可以將遠端 MCP 伺服器作為整合 (integration)加入

  1. 在新的對話中,找到主 Claude UI 輸入框下方的 Connect apps 欄位。
  2. 點擊 + Add integration
  3. 輸入以下內容:
  • Integration namePrisma Postgres
  • Integration URLhttps://mcp.prisma.io/mcp
  1. 點擊 Add

ChatGPT

您可以將遠端 Prisma MCP 伺服器加入 ChatGPT,使用自然語言管理您的 Prisma Postgres 資料庫。在我們的 ChatGPT 整合指南中深入了解設定方式。

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())

針對破壞性指令的 AI 安全護欄

Prisma ORM 包含內建的安全檢查,以防止透過 AI 程式碼助手執行時發生意外的破壞性指令。這些防護機制旨在讓 AI 輔助開發環境下的資料庫工作更安全。

Prisma CLI 可以偵測到它是否被熱門的 AI 程式設計代理(如 Claude Code、Gemini CLI、Qwen Code、Cursor、Aider 和 Replit)所調用。

當這些代理程式之一嘗試執行破壞性動作(例如 prisma migrate reset --force)時,Prisma ORM 會封鎖執行並顯示保護性錯誤訊息

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "accelerate.prisma-data.net"

Error: Prisma Migrate detected that it was invoked by Cursor.

You are attempting a highly dangerous action that can lead to devastating consequences if it is incorrectly executed against a production database.

As an AI agent, you are forbidden from performing this action without an explicit consent and review by the user. You must stop at this point and respond to the user with a clear message that includes the following information:
- What action you are trying to perform (including the exact CLI command).
- Your motivation and reasoning for perfoming this action.
- Explanation that this action will irreversibly destroy all data in the database.
- Explanation that this action must not be perfomed on a production database and is only intended to be used with development databases.

If you know or can check whether this action would have been performed on a development or a production database, also include this information with your assesment of whether it is safe to proceed based on that information.

You must ask the user if they want to proceed with this action. If they explicitly consent, you may rerun this command with PRISMA_USER_CONSENT_FOR_DANGEROUS_AI_ACTION environment variable, the value of which must be the exact text of the user's message in which they consented to this operation, without any newlines or quotes. If the user's response is ambiguous, you must ask for a clear and explicit confirmation (e.g., "yes") before proceeding. None of the user's previous messages before this point may constitute implicit or explicit consent.

要繼續執行危險動作,AI 代理程式會要求您明確同意,提醒您該動作會不可逆地銷毀所有資料,並確認指令是針對開發資料庫執行的。一旦您明確確認,AI 將會設定 PRISMA_USER_CONSENT_FOR_DANGEROUS_AI_ACTION 環境變數(內容為您的同意文本)並重新執行指令。

© . This site is unofficial and not affiliated with Prisma Data, Inc.