MCP 服务器
Model-Context-Protocol (MCP) 为大型语言模型 (LLM) 提供了一种调用 API 并以明确定义的方式访问外部系统的方法。Prisma 的 MCP 服务器使 LLM 能够管理 Prisma Postgres 数据库(例如,启动新的数据库实例或运行 schema 迁移)。
Prisma MCP 服务器可通过 Prisma CLI 命令 prisma platform mcp --early-access
获取,目前处于早期访问阶段 (Early Access)。请参阅下文,了解如何将其集成到您喜欢的 AI 工具中。它使用 stdio
传输机制。
用法
Prisma MCP 服务器遵循标准的基于 JSON 的 MCP 服务器配置。如下所示
{
"mcpServers": {
"Prisma": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
}
}
}
示例提示
以下是 MCP 服务器运行时可以使用的示例提示
- 将我登录到 Prisma 控制台。
- 在美国区域创建一个数据库。
- 在我的数据库中创建一个新的
Product
表。
集成到 AI 工具中
AI 工具集成 MCP 服务器的方式不同。在大多数情况下,有专门的配置文件,您可以在其中添加上述 JSON 配置。该配置包含一个用于启动服务器的命令,该命令将由相应的工具执行,以便该服务器可供其 LLM 使用。
在本节中,我们将介绍最流行的 AI 工具的配置格式。
Cursor
要了解有关 Cursor MCP 集成的更多信息,请查阅 Cursor MCP 文档。
通过 Cursor 设置 UI 添加
打开 Cursor 设置时,您可以按如下方式添加 Prisma MCP 服务器
- 在设置侧边导航中选择 MCP
- 点击 + 添加新的全局 MCP 服务器
- 将
Prisma
代码片段添加到mcpServers
JSON 对象中{
"mcpServers": {
"Prisma": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
}
}
}
全局配置
通过 Cursor 设置添加它将修改全局 ~/.cursor/mcp.json
配置文件。在这种情况下,Prisma MCP 服务器将在您所有的 Cursor 项目中可用。
{
"mcpServers": {
"Prisma": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
// other MCP servers
}
}
项目配置
如果您只想在特定的 Cursor 项目中启用 Prisma MCP 服务器,请将其添加到项目根目录下的 .cursor
目录中相应的 Cursor 配置文件中。
{
"mcpServers": {
"Prisma": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
// other MCP servers
}
}
Windsurf
要了解有关 Windsurf MCP 集成的更多信息,请查阅 Windsurf MCP 文档。
通过 Windsurf 设置 UI 添加
打开 Windsurf 设置时(通过 Windsurf - 设置 > 高级设置或命令面板 > 打开 Windsurf 设置页面),您可以按如下方式添加 Prisma MCP 服务器
- 在设置侧边导航中选择 Cascade
- 点击 Add Server
- 将
Prisma
代码片段添加到mcpServers
JSON 对象中{
"mcpServers": {
"Prisma": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
}
}
}
全局配置
通过 Windsurf 设置添加它将修改全局 ~/.codeium/windsurf/mcp_config.json
配置文件。或者,您也可以手动将其添加到该文件中
{
"mcpServers": {
"Prisma": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
// other MCP servers
}
}
Claude Code
Claude Code 是一个基于终端的 AI 工具,您可以使用 claud mcp add
命令添加 MCP 服务器
claude mcp add prisma npx prisma 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": {
"command": "npx",
"args": ["-y", "prisma", "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
# Async context required for MCPServerStdio
import asyncio
async def main():
# Start the Prisma MCP server using stdio
async with MCPServerStdio(
params={
"command": "npx",
"args": ["-y", "prisma", "mcp"]
}
) as prisma_server:
# Optional: view available tools
tools = await prisma_server.list_tools()
print("Available tools:", [tool.name for tool in tools])
# Set up the agent with MCP server
agent = Assistant(
name="Prisma Assistant",
instructions="Use the Prisma tools to help the user with database tasks.",
mcp_servers=[prisma_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())