|
| 1 | +export const revalidate = false; |
| 2 | + |
| 3 | +const skill = `--- |
| 4 | +name: prisma |
| 5 | +description: Set up and use Prisma ORM with Prisma Postgres — define a schema, run migrations, generate Prisma Client, and query a PostgreSQL database in TypeScript. Includes the remote Prisma MCP server for managing Prisma Postgres databases. |
| 6 | +license: Apache-2.0 |
| 7 | +compatibility: Node.js and TypeScript projects using Prisma ORM (Prisma Client) and Prisma Postgres. |
| 8 | +metadata: |
| 9 | + product: Prisma ORM + Prisma Postgres |
| 10 | + version: "7" |
| 11 | + documentation: https://www.prisma.io/docs |
| 12 | + llms_txt: https://www.prisma.io/docs/llms.txt |
| 13 | +allowed-tools: |
| 14 | + - Bash |
| 15 | + - Read |
| 16 | + - Edit |
| 17 | + - Write |
| 18 | +--- |
| 19 | +
|
| 20 | +# Prisma |
| 21 | +
|
| 22 | +Prisma is a next-generation TypeScript ORM and a managed PostgreSQL database: |
| 23 | +
|
| 24 | +- **Prisma ORM** — a type-safe database toolkit. You define your data model in a Prisma Schema, Prisma Migrate turns it into SQL migrations, and Prisma Client gives you a fully typed query API. |
| 25 | +- **Prisma Postgres** — a fully managed PostgreSQL database that scales to zero and integrates with Prisma ORM and Prisma Studio. |
| 26 | +
|
| 27 | +Prisma changes between versions. Before implementing a feature, verify against the current docs at https://www.prisma.io/docs and the changelog at https://www.prisma.io/changelog.md. Do not rely on training data for Prisma APIs, configuration, or conventions. |
| 28 | +
|
| 29 | +## Golden workflow |
| 30 | +
|
| 31 | +These are the core commands for a new TypeScript project (copied from the Prisma Postgres quickstart). Run the CLI with \`npx\`: |
| 32 | +
|
| 33 | +1. **Initialize the project and install dependencies** |
| 34 | +
|
| 35 | + \`\`\`bash |
| 36 | + npm init -y |
| 37 | + npm install typescript tsx @types/node --save-dev |
| 38 | + npm install prisma @types/pg --save-dev |
| 39 | + npm install @prisma/client @prisma/adapter-pg pg dotenv |
| 40 | + \`\`\` |
| 41 | +
|
| 42 | +2. **Scaffold Prisma ORM.** This creates \`prisma/schema.prisma\`, a \`.env\` with \`DATABASE_URL\`, and \`prisma.config.ts\`: |
| 43 | +
|
| 44 | + \`\`\`bash |
| 45 | + npx prisma init --output ../generated/prisma |
| 46 | + \`\`\` |
| 47 | +
|
| 48 | +3. **Provision a Prisma Postgres database** and replace \`DATABASE_URL\` in \`.env\` with the \`postgres://...\` connection string from the CLI output: |
| 49 | +
|
| 50 | + \`\`\`bash |
| 51 | + npx create-db |
| 52 | + \`\`\` |
| 53 | +
|
| 54 | +4. **Define your data model** in \`prisma/schema.prisma\`, for example: |
| 55 | +
|
| 56 | + \`\`\`prisma |
| 57 | + generator client { |
| 58 | + provider = "prisma-client" |
| 59 | + output = "../generated/prisma" |
| 60 | + } |
| 61 | +
|
| 62 | + datasource db { |
| 63 | + provider = "postgresql" |
| 64 | + } |
| 65 | +
|
| 66 | + model User { |
| 67 | + id Int @id @default(autoincrement()) |
| 68 | + email String @unique |
| 69 | + name String? |
| 70 | + posts Post[] |
| 71 | + } |
| 72 | +
|
| 73 | + model Post { |
| 74 | + id Int @id @default(autoincrement()) |
| 75 | + title String |
| 76 | + content String? |
| 77 | + published Boolean @default(false) |
| 78 | + author User @relation(fields: [authorId], references: [id]) |
| 79 | + authorId Int |
| 80 | + } |
| 81 | + \`\`\` |
| 82 | +
|
| 83 | +5. **Create and apply a migration**, then **generate Prisma Client**: |
| 84 | +
|
| 85 | + \`\`\`bash |
| 86 | + npx prisma migrate dev --name init |
| 87 | + npx prisma generate |
| 88 | + \`\`\` |
| 89 | +
|
| 90 | +6. **Instantiate Prisma Client** with the driver adapter and query your database: |
| 91 | +
|
| 92 | + \`\`\`typescript |
| 93 | + import "dotenv/config"; |
| 94 | + import { PrismaPg } from "@prisma/adapter-pg"; |
| 95 | + import { PrismaClient } from "../generated/prisma/client"; |
| 96 | +
|
| 97 | + const connectionString = \`\${process.env.DATABASE_URL}\`; |
| 98 | + const adapter = new PrismaPg({ connectionString }); |
| 99 | + const prisma = new PrismaClient({ adapter }); |
| 100 | +
|
| 101 | + const user = await prisma.user.create({ |
| 102 | + data: { name: "Alice", email: "alice@prisma.io" }, |
| 103 | + }); |
| 104 | + const users = await prisma.user.findMany({ include: { posts: true } }); |
| 105 | + \`\`\` |
| 106 | +
|
| 107 | +7. **Explore your data** visually with Prisma Studio: |
| 108 | +
|
| 109 | + \`\`\`bash |
| 110 | + npx prisma studio |
| 111 | + \`\`\` |
| 112 | +
|
| 113 | +When you change your schema later, re-run \`npx prisma migrate dev\` to create a new migration and \`npx prisma generate\` to update Prisma Client. |
| 114 | +
|
| 115 | +### Safety with destructive commands |
| 116 | +
|
| 117 | +Prisma ORM detects when it is invoked by AI coding agents and blocks destructive commands such as \`prisma migrate reset --force\`. Do not bypass this guardrail: stop, tell the user exactly which command you want to run and that it irreversibly destroys all data, and proceed only after explicit user consent. |
| 118 | +
|
| 119 | +## Prisma MCP server |
| 120 | +
|
| 121 | +Prisma provides a remote MCP server that lets AI tools manage Prisma Postgres databases (create databases, connection strings, and backups; run and introspect SQL) and search the Prisma documentation. It authenticates with Prisma Console via OAuth on first use. |
| 122 | +
|
| 123 | +Add it with the standard MCP configuration: |
| 124 | +
|
| 125 | +\`\`\`json |
| 126 | +{ |
| 127 | + "mcpServers": { |
| 128 | + "Prisma": { |
| 129 | + "url": "https://mcp.prisma.io/mcp" |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | +\`\`\` |
| 134 | +
|
| 135 | +The server exposes a \`search_prisma_documentation\` tool that returns cited answers grounded in the official Prisma docs — prefer it over training data for Prisma questions. |
| 136 | +
|
| 137 | +## Documentation for agents |
| 138 | +
|
| 139 | +- **Index:** https://www.prisma.io/docs/llms.txt — links to per-area indexes (Prisma ORM, Prisma Postgres, Guides, CLI, Studio, Platform, and more). |
| 140 | +- **Full content feed:** https://www.prisma.io/docs/llms-full.txt — the current docs as a single machine-readable file. |
| 141 | +- **Any page as Markdown:** append \`.md\` to any docs URL, e.g. https://www.prisma.io/docs/orm/prisma-client.md. |
| 142 | +- **Changelog:** https://www.prisma.io/changelog.md — check before implementing to catch breaking changes. |
| 143 | +`; |
| 144 | + |
| 145 | +export async function GET() { |
| 146 | + return new Response(skill, { |
| 147 | + headers: { |
| 148 | + "Content-Type": "text/markdown; charset=utf-8", |
| 149 | + }, |
| 150 | + }); |
| 151 | +} |
0 commit comments