db4app-mcp-server 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +134 -0
  3. package/dist/index.js +15019 -0
  4. package/package.json +50 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 db4app
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # @db4app/mcp-server
2
+
3
+ MCP server for db4.app - enables LLMs to interact with browser-based Postgres databases via Model Context Protocol.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g @db4app/mcp-server
9
+ ```
10
+
11
+ Or use with `npx` (no installation needed):
12
+
13
+ ```bash
14
+ npx @db4app/mcp-server
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### With LM Studio
20
+
21
+ 1. Locate your `mcp.json` file:
22
+ - **macOS:** `~/Library/Application Support/LM Studio/mcp.json`
23
+ - **Windows:** `%APPDATA%\LM Studio\mcp.json`
24
+ - **Linux:** `~/.config/LM Studio/mcp.json`
25
+
26
+ 2. Add this to the `mcpServers` object in your `mcp.json`:
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "postgres-wasm": {
32
+ "command": "npx",
33
+ "args": [
34
+ "-y",
35
+ "@db4app/mcp-server"
36
+ ],
37
+ "env": {
38
+ "MCP_PROXY_HTTP_URL": "http://localhost:8787/query",
39
+ "LM_STUDIO_EMBEDDING_URL": "http://localhost:1234/v1/embeddings",
40
+ "LM_STUDIO_EMBEDDING_MODEL": "text-embedding-qwen3-embedding-4b",
41
+ "MCP_ALLOWED_TABLES": "rag_mcp.documents",
42
+ "MCP_PUBLIC_KEY": "YOUR_PUBLIC_KEY_HERE",
43
+ "MCP_USE_ENCRYPTION": "true"
44
+ }
45
+ }
46
+ }
47
+ }
48
+ ```
49
+
50
+ **Note**: Replace `YOUR_PUBLIC_KEY_HERE` with your actual public key from the Database page → Management tab → Encryption section.
51
+
52
+ 3. **Install an Embedding Model** (Required for RAG features):
53
+ - Open LM Studio → Search tab
54
+ - Search for embedding models (e.g., "bge", "e5", "text-embedding")
55
+ - Download and load an embedding-capable model
56
+ - Update `LM_STUDIO_EMBEDDING_MODEL` in your `mcp.json` with the exact model name
57
+ - Enable headless server mode in LM Studio
58
+
59
+ 4. Restart LM Studio to load the configuration.
60
+
61
+ ### With Claude Desktop
62
+
63
+ Add to your `claude_desktop_config.json`:
64
+
65
+ ```json
66
+ {
67
+ "mcpServers": {
68
+ "postgres-wasm": {
69
+ "command": "npx",
70
+ "args": [
71
+ "-y",
72
+ "@db4app/mcp-server"
73
+ ],
74
+ "env": {
75
+ "MCP_PROXY_HTTP_URL": "http://localhost:8787/query",
76
+ "LM_STUDIO_EMBEDDING_URL": "http://localhost:1234/v1/embeddings",
77
+ "LM_STUDIO_EMBEDDING_MODEL": "text-embedding-qwen3-embedding-4b",
78
+ "MCP_ALLOWED_TABLES": "rag_mcp.documents",
79
+ "MCP_PUBLIC_KEY": "YOUR_PUBLIC_KEY_HERE",
80
+ "MCP_USE_ENCRYPTION": "true"
81
+ }
82
+ }
83
+ }
84
+ }
85
+ ```
86
+
87
+ **Note**: Replace `YOUR_PUBLIC_KEY_HERE` with your actual public key from the Database page → Management tab → Encryption section.
88
+
89
+ ## Configuration
90
+
91
+ All configuration is done via environment variables:
92
+
93
+ - `MCP_PROXY_HTTP_URL` - HTTP proxy endpoint (default: `http://localhost:8787/query`)
94
+ - `LM_STUDIO_EMBEDDING_URL` - LM Studio embedding API endpoint (default: `http://localhost:1234/v1/embeddings`)
95
+ - `LM_STUDIO_EMBEDDING_MODEL` - Optional model name for embeddings
96
+ - `MCP_ALLOWED_TABLES` - **Required for recipes**: Comma-separated list of allowed tables (e.g., `"schema.table1,schema.table2"`). The proxy validates all SQL queries against this whitelist. If not set, the MCP server can access all tables (for direct use, not recommended for recipes).
97
+ - `MCP_PUBLIC_KEY` - **Optional**: Base64-encoded public key for end-to-end encryption. If not provided, the MCP server will attempt to fetch it from the proxy's `/public-key` endpoint. Get your public key from the Database page → Management tab → Encryption section.
98
+ - `MCP_USE_ENCRYPTION` - Enable end-to-end encryption (default: `true` if `MCP_PUBLIC_KEY` is set, otherwise `false`). When enabled, all SQL queries are encrypted with RSA-OAEP before being sent to the proxy, ensuring the proxy cannot decrypt them.
99
+
100
+ ## Available Tools
101
+
102
+ - `query_database` - Execute SQL queries (respects `MCP_ALLOWED_TABLES` if set)
103
+ - `list_tables` - List tables in the database (only shows whitelisted tables if `MCP_ALLOWED_TABLES` is set)
104
+ - `remember` - Store information in memory with automatic embedding (requires `MCP_ALLOWED_TABLES` for recipe use)
105
+ - `search_memory` - Search through stored memories using semantic similarity (requires `MCP_ALLOWED_TABLES` for recipe use)
106
+
107
+ **Note**: When used with recipes, `MCP_ALLOWED_TABLES` must be set to restrict access to only the recipe's tables. The proxy server validates all queries against this whitelist.
108
+
109
+ ## End-to-End Encryption
110
+
111
+ This MCP server supports end-to-end encryption of SQL queries using RSA-OAEP (2048-bit). When encryption is enabled:
112
+
113
+ - SQL queries are encrypted in the MCP server using the browser's public key
114
+ - The proxy server relays encrypted queries without being able to decrypt them
115
+ - Only the browser (with the private key) can decrypt and execute queries
116
+ - This ensures complete privacy: even the proxy cannot see your SQL queries
117
+
118
+ To enable encryption:
119
+ 1. Get your public key from the Database page → Management tab → Encryption section
120
+ 2. Set `MCP_PUBLIC_KEY` to your public key (base64 string)
121
+ 3. Set `MCP_USE_ENCRYPTION` to `"true"`
122
+
123
+ If `MCP_PUBLIC_KEY` is not provided, the MCP server will automatically fetch it from the proxy's `/public-key` endpoint.
124
+
125
+ ## Requirements
126
+
127
+ - Node.js 18+
128
+ - Postgres WASM proxy running (default: `http://localhost:8787/query`)
129
+ - For RAG features: LM Studio with embedding-capable model loaded
130
+
131
+ ## License
132
+
133
+ MIT
134
+