or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

client-generation.mddatabase-operations.mdindex.mdmcp-server.mdmigration-management.mdplatform-integration.mdschema-management.mdstudio-interface.md

mcp-server.mddocs/

0

# MCP Server

1

2

Model Context Protocol server for AI development tools integration, providing structured access to Prisma operations through standardized AI-native interfaces.

3

4

## Capabilities

5

6

### MCP Server Launch

7

8

Start Prisma MCP server to provide AI development tools with structured access to Prisma CLI operations.

9

10

```bash { .api }

11

/**

12

* Start Prisma MCP server for AI development tools

13

* Provides structured interface for AI agents to interact with Prisma

14

*/

15

prisma mcp [options]

16

17

Options:

18

--early-access Enable early access MCP features

19

--help/-h Show MCP command help

20

```

21

22

**Usage Examples:**

23

24

```bash

25

# Start MCP server with default configuration

26

prisma mcp

27

28

# Start MCP server with early access features

29

prisma mcp --early-access

30

```

31

32

### MCP Tool Interface

33

34

The Prisma MCP server exposes standardized tools that AI development environments can invoke for database operations.

35

36

```typescript { .api }

37

/**

38

* MCP Tools provided by Prisma server

39

* Each tool provides structured input/output for AI agent interaction

40

*/

41

interface McpTools {

42

'migrate-status': MigrateStatusTool;

43

'migrate-dev': MigrateDevTool;

44

'migrate-reset': MigrateResetTool;

45

'Prisma-Studio': PrismaStudioTool;

46

}

47

48

interface MigrateStatusTool {

49

name: 'migrate-status';

50

description: 'Check database migration status and history';

51

inputSchema: {

52

type: 'object';

53

properties: {

54

schema?: { type: 'string'; description: 'Path to schema file' };

55

};

56

};

57

}

58

59

interface MigrateDevTool {

60

name: 'migrate-dev';

61

description: 'Create and apply development migrations';

62

inputSchema: {

63

type: 'object';

64

properties: {

65

name?: { type: 'string'; description: 'Migration name' };

66

createOnly?: { type: 'boolean'; description: 'Create migration without applying' };

67

skipGenerate?: { type: 'boolean'; description: 'Skip client generation' };

68

schema?: { type: 'string'; description: 'Path to schema file' };

69

};

70

};

71

}

72

73

interface MigrateResetTool {

74

name: 'migrate-reset';

75

description: 'Reset database and reapply all migrations';

76

inputSchema: {

77

type: 'object';

78

properties: {

79

force?: { type: 'boolean'; description: 'Skip confirmation prompt' };

80

skipGenerate?: { type: 'boolean'; description: 'Skip client generation' };

81

skipSeed?: { type: 'boolean'; description: 'Skip database seeding' };

82

schema?: { type: 'string'; description: 'Path to schema file' };

83

};

84

};

85

}

86

87

interface PrismaStudioTool {

88

name: 'Prisma-Studio';

89

description: 'Launch Prisma Studio database interface';

90

inputSchema: {

91

type: 'object';

92

properties: {

93

port?: { type: 'number'; description: 'Custom port number' };

94

browser?: { type: 'string'; description: 'Browser selection' };

95

hostname?: { type: 'string'; description: 'Hostname binding' };

96

schema?: { type: 'string'; description: 'Path to schema file' };

97

};

98

};

99

}

100

```

101

102

## MCP Tool Operations

103

104

### Migrate Status Tool

105

106

Check migration status and history through MCP interface with structured output for AI agents.

107

108

```json

109

{

110

"tool": "migrate-status",

111

"arguments": {

112

"schema": "./prisma/schema.prisma"

113

}

114

}

115

```

116

117

**Response Format:**

118

119

```json

120

{

121

"isSuccessful": true,

122

"content": [

123

{

124

"type": "text",

125

"text": "Migration Status:\n✓ Database schema is up to date\n\nApplied migrations:\n- 20240101120000_init\n- 20240102130000_add_user_profile\n\nNo pending migrations."

126

}

127

]

128

}

129

```

130

131

### Migrate Dev Tool

132

133

Create and apply development migrations through MCP with validation and error handling.

134

135

```json

136

{

137

"tool": "migrate-dev",

138

"arguments": {

139

"name": "add-user-posts",

140

"createOnly": false,

141

"skipGenerate": false

142

}

143

}

144

```

145

146

**Response Format:**

147

148

```json

149

{

150

"isSuccessful": true,

151

"content": [

152

{

153

"type": "text",

154

"text": "Migration created and applied successfully:\n- Created migration: 20240103140000_add_user_posts\n- Applied to database\n- Generated Prisma Client\n- Database synchronized"

155

}

156

]

157

}

158

```

159

160

### Migrate Reset Tool

161

162

Reset database through MCP interface with safety confirmation and structured feedback.

163

164

```json

165

{

166

"tool": "migrate-reset",

167

"arguments": {

168

"force": true,

169

"skipGenerate": false,

170

"skipSeed": true

171

}

172

}

173

```

174

175

**Response Format:**

176

177

```json

178

{

179

"isSuccessful": true,

180

"content": [

181

{

182

"type": "text",

183

"text": "Database reset completed:\n- Dropped all data\n- Reapplied all migrations\n- Generated Prisma Client\n- Ready for development"

184

}

185

]

186

}

187

```

188

189

### Prisma Studio Tool

190

191

Launch Studio interface through MCP with configuration options and status reporting.

192

193

```json

194

{

195

"tool": "Prisma-Studio",

196

"arguments": {

197

"port": 5555,

198

"hostname": "localhost",

199

"browser": "chrome"

200

}

201

}

202

```

203

204

**Response Format:**

205

206

```json

207

{

208

"isSuccessful": true,

209

"content": [

210

{

211

"type": "text",

212

"text": "Prisma Studio launched successfully:\n- URL: http://localhost:5555\n- Browser: chrome\n- Status: Running\n- Ready for database management"

213

}

214

]

215

}

216

```

217

218

## MCP Integration Patterns

219

220

### AI Development Workflow

221

222

AI development tools can use the MCP server to perform database operations:

223

224

```typescript

225

// AI agent workflow example

226

const mcpClient = new McpClient('prisma-mcp-server');

227

228

// 1. Check current migration status

229

const status = await mcpClient.callTool('migrate-status', {});

230

231

// 2. Create migration based on schema changes

232

const migration = await mcpClient.callTool('migrate-dev', {

233

name: 'ai-suggested-changes',

234

createOnly: true // Review before applying

235

});

236

237

// 3. Launch Studio for verification

238

const studio = await mcpClient.callTool('Prisma-Studio', {

239

port: 5555

240

});

241

```

242

243

### Development Environment Integration

244

245

```bash

246

# Start MCP server for development environment

247

prisma mcp &

248

249

# AI development tool connects to MCP server

250

# Provides structured database operations to AI agents

251

```

252

253

### CI/CD Integration with MCP

254

255

```typescript

256

// CI/CD pipeline using MCP interface

257

const mcpOperations = {

258

checkMigrations: () => mcpClient.callTool('migrate-status', {}),

259

applyMigrations: () => mcpClient.callTool('migrate-dev', {

260

skipGenerate: false

261

}),

262

resetTestDb: () => mcpClient.callTool('migrate-reset', {

263

force: true,

264

skipSeed: false

265

})

266

};

267

```

268

269

## MCP Server Configuration

270

271

### Server Startup Configuration

272

273

```typescript { .api }

274

interface McpServerConfig {

275

earlyAccess?: boolean; // Enable early access features

276

schemaPath?: string; // Default schema file path

277

port?: number; // MCP server port (not Studio port)

278

logLevel?: 'debug' | 'info' | 'warn' | 'error';

279

timeout?: number; // Tool execution timeout

280

}

281

```

282

283

### Environment Variables

284

285

```bash

286

# MCP server environment configuration

287

DATABASE_URL="postgresql://user:pass@localhost:5432/db"

288

PRISMA_SCHEMA_PATH="./prisma/schema.prisma"

289

MCP_LOG_LEVEL="info"

290

MCP_TIMEOUT="30000"

291

```

292

293

### Security Considerations

294

295

```typescript

296

// MCP server security features

297

interface McpSecurity {

298

toolWhitelist: string[]; // Allowed tools for security

299

schemaValidation: boolean; // Validate schema before operations

300

confirmationRequired: boolean; // Require confirmation for destructive ops

301

auditLogging: boolean; // Log all MCP operations

302

}

303

```

304

305

## Tool Output Formats

306

307

### Success Response

308

309

```typescript { .api }

310

interface McpSuccessResponse {

311

isSuccessful: true;

312

content: Array<{

313

type: 'text' | 'image' | 'resource';

314

text?: string;

315

data?: string;

316

uri?: string;

317

}>;

318

}

319

```

320

321

### Error Response

322

323

```typescript { .api }

324

interface McpErrorResponse {

325

isSuccessful: false;

326

content: Array<{

327

type: 'text';

328

text: string;

329

}>;

330

error?: {

331

code: string;

332

message: string;

333

details?: any;

334

};

335

}

336

```

337

338

## Advanced MCP Features

339

340

### Early Access Features

341

342

```bash

343

# Enable early access MCP features

344

prisma mcp --early-access

345

```

346

347

Early access features may include:

348

349

- **Extended Tool Set**: Additional tools for schema manipulation

350

- **Advanced Integrations**: Integration with more AI development platforms

351

- **Performance Optimizations**: Improved tool execution performance

352

- **Enhanced Logging**: Detailed operation logging and monitoring

353

354

### Custom Tool Extensions

355

356

```typescript

357

// Framework for custom MCP tool development

358

interface CustomMcpTool {

359

name: string;

360

description: string;

361

inputSchema: JSONSchema;

362

handler: (args: any) => Promise<McpResponse>;

363

}

364

```

365

366

### Monitoring and Observability

367

368

```typescript

369

// MCP server monitoring capabilities

370

interface McpMetrics {

371

toolInvocations: Record<string, number>;

372

averageExecutionTime: Record<string, number>;

373

errorRates: Record<string, number>;

374

activeConnections: number;

375

}

376

```

377

378

## Error Handling

379

380

Common MCP server errors:

381

382

- **Tool Execution Errors**: Database operations fail or timeout

383

- **Schema Validation Errors**: Invalid schema prevents tool execution

384

- **Connection Errors**: Database connectivity issues

385

- **Permission Errors**: Insufficient database or file system permissions

386

- **Configuration Errors**: Invalid MCP server configuration

387

- **Protocol Errors**: MCP protocol communication issues

388

389

## Integration Examples

390

391

### VS Code Extension Integration

392

393

```typescript

394

// VS Code extension using Prisma MCP

395

const mcpProvider = new PrismaMcpProvider();

396

397

// Add database operations to command palette

398

vscode.commands.registerCommand('prisma.checkMigrations', async () => {

399

const result = await mcpProvider.callTool('migrate-status', {});

400

vscode.window.showInformationMessage(result.content[0].text);

401

});

402

```

403

404

### AI Assistant Integration

405

406

```typescript

407

// AI assistant using Prisma MCP for database operations

408

class DatabaseAssistant {

409

constructor(private mcpClient: McpClient) {}

410

411

async handleDatabaseQuery(userQuery: string) {

412

// Analyze user intent

413

const intent = this.analyzeIntent(userQuery);

414

415

// Execute appropriate MCP tool

416

switch (intent.operation) {

417

case 'check-status':

418

return await this.mcpClient.callTool('migrate-status', {});

419

case 'create-migration':

420

return await this.mcpClient.callTool('migrate-dev', {

421

name: intent.migrationName

422

});

423

case 'open-studio':

424

return await this.mcpClient.callTool('Prisma-Studio', {});

425

}

426

}

427

}

428

```