@berthojoris/mcp-mysql-server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,287 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.validateShowCreateProcedure = exports.validateDropStoredProcedure = exports.validateStoredProcedureCreation = exports.validateStoredProcedureExecution = exports.validateGetStoredProcedureInfo = exports.validateListStoredProcedures = exports.validateExecuteInTransaction = exports.validateGetTransactionStatus = exports.validateRollbackTransaction = exports.validateCommitTransaction = exports.validateBeginTransaction = exports.validateGetTableRelationships = exports.validateRunQuery = exports.validateDeleteRecord = exports.validateUpdateRecord = exports.validateReadRecords = exports.validateCreateRecord = exports.validateReadTableSchema = exports.validateListTables = exports.showCreateProcedureSchema = exports.dropStoredProcedureSchema = exports.createStoredProcedureSchema = exports.executeStoredProcedureSchema = exports.getStoredProcedureInfoSchema = exports.listStoredProceduresSchema = exports.executeInTransactionSchema = exports.getTransactionStatusSchema = exports.rollbackTransactionSchema = exports.commitTransactionSchema = exports.beginTransactionSchema = exports.getTableRelationshipsSchema = exports.runQuerySchema = exports.deleteRecordSchema = exports.updateRecordSchema = exports.readRecordsSchema = exports.createRecordSchema = exports.readTableSchemaSchema = exports.listTablesSchema = void 0;
7
+ const ajv_1 = __importDefault(require("ajv"));
8
+ const ajv = new ajv_1.default();
9
+ // Schema definitions
10
+ exports.listTablesSchema = {
11
+ type: 'object',
12
+ properties: {
13
+ database: { type: 'string', nullable: true }
14
+ },
15
+ additionalProperties: false
16
+ };
17
+ exports.readTableSchemaSchema = {
18
+ type: 'object',
19
+ required: ['table_name'],
20
+ properties: {
21
+ table_name: { type: 'string' }
22
+ },
23
+ additionalProperties: false
24
+ };
25
+ exports.createRecordSchema = {
26
+ type: 'object',
27
+ required: ['table_name', 'data'],
28
+ properties: {
29
+ table_name: { type: 'string' },
30
+ data: {
31
+ type: 'object',
32
+ additionalProperties: true
33
+ }
34
+ },
35
+ additionalProperties: false
36
+ };
37
+ exports.readRecordsSchema = {
38
+ type: 'object',
39
+ required: ['table_name'],
40
+ properties: {
41
+ table_name: { type: 'string' },
42
+ filters: {
43
+ type: 'array',
44
+ items: {
45
+ type: 'object',
46
+ required: ['field', 'operator', 'value'],
47
+ properties: {
48
+ field: { type: 'string' },
49
+ operator: {
50
+ type: 'string',
51
+ enum: ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'like', 'in']
52
+ },
53
+ value: {}
54
+ }
55
+ },
56
+ nullable: true
57
+ },
58
+ pagination: {
59
+ type: 'object',
60
+ properties: {
61
+ page: { type: 'integer', minimum: 1 },
62
+ limit: { type: 'integer', minimum: 1, maximum: 1000 }
63
+ },
64
+ required: ['page', 'limit'],
65
+ nullable: true
66
+ },
67
+ sorting: {
68
+ type: 'object',
69
+ properties: {
70
+ field: { type: 'string' },
71
+ direction: { type: 'string', enum: ['asc', 'desc'] }
72
+ },
73
+ required: ['field', 'direction'],
74
+ nullable: true
75
+ }
76
+ },
77
+ additionalProperties: false
78
+ };
79
+ exports.updateRecordSchema = {
80
+ type: 'object',
81
+ required: ['table_name', 'data', 'conditions'],
82
+ properties: {
83
+ table_name: { type: 'string' },
84
+ data: {
85
+ type: 'object',
86
+ additionalProperties: true
87
+ },
88
+ conditions: {
89
+ type: 'array',
90
+ items: {
91
+ type: 'object',
92
+ required: ['field', 'operator', 'value'],
93
+ properties: {
94
+ field: { type: 'string' },
95
+ operator: {
96
+ type: 'string',
97
+ enum: ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'like', 'in']
98
+ },
99
+ value: {}
100
+ }
101
+ }
102
+ }
103
+ },
104
+ additionalProperties: false
105
+ };
106
+ exports.deleteRecordSchema = {
107
+ type: 'object',
108
+ required: ['table_name', 'conditions'],
109
+ properties: {
110
+ table_name: { type: 'string' },
111
+ conditions: {
112
+ type: 'array',
113
+ items: {
114
+ type: 'object',
115
+ required: ['field', 'operator', 'value'],
116
+ properties: {
117
+ field: { type: 'string' },
118
+ operator: {
119
+ type: 'string',
120
+ enum: ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'like', 'in']
121
+ },
122
+ value: {}
123
+ }
124
+ }
125
+ }
126
+ },
127
+ additionalProperties: false
128
+ };
129
+ exports.runQuerySchema = {
130
+ type: 'object',
131
+ required: ['query'],
132
+ properties: {
133
+ query: { type: 'string' },
134
+ params: {
135
+ type: 'array',
136
+ items: {},
137
+ nullable: true
138
+ }
139
+ },
140
+ additionalProperties: false
141
+ };
142
+ exports.getTableRelationshipsSchema = {
143
+ type: 'object',
144
+ required: ['table_name'],
145
+ properties: {
146
+ table_name: { type: 'string' }
147
+ },
148
+ additionalProperties: false
149
+ };
150
+ // Transaction Schemas
151
+ exports.beginTransactionSchema = {
152
+ type: 'object',
153
+ properties: {
154
+ transactionId: { type: 'string', nullable: true }
155
+ },
156
+ additionalProperties: false
157
+ };
158
+ exports.commitTransactionSchema = {
159
+ type: 'object',
160
+ required: ['transactionId'],
161
+ properties: {
162
+ transactionId: { type: 'string' }
163
+ },
164
+ additionalProperties: false
165
+ };
166
+ exports.rollbackTransactionSchema = {
167
+ type: 'object',
168
+ required: ['transactionId'],
169
+ properties: {
170
+ transactionId: { type: 'string' }
171
+ },
172
+ additionalProperties: false
173
+ };
174
+ exports.getTransactionStatusSchema = {
175
+ type: 'object',
176
+ properties: {},
177
+ additionalProperties: false
178
+ };
179
+ exports.executeInTransactionSchema = {
180
+ type: 'object',
181
+ required: ['transactionId', 'query'],
182
+ properties: {
183
+ transactionId: { type: 'string' },
184
+ query: { type: 'string' },
185
+ params: {
186
+ type: 'array',
187
+ items: {},
188
+ nullable: true
189
+ }
190
+ },
191
+ additionalProperties: false
192
+ };
193
+ // Stored procedure schemas
194
+ exports.listStoredProceduresSchema = {
195
+ type: 'object',
196
+ properties: {
197
+ database: { type: 'string', nullable: true }
198
+ },
199
+ additionalProperties: false
200
+ };
201
+ exports.getStoredProcedureInfoSchema = {
202
+ type: 'object',
203
+ required: ['procedure_name'],
204
+ properties: {
205
+ procedure_name: { type: 'string' },
206
+ database: { type: 'string', nullable: true }
207
+ },
208
+ additionalProperties: false
209
+ };
210
+ exports.executeStoredProcedureSchema = {
211
+ type: 'object',
212
+ required: ['procedure_name'],
213
+ properties: {
214
+ procedure_name: { type: 'string' },
215
+ parameters: {
216
+ type: 'array',
217
+ items: {},
218
+ nullable: true
219
+ },
220
+ database: { type: 'string', nullable: true }
221
+ },
222
+ additionalProperties: false
223
+ };
224
+ exports.createStoredProcedureSchema = {
225
+ type: 'object',
226
+ required: ['procedure_name', 'body'],
227
+ properties: {
228
+ procedure_name: { type: 'string' },
229
+ parameters: {
230
+ type: 'array',
231
+ items: {
232
+ type: 'object',
233
+ required: ['name', 'mode', 'data_type'],
234
+ properties: {
235
+ name: { type: 'string' },
236
+ mode: { type: 'string', enum: ['IN', 'OUT', 'INOUT'] },
237
+ data_type: { type: 'string' }
238
+ }
239
+ },
240
+ nullable: true
241
+ },
242
+ body: { type: 'string' },
243
+ comment: { type: 'string', nullable: true },
244
+ database: { type: 'string', nullable: true }
245
+ },
246
+ additionalProperties: false
247
+ };
248
+ exports.dropStoredProcedureSchema = {
249
+ type: 'object',
250
+ required: ['procedure_name'],
251
+ properties: {
252
+ procedure_name: { type: 'string' },
253
+ if_exists: { type: 'boolean', nullable: true },
254
+ database: { type: 'string', nullable: true }
255
+ },
256
+ additionalProperties: false
257
+ };
258
+ exports.showCreateProcedureSchema = {
259
+ type: 'object',
260
+ required: ['procedure_name'],
261
+ properties: {
262
+ procedure_name: { type: 'string' },
263
+ database: { type: 'string', nullable: true }
264
+ },
265
+ additionalProperties: false
266
+ };
267
+ // Compile validators
268
+ exports.validateListTables = ajv.compile(exports.listTablesSchema);
269
+ exports.validateReadTableSchema = ajv.compile(exports.readTableSchemaSchema);
270
+ exports.validateCreateRecord = ajv.compile(exports.createRecordSchema);
271
+ exports.validateReadRecords = ajv.compile(exports.readRecordsSchema);
272
+ exports.validateUpdateRecord = ajv.compile(exports.updateRecordSchema);
273
+ exports.validateDeleteRecord = ajv.compile(exports.deleteRecordSchema);
274
+ exports.validateRunQuery = ajv.compile(exports.runQuerySchema);
275
+ exports.validateGetTableRelationships = ajv.compile(exports.getTableRelationshipsSchema);
276
+ exports.validateBeginTransaction = ajv.compile(exports.beginTransactionSchema);
277
+ exports.validateCommitTransaction = ajv.compile(exports.commitTransactionSchema);
278
+ exports.validateRollbackTransaction = ajv.compile(exports.rollbackTransactionSchema);
279
+ exports.validateGetTransactionStatus = ajv.compile(exports.getTransactionStatusSchema);
280
+ exports.validateExecuteInTransaction = ajv.compile(exports.executeInTransactionSchema);
281
+ // Stored procedure validators
282
+ exports.validateListStoredProcedures = ajv.compile(exports.listStoredProceduresSchema);
283
+ exports.validateGetStoredProcedureInfo = ajv.compile(exports.getStoredProcedureInfoSchema);
284
+ exports.validateStoredProcedureExecution = ajv.compile(exports.executeStoredProcedureSchema);
285
+ exports.validateStoredProcedureCreation = ajv.compile(exports.createStoredProcedureSchema);
286
+ exports.validateDropStoredProcedure = ajv.compile(exports.dropStoredProcedureSchema);
287
+ exports.validateShowCreateProcedure = ajv.compile(exports.showCreateProcedureSchema);
package/manifest.json ADDED
@@ -0,0 +1,248 @@
1
+ {
2
+ "name": "mysql-mcp",
3
+ "description": "A Model Context Protocol for MySQL database interaction",
4
+ "version": "1.0.0",
5
+ "tools": [
6
+ {
7
+ "name": "list_databases",
8
+ "description": "Lists all databases available on the MySQL server.",
9
+ "input_schema": {},
10
+ "output_schema": {
11
+ "type": "array",
12
+ "items": { "type": "string" }
13
+ }
14
+ },
15
+ {
16
+ "name": "list_tables",
17
+ "description": "Lists all tables in the connected MySQL database.",
18
+ "input_schema": {},
19
+ "output_schema": {
20
+ "type": "array",
21
+ "items": { "type": "string" }
22
+ }
23
+ },
24
+ {
25
+ "name": "read_table_schema",
26
+ "description": "Reads the schema of a specified table.",
27
+ "input_schema": {
28
+ "type": "object",
29
+ "properties": {
30
+ "table_name": { "type": "string" }
31
+ },
32
+ "required": ["table_name"]
33
+ },
34
+ "output_schema": {
35
+ "type": "object",
36
+ "properties": {
37
+ "columns": {
38
+ "type": "array",
39
+ "items": {
40
+ "type": "object",
41
+ "properties": {
42
+ "name": { "type": "string" },
43
+ "type": { "type": "string" },
44
+ "nullable": { "type": "boolean" },
45
+ "default": { "type": ["string", "null"] },
46
+ "primary_key": { "type": "boolean" }
47
+ }
48
+ }
49
+ },
50
+ "primary_key": { "type": ["string", "null"] },
51
+ "indexes": {
52
+ "type": "array",
53
+ "items": { "type": "string" }
54
+ }
55
+ }
56
+ }
57
+ },
58
+ {
59
+ "name": "create_record",
60
+ "description": "Creates a new record in the specified table.",
61
+ "input_schema": {
62
+ "type": "object",
63
+ "properties": {
64
+ "table_name": { "type": "string" },
65
+ "data": { "type": "object" }
66
+ },
67
+ "required": ["table_name", "data"]
68
+ },
69
+ "output_schema": {
70
+ "type": "object",
71
+ "properties": {
72
+ "success": { "type": "boolean" },
73
+ "id": { "type": ["string", "number"] },
74
+ "affected_rows": { "type": "number" }
75
+ }
76
+ }
77
+ },
78
+ {
79
+ "name": "read_records",
80
+ "description": "Reads records from the specified table with optional filtering, pagination, and sorting.",
81
+ "input_schema": {
82
+ "type": "object",
83
+ "properties": {
84
+ "table_name": { "type": "string" },
85
+ "filters": { "type": "object" },
86
+ "limit": { "type": "number" },
87
+ "offset": { "type": "number" },
88
+ "sort_by": { "type": "string" },
89
+ "sort_direction": { "type": "string", "enum": ["ASC", "DESC"] }
90
+ },
91
+ "required": ["table_name"]
92
+ },
93
+ "output_schema": {
94
+ "type": "object",
95
+ "properties": {
96
+ "records": { "type": "array" },
97
+ "total": { "type": "number" }
98
+ }
99
+ }
100
+ },
101
+ {
102
+ "name": "update_record",
103
+ "description": "Updates an existing record in the specified table.",
104
+ "input_schema": {
105
+ "type": "object",
106
+ "properties": {
107
+ "table_name": { "type": "string" },
108
+ "id_field": { "type": "string" },
109
+ "id": { "type": ["string", "number"] },
110
+ "data": { "type": "object" }
111
+ },
112
+ "required": ["table_name", "id", "data"]
113
+ },
114
+ "output_schema": {
115
+ "type": "object",
116
+ "properties": {
117
+ "success": { "type": "boolean" },
118
+ "affected_rows": { "type": "number" }
119
+ }
120
+ }
121
+ },
122
+ {
123
+ "name": "delete_record",
124
+ "description": "Deletes a record from the specified table.",
125
+ "input_schema": {
126
+ "type": "object",
127
+ "properties": {
128
+ "table_name": { "type": "string" },
129
+ "id_field": { "type": "string" },
130
+ "id": { "type": ["string", "number"] }
131
+ },
132
+ "required": ["table_name", "id"]
133
+ },
134
+ "output_schema": {
135
+ "type": "object",
136
+ "properties": {
137
+ "success": { "type": "boolean" },
138
+ "affected_rows": { "type": "number" }
139
+ }
140
+ }
141
+ },
142
+ {
143
+ "name": "run_query",
144
+ "description": "Runs a read-only SQL query with optional parameters.",
145
+ "input_schema": {
146
+ "type": "object",
147
+ "properties": {
148
+ "query": { "type": "string" },
149
+ "params": { "type": "array" }
150
+ },
151
+ "required": ["query"]
152
+ },
153
+ "output_schema": {
154
+ "type": "object",
155
+ "properties": {
156
+ "results": { "type": "array" },
157
+ "fields": { "type": "array" }
158
+ }
159
+ }
160
+ },
161
+ {
162
+ "name": "execute_sql",
163
+ "description": "Executes a write SQL operation (INSERT, UPDATE, DELETE) with optional parameters.",
164
+ "input_schema": {
165
+ "type": "object",
166
+ "properties": {
167
+ "query": { "type": "string" },
168
+ "params": { "type": "array" }
169
+ },
170
+ "required": ["query"]
171
+ },
172
+ "output_schema": {
173
+ "type": "object",
174
+ "properties": {
175
+ "success": { "type": "boolean" },
176
+ "affected_rows": { "type": "number" },
177
+ "insert_id": { "type": ["number", "null"] }
178
+ }
179
+ }
180
+ },
181
+ {
182
+ "name": "describe_connection",
183
+ "description": "Returns information about the current database connection.",
184
+ "input_schema": {},
185
+ "output_schema": {
186
+ "type": "object",
187
+ "properties": {
188
+ "host": { "type": "string" },
189
+ "port": { "type": "number" },
190
+ "database": { "type": "string" },
191
+ "user": { "type": "string" },
192
+ "connected": { "type": "boolean" }
193
+ }
194
+ }
195
+ },
196
+ {
197
+ "name": "test_connection",
198
+ "description": "Tests the database connection and returns latency information.",
199
+ "input_schema": {},
200
+ "output_schema": {
201
+ "type": "object",
202
+ "properties": {
203
+ "success": { "type": "boolean" },
204
+ "latency_ms": { "type": "number" },
205
+ "message": { "type": "string" }
206
+ }
207
+ }
208
+ },
209
+ {
210
+ "name": "get_table_relationships",
211
+ "description": "Returns foreign key relationships for a specified table.",
212
+ "input_schema": {
213
+ "type": "object",
214
+ "properties": {
215
+ "table_name": { "type": "string" }
216
+ },
217
+ "required": ["table_name"]
218
+ },
219
+ "output_schema": {
220
+ "type": "object",
221
+ "properties": {
222
+ "as_parent": {
223
+ "type": "array",
224
+ "items": {
225
+ "type": "object",
226
+ "properties": {
227
+ "table": { "type": "string" },
228
+ "column": { "type": "string" },
229
+ "referenced_column": { "type": "string" }
230
+ }
231
+ }
232
+ },
233
+ "as_child": {
234
+ "type": "array",
235
+ "items": {
236
+ "type": "object",
237
+ "properties": {
238
+ "table": { "type": "string" },
239
+ "column": { "type": "string" },
240
+ "referenced_column": { "type": "string" }
241
+ }
242
+ }
243
+ }
244
+ }
245
+ }
246
+ }
247
+ ]
248
+ }
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "@berthojoris/mcp-mysql-server",
3
+ "version": "1.0.0",
4
+ "description": "Model Context Protocol server for MySQL database integration with dynamic per-project permissions",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "mcp-mysql": "./bin/mcp-mysql.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "start": "node dist/server.js",
13
+ "start:mcp": "node dist/mcp-server.js",
14
+ "start:api": "node dist/server.js",
15
+ "dev": "ts-node src/index.ts",
16
+ "dev:mcp": "ts-node src/mcp-server.ts",
17
+ "dev:api": "ts-node src/server.ts",
18
+ "test": "jest",
19
+ "prepare": "npm run build",
20
+ "prepublishOnly": "npm run build"
21
+ },
22
+ "keywords": [
23
+ "mcp",
24
+ "mysql",
25
+ "database",
26
+ "llm",
27
+ "ai",
28
+ "model-context-protocol",
29
+ "claude",
30
+ "cline",
31
+ "windsurf",
32
+ "agent",
33
+ "database-tools",
34
+ "sql",
35
+ "mysql-client",
36
+ "ai-tools"
37
+ ],
38
+ "author": "Your Name <your.email@example.com>",
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/your-username/mcp-mysql.git"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/your-username/mcp-mysql/issues"
46
+ },
47
+ "homepage": "https://github.com/your-username/mcp-mysql#readme",
48
+ "files": [
49
+ "dist",
50
+ "bin",
51
+ "README.md",
52
+ "LICENSE",
53
+ "manifest.json"
54
+ ],
55
+ "engines": {
56
+ "node": ">=18.0.0"
57
+ },
58
+ "dependencies": {
59
+ "@modelcontextprotocol/sdk": "^1.20.0",
60
+ "ajv": "^8.12.0",
61
+ "cors": "^2.8.5",
62
+ "dotenv": "^16.3.1",
63
+ "express": "^4.18.2",
64
+ "express-rate-limit": "^7.1.5",
65
+ "helmet": "^7.1.0",
66
+ "jsonwebtoken": "^9.0.2",
67
+ "morgan": "^1.10.0",
68
+ "mysql2": "^3.6.1",
69
+ "winston": "^3.11.0"
70
+ },
71
+ "devDependencies": {
72
+ "@types/cors": "^2.8.17",
73
+ "@types/express": "^4.17.21",
74
+ "@types/jest": "^29.5.4",
75
+ "@types/jsonwebtoken": "^9.0.5",
76
+ "@types/morgan": "^1.9.9",
77
+ "@types/node": "^20.6.0",
78
+ "jest": "^29.6.4",
79
+ "ts-jest": "^29.1.1",
80
+ "ts-node": "^10.9.1",
81
+ "typescript": "^5.2.2"
82
+ }
83
+ }