@infino-ai/mcp-server 0.3.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/README.md +3 -3
- package/dist/index.js +104 -47
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -243,9 +243,9 @@ The model must match what produced the stored vectors — a mismatch yields mean
|
|
|
243
243
|
|
|
244
244
|
| Tool | Arguments | What it does |
|
|
245
245
|
| --- | --- | --- |
|
|
246
|
-
| `infino_semantic_search` | `table`, `query`, `k`, `column?`, `vectorColumn?`, `filter?` | Find passages by **meaning** — embeds the query with a local model (no key) and ranks by vector similarity. Handles paraphrase and synonyms. Optional `filter` (`{column, query, mode?}`) restricts the ranking to rows whose keyword column matches first (a pushdown pre-filter). |
|
|
247
|
-
| `infino_keyword_search` | `table`, `query`, `k`, `column?` | BM25 full-text search — for exact terms, identifiers, error codes, product names. |
|
|
248
|
-
| `infino_hybrid_search` | `table`, `query`, `k`, `column?`, `vectorColumn?` | **Fused** keyword + semantic search in one ranking pass — BM25 over the text column combined with vector similarity, so rows matching the literal terms *and* the meaning rank highest. |
|
|
246
|
+
| `infino_semantic_search` | `table`, `query`, `k`, `column?`, `vectorColumn?`, `columns?`, `filter?` | Find passages by **meaning** — embeds the query with a local model (no key) and ranks by vector similarity. Handles paraphrase and synonyms. Optional `filter` (`{column, query, mode?}`) restricts the ranking to rows whose keyword column matches first (a pushdown pre-filter). Optional `columns` chooses which fields each hit returns (e.g. a path + line range to cite); defaults to the text column, with `_id` and `score` always included. |
|
|
247
|
+
| `infino_keyword_search` | `table`, `query`, `k`, `column?`, `columns?` | BM25 full-text search — for exact terms, identifiers, error codes, product names. |
|
|
248
|
+
| `infino_hybrid_search` | `table`, `query`, `k`, `column?`, `vectorColumn?`, `columns?` | **Fused** keyword + semantic search in one ranking pass — BM25 over the text column combined with vector similarity, so rows matching the literal terms *and* the meaning rank highest. |
|
|
249
249
|
| `infino_token_match` | `table`, `query`, `column?`, `mode?`, `limit?` | Unranked keyword filter — the set of rows whose text column contains the token(s). Use when you need the matches, not a relevance order. |
|
|
250
250
|
| `infino_exact_match` | `table`, `value`, `column?`, `limit?` | Unranked exact-equality filter over an indexed column (tag, status, id string). |
|
|
251
251
|
| `infino_count` | `table`, `query`, `column?`, `mode?` | Count how many rows match a keyword query, without fetching them — a fast tally over the text column. For the matching rows use `infino_keyword_search` or `infino_token_match`. |
|
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
|
}
|
|
@@ -203,6 +225,15 @@ server.registerTool("infino_describe_table", {
|
|
|
203
225
|
return fail(`describe_table failed: ${err.message}`);
|
|
204
226
|
}
|
|
205
227
|
});
|
|
228
|
+
// Build the returned-column projection for a search hit. A caller-supplied
|
|
229
|
+
// `columns` list is honored so clients can retrieve the fields they need
|
|
230
|
+
// (e.g. a path + line range to cite), with `_id` and `score` always appended
|
|
231
|
+
// so every hit keeps its id and ranking score. Defaults to the (searched)
|
|
232
|
+
// text column plus `_id`/`score`.
|
|
233
|
+
function searchProjection(columns, textCol) {
|
|
234
|
+
const base = columns && columns.length > 0 ? columns : textCol ? [textCol] : [];
|
|
235
|
+
return [...new Set([...base, "_id", "score"])];
|
|
236
|
+
}
|
|
206
237
|
server.registerTool("infino_semantic_search", {
|
|
207
238
|
title: "Semantic (vector) search",
|
|
208
239
|
description: "Use when searching for a concept by meaning and the exact wording is unknown — this retrieves paraphrases and " +
|
|
@@ -217,6 +248,10 @@ server.registerTool("infino_semantic_search", {
|
|
|
217
248
|
k: z.number().int().positive().max(100).default(10).describe("Maximum results."),
|
|
218
249
|
column: z.string().optional().describe("Text column to return with each hit; inferred if omitted."),
|
|
219
250
|
vectorColumn: z.string().optional().describe("Vector column to search; inferred if omitted."),
|
|
251
|
+
columns: z
|
|
252
|
+
.array(z.string())
|
|
253
|
+
.optional()
|
|
254
|
+
.describe("Columns to return with each hit (e.g. an id, path, or line range to cite). Defaults to the text column; '_id' and 'score' are always included."),
|
|
220
255
|
filter: z
|
|
221
256
|
.object({
|
|
222
257
|
column: z.string().describe("Keyword-indexed (FTS) column the predicate applies to."),
|
|
@@ -229,7 +264,7 @@ server.registerTool("infino_semantic_search", {
|
|
|
229
264
|
.optional()
|
|
230
265
|
.describe("Pre-filter: rank the kNN only among rows whose FTS 'column' matches 'query' (a pushdown pre-filter, not a post-filter on the results)."),
|
|
231
266
|
},
|
|
232
|
-
}, async ({ table, query, k, column, vectorColumn, filter }) => {
|
|
267
|
+
}, async ({ table, query, k, column, vectorColumn, columns, filter }) => {
|
|
233
268
|
try {
|
|
234
269
|
const handle = db.openTable(table);
|
|
235
270
|
const vecCol = vectorColumn ?? inferVectorColumn(handle);
|
|
@@ -237,9 +272,9 @@ server.registerTool("infino_semantic_search", {
|
|
|
237
272
|
return fail(`semantic_search: no vector column in '${table}' — pass 'vectorColumn'.`);
|
|
238
273
|
const textCol = column ?? inferTextColumn(handle);
|
|
239
274
|
const vector = await embed(query);
|
|
240
|
-
const projection =
|
|
241
|
-
const results = handle.vectorSearch(vecCol, vector, k, { projection, filter });
|
|
242
|
-
return ok({ table, query, results });
|
|
275
|
+
const projection = searchProjection(columns, textCol);
|
|
276
|
+
const { value: results, tookMs } = timed(() => handle.vectorSearch(vecCol, vector, k, { projection, filter }));
|
|
277
|
+
return ok({ table, query, results, took_ms: tookMs });
|
|
243
278
|
}
|
|
244
279
|
catch (err) {
|
|
245
280
|
return fail(`semantic_search failed: ${err.message}`);
|
|
@@ -260,16 +295,20 @@ server.registerTool("infino_keyword_search", {
|
|
|
260
295
|
.string()
|
|
261
296
|
.optional()
|
|
262
297
|
.describe("Text column to search; inferred from the table schema when omitted."),
|
|
298
|
+
columns: z
|
|
299
|
+
.array(z.string())
|
|
300
|
+
.optional()
|
|
301
|
+
.describe("Columns to return with each hit (e.g. an id, path, or line range to cite). Defaults to the searched column; '_id' and 'score' are always included."),
|
|
263
302
|
},
|
|
264
|
-
}, async ({ table, query, k, column }) => {
|
|
303
|
+
}, async ({ table, query, k, column, columns }) => {
|
|
265
304
|
try {
|
|
266
305
|
const handle = db.openTable(table);
|
|
267
306
|
const col = column ?? inferTextColumn(handle);
|
|
268
307
|
if (!col) {
|
|
269
308
|
return fail(`keyword_search: no text column found in '${table}' — pass 'column' explicitly.`);
|
|
270
309
|
}
|
|
271
|
-
const results = handle.bm25Search(col, query, k, { projection:
|
|
272
|
-
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 });
|
|
273
312
|
}
|
|
274
313
|
catch (err) {
|
|
275
314
|
return fail(`keyword_search failed: ${err.message}`);
|
|
@@ -287,8 +326,12 @@ server.registerTool("infino_hybrid_search", {
|
|
|
287
326
|
k: z.number().int().positive().max(100).default(10).describe("Maximum results."),
|
|
288
327
|
column: z.string().optional().describe("Text column for the keyword half; inferred if omitted."),
|
|
289
328
|
vectorColumn: z.string().optional().describe("Vector column for the semantic half; inferred if omitted."),
|
|
329
|
+
columns: z
|
|
330
|
+
.array(z.string())
|
|
331
|
+
.optional()
|
|
332
|
+
.describe("Columns to return with each hit (e.g. an id, path, or line range to cite). Defaults to the text column; '_id' and 'score' are always included."),
|
|
290
333
|
},
|
|
291
|
-
}, async ({ table, query, k, column, vectorColumn }) => {
|
|
334
|
+
}, async ({ table, query, k, column, vectorColumn, columns }) => {
|
|
292
335
|
try {
|
|
293
336
|
const handle = db.openTable(table);
|
|
294
337
|
const textCol = column ?? inferTextColumn(handle);
|
|
@@ -298,10 +341,10 @@ server.registerTool("infino_hybrid_search", {
|
|
|
298
341
|
if (!vecCol)
|
|
299
342
|
return fail(`hybrid_search: no vector column in '${table}' — pass 'vectorColumn'.`);
|
|
300
343
|
const vector = await embed(query);
|
|
301
|
-
const results = handle.hybridSearch(textCol, query, vecCol, vector, k, {
|
|
302
|
-
projection:
|
|
303
|
-
});
|
|
304
|
-
return ok({ table, query, results });
|
|
344
|
+
const { value: results, tookMs } = timed(() => handle.hybridSearch(textCol, query, vecCol, vector, k, {
|
|
345
|
+
projection: searchProjection(columns, textCol),
|
|
346
|
+
}));
|
|
347
|
+
return ok({ table, query, results, took_ms: tookMs });
|
|
305
348
|
}
|
|
306
349
|
catch (err) {
|
|
307
350
|
return fail(`hybrid_search failed: ${err.message}`);
|
|
@@ -334,8 +377,8 @@ server.registerTool("infino_token_match", {
|
|
|
334
377
|
const col = column ?? inferTextColumn(handle);
|
|
335
378
|
if (!col)
|
|
336
379
|
return fail(`token_match: no text column in '${table}' — pass 'column'.`);
|
|
337
|
-
const rows = handle.tokenMatch(col, query, { mode, projection: [col, "_id"] });
|
|
338
|
-
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 });
|
|
339
382
|
}
|
|
340
383
|
catch (err) {
|
|
341
384
|
return fail(`token_match failed: ${err.message}`);
|
|
@@ -364,8 +407,8 @@ server.registerTool("infino_exact_match", {
|
|
|
364
407
|
const col = column ?? inferTextColumn(handle);
|
|
365
408
|
if (!col)
|
|
366
409
|
return fail(`exact_match: no column found in '${table}' — pass 'column'.`);
|
|
367
|
-
const rows = handle.exactMatch(col, value, { projection: [col, "_id"] });
|
|
368
|
-
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 });
|
|
369
412
|
}
|
|
370
413
|
catch (err) {
|
|
371
414
|
return fail(`exact_match failed: ${err.message}`);
|
|
@@ -395,8 +438,8 @@ server.registerTool("infino_count", {
|
|
|
395
438
|
if (!col) {
|
|
396
439
|
return fail(`count: no text column found in '${table}' — pass 'column' explicitly.`);
|
|
397
440
|
}
|
|
398
|
-
const count = handle.count(col, query, { mode });
|
|
399
|
-
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 });
|
|
400
443
|
}
|
|
401
444
|
catch (err) {
|
|
402
445
|
return fail(`count failed: ${err.message}`);
|
|
@@ -404,21 +447,35 @@ server.registerTool("infino_count", {
|
|
|
404
447
|
});
|
|
405
448
|
server.registerTool("infino_sql", {
|
|
406
449
|
title: "SQL over Infino",
|
|
407
|
-
description: "Use for structural or analytical questions — counts, GROUP BY, joins, aggregates, filtering by
|
|
408
|
-
"
|
|
409
|
-
"
|
|
410
|
-
"
|
|
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. " +
|
|
411
458
|
(writesEnabled
|
|
412
459
|
? "Any single statement is allowed (including DDL/DML), since INFINO_MCP_ENABLE_WRITES is set."
|
|
413
460
|
: "Read-only: a single SELECT / WITH statement; DDL/DML is rejected."),
|
|
414
461
|
inputSchema: {
|
|
415
462
|
query: writesEnabled
|
|
416
|
-
? z.string().describe("A single SQL statement.")
|
|
417
|
-
: 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}}.'),
|
|
418
473
|
},
|
|
419
|
-
}, async ({ query }) => {
|
|
474
|
+
}, async ({ query, embed: embeds }) => {
|
|
420
475
|
try {
|
|
421
|
-
|
|
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 });
|
|
422
479
|
}
|
|
423
480
|
catch (err) {
|
|
424
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",
|