MCP 服务器
概述
模型-上下文-协议 (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 服务器
您可以按如下方式启动本地 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 工具的配置格式。
VS Code
使用下面的链接,一键在 VS Code 中安装 Prisma MCP 服务器
这将提示您打开 VS Code。打开后,您将被引导将 Prisma MCP 服务器直接安装到您的 VS Code 配置中。
如果您的浏览器阻止了该链接,您可以通过在工作区中创建 .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,点击以下链接
这将提示您在浏览器中打开 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 服务器作为设置命令启动。您可以选择使用 start_on_launch 标志配置 Prisma 在启动时激活
{
"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 服务器
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 和 Web
另外,您可以将远程 MCP 服务器添加为集成
- 在新聊天中,在主要 Claude UI 中输入提示字段下方找到连接应用程序字段
- 点击+ 添加集成
- 输入以下内容
- 集成名称:
Prisma Postgres - 集成 URL:
https://mcp.prisma.io/mcp
- 点击添加
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 环境变量,其中包含您同意的确切文本,并重新运行该命令。