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
片段添加到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 设置添加将修改全局 ~/.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
片段添加到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 设置添加将修改全局 ~/.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())