跳到主要内容

MCP 服务器

模型-上下文-协议 (MCP) 为 LLM 提供了一种调用 API 的方式,从而以明确定义的方式访问外部系统。Prisma 的 MCP 服务器使 LLM 能够管理 Prisma Postgres 数据库(例如,启动新的数据库实例或运行模式迁移)。

注意

Prisma MCP 服务器通过 Prisma CLI 命令 prisma platform mcp --early-access 提供,目前处于 Early Access 阶段。请参阅下文,了解如何将其集成到您喜爱的 AI 工具中。它使用 stdio 传输机制。

用法

Prisma MCP 服务器遵循 MCP 服务器的标准基于 JSON 的配置。以下是它的外观:

{
"mcpServers": {
"Prisma": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
}
}
}

示例提示

以下是一些在 MCP 服务器运行时可以使用的示例提示:

  • 让我登录到 Prisma Console。
  • 在美国区域创建一个数据库。
  • 在我的数据库中创建一个新的 Product 表。

集成到 AI 工具中

AI 工具集成 MCP 服务器的方式各不相同。在大多数情况下,都有专门的配置文件,您可以在其中添加上面的 JSON 配置。该配置包含一个用于启动服务器的命令,该命令将由相应的工具执行,以便服务器可供其 LLM 使用。

在本节中,我们将介绍最流行的 AI 工具的配置格式。

Cursor

要了解有关 Cursor 的 MCP 集成的更多信息,请查看 Cursor MCP 文档

通过 Cursor 设置 UI 添加

打开Cursor 设置时,您可以按如下方式添加 Prisma MCP 服务器

  1. 在设置侧边栏中选择 MCP
  2. 点击 + 添加新的全局 MCP 服务器
  3. Prisma 代码段添加到 mcpServers JSON 对象
    {
    "mcpServers": {
    "Prisma": {
    "command": "npx",
    "args": ["-y", "prisma", "mcp"]
    }
    }
    }

全局配置

通过 Cursor 设置 添加它将修改全局 ~/.cursor/mcp.json 配置文件。在这种情况下,Prisma MCP 服务器将在所有 Cursor 项目中可用

~/.cursor/mcp.json
{
"mcpServers": {
"Prisma": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
// other MCP servers
}
}

项目配置

如果您希望 Prisma MCP 服务器仅在特定的 Cursor 项目中可用,请将其添加到项目根目录中 .cursor 目录内相应项目的 Cursor 配置中

.cursor/mcp.json
{
"mcpServers": {
"Prisma": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
},
// other MCP servers
}
}

Windsurf

要了解有关 Windsurf 的 MCP 集成的更多信息,请查看 Windsurf MCP 文档

通过 Windsurf 设置 UI 添加

打开Windsurf 设置(通过Windsurf - 设置 > 高级设置或命令面板 > 打开 Windsurf 设置页面),您可以按如下方式添加 Prisma MCP 服务器

  1. 在设置侧边栏中选择 Cascade
  2. 点击 添加服务器
  3. Prisma 代码段添加到 mcpServers JSON 对象
    {
    "mcpServers": {
    "Prisma": {
    "command": "npx",
    "args": ["-y", "prisma", "mcp"]
    }
    }
    }

全局配置

通过 Windsurf 设置 添加它将修改全局 ~/.codeium/windsurf/mcp_config.json 配置文件。或者,您也可以手动将其添加到该文件中

~/.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())