MCP ExplorerExplorer

Prisma MCP Server

@prismaon 13 days ago
42504 Apache 2.0
FreeCommunity
Dev Tools
#database#ORM#TypeScript#Node.js#PostgreSQL#Prisma#MCP
Prisma ORM is a **next-generation ORM** that consists of these tools:

Overview

What is Prisma MCP Server

Prisma ORM is a next-generation Object-Relational Mapping tool that simplifies database interactions. It consists of several components: Prisma Client, a type-safe query builder for Node.js and TypeScript; Prisma Migrate, a system for managing database migrations; and Prisma Studio, a GUI for editing and viewing database data. This toolkit caters to developers working with various backend applications, including REST and GraphQL APIs.

Use cases

Prisma can be utilized in numerous scenarios, including web and mobile applications that require reliable database operations. It is suitable for building REST APIs, GraphQL endpoints, and serverless applications, among other backend services. It supports different databases, making it versatile for various development environments.

How to use

To start using Prisma, install the Prisma Client package via npm which triggers the client code generation based on your Prisma schema. You can define your database models in the schema file, generate the Prisma Client to access your models, and execute queries against your database using the API provided by the generated client. Ensure to re-run the generation command whenever changes are made to the data model.

Key features

Key features of Prisma include an auto-generated type-safe query builder via Prisma Client, a declarative data modeling and migration system through Prisma Migrate, and visual data handling with Prisma Studio. It provides strong type safety if used with TypeScript, which helps prevent runtime errors due to incorrect property access and enhances overall developer experience.

Where to use

Prisma can be used in any Node.js or TypeScript backend application, making it particularly effective in developing REST and GraphQL APIs, serverless functions, and microservices. It’s designed to work seamlessly with various relational databases such as PostgreSQL and SQLite, making it a suitable choice for both new projects and integrating into existing applications.

Content

Prisma

Prisma

Discord

Quickstart   •   Website   •   Docs   •   Examples   •   Blog   •   Discord   •   Twitter   •   Youtube

What is Prisma?

Prisma ORM is a next-generation ORM that consists of these tools:

  • Prisma Client: Auto-generated and type-safe query builder for Node.js & TypeScript
  • Prisma Migrate: Declarative data modeling & migration system
  • Prisma Studio: GUI to view and edit data in your database

Prisma Client can be used in any Node.js or TypeScript backend application (including serverless applications and microservices). This can be a REST API, a GraphQL API, a gRPC API, or anything else that needs a database.

If you need a database to use with Prisma ORM, check out Prisma Postgres.

Getting started

Quickstart (5min)

The fastest way to get started with Prisma is by following the quickstart guides. You can choose either of two databases:

Bring your own database

If you already have your own database, you can follow these guides:

How Prisma ORM works

This section provides a high-level overview of how Prisma ORM works and its most important technical components. For a more thorough introduction, visit the Prisma documentation.

The Prisma schema

Every project that uses a tool from the Prisma toolkit starts with a Prisma schema file. The Prisma schema allows developers to define their application models in an intuitive data modeling language. It also contains the connection to a database and defines a generator:

// Data source
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

// Generator
generator client {
  provider = "prisma-client-js"
}

// Data model
model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User?   @relation(fields:  [authorId], references: [id])
  authorId  Int?
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

In this schema, you configure three things:

  • Data source: Specifies your database connection (via an environment variable)
  • Generator: Indicates that you want to generate Prisma Client
  • Data model: Defines your application models

The Prisma data model

On this page, the focus is on the data model. You can learn more about Data sources and Generators on the respective docs pages.

Functions of Prisma models

The data model is a collection of models. A model has two major functions:

  • Represent a table in the underlying database
  • Provide the foundation for the queries in the Prisma Client API

Getting a data model

There are two major workflows for “getting” a data model into your Prisma schema:

  • Generate the data model from introspecting a database
  • Manually writing the data model and mapping it to the database with Prisma Migrate

Once the data model is defined, you can generate Prisma Client which will expose CRUD and more queries for the defined models. If you’re using TypeScript, you’ll get full type-safety for all queries (even when only retrieving the subsets of a model’s fields).


Accessing your database with Prisma Client

Generating Prisma Client

The first step when using Prisma Client is installing its npm package:

npm install @prisma/client

Note that the installation of this package invokes the prisma generate command which reads your Prisma schema and generates the Prisma Client code. The code will be located in node_modules/.prisma/client, which is exported by node_modules/@prisma/client/index.d.ts.

After you change your data model, you’ll need to manually re-generate Prisma Client to ensure the code inside node_modules/.prisma/client gets updated:

npx prisma generate

Refer to the documentation for more information about “generating the Prisma client”.

Using Prisma Client to send queries to your database

Once the Prisma Client is generated, you can import it in your code and send queries to your database. This is what the setup code looks like.

Import and instantiate Prisma Client

You can import and instantiate Prisma Client as follows:

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

or

const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()

Now you can start sending queries via the generated Prisma Client API, here are a few sample queries. Note that all Prisma Client queries return plain old JavaScript objects.

Learn more about the available operations in the Prisma Client docs or watch this demo video (2 min).

Retrieve all User records from the database
const allUsers = await prisma.user.findMany()
Include the posts relation on each returned User object
const allUsers = await prisma.user.findMany({
  include: { posts: true },
})
Filter all Post records that contain "prisma"
const filteredPosts = await prisma.post.findMany({
  where: {
    OR: [{ title: { contains: 'prisma' } }, { content: { contains: 'prisma' } }],
  },
})
Create a new User and a new Post record in the same query
const user = await prisma.user.create({
  data: {
    name: 'Alice',
    email: '[email protected]',
    posts: {
      create: { title: 'Join us for Prisma Day 2021' },
    },
  },
})
Update an existing Post record
const post = await prisma.post.update({
  where: { id: 42 },
  data: { published: true },
})

Usage with TypeScript

Note that when using TypeScript, the result of this query will be statically typed so that you can’t accidentally access a property that doesn’t exist (and any typos are caught at compile-time). Learn more about leveraging Prisma Client’s generated types on the Advanced usage of generated types page in the docs.

Community

Prisma has a large and supportive community of enthusiastic application developers. You can join us on Discord and here on GitHub.

Badges

Made with Prisma Made with Prisma

Built something awesome with Prisma? 🌟 Show it off with these badges, perfect for your readme or website.

[![Made with Prisma](http://made-with.prisma.io/dark.svg)](https://prisma.io)
[![Made with Prisma](http://made-with.prisma.io/indigo.svg)](https://prisma.io)

MCP server

The Prisma CLI includes a Prisma MCP server. It’s started via this CLI command:

npx prisma mcp

Most AI tools support a JSON-based configuration for MCP servers looking like this:

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

Prisma’s MCP server gives AI agents the ability to manage Prisma Postgres databases (e.g. spin up new database instances or run schema migrations).

Security

If you have a security issue to report, please contact us at [email protected].

Support

Ask a question about Prisma

You can ask questions and initiate discussions about Prisma-related topics in the prisma repository on GitHub.

👉 Ask a question

Create a bug report for Prisma

If you see an error message or run into an issue, please make sure to create a bug report! You can find best practices for creating bug reports (like including additional debugging output) in the docs.

👉 Create bug report

Submit a feature request

If Prisma currently doesn’t have a certain feature, be sure to check out the roadmap to see if this is already planned for the future.

If the feature on the roadmap is linked to a GitHub issue, please make sure to leave a 👍 reaction on the issue and ideally a comment with your thoughts about the feature!

👉 Submit feature request

Contributing

Refer to our contribution guidelines and Code of Conduct for contributors.

Tests Status

  • Prisma Tests Status:
    Prisma Tests Status
  • Ecosystem Tests Status:
    Ecosystem Tests Status

Tools

migrate-status
The prisma migrate status command looks up the migrations in ./prisma/migrations/* folder and the entries in the _prisma_migrations table and compiles information about the state of the migrations in your database. Example output: Status 3 migrations found in prisma/migrations Your local migration history and the migrations table from your database are different: The last common migration is: 20201127134938_new_migration The migration have not yet been applied: 20201208100950_test_migration The migrations from the database are not found locally in prisma/migrations: 20201208100950_new_migration
migrate-dev
Prisma Migrate Dev is used to update Prisma whenever the schema.prisma file has been modified. Always provide a descriptive name argument describing the change that was made to the Prisma Schema. The migrate dev command performs these steps: 1. Reruns the existing migration history in the shadow database in order to detect schema drift (edited or deleted migration file, or a manual changes to the database schema) 2. Applies pending migrations to the shadow database (for example, new migrations created by colleagues) 3. Generates a new migration from any changes you made to the Prisma schema before running migrate dev 4. Applies all unapplied migrations to the development database and updates the _prisma_migrations table 5. Triggers the generation of artifacts (for example, Prisma Client)
migrate-reset
Prisma Migrate Reset --force is used to reset the database and migration history if drift is detected. Only run this command on a development database - never on production databases! If in doubt, ask the user to confirm. The migrate reset command performs these steps: 1. Drops the database/schema if possible, or performs a soft reset if the environment does not allow deleting databases/schemas 2. Creates a new database/schema with the same name if the database/schema was dropped 3. Applies all migrations 4. Runs seed scripts
Prisma-Postgres-account-status
Prisma Platform Auth Show provides information about the currently logged in user. If the user is not logged in, you should instruct them to do so by running `npx prisma platform auth login --early-access` and then re-running this command to verify.
Create-Prisma-Postgres-Database
Create a new online Prisma Postgres database. Specify a name that makes sense to the user - maybe the name of the project they are working on. Specify a region that makes sense for the user. Pick between these three options: us-east-1, eu-west-3, ap-northeast-1. If you are unsure, pick us-east-1. Provide the current working directory of the users project. This should be the top level directory of the project. If the response idicates that you have reached the workspace plan limit, you should instruct the user to do one of these things: - If they want to connect to an existing database, they should go to console.prisma.io and copy the connection string - If they want to upgrade their plan, they should go to console.prisma.io and upgrade their plan in order to be able to create more databases - If they want to delete a database they no longer need, they should go to console.prisma.io and delete the database project
Prisma-Login
Login or create an account in order to be able to use Prisma Postgres.
Prisma-Studio
Open Prisma Studio to view data in your database in a pleasing visual ui. Provide the current working directory of the users project. This should be the top level directory of the project.

Comments