@jsondb-cloud/mcp 1.0.14 → 1.0.25
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/LICENSE +21 -0
- package/README.md +36 -5
- package/dist/index.js +236 -12
- package/dist/index.mjs +214 -12
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 SIA Billy
|
|
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.
|
package/README.md
CHANGED
|
@@ -82,11 +82,14 @@ Add to `.cursor/mcp.json`:
|
|
|
82
82
|
|
|
83
83
|
### Environment Variables
|
|
84
84
|
|
|
85
|
-
| Variable
|
|
86
|
-
|
|
|
87
|
-
| `JSONDB_API_KEY`
|
|
88
|
-
| `JSONDB_PROJECT`
|
|
89
|
-
| `JSONDB_BASE_URL`
|
|
85
|
+
| Variable | Required | Default | Description |
|
|
86
|
+
| ---------------------- | -------- | -------------------------- | --------------------------------------------------- |
|
|
87
|
+
| `JSONDB_API_KEY` | Yes | — | API key (`jdb_sk_live_...` or `jdb_sk_test_...`) |
|
|
88
|
+
| `JSONDB_PROJECT` | No | `v1` | Project namespace |
|
|
89
|
+
| `JSONDB_BASE_URL` | No | `https://api.jsondb.cloud` | API base URL |
|
|
90
|
+
| `JSONDB_MCP_TRANSPORT` | No | `stdio` | Transport type: `stdio` or `http` |
|
|
91
|
+
| `JSONDB_MCP_PORT` | No | `3100` | HTTP server port (only used with `http` transport) |
|
|
92
|
+
| `JSONDB_MCP_HOST` | No | `127.0.0.1` | HTTP bind address (only used with `http` transport) |
|
|
90
93
|
|
|
91
94
|
## Tools
|
|
92
95
|
|
|
@@ -141,6 +144,34 @@ Add to `.cursor/mcp.json`:
|
|
|
141
144
|
| `delete_webhook` | Delete a webhook |
|
|
142
145
|
| `test_webhook` | Send a test event to verify delivery |
|
|
143
146
|
|
|
147
|
+
### Vectors
|
|
148
|
+
|
|
149
|
+
| Tool | Description |
|
|
150
|
+
| ---------------------- | --------------------------------------------------------------------------------- |
|
|
151
|
+
| `semantic_search` | Search documents using natural language semantic similarity with relevance scores |
|
|
152
|
+
| `store_with_embedding` | Store a document and auto-generate a vector embedding for semantic search |
|
|
153
|
+
|
|
154
|
+
Embeddings are generated **asynchronously by the jsondb.cloud backend** using **Ollama** (`nomic-embed-text`, 768 dimensions). The MCP server delegates to the REST API — no local embedding model or API key is needed.
|
|
155
|
+
|
|
156
|
+
## HTTP Transport
|
|
157
|
+
|
|
158
|
+
By default the server uses **stdio** transport (for Claude Desktop, Cursor, etc.). To run as an HTTP server instead, set:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
JSONDB_MCP_TRANSPORT=http JSONDB_API_KEY=jdb_sk_live_... npx @jsondb-cloud/mcp
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
This starts a stateless Streamable HTTP server that creates a fresh `McpServer` + transport per request (no session affinity required). Endpoints:
|
|
165
|
+
|
|
166
|
+
| Method | Path | Description |
|
|
167
|
+
| -------- | --------- | ---------------------------------------- |
|
|
168
|
+
| `POST` | `/mcp` | MCP JSON-RPC requests |
|
|
169
|
+
| `GET` | `/mcp` | SSE stream for server notifications |
|
|
170
|
+
| `DELETE` | `/mcp` | Session termination |
|
|
171
|
+
| `GET` | `/health` | Health check (returns `{"status":"ok"}`) |
|
|
172
|
+
|
|
173
|
+
Configure the host and port with `JSONDB_MCP_HOST` and `JSONDB_MCP_PORT` (defaults: `127.0.0.1:3100`).
|
|
174
|
+
|
|
144
175
|
## Documentation
|
|
145
176
|
|
|
146
177
|
Full documentation at [jsondb.cloud/docs](https://jsondb.cloud/docs).
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
2
24
|
|
|
3
25
|
// src/index.ts
|
|
4
26
|
var import_mcp2 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
5
27
|
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
28
|
+
var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
6
29
|
var import_client = require("@jsondb-cloud/client");
|
|
30
|
+
var import_node_http = __toESM(require("http"));
|
|
7
31
|
|
|
8
32
|
// src/tools/documents.ts
|
|
9
33
|
var import_zod = require("zod");
|
|
@@ -1177,6 +1201,171 @@ function registerWebhookTools(server, _db) {
|
|
|
1177
1201
|
);
|
|
1178
1202
|
}
|
|
1179
1203
|
|
|
1204
|
+
// src/tools/vectors.ts
|
|
1205
|
+
var import_zod6 = require("zod");
|
|
1206
|
+
|
|
1207
|
+
// src/tools/_helpers.ts
|
|
1208
|
+
function success6(data) {
|
|
1209
|
+
return {
|
|
1210
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
function error6(code, message, suggestion) {
|
|
1214
|
+
return {
|
|
1215
|
+
content: [
|
|
1216
|
+
{
|
|
1217
|
+
type: "text",
|
|
1218
|
+
text: JSON.stringify({ error: { code, message, suggestion } }, null, 2)
|
|
1219
|
+
}
|
|
1220
|
+
],
|
|
1221
|
+
isError: true
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
function resolveEnv3() {
|
|
1225
|
+
return {
|
|
1226
|
+
apiKey: process.env.JSONDB_API_KEY || "",
|
|
1227
|
+
project: process.env.JSONDB_PROJECT || process.env.JSONDB_NAMESPACE || "v1",
|
|
1228
|
+
baseUrl: (process.env.JSONDB_BASE_URL || "https://api.jsondb.cloud").replace(/\/$/, "")
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
async function apiFetch(url, apiKey, method = "GET", body) {
|
|
1232
|
+
const opts = {
|
|
1233
|
+
method,
|
|
1234
|
+
headers: {
|
|
1235
|
+
Authorization: `Bearer ${apiKey}`,
|
|
1236
|
+
"Content-Type": "application/json"
|
|
1237
|
+
}
|
|
1238
|
+
};
|
|
1239
|
+
if (body !== void 0 && ["POST", "PUT", "PATCH"].includes(method)) {
|
|
1240
|
+
opts.body = JSON.stringify(body);
|
|
1241
|
+
}
|
|
1242
|
+
const res = await fetch(url, opts);
|
|
1243
|
+
if (!res.ok) {
|
|
1244
|
+
const b = await res.json().catch(() => ({}));
|
|
1245
|
+
throw {
|
|
1246
|
+
status: res.status,
|
|
1247
|
+
message: b.error || res.statusText
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
if (res.status === 204) return { ok: true };
|
|
1251
|
+
return res.json();
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
// src/tools/vectors.ts
|
|
1255
|
+
function registerVectorTools(server, _db) {
|
|
1256
|
+
server.tool(
|
|
1257
|
+
"semantic_search",
|
|
1258
|
+
"Search documents using natural language semantic similarity. Returns ranked results with relevance scores. Requires documents to have been stored with embeddings.",
|
|
1259
|
+
{
|
|
1260
|
+
collection: import_zod6.z.string().describe("Collection to search in"),
|
|
1261
|
+
query: import_zod6.z.string().describe("Natural language search query"),
|
|
1262
|
+
limit: import_zod6.z.number().min(1).max(100).default(10).optional().describe("Max results to return"),
|
|
1263
|
+
threshold: import_zod6.z.number().min(0).max(1).default(0.7).optional().describe("Minimum similarity score (0-1)"),
|
|
1264
|
+
filter: import_zod6.z.record(import_zod6.z.unknown()).optional().describe("Additional filter criteria")
|
|
1265
|
+
},
|
|
1266
|
+
async ({ collection, query, limit, threshold, filter }) => {
|
|
1267
|
+
try {
|
|
1268
|
+
const { apiKey, project, baseUrl } = resolveEnv3();
|
|
1269
|
+
const body = { query };
|
|
1270
|
+
if (limit !== void 0) body.limit = limit;
|
|
1271
|
+
if (threshold !== void 0) body.threshold = threshold;
|
|
1272
|
+
if (filter !== void 0) body.filter = filter;
|
|
1273
|
+
const data = await apiFetch(
|
|
1274
|
+
`${baseUrl}/${project}/${collection}/_search`,
|
|
1275
|
+
apiKey,
|
|
1276
|
+
"POST",
|
|
1277
|
+
body
|
|
1278
|
+
);
|
|
1279
|
+
return success6(data);
|
|
1280
|
+
} catch (err) {
|
|
1281
|
+
const e = err;
|
|
1282
|
+
if (e.status === 404) {
|
|
1283
|
+
return error6(
|
|
1284
|
+
"COLLECTION_NOT_FOUND",
|
|
1285
|
+
`Collection '${collection}' not found or has no embeddings.`,
|
|
1286
|
+
`Ensure the collection exists and documents were stored with store_with_embedding. Use list_collections to see available collections.`
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
if (e.status === 400) {
|
|
1290
|
+
return error6(
|
|
1291
|
+
"INVALID_SEARCH",
|
|
1292
|
+
e.message || `Invalid search request for collection '${collection}'.`,
|
|
1293
|
+
`Check that the query is a non-empty string and threshold is between 0 and 1.`
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1296
|
+
if (e.status === 403) {
|
|
1297
|
+
return error6(
|
|
1298
|
+
"SEARCH_NOT_AVAILABLE",
|
|
1299
|
+
e.message || "Semantic search is not available on your current plan.",
|
|
1300
|
+
`Upgrade your plan at https://jsondb.cloud/dashboard/billing to enable vector search.`
|
|
1301
|
+
);
|
|
1302
|
+
}
|
|
1303
|
+
return error6(
|
|
1304
|
+
"SEARCH_FAILED",
|
|
1305
|
+
e.message || `Failed to search collection '${collection}'.`,
|
|
1306
|
+
`Verify the collection name and that documents have been stored with embeddings.`
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
);
|
|
1311
|
+
server.tool(
|
|
1312
|
+
"store_with_embedding",
|
|
1313
|
+
"Store a document and automatically generate a vector embedding for semantic search. The embed_field specifies which field's text content should be embedded.",
|
|
1314
|
+
{
|
|
1315
|
+
collection: import_zod6.z.string().describe("Collection to store in"),
|
|
1316
|
+
data: import_zod6.z.record(import_zod6.z.unknown()).describe("Document data to store"),
|
|
1317
|
+
embed_field: import_zod6.z.string().describe("Field name whose content will be embedded for search"),
|
|
1318
|
+
id: import_zod6.z.string().optional().describe("Optional custom document ID")
|
|
1319
|
+
},
|
|
1320
|
+
async ({ collection, data, embed_field, id }) => {
|
|
1321
|
+
try {
|
|
1322
|
+
const { apiKey, project, baseUrl } = resolveEnv3();
|
|
1323
|
+
const payload = { ...data, $embed: embed_field };
|
|
1324
|
+
let result;
|
|
1325
|
+
if (id) {
|
|
1326
|
+
result = await apiFetch(
|
|
1327
|
+
`${baseUrl}/${project}/${collection}/${id}`,
|
|
1328
|
+
apiKey,
|
|
1329
|
+
"PUT",
|
|
1330
|
+
payload
|
|
1331
|
+
);
|
|
1332
|
+
} else {
|
|
1333
|
+
result = await apiFetch(`${baseUrl}/${project}/${collection}`, apiKey, "POST", payload);
|
|
1334
|
+
}
|
|
1335
|
+
return success6(result);
|
|
1336
|
+
} catch (err) {
|
|
1337
|
+
const e = err;
|
|
1338
|
+
if (e.status === 400) {
|
|
1339
|
+
return error6(
|
|
1340
|
+
"VALIDATION_ERROR",
|
|
1341
|
+
e.message || `The document failed validation for collection '${collection}'.`,
|
|
1342
|
+
`Ensure the embed_field '${embed_field}' exists in your data and contains text content suitable for embedding.`
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1345
|
+
if (e.status === 413) {
|
|
1346
|
+
return error6(
|
|
1347
|
+
"DOCUMENT_TOO_LARGE",
|
|
1348
|
+
`The document exceeds the maximum allowed size.`,
|
|
1349
|
+
`Reduce the document size. Free plans allow up to 16 KB per document, Pro plans allow up to 1 MB.`
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1352
|
+
if (e.status === 403) {
|
|
1353
|
+
return error6(
|
|
1354
|
+
"EMBEDDING_NOT_AVAILABLE",
|
|
1355
|
+
e.message || "Embedding generation is not available on your current plan.",
|
|
1356
|
+
`Upgrade your plan at https://jsondb.cloud/dashboard/billing to enable automatic embeddings.`
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
return error6(
|
|
1360
|
+
"STORE_EMBEDDING_FAILED",
|
|
1361
|
+
e.message || `Failed to store document with embedding in collection '${collection}'.`,
|
|
1362
|
+
`Check that the collection name is valid, the data is a valid JSON object, and the embed_field references an existing text field.`
|
|
1363
|
+
);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1180
1369
|
// src/resources/collections.ts
|
|
1181
1370
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
1182
1371
|
function registerCollectionResources(server, db) {
|
|
@@ -1304,18 +1493,53 @@ async function main() {
|
|
|
1304
1493
|
project,
|
|
1305
1494
|
baseUrl
|
|
1306
1495
|
});
|
|
1307
|
-
|
|
1308
|
-
name: "jsondb-cloud",
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1496
|
+
function createServer() {
|
|
1497
|
+
const s = new import_mcp2.McpServer({ name: "jsondb-cloud", version: "1.0.0" });
|
|
1498
|
+
registerDocumentTools(s, db);
|
|
1499
|
+
registerCollectionTools(s, db);
|
|
1500
|
+
registerSchemaTools(s, db);
|
|
1501
|
+
registerVersionTools(s, db);
|
|
1502
|
+
registerWebhookTools(s, db);
|
|
1503
|
+
registerVectorTools(s, db);
|
|
1504
|
+
registerCollectionResources(s, db);
|
|
1505
|
+
return s;
|
|
1506
|
+
}
|
|
1507
|
+
const transportType = process.env.JSONDB_MCP_TRANSPORT || "stdio";
|
|
1508
|
+
if (transportType === "http") {
|
|
1509
|
+
const port = parseInt(process.env.JSONDB_MCP_PORT || "3100", 10);
|
|
1510
|
+
const host = process.env.JSONDB_MCP_HOST || "127.0.0.1";
|
|
1511
|
+
const httpServer = import_node_http.default.createServer(async (req, res) => {
|
|
1512
|
+
if (req.method === "GET" && req.url === "/health") {
|
|
1513
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1514
|
+
res.end(JSON.stringify({ status: "ok" }));
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
if (req.url === "/mcp") {
|
|
1518
|
+
const server = createServer();
|
|
1519
|
+
const transport = new import_streamableHttp.StreamableHTTPServerTransport({
|
|
1520
|
+
sessionIdGenerator: void 0
|
|
1521
|
+
});
|
|
1522
|
+
res.on("close", () => {
|
|
1523
|
+
transport.close().catch(() => {
|
|
1524
|
+
});
|
|
1525
|
+
server.close().catch(() => {
|
|
1526
|
+
});
|
|
1527
|
+
});
|
|
1528
|
+
await server.connect(transport);
|
|
1529
|
+
await transport.handleRequest(req, res);
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
1533
|
+
res.end(JSON.stringify({ error: "Not found" }));
|
|
1534
|
+
});
|
|
1535
|
+
httpServer.listen(port, host, () => {
|
|
1536
|
+
console.error(`MCP HTTP server listening on ${host}:${port}`);
|
|
1537
|
+
});
|
|
1538
|
+
} else {
|
|
1539
|
+
const server = createServer();
|
|
1540
|
+
const transport = new import_stdio.StdioServerTransport();
|
|
1541
|
+
await server.connect(transport);
|
|
1542
|
+
}
|
|
1319
1543
|
}
|
|
1320
1544
|
main().catch((err) => {
|
|
1321
1545
|
console.error("Fatal error starting MCP server:", err);
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { McpServer as McpServer2 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
4
5
|
import { JsonDB } from "@jsondb-cloud/client";
|
|
6
|
+
import http from "http";
|
|
5
7
|
|
|
6
8
|
// src/tools/documents.ts
|
|
7
9
|
import { z } from "zod";
|
|
@@ -1175,6 +1177,171 @@ function registerWebhookTools(server, _db) {
|
|
|
1175
1177
|
);
|
|
1176
1178
|
}
|
|
1177
1179
|
|
|
1180
|
+
// src/tools/vectors.ts
|
|
1181
|
+
import { z as z6 } from "zod";
|
|
1182
|
+
|
|
1183
|
+
// src/tools/_helpers.ts
|
|
1184
|
+
function success6(data) {
|
|
1185
|
+
return {
|
|
1186
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
function error6(code, message, suggestion) {
|
|
1190
|
+
return {
|
|
1191
|
+
content: [
|
|
1192
|
+
{
|
|
1193
|
+
type: "text",
|
|
1194
|
+
text: JSON.stringify({ error: { code, message, suggestion } }, null, 2)
|
|
1195
|
+
}
|
|
1196
|
+
],
|
|
1197
|
+
isError: true
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
function resolveEnv3() {
|
|
1201
|
+
return {
|
|
1202
|
+
apiKey: process.env.JSONDB_API_KEY || "",
|
|
1203
|
+
project: process.env.JSONDB_PROJECT || process.env.JSONDB_NAMESPACE || "v1",
|
|
1204
|
+
baseUrl: (process.env.JSONDB_BASE_URL || "https://api.jsondb.cloud").replace(/\/$/, "")
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
async function apiFetch(url, apiKey, method = "GET", body) {
|
|
1208
|
+
const opts = {
|
|
1209
|
+
method,
|
|
1210
|
+
headers: {
|
|
1211
|
+
Authorization: `Bearer ${apiKey}`,
|
|
1212
|
+
"Content-Type": "application/json"
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
if (body !== void 0 && ["POST", "PUT", "PATCH"].includes(method)) {
|
|
1216
|
+
opts.body = JSON.stringify(body);
|
|
1217
|
+
}
|
|
1218
|
+
const res = await fetch(url, opts);
|
|
1219
|
+
if (!res.ok) {
|
|
1220
|
+
const b = await res.json().catch(() => ({}));
|
|
1221
|
+
throw {
|
|
1222
|
+
status: res.status,
|
|
1223
|
+
message: b.error || res.statusText
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
if (res.status === 204) return { ok: true };
|
|
1227
|
+
return res.json();
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
// src/tools/vectors.ts
|
|
1231
|
+
function registerVectorTools(server, _db) {
|
|
1232
|
+
server.tool(
|
|
1233
|
+
"semantic_search",
|
|
1234
|
+
"Search documents using natural language semantic similarity. Returns ranked results with relevance scores. Requires documents to have been stored with embeddings.",
|
|
1235
|
+
{
|
|
1236
|
+
collection: z6.string().describe("Collection to search in"),
|
|
1237
|
+
query: z6.string().describe("Natural language search query"),
|
|
1238
|
+
limit: z6.number().min(1).max(100).default(10).optional().describe("Max results to return"),
|
|
1239
|
+
threshold: z6.number().min(0).max(1).default(0.7).optional().describe("Minimum similarity score (0-1)"),
|
|
1240
|
+
filter: z6.record(z6.unknown()).optional().describe("Additional filter criteria")
|
|
1241
|
+
},
|
|
1242
|
+
async ({ collection, query, limit, threshold, filter }) => {
|
|
1243
|
+
try {
|
|
1244
|
+
const { apiKey, project, baseUrl } = resolveEnv3();
|
|
1245
|
+
const body = { query };
|
|
1246
|
+
if (limit !== void 0) body.limit = limit;
|
|
1247
|
+
if (threshold !== void 0) body.threshold = threshold;
|
|
1248
|
+
if (filter !== void 0) body.filter = filter;
|
|
1249
|
+
const data = await apiFetch(
|
|
1250
|
+
`${baseUrl}/${project}/${collection}/_search`,
|
|
1251
|
+
apiKey,
|
|
1252
|
+
"POST",
|
|
1253
|
+
body
|
|
1254
|
+
);
|
|
1255
|
+
return success6(data);
|
|
1256
|
+
} catch (err) {
|
|
1257
|
+
const e = err;
|
|
1258
|
+
if (e.status === 404) {
|
|
1259
|
+
return error6(
|
|
1260
|
+
"COLLECTION_NOT_FOUND",
|
|
1261
|
+
`Collection '${collection}' not found or has no embeddings.`,
|
|
1262
|
+
`Ensure the collection exists and documents were stored with store_with_embedding. Use list_collections to see available collections.`
|
|
1263
|
+
);
|
|
1264
|
+
}
|
|
1265
|
+
if (e.status === 400) {
|
|
1266
|
+
return error6(
|
|
1267
|
+
"INVALID_SEARCH",
|
|
1268
|
+
e.message || `Invalid search request for collection '${collection}'.`,
|
|
1269
|
+
`Check that the query is a non-empty string and threshold is between 0 and 1.`
|
|
1270
|
+
);
|
|
1271
|
+
}
|
|
1272
|
+
if (e.status === 403) {
|
|
1273
|
+
return error6(
|
|
1274
|
+
"SEARCH_NOT_AVAILABLE",
|
|
1275
|
+
e.message || "Semantic search is not available on your current plan.",
|
|
1276
|
+
`Upgrade your plan at https://jsondb.cloud/dashboard/billing to enable vector search.`
|
|
1277
|
+
);
|
|
1278
|
+
}
|
|
1279
|
+
return error6(
|
|
1280
|
+
"SEARCH_FAILED",
|
|
1281
|
+
e.message || `Failed to search collection '${collection}'.`,
|
|
1282
|
+
`Verify the collection name and that documents have been stored with embeddings.`
|
|
1283
|
+
);
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
);
|
|
1287
|
+
server.tool(
|
|
1288
|
+
"store_with_embedding",
|
|
1289
|
+
"Store a document and automatically generate a vector embedding for semantic search. The embed_field specifies which field's text content should be embedded.",
|
|
1290
|
+
{
|
|
1291
|
+
collection: z6.string().describe("Collection to store in"),
|
|
1292
|
+
data: z6.record(z6.unknown()).describe("Document data to store"),
|
|
1293
|
+
embed_field: z6.string().describe("Field name whose content will be embedded for search"),
|
|
1294
|
+
id: z6.string().optional().describe("Optional custom document ID")
|
|
1295
|
+
},
|
|
1296
|
+
async ({ collection, data, embed_field, id }) => {
|
|
1297
|
+
try {
|
|
1298
|
+
const { apiKey, project, baseUrl } = resolveEnv3();
|
|
1299
|
+
const payload = { ...data, $embed: embed_field };
|
|
1300
|
+
let result;
|
|
1301
|
+
if (id) {
|
|
1302
|
+
result = await apiFetch(
|
|
1303
|
+
`${baseUrl}/${project}/${collection}/${id}`,
|
|
1304
|
+
apiKey,
|
|
1305
|
+
"PUT",
|
|
1306
|
+
payload
|
|
1307
|
+
);
|
|
1308
|
+
} else {
|
|
1309
|
+
result = await apiFetch(`${baseUrl}/${project}/${collection}`, apiKey, "POST", payload);
|
|
1310
|
+
}
|
|
1311
|
+
return success6(result);
|
|
1312
|
+
} catch (err) {
|
|
1313
|
+
const e = err;
|
|
1314
|
+
if (e.status === 400) {
|
|
1315
|
+
return error6(
|
|
1316
|
+
"VALIDATION_ERROR",
|
|
1317
|
+
e.message || `The document failed validation for collection '${collection}'.`,
|
|
1318
|
+
`Ensure the embed_field '${embed_field}' exists in your data and contains text content suitable for embedding.`
|
|
1319
|
+
);
|
|
1320
|
+
}
|
|
1321
|
+
if (e.status === 413) {
|
|
1322
|
+
return error6(
|
|
1323
|
+
"DOCUMENT_TOO_LARGE",
|
|
1324
|
+
`The document exceeds the maximum allowed size.`,
|
|
1325
|
+
`Reduce the document size. Free plans allow up to 16 KB per document, Pro plans allow up to 1 MB.`
|
|
1326
|
+
);
|
|
1327
|
+
}
|
|
1328
|
+
if (e.status === 403) {
|
|
1329
|
+
return error6(
|
|
1330
|
+
"EMBEDDING_NOT_AVAILABLE",
|
|
1331
|
+
e.message || "Embedding generation is not available on your current plan.",
|
|
1332
|
+
`Upgrade your plan at https://jsondb.cloud/dashboard/billing to enable automatic embeddings.`
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
return error6(
|
|
1336
|
+
"STORE_EMBEDDING_FAILED",
|
|
1337
|
+
e.message || `Failed to store document with embedding in collection '${collection}'.`,
|
|
1338
|
+
`Check that the collection name is valid, the data is a valid JSON object, and the embed_field references an existing text field.`
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1178
1345
|
// src/resources/collections.ts
|
|
1179
1346
|
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
1180
1347
|
function registerCollectionResources(server, db) {
|
|
@@ -1302,18 +1469,53 @@ async function main() {
|
|
|
1302
1469
|
project,
|
|
1303
1470
|
baseUrl
|
|
1304
1471
|
});
|
|
1305
|
-
|
|
1306
|
-
name: "jsondb-cloud",
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1472
|
+
function createServer() {
|
|
1473
|
+
const s = new McpServer2({ name: "jsondb-cloud", version: "1.0.0" });
|
|
1474
|
+
registerDocumentTools(s, db);
|
|
1475
|
+
registerCollectionTools(s, db);
|
|
1476
|
+
registerSchemaTools(s, db);
|
|
1477
|
+
registerVersionTools(s, db);
|
|
1478
|
+
registerWebhookTools(s, db);
|
|
1479
|
+
registerVectorTools(s, db);
|
|
1480
|
+
registerCollectionResources(s, db);
|
|
1481
|
+
return s;
|
|
1482
|
+
}
|
|
1483
|
+
const transportType = process.env.JSONDB_MCP_TRANSPORT || "stdio";
|
|
1484
|
+
if (transportType === "http") {
|
|
1485
|
+
const port = parseInt(process.env.JSONDB_MCP_PORT || "3100", 10);
|
|
1486
|
+
const host = process.env.JSONDB_MCP_HOST || "127.0.0.1";
|
|
1487
|
+
const httpServer = http.createServer(async (req, res) => {
|
|
1488
|
+
if (req.method === "GET" && req.url === "/health") {
|
|
1489
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1490
|
+
res.end(JSON.stringify({ status: "ok" }));
|
|
1491
|
+
return;
|
|
1492
|
+
}
|
|
1493
|
+
if (req.url === "/mcp") {
|
|
1494
|
+
const server = createServer();
|
|
1495
|
+
const transport = new StreamableHTTPServerTransport({
|
|
1496
|
+
sessionIdGenerator: void 0
|
|
1497
|
+
});
|
|
1498
|
+
res.on("close", () => {
|
|
1499
|
+
transport.close().catch(() => {
|
|
1500
|
+
});
|
|
1501
|
+
server.close().catch(() => {
|
|
1502
|
+
});
|
|
1503
|
+
});
|
|
1504
|
+
await server.connect(transport);
|
|
1505
|
+
await transport.handleRequest(req, res);
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
1509
|
+
res.end(JSON.stringify({ error: "Not found" }));
|
|
1510
|
+
});
|
|
1511
|
+
httpServer.listen(port, host, () => {
|
|
1512
|
+
console.error(`MCP HTTP server listening on ${host}:${port}`);
|
|
1513
|
+
});
|
|
1514
|
+
} else {
|
|
1515
|
+
const server = createServer();
|
|
1516
|
+
const transport = new StdioServerTransport();
|
|
1517
|
+
await server.connect(transport);
|
|
1518
|
+
}
|
|
1317
1519
|
}
|
|
1318
1520
|
main().catch((err) => {
|
|
1319
1521
|
console.error("Fatal error starting MCP server:", err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsondb-cloud/mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"description": "MCP (Model Context Protocol) server for jsondb.cloud — lets AI agents interact with your JSON database",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"prepare": "husky"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@jsondb-cloud/client": "
|
|
30
|
+
"@jsondb-cloud/client": "^1.0.18",
|
|
31
31
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
32
32
|
"zod": "^3.23.0"
|
|
33
33
|
},
|