easy-sqlite-mcp 1.0.1
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.
- package/README.md +66 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/services/sqlite-manager.d.ts +71 -0
- package/dist/services/sqlite-manager.d.ts.map +1 -0
- package/dist/services/sqlite-manager.js +141 -0
- package/dist/services/sqlite-manager.js.map +1 -0
- package/dist/tools/sqlite.d.ts +6 -0
- package/dist/tools/sqlite.d.ts.map +1 -0
- package/dist/tools/sqlite.js +269 -0
- package/dist/tools/sqlite.js.map +1 -0
- package/package.json +52 -0
- package/skills/sqlite-mcp/SKILL.md +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Easy SQLite MCP
|
|
2
|
+
|
|
3
|
+
A [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server implemented in Node.js and TypeScript, designed to enable LLMs to interact directly with SQLite databases.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
This server provides 7 core tools covering all requirements from connection management to data querying:
|
|
8
|
+
|
|
9
|
+
1. **Connection Management**:
|
|
10
|
+
* `sqlite_open`: Open a specific SQLite database file path.
|
|
11
|
+
* `sqlite_close`: Close the current database connection.
|
|
12
|
+
* `sqlite_status`: Check connection status, file path, and database summary.
|
|
13
|
+
2. **Data Operations**:
|
|
14
|
+
* `sqlite_query`: Execute read-only `SELECT` queries and return results in a structured format.
|
|
15
|
+
* `sqlite_execute`: Execute write or modification operations (e.g., `INSERT`, `UPDATE`, `DELETE`, `CREATE`, `DROP`).
|
|
16
|
+
3. **Schema Discovery**:
|
|
17
|
+
* `sqlite_list_tables`: List all user-defined tables in the database.
|
|
18
|
+
* `sqlite_describe_table`: Get column information, types, and total row count for a specific table.
|
|
19
|
+
|
|
20
|
+
## Installation and Execution
|
|
21
|
+
|
|
22
|
+
### 1. Run via npx
|
|
23
|
+
If the project is published on npm, you can start it directly using `npx` without prior installation:
|
|
24
|
+
```bash
|
|
25
|
+
npx easy-sqlite-mcp
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Local Development and Build
|
|
29
|
+
To develop locally or build from source, follow these steps:
|
|
30
|
+
```bash
|
|
31
|
+
npm install
|
|
32
|
+
npm run build
|
|
33
|
+
npm run dev # Watch for changes and run in development mode
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## MCP Client Configuration
|
|
37
|
+
|
|
38
|
+
To use this with Claude Desktop or other MCP-compatible clients, add the following to your configuration:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"mcpServers": {
|
|
43
|
+
"easy-sqlite-mcp": {
|
|
44
|
+
"command": "npx",
|
|
45
|
+
"args": [
|
|
46
|
+
"-y",
|
|
47
|
+
"easy-sqlite-mcp"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Agent Skills (`/skills`)
|
|
55
|
+
|
|
56
|
+
The `/skills` directory contains Agent Skills designed to work in conjunction with this MCP Server. These skill documents provide Large Language Models (LLMs) with the knowledge of how to use this server for professional, high-level database operations. You can add these skills to your AI agent's workspace.
|
|
57
|
+
|
|
58
|
+
## Tech Stack
|
|
59
|
+
- **Runtime**: Node.js (>= 18)
|
|
60
|
+
- **Language**: TypeScript
|
|
61
|
+
- **SDK**: @modelcontextprotocol/sdk
|
|
62
|
+
- **Database**: better-sqlite3 (High performance with support for synchronous operations)
|
|
63
|
+
- **Validation**: Zod (Strict parameter validation)
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
Developed with the assistance of Antigravity.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* SQLite MCP Server
|
|
4
|
+
*
|
|
5
|
+
* This server provides tools to interact with SQLite databases via
|
|
6
|
+
* the Model Context Protocol (MCP). It supports opening/closing databases,
|
|
7
|
+
* querying, executing statements, listing tables, and describing schemas.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;GAMG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* SQLite MCP Server
|
|
4
|
+
*
|
|
5
|
+
* This server provides tools to interact with SQLite databases via
|
|
6
|
+
* the Model Context Protocol (MCP). It supports opening/closing databases,
|
|
7
|
+
* querying, executing statements, listing tables, and describing schemas.
|
|
8
|
+
*/
|
|
9
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
11
|
+
import { registerSqliteTools } from "./tools/sqlite.js";
|
|
12
|
+
// Create MCP server instance
|
|
13
|
+
const server = new McpServer({
|
|
14
|
+
name: "easy-sqlite-mcp",
|
|
15
|
+
version: "1.0.0",
|
|
16
|
+
});
|
|
17
|
+
// Register all SQLite tools
|
|
18
|
+
registerSqliteTools(server);
|
|
19
|
+
// Start the server with stdio transport
|
|
20
|
+
async function main() {
|
|
21
|
+
const transport = new StdioServerTransport();
|
|
22
|
+
await server.connect(transport);
|
|
23
|
+
console.error("SQLite MCP server running via stdio");
|
|
24
|
+
}
|
|
25
|
+
main().catch((error) => {
|
|
26
|
+
console.error("Server error:", error);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,6BAA6B;AAC7B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAC3B,IAAI,EAAE,iBAAiB;IACvB,OAAO,EAAE,OAAO;CACjB,CAAC,CAAC;AAEH,4BAA4B;AAC5B,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAE5B,wCAAwC;AACxC,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;AACvD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages a single SQLite database connection.
|
|
3
|
+
*/
|
|
4
|
+
export declare class SqliteManager {
|
|
5
|
+
private db;
|
|
6
|
+
private filePath;
|
|
7
|
+
/**
|
|
8
|
+
* Open an SQLite database file.
|
|
9
|
+
*/
|
|
10
|
+
open(filePath: string): {
|
|
11
|
+
success: boolean;
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Close the current database connection.
|
|
16
|
+
*/
|
|
17
|
+
close(): {
|
|
18
|
+
success: boolean;
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Get the current database status.
|
|
23
|
+
*/
|
|
24
|
+
status(): {
|
|
25
|
+
isOpen: boolean;
|
|
26
|
+
filePath: string | null;
|
|
27
|
+
memoryUsage: number | null;
|
|
28
|
+
tables: number | null;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Execute a read-only SELECT query.
|
|
32
|
+
*/
|
|
33
|
+
query(sql: string, params?: Record<string, unknown>): {
|
|
34
|
+
columns: string[];
|
|
35
|
+
rows: unknown[][];
|
|
36
|
+
rowCount: number;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Execute a write operation (INSERT, UPDATE, DELETE, CREATE, DROP, ALTER).
|
|
40
|
+
*/
|
|
41
|
+
execute(sql: string, params?: Record<string, unknown>): {
|
|
42
|
+
changes: number;
|
|
43
|
+
lastInsertRowid: number | bigint;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* List all tables in the database.
|
|
47
|
+
*/
|
|
48
|
+
listTables(): {
|
|
49
|
+
tables: string[];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Describe the schema of a specific table.
|
|
53
|
+
*/
|
|
54
|
+
describeTable(tableName: string): {
|
|
55
|
+
name: string;
|
|
56
|
+
columns: {
|
|
57
|
+
cid: number;
|
|
58
|
+
name: string;
|
|
59
|
+
type: string;
|
|
60
|
+
notnull: boolean;
|
|
61
|
+
defaultValue: unknown;
|
|
62
|
+
pk: boolean;
|
|
63
|
+
}[];
|
|
64
|
+
rowCount: number;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Ensure the database is open before running a query.
|
|
68
|
+
*/
|
|
69
|
+
private ensureOpen;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=sqlite-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-manager.d.ts","sourceRoot":"","sources":["../../src/services/sqlite-manager.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,EAAE,C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;SACb,EAAE,CAAC;QACJ,QAAQ,EAAE,MAAM,CAAC;KAClB;IAoCD;;OAEG;IACH,OAAO,CAAC,UAAU;CAOnB"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import Database from "better-sqlite3";
|
|
2
|
+
/**
|
|
3
|
+
* Manages a single SQLite database connection.
|
|
4
|
+
*/
|
|
5
|
+
export class SqliteManager {
|
|
6
|
+
db = null;
|
|
7
|
+
filePath = null;
|
|
8
|
+
/**
|
|
9
|
+
* Open an SQLite database file.
|
|
10
|
+
*/
|
|
11
|
+
open(filePath) {
|
|
12
|
+
try {
|
|
13
|
+
// Close existing connection if any
|
|
14
|
+
if (this.db) {
|
|
15
|
+
this.close();
|
|
16
|
+
}
|
|
17
|
+
this.db = new Database(filePath);
|
|
18
|
+
// Enable WAL mode for better concurrency
|
|
19
|
+
this.db.pragma("journal_mode = WAL");
|
|
20
|
+
this.filePath = filePath;
|
|
21
|
+
return { success: true, message: `Database opened: ${filePath}` };
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return {
|
|
25
|
+
success: false,
|
|
26
|
+
message: `Failed to open database: ${error instanceof Error ? error.message : String(error)}`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Close the current database connection.
|
|
32
|
+
*/
|
|
33
|
+
close() {
|
|
34
|
+
if (!this.db) {
|
|
35
|
+
return { success: false, message: "No database is currently open." };
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
this.db.close();
|
|
39
|
+
const closedPath = this.filePath;
|
|
40
|
+
this.db = null;
|
|
41
|
+
this.filePath = null;
|
|
42
|
+
return { success: true, message: `Database closed: ${closedPath}` };
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return {
|
|
46
|
+
success: false,
|
|
47
|
+
message: `Failed to close database: ${error instanceof Error ? error.message : String(error)}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the current database status.
|
|
53
|
+
*/
|
|
54
|
+
status() {
|
|
55
|
+
if (!this.db) {
|
|
56
|
+
return { isOpen: false, filePath: null, memoryUsage: null, tables: null };
|
|
57
|
+
}
|
|
58
|
+
let tableCount = null;
|
|
59
|
+
try {
|
|
60
|
+
const result = this.db
|
|
61
|
+
.prepare("SELECT COUNT(*) as count FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'")
|
|
62
|
+
.get();
|
|
63
|
+
tableCount = result.count;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// ignore
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
isOpen: true,
|
|
70
|
+
filePath: this.filePath,
|
|
71
|
+
memoryUsage: null,
|
|
72
|
+
tables: tableCount,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Execute a read-only SELECT query.
|
|
77
|
+
*/
|
|
78
|
+
query(sql, params) {
|
|
79
|
+
this.ensureOpen();
|
|
80
|
+
const stmt = this.db.prepare(sql);
|
|
81
|
+
const rows = params ? stmt.all(params) : stmt.all();
|
|
82
|
+
if (rows.length === 0) {
|
|
83
|
+
return { columns: [], rows: [], rowCount: 0 };
|
|
84
|
+
}
|
|
85
|
+
const columns = Object.keys(rows[0]);
|
|
86
|
+
const dataRows = rows.map((row) => columns.map((col) => row[col]));
|
|
87
|
+
return { columns, rows: dataRows, rowCount: rows.length };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Execute a write operation (INSERT, UPDATE, DELETE, CREATE, DROP, ALTER).
|
|
91
|
+
*/
|
|
92
|
+
execute(sql, params) {
|
|
93
|
+
this.ensureOpen();
|
|
94
|
+
const stmt = this.db.prepare(sql);
|
|
95
|
+
const result = params ? stmt.run(params) : stmt.run();
|
|
96
|
+
return {
|
|
97
|
+
changes: result.changes,
|
|
98
|
+
lastInsertRowid: result.lastInsertRowid,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* List all tables in the database.
|
|
103
|
+
*/
|
|
104
|
+
listTables() {
|
|
105
|
+
this.ensureOpen();
|
|
106
|
+
const rows = this.db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name").all();
|
|
107
|
+
return { tables: rows.map((r) => r.name) };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Describe the schema of a specific table.
|
|
111
|
+
*/
|
|
112
|
+
describeTable(tableName) {
|
|
113
|
+
this.ensureOpen();
|
|
114
|
+
const columns = this.db.prepare(`PRAGMA table_info('${tableName}')`).all();
|
|
115
|
+
if (columns.length === 0) {
|
|
116
|
+
throw new Error(`Table '${tableName}' not found.`);
|
|
117
|
+
}
|
|
118
|
+
const countResult = this.db.prepare(`SELECT COUNT(*) as count FROM "${tableName}"`).get();
|
|
119
|
+
return {
|
|
120
|
+
name: tableName,
|
|
121
|
+
columns: columns.map((col) => ({
|
|
122
|
+
cid: col.cid,
|
|
123
|
+
name: col.name,
|
|
124
|
+
type: col.type,
|
|
125
|
+
notnull: col.notnull === 1,
|
|
126
|
+
defaultValue: col.dflt_value,
|
|
127
|
+
pk: col.pk === 1,
|
|
128
|
+
})),
|
|
129
|
+
rowCount: countResult.count,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Ensure the database is open before running a query.
|
|
134
|
+
*/
|
|
135
|
+
ensureOpen() {
|
|
136
|
+
if (!this.db) {
|
|
137
|
+
throw new Error("No database is currently open. Use sqlite_open to open a database first.");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=sqlite-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-manager.js","sourceRoot":"","sources":["../../src/services/sqlite-manager.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAE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,EAAG,CAAC,OAAO,CAC9B,sBAAsB,SAAS,IAAI,CACpC,CAAC,GAAG,EAOF,CAAC;QAEJ,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,UAAU,SAAS,cAAc,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,EAAG,CAAC,OAAO,CAClC,kCAAkC,SAAS,GAAG,CAC/C,CAAC,GAAG,EAAuB,CAAC;QAE7B,OAAO;YACL,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;gBAC7B,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,OAAO,EAAE,GAAG,CAAC,OAAO,KAAK,CAAC;gBAC1B,YAAY,EAAE,GAAG,CAAC,UAAU;gBAC5B,EAAE,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC;aACjB,CAAC,CAAC;YACH,QAAQ,EAAE,WAAW,CAAC,KAAK;SAC5B,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,UAAU;QAChB,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CACb,0EAA0E,CAC3E,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/tools/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAMpE;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAmS3D"}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SqliteManager } from "../services/sqlite-manager.js";
|
|
3
|
+
const sqliteManager = new SqliteManager();
|
|
4
|
+
/**
|
|
5
|
+
* Register all SQLite tools on the MCP server.
|
|
6
|
+
*/
|
|
7
|
+
export function registerSqliteTools(server) {
|
|
8
|
+
// ─── sqlite_open ───────────────────────────────────────────────
|
|
9
|
+
server.registerTool("sqlite_open", {
|
|
10
|
+
title: "Open SQLite Database",
|
|
11
|
+
description: `Open an SQLite database file at the specified path.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
- file_path (string): Absolute or relative path to the .db / .sqlite file.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
{ "success": boolean, "message": string }
|
|
18
|
+
|
|
19
|
+
Examples:
|
|
20
|
+
- "Open the users database" -> file_path="/data/users.db"
|
|
21
|
+
|
|
22
|
+
Error Handling:
|
|
23
|
+
- Returns success=false with message if the file cannot be opened.`,
|
|
24
|
+
inputSchema: {
|
|
25
|
+
file_path: z
|
|
26
|
+
.string()
|
|
27
|
+
.min(1, "file_path is required")
|
|
28
|
+
.describe("Path to the SQLite database file"),
|
|
29
|
+
},
|
|
30
|
+
annotations: {
|
|
31
|
+
readOnlyHint: false,
|
|
32
|
+
destructiveHint: false,
|
|
33
|
+
idempotentHint: true,
|
|
34
|
+
openWorldHint: false,
|
|
35
|
+
},
|
|
36
|
+
}, async ({ file_path }) => {
|
|
37
|
+
const result = sqliteManager.open(file_path);
|
|
38
|
+
return {
|
|
39
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
40
|
+
structuredContent: result,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
// ─── sqlite_close ──────────────────────────────────────────────
|
|
44
|
+
server.registerTool("sqlite_close", {
|
|
45
|
+
title: "Close SQLite Database",
|
|
46
|
+
description: `Close the currently open SQLite database connection.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
{ "success": boolean, "message": string }
|
|
50
|
+
|
|
51
|
+
Error Handling:
|
|
52
|
+
- Returns success=false if no database is currently open.`,
|
|
53
|
+
inputSchema: {},
|
|
54
|
+
annotations: {
|
|
55
|
+
readOnlyHint: false,
|
|
56
|
+
destructiveHint: false,
|
|
57
|
+
idempotentHint: true,
|
|
58
|
+
openWorldHint: false,
|
|
59
|
+
},
|
|
60
|
+
}, async () => {
|
|
61
|
+
const result = sqliteManager.close();
|
|
62
|
+
return {
|
|
63
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
64
|
+
structuredContent: result,
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
// ─── sqlite_status ─────────────────────────────────────────────
|
|
68
|
+
server.registerTool("sqlite_status", {
|
|
69
|
+
title: "SQLite Database Status",
|
|
70
|
+
description: `Get the current status of the SQLite database connection.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
{
|
|
74
|
+
"isOpen": boolean,
|
|
75
|
+
"filePath": string | null,
|
|
76
|
+
"memoryUsage": number | null,
|
|
77
|
+
"tables": number | null
|
|
78
|
+
}`,
|
|
79
|
+
inputSchema: {},
|
|
80
|
+
annotations: {
|
|
81
|
+
readOnlyHint: true,
|
|
82
|
+
destructiveHint: false,
|
|
83
|
+
idempotentHint: true,
|
|
84
|
+
openWorldHint: false,
|
|
85
|
+
},
|
|
86
|
+
}, async () => {
|
|
87
|
+
const result = sqliteManager.status();
|
|
88
|
+
return {
|
|
89
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
90
|
+
structuredContent: result,
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
// ─── sqlite_query ──────────────────────────────────────────────
|
|
94
|
+
server.registerTool("sqlite_query", {
|
|
95
|
+
title: "Query SQLite Database",
|
|
96
|
+
description: `Execute a read-only SQL query (SELECT) on the currently open database.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
- sql (string): The SQL SELECT statement to execute.
|
|
100
|
+
- params (object, optional): Named parameters for the query (e.g. { ":id": 1 }).
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
{ "columns": string[], "rows": unknown[][], "rowCount": number }
|
|
104
|
+
|
|
105
|
+
Error Handling:
|
|
106
|
+
- Throws if no database is open. Use sqlite_open first.
|
|
107
|
+
- Returns SQL error message if the query is invalid.`,
|
|
108
|
+
inputSchema: {
|
|
109
|
+
sql: z
|
|
110
|
+
.string()
|
|
111
|
+
.min(1, "SQL query is required")
|
|
112
|
+
.describe("SQL SELECT statement to execute"),
|
|
113
|
+
params: z
|
|
114
|
+
.record(z.unknown())
|
|
115
|
+
.optional()
|
|
116
|
+
.describe("Optional named parameters for the query"),
|
|
117
|
+
},
|
|
118
|
+
annotations: {
|
|
119
|
+
readOnlyHint: true,
|
|
120
|
+
destructiveHint: false,
|
|
121
|
+
idempotentHint: true,
|
|
122
|
+
openWorldHint: false,
|
|
123
|
+
},
|
|
124
|
+
}, async ({ sql, params }) => {
|
|
125
|
+
try {
|
|
126
|
+
const result = sqliteManager.query(sql, params);
|
|
127
|
+
return {
|
|
128
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
129
|
+
structuredContent: result,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
134
|
+
return {
|
|
135
|
+
content: [{ type: "text", text: `Error: ${message}` }],
|
|
136
|
+
isError: true,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
// ─── sqlite_execute ────────────────────────────────────────────
|
|
141
|
+
server.registerTool("sqlite_execute", {
|
|
142
|
+
title: "Execute SQL Statement",
|
|
143
|
+
description: `Execute a write SQL statement (INSERT, UPDATE, DELETE, CREATE, DROP, ALTER) on the currently open database.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
- sql (string): The SQL statement to execute.
|
|
147
|
+
- params (object, optional): Named parameters for the statement.
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
{ "changes": number, "lastInsertRowid": number }
|
|
151
|
+
|
|
152
|
+
Error Handling:
|
|
153
|
+
- Throws if no database is open. Use sqlite_open first.
|
|
154
|
+
- Returns SQL error message if the statement is invalid.`,
|
|
155
|
+
inputSchema: {
|
|
156
|
+
sql: z
|
|
157
|
+
.string()
|
|
158
|
+
.min(1, "SQL statement is required")
|
|
159
|
+
.describe("SQL statement to execute (INSERT, UPDATE, DELETE, etc.)"),
|
|
160
|
+
params: z
|
|
161
|
+
.record(z.unknown())
|
|
162
|
+
.optional()
|
|
163
|
+
.describe("Optional named parameters for the statement"),
|
|
164
|
+
},
|
|
165
|
+
annotations: {
|
|
166
|
+
readOnlyHint: false,
|
|
167
|
+
destructiveHint: true,
|
|
168
|
+
idempotentHint: false,
|
|
169
|
+
openWorldHint: false,
|
|
170
|
+
},
|
|
171
|
+
}, async ({ sql, params }) => {
|
|
172
|
+
try {
|
|
173
|
+
const result = sqliteManager.execute(sql, params);
|
|
174
|
+
return {
|
|
175
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
176
|
+
structuredContent: result,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
181
|
+
return {
|
|
182
|
+
content: [{ type: "text", text: `Error: ${message}` }],
|
|
183
|
+
isError: true,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
// ─── sqlite_list_tables ────────────────────────────────────────
|
|
188
|
+
server.registerTool("sqlite_list_tables", {
|
|
189
|
+
title: "List SQLite Tables",
|
|
190
|
+
description: `List all user tables in the currently open SQLite database.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
{ "tables": string[] }
|
|
194
|
+
|
|
195
|
+
Error Handling:
|
|
196
|
+
- Throws if no database is open. Use sqlite_open first.`,
|
|
197
|
+
inputSchema: {},
|
|
198
|
+
annotations: {
|
|
199
|
+
readOnlyHint: true,
|
|
200
|
+
destructiveHint: false,
|
|
201
|
+
idempotentHint: true,
|
|
202
|
+
openWorldHint: false,
|
|
203
|
+
},
|
|
204
|
+
}, async () => {
|
|
205
|
+
try {
|
|
206
|
+
const result = sqliteManager.listTables();
|
|
207
|
+
return {
|
|
208
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
209
|
+
structuredContent: result,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
214
|
+
return {
|
|
215
|
+
content: [{ type: "text", text: `Error: ${message}` }],
|
|
216
|
+
isError: true,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
// ─── sqlite_describe_table ─────────────────────────────────────
|
|
221
|
+
server.registerTool("sqlite_describe_table", {
|
|
222
|
+
title: "Describe SQLite Table",
|
|
223
|
+
description: `Describe the schema of a specific table in the currently open SQLite database.
|
|
224
|
+
|
|
225
|
+
Args:
|
|
226
|
+
- table_name (string): Name of the table to describe.
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
{
|
|
230
|
+
"name": string,
|
|
231
|
+
"columns": [
|
|
232
|
+
{ "cid": number, "name": string, "type": string, "notnull": boolean, "defaultValue": unknown, "pk": boolean }
|
|
233
|
+
],
|
|
234
|
+
"rowCount": number
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
Error Handling:
|
|
238
|
+
- Throws if no database is open. Use sqlite_open first.
|
|
239
|
+
- Returns error if the table does not exist.`,
|
|
240
|
+
inputSchema: {
|
|
241
|
+
table_name: z
|
|
242
|
+
.string()
|
|
243
|
+
.min(1, "Table name is required")
|
|
244
|
+
.describe("Name of the table to describe"),
|
|
245
|
+
},
|
|
246
|
+
annotations: {
|
|
247
|
+
readOnlyHint: true,
|
|
248
|
+
destructiveHint: false,
|
|
249
|
+
idempotentHint: true,
|
|
250
|
+
openWorldHint: false,
|
|
251
|
+
},
|
|
252
|
+
}, async ({ table_name }) => {
|
|
253
|
+
try {
|
|
254
|
+
const result = sqliteManager.describeTable(table_name);
|
|
255
|
+
return {
|
|
256
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
257
|
+
structuredContent: result,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
262
|
+
return {
|
|
263
|
+
content: [{ type: "text", text: `Error: ${message}` }],
|
|
264
|
+
isError: true,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=sqlite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/tools/sqlite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;AAE1C;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAiB;IACnD,kEAAkE;IAClE,MAAM,CAAC,YAAY,CACjB,aAAa,EACb;QACE,KAAK,EAAE,sBAAsB;QAC7B,WAAW,EAAE;;;;;;;;;;;;qEAYkD;QAC/D,WAAW,EAAE;YACX,SAAS,EAAE,CAAC;iBACT,MAAM,EAAE;iBACR,GAAG,CAAC,CAAC,EAAE,uBAAuB,CAAC;iBAC/B,QAAQ,CAAC,kCAAkC,CAAC;SAChD;QACD,WAAW,EAAE;YACX,YAAY,EAAE,KAAK;YACnB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,KAAK;SACrB;KACF,EACD,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;QACtB,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7C,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE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AI;YACpB,aAAa,EAAE,KAAK;SACrB;KACF,EACD,KAAK,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE;QACvB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,aAAa,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACvD,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;gBAClE,iBAAiB,EAAE,MAAM;aAC1B,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,OAAO,EAAE,EAAE,CAAC;gBACtD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "easy-sqlite-mcp",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A high-performance Model Context Protocol (MCP) server for SQLite database interaction.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"mcp-server",
|
|
8
|
+
"sqlite",
|
|
9
|
+
"database",
|
|
10
|
+
"better-sqlite3"
|
|
11
|
+
],
|
|
12
|
+
"author": "chenkumi",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/chenkumi/easy-sqlite-mcp.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/chenkumi/easy-sqlite-mcp/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/chenkumi/easy-sqlite-mcp#readme",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"skills",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"main": "dist/index.js",
|
|
29
|
+
"bin": {
|
|
30
|
+
"easy-sqlite-mcp": "dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"start": "node dist/index.js",
|
|
34
|
+
"dev": "tsx watch src/index.ts",
|
|
35
|
+
"build": "tsc",
|
|
36
|
+
"clean": "rimraf dist"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@modelcontextprotocol/sdk": "^1.6.1",
|
|
43
|
+
"better-sqlite3": "^11.7.0",
|
|
44
|
+
"zod": "^3.23.8"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/better-sqlite3": "^7.6.12",
|
|
48
|
+
"@types/node": "^22.10.0",
|
|
49
|
+
"tsx": "^4.19.2",
|
|
50
|
+
"typescript": "^5.7.2"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sqlite-mcp
|
|
3
|
+
description: A skill specialized in operating SQLite databases. Use this skill when users mention "query database", "read .db or .sqlite files", "store structured data in SQLite", or need to perform SQL operations. This skill provides functionality to open/close databases, execute SQL queries (SELECT), perform write operations (INSERT/UPDATE/DELETE), and explore table schemas.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# SQLite MCP Skill
|
|
7
|
+
|
|
8
|
+
This skill allows you to interact with SQLite databases through a series of MCP tools.
|
|
9
|
+
|
|
10
|
+
## Core Workflow
|
|
11
|
+
|
|
12
|
+
### 1. Open Database
|
|
13
|
+
Before any operation, you must use `sqlite_open` to open the database file.
|
|
14
|
+
- **Tool**: `sqlite_open`
|
|
15
|
+
- **Parameters**: `file_path` (Absolute or relative path)
|
|
16
|
+
|
|
17
|
+
### 2. Explore Structure (Optional)
|
|
18
|
+
If the database content is unclear, you can list tables or view table definitions first.
|
|
19
|
+
- **List Tables**: `sqlite_list_tables`
|
|
20
|
+
- **View Structure**: `sqlite_describe_table` (requires `table_name`)
|
|
21
|
+
|
|
22
|
+
### 3. Data Operation
|
|
23
|
+
- **Read Data**: Use `sqlite_query` to execute `SELECT` statements.
|
|
24
|
+
- **Write Data**: Use `sqlite_execute` to execute `INSERT`, `UPDATE`, `DELETE`, or DDL statements (e.g., `CREATE TABLE`).
|
|
25
|
+
- **Parameterized Queries**: It is recommended to use the `params` parameter (e.g., `{ ":id": 1 }`) to prevent SQL injection.
|
|
26
|
+
|
|
27
|
+
### 4. Check Status
|
|
28
|
+
You can use `sqlite_status` at any time to confirm the current database path and connection status.
|
|
29
|
+
|
|
30
|
+
### 5. Close Database
|
|
31
|
+
After work is finished, use `sqlite_close` to release resources.
|
|
32
|
+
|
|
33
|
+
## Best Practices
|
|
34
|
+
- **Security First**: Prioritize parameterized queries over direct SQL string concatenation.
|
|
35
|
+
- **Transaction Management**: Ensure logical consistency for multi-step write operations.
|
|
36
|
+
- **Path Handling**: Ensure correct path formatting (supports `/` or `\\`).
|
|
37
|
+
- **Error Handling**: If an operation fails, check `sqlite_status` to ensure the database is correctly opened.
|