MCP 服务器
概述
¥Overview
模型-上下文-协议 (MCP) 为 LLM 提供了一种调用 API 的方式,从而以明确定义的方式访问外部系统。
¥The Model-Context-Protocol (MCP) gives LLMs a way to call APIs and thus access external systems in a well-defined manner.
Prisma 提供两个 MCP 服务器:一个本地服务器和一个远程服务器。有关每个服务器的具体信息,请参见下文。
¥Prisma's provides two MCP servers: a local and a remote one. See below for specific information on each.
如果你是使用本地机器的开发者,并且希望你的 AI 代理能够帮助你处理数据库工作流,请使用本地 MCP 服务器。
¥If you're a developer working on a local machine and want your AI agent to help with your database workflows, use the local MCP server.
如果你正在构建 "AI 平台" 并希望赋予用户管理数据库的能力,请使用远程 MCP 服务器。
¥If you're building an "AI platform" and want to give the ability to manage database to your users, use the remote MCP server.
远程 MCP 服务器
¥Remote MCP server
你可以按如下方式启动远程 MCP 服务器:
¥You can start the remote MCP server as follows:
npx -y mcp-remote https://mcp.prisma.io/mcp
工具
¥Tools
工具 代表 MCP 服务器的功能。以下是远程 MCP 服务器公开的工具列表:
¥Tools represent the capabilities of an MCP server. Here's the list of tools exposed by the remote MCP server:
-
CreateBackupTool
:创建一个新的托管 Prisma Postgres 备份。¥
CreateBackupTool
: Create a new managed Prisma Postgres Backup. -
CreateConnectionStringTool
:为指定 ID 的 Prisma Postgres 数据库创建新的连接字符串。¥
CreateConnectionStringTool
: Create a new Connection String for a Prisma Postgres database with the given id. -
CreateRecoveryTool
:使用给定的备份 ID 将 Prisma Postgres 数据库恢复到新数据库。¥
CreateRecoveryTool
: Restore a Prisma Postgres Database to a new database with the given Backup id. -
DeleteConnectionStringTool
:删除指定 ID 的连接字符串。¥
DeleteConnectionStringTool
: Delete a Connection String with the given connection string id. -
DeleteDatabaseTool
:删除指定 ID 的 Prisma Postgres 数据库。¥
DeleteDatabaseTool
: Delete a Prisma Postgres database with the given id. -
ListBackupsTool
:获取给定数据库 ID 和环境 ID 的可用 Prisma Postgres 备份列表。¥
ListBackupsTool
: Fetch a list of available Prisma Postgres Backups for the given database id and environment id. -
ListConnectionStringsTool
:获取给定数据库 ID 和环境 ID 的可用 Prisma Postgres 数据库连接字符串列表。¥
ListConnectionStringsTool
: Fetch a list of available Prisma Postgres Database Connection Strings for the given database id and environment id. -
ListDatabasesTool
:获取用户工作区可用的 Prisma Postgres 数据库列表。¥
ListDatabasesTool
: Fetch a list of available Prisma Postgres Databases for user's workspace. -
ExecuteSqlQueryTool
:使用给定 ID 对 Prisma Postgres 数据库执行 SQL 查询。¥
ExecuteSqlQueryTool
: Execute a SQL query on a Prisma Postgres database with the given id. -
IntrospectSchemaTool
:使用给定的 ID 检查 Prisma Postgres 数据库的架构。¥
IntrospectSchemaTool
: Introspect the schema of a Prisma Postgres database with the given id.
连接到远程 MCP 服务器后,你还可以随时提示你的 AI 代理访问 "列出 Prisma 工具",以获取最新支持工具的完整概述。
¥Once you're connected to the remote MCP server, you can also always prompt your AI agent to "List the Prisma tools" to get a full overview of the latest supported tools.
用法
¥Usage
远程 Prisma MCP 服务器遵循 MCP 服务器基于 JSON 的标准配置。其外观如下:
¥The remote Prisma MCP server follows the standard JSON-based configuration for MCP servers. Here's what it looks like:
{
"mcpServers": {
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
}
}
}
如果你想尝试远程 MCP 服务器并探索其功能,我们推荐使用 Cloudflare 的 AI 实践。将 https://mcp.prisma.io/mcp
URL 添加到带有“输入 MCP 服务器 URL”占位符的文本字段中,点击“连接”,然后在弹出窗口中使用 进行身份验证。连接后,你可以向 Playground 发送提示,并查看 LLM 根据你的提示选择的 MCP 工具。
¥If you want to try it the remote MCP server and explore it's capabilities, we recommend Cloudflare's AI Playground for that. Add the https://mcp.prisma.io/mcp
URL into the text field with the Enter MCP server URL placeholder, click Connect, and then authenticate with the in the popup window. Once connected, you can send prompts to the Playground and see what MCP tools the LLM chooses based on your prompts.
示例提示
¥Sample prompts
-
"显示我账户中所有数据库的列表。"
¥"Show me a list of all the databases in my account."
-
"在美国地区为我创建一个新的数据库。"
¥"Create a new database in the US region for me."
-
"使用看似真实的数据填充我的数据库,但请事先创建备份。"
¥"Seed my database with real-looking data but create a backup beforehand."
-
"显示我数据库的所有可用备份。"
¥"Show me all available backups of my database."
-
"显示所有客户并对其订单进行分析。"
¥"Show me all customers and run an analysis over their orders."
本地 MCP 服务器
¥Local MCP server
你可以按如下方式启动本地 MCP 服务器:
¥You can start the local MCP server as follows:
npx -y prisma mcp
如果你使用的是 VS Code,则可以使用 VS Code 代理模式 直接在聊天中输入提示,例如 "创建 Postgres 数据库" 或 "应用模式迁移"。VS Code 代理会自动处理所有底层 Prisma CLI 调用和 API 调用。有关更多详细信息,请参阅我们的 VS Code 代理文档。
¥If you're using VS Code, you can use VS Code agent mode to enter prompts such as "create Postgres database" or "apply schema migration" directly in the chat. The VS code agent handles all underlying Prisma CLI invocations and API calls automatically. See our VS Code Agent documentation for more details.
工具
¥Tools
工具 代表 MCP 服务器的功能。以下是本地 MCP 服务器公开的工具列表:
¥Tools represent the capabilities of an MCP server. Here's the list of tools exposed by the local MCP server:
-
migrate-status
:通过prisma migrate status
命令检查你的迁移状态。¥
migrate-status
: Checks your migration status via theprisma migrate status
command. -
migrate-dev
:通过prisma migrate dev --name <name>
命令创建并执行迁移。LLM 将提供<name>
选项。¥
migrate-dev
: Creates and executes a migration via theprisma migrate dev --name <name>
command. The LLM will provide the<name>
option. -
migrate-reset
:通过prisma migrate reset --force
命令重置数据库。¥
migrate-reset
: Resets your database via theprisma migrate reset --force
command. -
Prisma-Postgres-account-status
:通过platform auth show --early-access
命令检查你的身份验证状态。¥
Prisma-Postgres-account-status
: Checks your authentication status with via theplatform auth show --early-access
command. -
Create-Prisma-Postgres-Database
:通过'init --db --name' <name> '--region' <region> '--non-interactive'
命令创建一个新的 Prisma Postgres 数据库。LLM 将提供<name>
和<region>
选项。¥
Create-Prisma-Postgres-Database
: Creates a new Prisma Postgres database via the'init --db --name' <name> '--region' <region> '--non-interactive'
command. The LLM will provide the<name>
and<region>
options. -
Prisma-Login
:通过platform auth login --early-access
命令使用 进行身份验证。¥
Prisma-Login
: Authenticates with via theplatform auth login --early-access
command. -
Prisma-Studio
:通过prisma studio
命令打开 Prisma Studio。¥
Prisma-Studio
: Open Prisma Studio via theprisma studio
command.
用法
¥Usage
本地 Prisma MCP 服务器遵循 MCP 服务器基于 JSON 的标准配置。其外观如下:
¥The local Prisma MCP server follows the standard JSON-based configuration for MCP servers. Here's what it looks like:
{
"mcpServers": {
"Prisma-Local": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
}
}
}
示例提示
¥Sample prompts
以下是一些你可以在 MCP 服务器运行时使用的示例提示:
¥Here are some sample prompts you can use when the MCP server is running:
-
"登录 Prisma 控制台。"
¥"Log me into the Prisma Console."
-
"在美国地区创建一个数据库。"
¥"Create a database in the US region."
-
“在我的数据库中创建一个新的
Product
表。”¥"Create a new
Product
table in my database."
集成到 AI 工具中
¥Integrating in AI tools
AI 工具集成 MCP 服务器的方式多种多样。在大多数情况下,都有专用的配置文件,你可以在其中添加上述 JSON 配置。配置包含一个用于启动服务器的命令,该命令将由相应的工具执行,以便服务器可供其 LLM 使用。
¥AI tools have different ways of integrating MCP servers. In most cases, there are dedicated configuration files in which you add the JSON configuration from above. The configuration contains a command for starting the server that'll be executed by the respective tool so that the server is available to its LLM.
在本节中,我们将介绍最流行的 AI 工具的配置格式。
¥In this section, we're covering the config formats of the most popular AI tools.
Cursor
要了解有关 Cursor MCP 集成的更多信息,请查看 Cursor MCP 文档。
¥To learn more about Cursor's MCP integration, check out the Cursor MCP docs.
通过一键安装添加
¥Add via one-click installation
你可以通过点击以下链接,使用 一键安装 将 Prisma MCP 服务器添加到 Cursor:
¥You can add the Prisma MCP server to Cursor using the one-click installation by clicking on the following link:
这将提示你在浏览器中打开 Cursor 应用。打开后,系统将引导你将 Prisma MCP 服务器直接安装到你的 Cursor 配置中。
¥This will prompt you to open the Cursor app in your browser. Once opened, you'll be guided to install the Prisma MCP server directly into your Cursor configuration.
通过游标设置 UI 添加
¥Add via Cursor Settings UI
打开“游标设置”时,你可以按如下方式添加 Prisma MCP 服务器:
¥When opening the Cursor Settings, you can add the Prisma MCP Server as follows:
-
在设置侧边栏中选择 MCP
¥Select MCP in the settings sidenav
-
点击“+ 添加新的全局 MCP 服务器”
¥Click + Add new global MCP server
-
将
Prisma
代码片段添加到mcpServers
JSON 对象:¥Add the
Prisma
snippet to themcpServers
JSON object:{
"mcpServers": {
"Prisma-Local": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
}
}
}
全局配置
¥Global configuration
通过“游标设置”添加它将修改全局 ~/.cursor/mcp.json
配置文件。在这种情况下,Prisma MCP 服务器将在所有 Cursor 项目中可用:
¥Adding it via the Cursor Settings settings will modify the global ~/.cursor/mcp.json
config file. In this case, the Prisma MCP server will be available in all your Cursor projects:
{
"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
}
}
项目配置
¥Project configuration
如果你希望 Prisma MCP 服务器仅在特定的 Cursor 项目中可用,请将其添加到项目根目录下 .cursor
目录中相应项目的 Cursor 配置中:
¥If you want the Prisma MCP server to be available only in specific Cursor projects, add it to the Cursor config of the respective project inside the .cursor
directory in the project's root:
{
"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 文档。
¥To learn more about Windsurf's MCP integration, check out the Windsurf MCP docs.
通过 Windsurf MCP 插件商店添加(推荐)
¥Add via Windsurf MCP Plugin Store (Recommended)
使用 Windsurf MCP 插件商店 中的 Prisma MCP 插件。按照 步骤如下 在 Windsurf 中添加 Prisma MCP 插件。这是将 Prisma MCP 服务器添加到 Windsurf 的最简单且推荐的方法。
¥Use the Prisma MCP plugin from the Windsurf MCP Plugin Store. Follow the steps here to add the Prisma MCP plugin in Windsurf. This is the simplest and recommended way to add the Prisma MCP server to Windsurf.
通过 Windsurf 设置 UI 添加
¥Add via Windsurf Settings UI
打开“Windsurf 设置”(通过“Windsurf - 设置”>“高级设置”或“命令面板”>“打开 Windsurf 设置页面”),你可以按如下方式添加 Prisma MCP 服务器:
¥When opening the Windsurf Settings (via Windsurf - Settings > Advanced Settings or Command Palette > Open Windsurf Settings Page), you can add the Prisma MCP Server as follows:
-
在设置侧边栏中选择 Cascade
¥Select Cascade in the settings sidenav
-
点击“添加服务器”
¥Click Add Server
-
将
Prisma-Local
和/或Prisma-Remote
代码片段添加到mcpServers
JSON 对象:¥Add the
Prisma-Local
and/orPrisma-Remote
snippets to themcpServers
JSON object:{
"mcpServers": {
"Prisma-Local": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
"Prisma-Remote": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.prisma.io/mcp"]
}
}
}
全局配置
¥Global configuration
通过“Windsurf 设置”添加它将修改全局 ~/.codeium/windsurf/mcp_config.json
配置文件。或者,你也可以手动将其添加到该文件:
¥Adding it via the Windsurf Settings will modify the global ~/.codeium/windsurf/mcp_config.json
config file. Alternatively, you can also manually add it to that file:
{
"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 配置为在启动时激活:
¥You can add the Prisma MCP to Warp as a globally available tool. First, visit your MCP settings and click + Add. From here, you can configure the Prisma MCP server as JSON. Use the command
and args
properties to start the Prisma MCP server as a setup command. You can optionally configure Prisma to activate on startup using the start_on_launch
flag:
{
"Prisma": {
"command": "npx",
"args": [
"-y",
"prisma",
"mcp"
],
"env": {},
"working_directory": null,
"start_on_launch": true
}
}
点击“保存”,并确保 MCP 服务器已在 MCP 设置面板中运行。然后,打开一个新的终端窗口,并让 Warp 管理你的 Prisma 数据库。它应该会自动连接到 Prisma MCP 服务器。
¥Hit Save and ensure the MCP server is running from your MCP settings panel. Then, open a new terminal window and ask Warp to manage your Prisma database. It should reach for the Prisma MCP server automatically.
要了解更多关于 Warp 的 MCP 集成,请访问 Warp MCP 文档。
¥To learn more about Warp's MCP integration, visit the Warp MCP docs.
Claude 代码
¥Claude Code
Claude Code 是一款基于终端的 AI 工具,你可以使用 claud mcp add
命令为本地 MCP 服务器添加 MCP 服务器:
¥Claude Code is a terminal-based AI tool where you can add MCP server using the claud mcp add
command for the local MCP server:
claude mcp add prisma-local npx prisma mcp
或者对于远程 MCP 服务器:
¥or for the remote MCP server:
claude mcp add prisma-remote npx mcp-remote https://mcp.prisma.io/mcp
在 Claude Code MCP 文档 中了解更多信息。
¥Learn more in the Claude Code MCP docs.
Claude 桌面
¥Claude Desktop
按照 Claude Desktop MCP 文档 中的说明创建所需的配置文件:
¥Follow the instructions in the Claude Desktop MCP docs to create the required configuration file:
-
macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
-
Windows 系统:
%APPDATA%\Claude\claude_desktop_config.json
¥Windows:
%APPDATA%\Claude\claude_desktop_config.json
然后将 JSON 代码片段添加到该配置文件:
¥Then add the JSON snippet to that configuration file:
{
"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 服务器的示例:
¥Here's an example for using the Prisma MCP servers in a Python script via the OpenAI Agents SDK:
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())