@infino-ai/mcp-server 0.4.0 → 0.6.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.
- package/dist/index.js +78 -42
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -97,6 +97,41 @@ const writesEnabled = ["1", "true", "yes"].includes((process.env.INFINO_MCP_ENAB
|
|
|
97
97
|
// `_id` comes back as a bigint, which JSON can't serialize — render it as a string.
|
|
98
98
|
const toText = (value) => JSON.stringify(value, (_k, v) => (typeof v === "bigint" ? v.toString() : v), 2);
|
|
99
99
|
const ok = (value) => ({ content: [{ type: "text", text: toText(value) }] });
|
|
100
|
+
// Wall-clock of a synchronous engine call, so results can carry the true engine
|
|
101
|
+
// time (`took_ms`) — this excludes query embedding and the MCP/stdio transport,
|
|
102
|
+
// which the client can't isolate from its own round-trip timing.
|
|
103
|
+
function timed(fn) {
|
|
104
|
+
const t0 = performance.now();
|
|
105
|
+
const value = fn();
|
|
106
|
+
return { value, tookMs: Math.round((performance.now() - t0) * 1000) / 1000 };
|
|
107
|
+
}
|
|
108
|
+
const PLACEHOLDER = /\{\{\s*([A-Za-z_][A-Za-z0-9_]*)\s*\}\}/g;
|
|
109
|
+
// Substitute `{{name}}` placeholders in a SQL string with a query vector: embed
|
|
110
|
+
// each `embeds[name]` text with the server's embedder and inline it as a
|
|
111
|
+
// comma-separated float literal. This is what lets the vector_search /
|
|
112
|
+
// hybrid_search TVFs run from SQL (the engine itself never embeds). The
|
|
113
|
+
// injected values are model-generated floats, so there's no injection surface;
|
|
114
|
+
// a referenced placeholder with no supplied text is a hard error.
|
|
115
|
+
async function applyEmbeds(sql, embeds) {
|
|
116
|
+
const referenced = new Set();
|
|
117
|
+
for (const m of sql.matchAll(PLACEHOLDER))
|
|
118
|
+
referenced.add(m[1]);
|
|
119
|
+
if (referenced.size === 0)
|
|
120
|
+
return sql;
|
|
121
|
+
if (!embeds) {
|
|
122
|
+
throw new Error(`query has placeholder(s) {{${[...referenced].join("}}, {{")}}} but no 'embed' map was provided`);
|
|
123
|
+
}
|
|
124
|
+
const literals = new Map();
|
|
125
|
+
for (const name of referenced) {
|
|
126
|
+
const text = embeds[name];
|
|
127
|
+
if (typeof text !== "string" || text.length === 0) {
|
|
128
|
+
throw new Error(`no 'embed' text supplied for placeholder {{${name}}}`);
|
|
129
|
+
}
|
|
130
|
+
const vec = await embed(text);
|
|
131
|
+
literals.set(name, `'${Array.from(vec).join(",")}'`);
|
|
132
|
+
}
|
|
133
|
+
return sql.replace(PLACEHOLDER, (full, name) => literals.get(name) ?? full);
|
|
134
|
+
}
|
|
100
135
|
const fail = (message) => ({
|
|
101
136
|
content: [{ type: "text", text: message }],
|
|
102
137
|
isError: true,
|
|
@@ -123,31 +158,18 @@ async function embedRows(handle, rows) {
|
|
|
123
158
|
}
|
|
124
159
|
// Search table functions are routed to the dedicated search tools instead of
|
|
125
160
|
// infino_sql. This is now a usability policy, not a technical limit: search
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
// do work through query_sql now, but the typed retrieval tools are the
|
|
135
|
-
// intended interface (they handle embedding and projection), so free-form
|
|
136
|
-
// SQL is kept to filters/joins/aggregates and retrieval goes through them.
|
|
137
|
-
// - The read-only restriction (single statement, must start with SELECT/WITH)
|
|
138
|
-
// is policy, gated by the same INFINO_MCP_ENABLE_WRITES switch as
|
|
139
|
-
// infino_add_documents. Off → read-only only, so the default install can't
|
|
140
|
-
// write through SQL. On → any single statement (DDL/DML) is allowed, which
|
|
141
|
-
// makes the binding's querySql fully reachable.
|
|
161
|
+
// Guard for infino_sql. The engine's search TVFs (bm25_search / vector_search /
|
|
162
|
+
// hybrid_search / token_match / exact_match) ARE allowed here — they compose
|
|
163
|
+
// with GROUP BY / joins / aggregates, which is the point of exposing SQL. The
|
|
164
|
+
// vector TVFs need a query vector, which applyEmbeds() supplies from {{name}}
|
|
165
|
+
// placeholders. The one restriction is the read-only policy (single statement,
|
|
166
|
+
// must start with SELECT/WITH), gated by the same INFINO_MCP_ENABLE_WRITES
|
|
167
|
+
// switch as infino_add_documents: off → read-only, so the default install can't
|
|
168
|
+
// write through SQL; on → any single statement (DDL/DML) is allowed.
|
|
142
169
|
function guardSql(sql, allowWrites) {
|
|
143
170
|
const stripped = sql.trim().replace(/;\s*$/, "");
|
|
144
171
|
if (stripped.includes(";"))
|
|
145
172
|
throw new Error("only a single statement is allowed");
|
|
146
|
-
const tvf = SEARCH_TVFS.find((fn) => new RegExp(`\\b${fn}\\s*\\(`, "i").test(stripped));
|
|
147
|
-
if (tvf) {
|
|
148
|
-
throw new Error(`${tvf}() isn't available through infino_sql — use the dedicated retrieval tools (infino_keyword_search, ` +
|
|
149
|
-
`infino_semantic_search, infino_hybrid_search) instead. infino_sql is for filters, joins, and aggregates over your tables.`);
|
|
150
|
-
}
|
|
151
173
|
if (!allowWrites && !/^(select|with)\b/i.test(stripped)) {
|
|
152
174
|
throw new Error("only read-only SELECT / WITH queries are allowed (set INFINO_MCP_ENABLE_WRITES to permit DDL/DML through SQL)");
|
|
153
175
|
}
|
|
@@ -251,8 +273,8 @@ server.registerTool("infino_semantic_search", {
|
|
|
251
273
|
const textCol = column ?? inferTextColumn(handle);
|
|
252
274
|
const vector = await embed(query);
|
|
253
275
|
const projection = searchProjection(columns, textCol);
|
|
254
|
-
const results = handle.vectorSearch(vecCol, vector, k, { projection, filter });
|
|
255
|
-
return ok({ table, query, results });
|
|
276
|
+
const { value: results, tookMs } = timed(() => handle.vectorSearch(vecCol, vector, k, { projection, filter }));
|
|
277
|
+
return ok({ table, query, results, took_ms: tookMs });
|
|
256
278
|
}
|
|
257
279
|
catch (err) {
|
|
258
280
|
return fail(`semantic_search failed: ${err.message}`);
|
|
@@ -285,8 +307,8 @@ server.registerTool("infino_keyword_search", {
|
|
|
285
307
|
if (!col) {
|
|
286
308
|
return fail(`keyword_search: no text column found in '${table}' — pass 'column' explicitly.`);
|
|
287
309
|
}
|
|
288
|
-
const results = handle.bm25Search(col, query, k, { projection: searchProjection(columns, col) });
|
|
289
|
-
return ok({ table, column: col, query, results });
|
|
310
|
+
const { value: results, tookMs } = timed(() => handle.bm25Search(col, query, k, { projection: searchProjection(columns, col) }));
|
|
311
|
+
return ok({ table, column: col, query, results, took_ms: tookMs });
|
|
290
312
|
}
|
|
291
313
|
catch (err) {
|
|
292
314
|
return fail(`keyword_search failed: ${err.message}`);
|
|
@@ -319,10 +341,10 @@ server.registerTool("infino_hybrid_search", {
|
|
|
319
341
|
if (!vecCol)
|
|
320
342
|
return fail(`hybrid_search: no vector column in '${table}' — pass 'vectorColumn'.`);
|
|
321
343
|
const vector = await embed(query);
|
|
322
|
-
const results = handle.hybridSearch(textCol, query, vecCol, vector, k, {
|
|
344
|
+
const { value: results, tookMs } = timed(() => handle.hybridSearch(textCol, query, vecCol, vector, k, {
|
|
323
345
|
projection: searchProjection(columns, textCol),
|
|
324
|
-
});
|
|
325
|
-
return ok({ table, query, results });
|
|
346
|
+
}));
|
|
347
|
+
return ok({ table, query, results, took_ms: tookMs });
|
|
326
348
|
}
|
|
327
349
|
catch (err) {
|
|
328
350
|
return fail(`hybrid_search failed: ${err.message}`);
|
|
@@ -355,8 +377,8 @@ server.registerTool("infino_token_match", {
|
|
|
355
377
|
const col = column ?? inferTextColumn(handle);
|
|
356
378
|
if (!col)
|
|
357
379
|
return fail(`token_match: no text column in '${table}' — pass 'column'.`);
|
|
358
|
-
const rows = handle.tokenMatch(col, query, { mode, projection: [col, "_id"] });
|
|
359
|
-
return ok({ table, column: col, query, matched: rows.length, results: rows.slice(0, limit) });
|
|
380
|
+
const { value: rows, tookMs } = timed(() => handle.tokenMatch(col, query, { mode, projection: [col, "_id"] }));
|
|
381
|
+
return ok({ table, column: col, query, matched: rows.length, results: rows.slice(0, limit), took_ms: tookMs });
|
|
360
382
|
}
|
|
361
383
|
catch (err) {
|
|
362
384
|
return fail(`token_match failed: ${err.message}`);
|
|
@@ -385,8 +407,8 @@ server.registerTool("infino_exact_match", {
|
|
|
385
407
|
const col = column ?? inferTextColumn(handle);
|
|
386
408
|
if (!col)
|
|
387
409
|
return fail(`exact_match: no column found in '${table}' — pass 'column'.`);
|
|
388
|
-
const rows = handle.exactMatch(col, value, { projection: [col, "_id"] });
|
|
389
|
-
return ok({ table, column: col, value, matched: rows.length, results: rows.slice(0, limit) });
|
|
410
|
+
const { value: rows, tookMs } = timed(() => handle.exactMatch(col, value, { projection: [col, "_id"] }));
|
|
411
|
+
return ok({ table, column: col, value, matched: rows.length, results: rows.slice(0, limit), took_ms: tookMs });
|
|
390
412
|
}
|
|
391
413
|
catch (err) {
|
|
392
414
|
return fail(`exact_match failed: ${err.message}`);
|
|
@@ -416,8 +438,8 @@ server.registerTool("infino_count", {
|
|
|
416
438
|
if (!col) {
|
|
417
439
|
return fail(`count: no text column found in '${table}' — pass 'column' explicitly.`);
|
|
418
440
|
}
|
|
419
|
-
const count = handle.count(col, query, { mode });
|
|
420
|
-
return ok({ table, column: col, query, count });
|
|
441
|
+
const { value: count, tookMs } = timed(() => handle.count(col, query, { mode }));
|
|
442
|
+
return ok({ table, column: col, query, count, took_ms: tookMs });
|
|
421
443
|
}
|
|
422
444
|
catch (err) {
|
|
423
445
|
return fail(`count failed: ${err.message}`);
|
|
@@ -425,21 +447,35 @@ server.registerTool("infino_count", {
|
|
|
425
447
|
});
|
|
426
448
|
server.registerTool("infino_sql", {
|
|
427
449
|
title: "SQL over Infino",
|
|
428
|
-
description: "Use for structural or analytical questions — counts, GROUP BY, joins, aggregates, filtering by
|
|
429
|
-
"
|
|
430
|
-
"
|
|
431
|
-
"
|
|
450
|
+
description: "Use for structural or analytical questions — counts, GROUP BY, joins, aggregates, filtering by column value — " +
|
|
451
|
+
"returning result rows. The engine's search functions are callable as table-valued relations, so a single query " +
|
|
452
|
+
"can rank AND aggregate: bm25_search('table','text_col','terms', k) — also bm25_search_prefix / token_match / " +
|
|
453
|
+
"exact_match — need no embedding. vector_search('table','vec_col', {{q}}, k) and " +
|
|
454
|
+
"hybrid_search('table','text_col','terms','vec_col', {{q}}, k) need a query vector: put a {{name}} placeholder " +
|
|
455
|
+
"where the vector goes and pass embed:{\"name\":\"query text\"} — the server embeds the text and substitutes the " +
|
|
456
|
+
"vector in. Example: SELECT path, SUM(end_line - start_line + 1) AS lines FROM " +
|
|
457
|
+
"bm25_search('docs','body','error timeout', 300) GROUP BY path ORDER BY lines DESC. " +
|
|
432
458
|
(writesEnabled
|
|
433
459
|
? "Any single statement is allowed (including DDL/DML), since INFINO_MCP_ENABLE_WRITES is set."
|
|
434
460
|
: "Read-only: a single SELECT / WITH statement; DDL/DML is rejected."),
|
|
435
461
|
inputSchema: {
|
|
436
462
|
query: writesEnabled
|
|
437
|
-
? z.string().describe("A single SQL statement.")
|
|
438
|
-
: z
|
|
463
|
+
? z.string().describe("A single SQL statement. May use search TVFs and {{name}} vector placeholders.")
|
|
464
|
+
: z
|
|
465
|
+
.string()
|
|
466
|
+
.describe("A single read-only SELECT or WITH statement. May use search TVFs and {{name}} vector placeholders."),
|
|
467
|
+
embed: z
|
|
468
|
+
.record(z.string())
|
|
469
|
+
.optional()
|
|
470
|
+
.describe("Map of placeholder name -> query text. Each text is embedded with the server's embedder and its vector " +
|
|
471
|
+
"is substituted for every {{name}} in the query — required to use vector_search / hybrid_search. " +
|
|
472
|
+
'E.g. {"q":"error timeout"} fills {{q}}.'),
|
|
439
473
|
},
|
|
440
|
-
}, async ({ query }) => {
|
|
474
|
+
}, async ({ query, embed: embeds }) => {
|
|
441
475
|
try {
|
|
442
|
-
|
|
476
|
+
const sql = await applyEmbeds(query, embeds);
|
|
477
|
+
const { value: rows, tookMs } = timed(() => db.querySql(guardSql(sql, writesEnabled)));
|
|
478
|
+
return ok({ rows, took_ms: tookMs });
|
|
443
479
|
}
|
|
444
480
|
catch (err) {
|
|
445
481
|
return fail(`sql failed: ${err.message}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infino-ai/mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "MCP server for Infino — keyword, vector, hybrid, and SQL retrieval over data on object storage, for AI agents.",
|
|
5
5
|
"mcpName": "io.github.infino-ai/mcp-server",
|
|
6
6
|
"license": "Apache-2.0",
|