@infino-ai/mcp-server 0.12.0 → 0.14.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 +36 -20
- package/dist/embedding.js +56 -17
- package/dist/guards.js +64 -0
- package/dist/index.js +382 -162
- package/package.json +20 -8
package/README.md
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
[](https://registry.modelcontextprotocol.io/?search=io.github.infino-ai/mcp-server)
|
|
5
5
|
[](./LICENSE)
|
|
6
6
|
|
|
7
|
-
An [MCP](https://modelcontextprotocol.io) server for [Infino](https://github.com/infino-ai/infino) — it lets an AI agent run **keyword**, **semantic**, **hybrid**, and **SQL** retrieval over your data on object storage, from any MCP-compatible client (Claude Code, Claude Desktop, Cursor, VS Code, and others). Published on npm as [`@infino-ai/mcp-server`](https://www.npmjs.com/package/@infino-ai/mcp-server) and listed on the [official MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.infino-ai/mcp-server` (which propagates to catalogs like Smithery, Glama, and PulseMCP).
|
|
7
|
+
An [MCP](https://modelcontextprotocol.io) server for [Infino](https://github.com/infino-ai/infino) — it lets an AI agent run **keyword**, **semantic**, **hybrid**, and **SQL** retrieval over your data on object storage — the retrieval layer for RAG, persistent agent memory, and search over your own files — from any MCP-compatible client (Claude Code, Claude Desktop, Cursor, VS Code, and others). Published on npm as [`@infino-ai/mcp-server`](https://www.npmjs.com/package/@infino-ai/mcp-server) and listed on the [official MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.infino-ai/mcp-server` (which propagates to catalogs like Smithery, Glama, and PulseMCP).
|
|
8
8
|
|
|
9
9
|
- **Local embeddings, no key.** Semantic search embeds queries with a local model — nothing leaves the machine for embedding.
|
|
10
|
-
- **
|
|
10
|
+
- **The agent owns the data.** Every tool, writes included, is always available. On Infino Cloud the API key's capabilities decide what a connection may do; every tool carries MCP annotations so your client can ask before a destructive call.
|
|
11
11
|
- **Local or hosted.** Point it at a local path, your own bucket (S3, Azure, or any S3-compatible store), or a hosted Infino Cloud endpoint with an API key.
|
|
12
|
+
- **The index is a valid Parquet file.** A table stores the data and its search indexes in plain Parquet on the storage — open the same file with DuckDB or pyarrow. No export, no lock-in.
|
|
12
13
|
|
|
13
14
|
---
|
|
14
15
|
|
|
@@ -37,7 +38,7 @@ An [MCP](https://modelcontextprotocol.io) server for [Infino](https://github.com
|
|
|
37
38
|
|
|
38
39
|
## Requirements
|
|
39
40
|
|
|
40
|
-
- **Node.js ≥
|
|
41
|
+
- **Node.js ≥ 20** (the server runs as a Node process over stdio).
|
|
41
42
|
- **An MCP-compatible client** (Claude Code, Claude Desktop, Cursor, VS Code, …).
|
|
42
43
|
- **Data reachable by Infino** — a local directory, a bucket with credentials available in the environment, or a hosted Infino Cloud endpoint with an API key (see [Storage backends](#storage-backends)).
|
|
43
44
|
- On first run the server downloads the local embedding model (~90 MB) once and caches it; subsequent runs are offline for embedding.
|
|
@@ -59,8 +60,8 @@ The server is launched by your MCP client over stdio — you don't run it direct
|
|
|
59
60
|
```
|
|
60
61
|
|
|
61
62
|
To serve a **hosted Infino Cloud** database instead, point `INFINO_MCP_URI` at
|
|
62
|
-
the `https://<host>/<database>` endpoint and supply your API key
|
|
63
|
-
else
|
|
63
|
+
the `https://<host>/<database>` endpoint and supply your API key. Everything
|
|
64
|
+
else is identical:
|
|
64
65
|
|
|
65
66
|
```jsonc
|
|
66
67
|
{
|
|
@@ -86,7 +87,7 @@ For [Claude Code](https://claude.com/claude-code), this repo is also a plugin ma
|
|
|
86
87
|
/plugin install infino@infino-ai
|
|
87
88
|
```
|
|
88
89
|
|
|
89
|
-
On enable you'll be prompted for your **Infino data URI** (`INFINO_MCP_URI`) and
|
|
90
|
+
On enable you'll be prompted for your **Infino data URI** (`INFINO_MCP_URI`) and, for Infino Cloud, your **API key**. That's it: the `infino_*` tools, the `using-infino` skill, and `/infino-search <query>` are then available. (Other clients: use the [Client setup](#client-setup) configs below.)
|
|
90
91
|
|
|
91
92
|
---
|
|
92
93
|
|
|
@@ -103,7 +104,7 @@ claude mcp add infino \
|
|
|
103
104
|
-- npx -y @infino-ai/mcp-server
|
|
104
105
|
```
|
|
105
106
|
|
|
106
|
-
Add more knobs with repeated `-e` flags, e.g. `-e
|
|
107
|
+
Add more knobs with repeated `-e` flags, e.g. `-e INFINO_MCP_VALIDATE=true`. Verify with:
|
|
107
108
|
|
|
108
109
|
```sh
|
|
109
110
|
claude mcp list
|
|
@@ -195,7 +196,6 @@ All configuration is via environment variables — there are no config files and
|
|
|
195
196
|
| --- | --- | --- | --- |
|
|
196
197
|
| `INFINO_MCP_URI` | No | `~/.infino/mcp` (persistent) | Data to serve: a local path (`/Users/me/.infino/memory`), a bucket URI (`s3://…`, `az://…`), or a hosted endpoint (`https://<host>/<database>`, Infino Cloud). If unset, a durable per-user directory (`~/.infino/mcp`) is used so data persists across restarts; it falls back to an ephemeral in-process catalog (`memory://`) only if that directory can't be created. |
|
|
197
198
|
| `INFINO_API_KEY` | With a hosted URI | — | API key (`inf_…`) for a hosted `https://` endpoint. Required when `INFINO_MCP_URI` is an `https://` URI; ignored for local and object-storage connections. |
|
|
198
|
-
| `INFINO_MCP_ENABLE_WRITES` | No | _off_ | When set (`1`/`true`/`yes`), exposes `infino_add_documents` **and** lets `infino_sql` run DDL/DML. Omit for a strictly read-only server. |
|
|
199
199
|
| `INFINO_MCP_EMBED_PROVIDER` | No | `local` | Embedding provider: `local` (Hugging Face transformers.js, no key, nothing leaves the machine) or `openai` (any OpenAI-compatible `/embeddings` endpoint — OpenAI, Azure OpenAI's `/openai/v1` surface, or a compatible server). Inferred as `openai` when `INFINO_MCP_EMBED_BASE_URL` is set. |
|
|
200
200
|
| `INFINO_MCP_EMBED_BASE_URL` | With `openai` | — | Base URL of the OpenAI-compatible embeddings API, e.g. `https://api.openai.com/v1` or `https://<resource>.openai.azure.com/openai/v1`. The server POSTs to `<base>/embeddings`. |
|
|
201
201
|
| `INFINO_MCP_EMBED_API_KEY` | No | — | API key for the `openai` provider. Sent as both `Authorization: Bearer` and `api-key`, so one value works for OpenAI and Azure OpenAI. Omit to call an unauthenticated or ambient-identity endpoint. |
|
|
@@ -260,7 +260,7 @@ The model must match what produced the stored vectors — a mismatch yields mean
|
|
|
260
260
|
}
|
|
261
261
|
```
|
|
262
262
|
|
|
263
|
-
On a hosted connection the search, SQL, and
|
|
263
|
+
On a hosted connection the search, SQL, and write tools all
|
|
264
264
|
behave exactly as they do locally — the only difference is where the data
|
|
265
265
|
lives. Compaction and garbage collection are handled server-side, so they are
|
|
266
266
|
not exposed as client operations. Note that semantic and hybrid search still
|
|
@@ -276,21 +276,37 @@ the data.
|
|
|
276
276
|
| Tool | Arguments | What it does |
|
|
277
277
|
| --- | --- | --- |
|
|
278
278
|
| `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. `score` is a **distance** (lower is closer). 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. |
|
|
279
|
-
| `infino_keyword_search` | `table`, `query`, `k`, `column?`, `columns?` | BM25 full-text search — for exact terms, identifiers, error codes, product names. `score` is a relevance (higher is better). |
|
|
280
|
-
| `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. `score` is the fused rank (higher is better). |
|
|
279
|
+
| `infino_keyword_search` | `table`, `query`, `k`, `column?`, `mode?`, `stats?`, `columns?` | BM25 full-text search — for exact terms, identifiers, error codes, product names. `score` is a relevance (higher is better). `mode` is `or` (default) or `and`; `stats` is `per_superfile` (default) or `global` for one table-wide idf. |
|
|
280
|
+
| `infino_hybrid_search` | `table`, `query`, `k`, `column?`, `vectorColumn?`, `mode?`, `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. `score` is the fused rank (higher is better). |
|
|
281
281
|
| `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. |
|
|
282
282
|
| `infino_exact_match` | `table`, `value`, `column?`, `limit?` | Unranked exact-equality filter over an indexed column (tag, status, id string). |
|
|
283
283
|
| `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`. |
|
|
284
|
-
| `infino_sql` | `query` | SQL for counts, filters, joins, aggregates.
|
|
284
|
+
| `infino_sql` | `query`, `embed?` | SQL for counts, filters, joins, aggregates. The engine's search table functions are callable inside it; a `{{name}}` placeholder is filled with the vector of `embed[name]`. Any single statement, DDL/DML included. |
|
|
285
285
|
| `infino_list_tables` | — | List the tables in the connected catalog. |
|
|
286
286
|
| `infino_describe_table` | `table` | Column names and types for a table. |
|
|
287
|
-
| `
|
|
288
|
-
| `
|
|
289
|
-
| `
|
|
287
|
+
| `infino_create_database` | — | Provision the database the connection names (Infino Cloud); a no-op success locally. Idempotent. |
|
|
288
|
+
| `infino_create_table` | `table`, `columns`, `fts?`, `vector?` | Create a table from a `{column: type}` descriptor. Full-text indexes on `fts` (default: every `large_utf8` column). `vector: true` adds an `embedding` column sized to the server's embedder, with a cosine index. |
|
|
289
|
+
| `infino_drop_table` | `table`, `purge?` | Drop a table and, by default, delete its storage objects; `purge: false` only unregisters the name. |
|
|
290
|
+
| `infino_add_documents` | `table`, `documents` | Append rows (one call = one commit). Rows without a vector are embedded from the text column, all in one batch; the result reports `appended` and `embedded`. A key that is not a column is an error. |
|
|
291
|
+
| `infino_update_documents` | `table`, `predicate`, `documents` | Replace the rows matching a SQL predicate with new documents, 1:1 (missing vectors are embedded). Durable storage only. |
|
|
292
|
+
| `infino_delete_documents` | `table`, `predicate` | Delete the rows matching a SQL predicate. Durable storage only. |
|
|
290
293
|
|
|
291
294
|
Search hits return **full column values** — the `columns` argument is a projection passed straight to the engine (embedded or hosted), so any column in the table can come back with each hit: `["id"]` for compact hits at a large `k`, `["id", "text"]` for the full text alongside an id to cite, metadata columns for filtering. It defaults to the text column, with `_id` and `score` always included, and nothing is ever truncated; to keep results small, project fewer columns or ask for a smaller `k`. Every search response also carries `score_kind`, stating whether its `score` is a distance (semantic: lower is closer) or a relevance (keyword and hybrid: higher is better).
|
|
292
295
|
|
|
293
|
-
|
|
296
|
+
For plain retrieval prefer the dedicated search tools, which embed and project for you. `infino_sql` is for filters, joins, and aggregates, including over a search table function's results, so one query can rank and aggregate at once.
|
|
297
|
+
|
|
298
|
+
### Writing data
|
|
299
|
+
|
|
300
|
+
The write path an agent follows, each step one tool call and one commit:
|
|
301
|
+
|
|
302
|
+
1. `infino_create_database` if a hosted database answers 404.
|
|
303
|
+
2. `infino_create_table` with a `utf8` key column, `large_utf8` text columns, and `vector: true` for semantic search. The server sizes the vector column to its embedder; the agent never types a dimension. Keep the result: its `indexes` field is the only record of which columns are indexed.
|
|
304
|
+
3. `infino_add_documents`, tens of rows per call, always including the key. Missing vectors are embedded in one batch.
|
|
305
|
+
4. To replace rows, `infino_delete_documents` by key predicate, then add again. To remove rows, check the predicate with `infino_count` first.
|
|
306
|
+
|
|
307
|
+
A tool call carries tens of documents. For a whole corpus, use the [`infino` CLI](https://github.com/infino-ai/infino-cli) (`infino ingest` takes Parquet or NDJSON against the same URI) or an SDK. The CLI is bring-your-own-vectors like the engine, so include the `embedding` column in the rows or load text and search by keyword.
|
|
308
|
+
|
|
309
|
+
There is no server-side write gate, and the retired `INFINO_MCP_ENABLE_WRITES` variable is ignored (the server says so on stderr if it is set). On Infino Cloud the API key's capabilities bound what the connection may do: a read-scoped key is refused every write, and the tool result says to mint one with write capability. Locally, point the server only at data the agent may change.
|
|
294
310
|
|
|
295
311
|
---
|
|
296
312
|
|
|
@@ -299,9 +315,9 @@ The engine's search table functions (`bm25_search`, `vector_search`, `hybrid_sea
|
|
|
299
315
|
This server runs locally, beside the client, and keeps data and credentials on the user's machine.
|
|
300
316
|
|
|
301
317
|
- **Local execution, no inbound listener.** It runs as a subprocess of your MCP client over stdio and opens no network listener. In the default local/bucket mode it contacts no remote service. When `INFINO_MCP_URI` is a hosted `https://` endpoint, it makes **outbound** TLS calls to that endpoint to serve searches, SQL, and (if enabled) writes — so the data in those requests reaches the hosted service you configured, and nothing else.
|
|
302
|
-
- **No data sent for embedding.**
|
|
318
|
+
- **No data sent for embedding, by default.** With the default provider, query and document embedding uses a local model, so text is never sent to a third-party embedding API and there is no embedding API key to provision or leak. In hosted mode only the resulting vector, not the text, reaches the Infino Cloud endpoint. If you configure the OpenAI-compatible provider, the text being embedded is sent to the endpoint you name.
|
|
303
319
|
- **Credentials stay in the environment.** Storage credentials (`AWS_*`/`AZURE_*`) and the hosted API key (`INFINO_API_KEY`) are read from environment variables and used only to reach the store or endpoint you configured. They are never logged or returned in tool output.
|
|
304
|
-
- **
|
|
320
|
+
- **Who can write is decided outside the server.** The full toolset, writes included, is always available to the agent. On Infino Cloud the API key's capabilities bound what the connection may do (a read-scoped key is refused every write). Locally, point the server only at data the agent may change. Every tool carries MCP annotations (`readOnlyHint`, `destructiveHint`) so your client can ask for confirmation on its own terms.
|
|
305
321
|
- **Least privilege.** Point `INFINO_MCP_URI` at the narrowest dataset the task needs, and supply storage credentials scoped to that bucket/prefix.
|
|
306
322
|
|
|
307
323
|
---
|
|
@@ -320,11 +336,11 @@ If you change `INFINO_MCP_EMBED_MODEL`, the table's vector index must match the
|
|
|
320
336
|
| --- | --- |
|
|
321
337
|
| Client shows no Infino tools | Server didn't start — check the client's MCP logs (stderr). Confirm `npx` is on `PATH` and `INFINO_MCP_URI` is set. Fully restart the client after editing config. |
|
|
322
338
|
| `INFINO_MCP_URI is required` | The env var isn't reaching the subprocess. In GUI clients, env must be inside the server's `env` block (the process won't inherit your shell). |
|
|
323
|
-
|
|
|
339
|
+
| A write says the key "was rejected or lacks write capability" | On Infino Cloud the API key is read-scoped (HTTP 403) or wrong. Mint a key with write capability and restart the server with it. |
|
|
340
|
+
| A write says "another writer won the commit race" | Two writers hit the same table at once and this call did not land. Reissue it. |
|
|
324
341
|
| Slow first query | One-time embedding-model download (~90 MB). Subsequent runs use the cache. |
|
|
325
342
|
| Auth error against a hosted `https://` URI | `INFINO_API_KEY` is missing, wrong, or lacks access to that database. Confirm the key (`inf_…`) and that the URI's last path segment is a database you can reach. |
|
|
326
343
|
| Dimension / vector errors on semantic search | The table's vector index doesn't match the embedding model's dimension. Re-ingest, or set `INFINO_MCP_EMBED_MODEL` to the model the index was built with. |
|
|
327
|
-
| `… in SQL isn't supported from the server yet` | You called a search table function inside `infino_sql`. Use `infino_semantic_search` / `infino_keyword_search` instead. |
|
|
328
344
|
|
|
329
345
|
---
|
|
330
346
|
|
package/dist/embedding.js
CHANGED
|
@@ -32,10 +32,13 @@ const USE_REMOTE = PROVIDER === "openai" ||
|
|
|
32
32
|
(PROVIDER === "" && typeof BASE_URL === "string" && BASE_URL.length > 0);
|
|
33
33
|
const LOCAL_MODEL_DEFAULT = "Xenova/all-MiniLM-L6-v2";
|
|
34
34
|
const REMOTE_MODEL_DEFAULT = "text-embedding-3-small";
|
|
35
|
-
const MODEL = process.env.INFINO_MCP_EMBED_MODEL ??
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
//
|
|
35
|
+
const MODEL = process.env.INFINO_MCP_EMBED_MODEL ?? (USE_REMOTE ? REMOTE_MODEL_DEFAULT : LOCAL_MODEL_DEFAULT);
|
|
36
|
+
// Batch sizes. The local pipeline runs one forward pass per call, so a batch
|
|
37
|
+
// amortizes model overhead across texts without letting the ONNX arenas grow
|
|
38
|
+
// past what a handful of documents needs. The remote size stays well inside
|
|
39
|
+
// every OpenAI-compatible provider's per-request input limit.
|
|
40
|
+
const LOCAL_BATCH = 32;
|
|
41
|
+
const REMOTE_BATCH = 100;
|
|
39
42
|
let pipe = null;
|
|
40
43
|
function getPipe() {
|
|
41
44
|
if (!pipe) {
|
|
@@ -46,8 +49,8 @@ function getPipe() {
|
|
|
46
49
|
}
|
|
47
50
|
return pipe;
|
|
48
51
|
}
|
|
49
|
-
/** Embed
|
|
50
|
-
async function
|
|
52
|
+
/** Embed up to REMOTE_BATCH texts in one OpenAI-compatible /embeddings call. */
|
|
53
|
+
async function embedRemoteBatch(texts) {
|
|
51
54
|
if (!BASE_URL) {
|
|
52
55
|
throw new Error("INFINO_MCP_EMBED_BASE_URL is required when INFINO_MCP_EMBED_PROVIDER is 'openai'.");
|
|
53
56
|
}
|
|
@@ -62,27 +65,63 @@ async function embedRemote(text) {
|
|
|
62
65
|
const res = await fetch(url, {
|
|
63
66
|
method: "POST",
|
|
64
67
|
headers,
|
|
65
|
-
body: JSON.stringify({ model: MODEL, input:
|
|
68
|
+
body: JSON.stringify({ model: MODEL, input: texts }),
|
|
66
69
|
});
|
|
67
70
|
if (!res.ok) {
|
|
68
71
|
const detail = await res.text().catch(() => "");
|
|
69
72
|
throw new Error(`embeddings request failed: HTTP ${res.status} ${detail.slice(0, 300)}`);
|
|
70
73
|
}
|
|
71
74
|
const body = (await res.json());
|
|
72
|
-
const
|
|
73
|
-
if (!Array.isArray(
|
|
74
|
-
throw new Error(
|
|
75
|
+
const data = body?.data;
|
|
76
|
+
if (!Array.isArray(data) || data.length !== texts.length) {
|
|
77
|
+
throw new Error(`embeddings response carried ${Array.isArray(data) ? data.length : 0} vectors for ${texts.length} inputs`);
|
|
75
78
|
}
|
|
76
|
-
|
|
79
|
+
// The spec orders `data` by `index`, but a provider may not; honor the
|
|
80
|
+
// index so vectors land on the text that produced them.
|
|
81
|
+
const out = new Array(texts.length);
|
|
82
|
+
data.forEach((item, position) => {
|
|
83
|
+
const at = typeof item.index === "number" ? item.index : position;
|
|
84
|
+
if (!Array.isArray(item.embedding) || at < 0 || at >= texts.length || out[at]) {
|
|
85
|
+
throw new Error("embeddings response did not contain one embedding per input");
|
|
86
|
+
}
|
|
87
|
+
out[at] = Array.from(item.embedding, Number);
|
|
88
|
+
});
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
/** Embed up to LOCAL_BATCH texts in one forward pass of the local model. */
|
|
92
|
+
async function embedLocalBatch(texts) {
|
|
93
|
+
const extractor = await getPipe();
|
|
94
|
+
// Mean-pool token vectors and L2-normalize → one sentence embedding per text,
|
|
95
|
+
// returned as an [n, dim] tensor.
|
|
96
|
+
const output = await extractor(texts, { pooling: "mean", normalize: true });
|
|
97
|
+
const dim = output.dims[output.dims.length - 1];
|
|
98
|
+
const flat = Array.from(output.data, Number);
|
|
99
|
+
return texts.map((_, i) => flat.slice(i * dim, (i + 1) * dim));
|
|
100
|
+
}
|
|
101
|
+
/** Embed many texts with the configured provider, in batches, preserving order. */
|
|
102
|
+
export async function embedMany(texts) {
|
|
103
|
+
if (texts.length === 0)
|
|
104
|
+
return [];
|
|
105
|
+
const size = USE_REMOTE ? REMOTE_BATCH : LOCAL_BATCH;
|
|
106
|
+
const run = USE_REMOTE ? embedRemoteBatch : embedLocalBatch;
|
|
107
|
+
const out = [];
|
|
108
|
+
for (let i = 0; i < texts.length; i += size) {
|
|
109
|
+
out.push(...(await run(texts.slice(i, i + size))));
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
77
112
|
}
|
|
78
113
|
/** Embed one text into a vector with the configured provider. */
|
|
79
114
|
export async function embed(text) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
115
|
+
return (await embedMany([text]))[0];
|
|
116
|
+
}
|
|
117
|
+
// The embedder's output width, learned once by embedding a short constant
|
|
118
|
+
// string. Sizes the vector column of a table the server creates, and is
|
|
119
|
+
// compared against the vector column of any table it embeds into.
|
|
120
|
+
let dim = null;
|
|
121
|
+
export function embedderDim() {
|
|
122
|
+
if (!dim)
|
|
123
|
+
dim = embed("infino").then((v) => v.length);
|
|
124
|
+
return dim;
|
|
86
125
|
}
|
|
87
126
|
/** Human-readable description of the embedder, for the startup log. */
|
|
88
127
|
export function embedderInfo() {
|
package/dist/guards.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright The Infino Authors
|
|
3
|
+
//
|
|
4
|
+
// Pure helpers between the agent and the engine: the SQL guard, and the
|
|
5
|
+
// translation of raw engine / hosted-transport errors into messages that say
|
|
6
|
+
// what to do next. Kept free of server state so they can be unit-tested.
|
|
7
|
+
/**
|
|
8
|
+
* Translate a raw engine or hosted-transport error into an actionable
|
|
9
|
+
* message. Two sources of signal: the HTTP status a hosted connection attaches
|
|
10
|
+
* to thrown errors as `status`, and the engine's own error texts.
|
|
11
|
+
*
|
|
12
|
+
* The hosted transport folds 401 and 403 into one message with no status, so
|
|
13
|
+
* that text is matched directly. It also reports both a name collision and a
|
|
14
|
+
* lost commit race as 409, dropping the worker's `Retry-After` that tells them
|
|
15
|
+
* apart, so the 409 is read by which operation raised it: a create collided,
|
|
16
|
+
* a write lost the race and can be reissued.
|
|
17
|
+
*/
|
|
18
|
+
export function errText(err, ctx = {}) {
|
|
19
|
+
const e = err;
|
|
20
|
+
const message = e?.message ?? String(err);
|
|
21
|
+
if (/KV metadata key "inf\.fts\./.test(message)) {
|
|
22
|
+
return ("this table has no full-text index, so keyword/BM25/hybrid search is " +
|
|
23
|
+
"unavailable on it; query it with infino_sql instead, or recreate the " +
|
|
24
|
+
"table with an FTS index on the text column");
|
|
25
|
+
}
|
|
26
|
+
if (/KV metadata key "inf\.vec\./.test(message)) {
|
|
27
|
+
return ("this table has no vector index, so semantic/hybrid search is " +
|
|
28
|
+
"unavailable on it; query it with infino_sql instead, or recreate the " +
|
|
29
|
+
"table with a vector index");
|
|
30
|
+
}
|
|
31
|
+
if (e?.status === 401 || e?.status === 403 || /unauthorized \(check the API key\)/.test(message)) {
|
|
32
|
+
return ("the API key was rejected or lacks write capability for this database; " +
|
|
33
|
+
"for writes, mint a key with write capability and restart the server with it");
|
|
34
|
+
}
|
|
35
|
+
if (e?.status === 413) {
|
|
36
|
+
return "the batch is over the hosted 128 MiB request-body cap; send fewer documents per call";
|
|
37
|
+
}
|
|
38
|
+
if (e?.status === 503) {
|
|
39
|
+
return "the database is starting up (transient 503); retry in a few seconds";
|
|
40
|
+
}
|
|
41
|
+
if (e?.status === 404) {
|
|
42
|
+
return ctx.hosted
|
|
43
|
+
? `not found (404): ${message}. If the database itself is missing, call infino_create_database`
|
|
44
|
+
: `not found (404): ${message}`;
|
|
45
|
+
}
|
|
46
|
+
if (e?.status === 409) {
|
|
47
|
+
return ctx.op === "write"
|
|
48
|
+
? "another writer won the commit race on this table; nothing was written, so reissue the call"
|
|
49
|
+
: `already exists (409): ${message}`;
|
|
50
|
+
}
|
|
51
|
+
return message;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Guard for infino_sql. The engine's search table functions compose with
|
|
55
|
+
* GROUP BY / joins / aggregates, which is the point of exposing SQL, and any
|
|
56
|
+
* statement is allowed, DDL/DML included. The one restriction is one
|
|
57
|
+
* statement per call, so a result always answers exactly one query.
|
|
58
|
+
*/
|
|
59
|
+
export function guardSql(sql) {
|
|
60
|
+
const stripped = sql.trim().replace(/;\s*$/, "");
|
|
61
|
+
if (stripped.includes(";"))
|
|
62
|
+
throw new Error("only a single statement is allowed");
|
|
63
|
+
return stripped;
|
|
64
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -2,19 +2,32 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright The Infino Authors
|
|
4
4
|
//
|
|
5
|
-
// MCP server for Infino
|
|
6
|
-
// storage from any MCP client. Exposes catalog discovery
|
|
7
|
-
// keyword (BM25), semantic (local-embedding
|
|
8
|
-
// search, unranked token/exact match,
|
|
9
|
-
// (add/update/delete)
|
|
5
|
+
// MCP server for Infino. Lets an agent run retrieval and writes over data on
|
|
6
|
+
// object storage from any MCP client. Exposes catalog discovery and management
|
|
7
|
+
// (list/describe/create/drop), keyword (BM25), semantic (local-embedding
|
|
8
|
+
// vector), and hybrid (fused) search, unranked token/exact match, SQL, and
|
|
9
|
+
// document writes (add/update/delete).
|
|
10
|
+
//
|
|
11
|
+
// Scope rule: one tool per operation the `@infino-ai/infino` binding exposes,
|
|
12
|
+
// plus the one piece of glue the engine's bring-your-own-vectors model forces
|
|
13
|
+
// on an agent: turning text into a vector (see embedding.ts). Nothing else is
|
|
14
|
+
// invented here; bulk ingestion, chunking, and upsert live in the CLI, the
|
|
15
|
+
// SDKs, or the engine.
|
|
16
|
+
//
|
|
17
|
+
// The full surface is always advertised. Who may write is decided by the
|
|
18
|
+
// hosted API key's capabilities (a read-scoped key gets 403 on writes) and by
|
|
19
|
+
// whoever configured the local path or bucket credentials; how much a client
|
|
20
|
+
// confirms before a destructive call is the client's decision, driven by the
|
|
21
|
+
// tool annotations below. There is no server-side write gate.
|
|
10
22
|
import { mkdirSync } from "node:fs";
|
|
11
23
|
import { homedir } from "node:os";
|
|
12
24
|
import { join } from "node:path";
|
|
13
25
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
14
26
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
15
27
|
import { z } from "zod";
|
|
16
|
-
import { connect } from "@infino-ai/infino";
|
|
17
|
-
import { embed, embedderInfo } from "./embedding.js";
|
|
28
|
+
import { connect, IndexSpec } from "@infino-ai/infino";
|
|
29
|
+
import { embed, embedMany, embedderDim, embedderInfo } from "./embedding.js";
|
|
30
|
+
import { errText as translate, guardSql } from "./guards.js";
|
|
18
31
|
// --- connection (env-configured, opened once at startup) -------------------
|
|
19
32
|
//
|
|
20
33
|
// The agent never manages connections: the server is pointed at the data via
|
|
@@ -35,15 +48,14 @@ function defaultUri() {
|
|
|
35
48
|
const dir = join(homedir(), ".infino", "mcp");
|
|
36
49
|
try {
|
|
37
50
|
mkdirSync(dir, { recursive: true });
|
|
38
|
-
console.error(`INFINO_MCP_URI not set
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"endpoint.");
|
|
51
|
+
console.error(`INFINO_MCP_URI not set; using ${dir} (persistent). Set INFINO_MCP_URI to ` +
|
|
52
|
+
"point at your own path, an s3://|az:// bucket, or a hosted " +
|
|
53
|
+
"https://<host>/<database> endpoint.");
|
|
42
54
|
return dir;
|
|
43
55
|
}
|
|
44
56
|
catch (err) {
|
|
45
57
|
console.error(`INFINO_MCP_URI not set and ${dir} is not writable ` +
|
|
46
|
-
`(${
|
|
58
|
+
`(${translate(err)}); serving an ephemeral in-process ` +
|
|
47
59
|
"catalog (memory://).");
|
|
48
60
|
return "memory://";
|
|
49
61
|
}
|
|
@@ -119,13 +131,42 @@ try {
|
|
|
119
131
|
db = connect(uri, connectOptions);
|
|
120
132
|
}
|
|
121
133
|
catch (err) {
|
|
122
|
-
console.error(`Failed to connect to ${uri}: ${
|
|
134
|
+
console.error(`Failed to connect to ${uri}: ${translate(err, { hosted: isHosted })}`);
|
|
123
135
|
process.exit(1);
|
|
124
136
|
}
|
|
125
|
-
// Writes
|
|
126
|
-
//
|
|
127
|
-
|
|
137
|
+
// Writes used to sit behind INFINO_MCP_ENABLE_WRITES. The variable is accepted
|
|
138
|
+
// and ignored so an existing config keeps booting; it is never honored, because
|
|
139
|
+
// honoring it would reintroduce the read-only mode this server no longer has.
|
|
140
|
+
if (process.env.INFINO_MCP_ENABLE_WRITES !== undefined) {
|
|
141
|
+
console.error("INFINO_MCP_ENABLE_WRITES is set but no longer read: writes are always on. " +
|
|
142
|
+
"Remove the variable; scope the API key instead to restrict a hosted connection.");
|
|
143
|
+
}
|
|
128
144
|
// --- helpers ---------------------------------------------------------------
|
|
145
|
+
// Tool annotations, per the MCP spec: the client reads these to decide what to
|
|
146
|
+
// confirm with its user. With no server-side write gate they are the safety
|
|
147
|
+
// signal, so every tool carries one. `openWorldHint` says whether the call
|
|
148
|
+
// leaves the machine, which on a hosted connection every one of them does.
|
|
149
|
+
const READ_ONLY = {
|
|
150
|
+
readOnlyHint: true,
|
|
151
|
+
destructiveHint: false,
|
|
152
|
+
idempotentHint: true,
|
|
153
|
+
openWorldHint: isHosted,
|
|
154
|
+
};
|
|
155
|
+
// Adds data without replacing or removing any: a repeat is a duplicate, not a loss.
|
|
156
|
+
const ADDITIVE = {
|
|
157
|
+
readOnlyHint: false,
|
|
158
|
+
destructiveHint: false,
|
|
159
|
+
idempotentHint: false,
|
|
160
|
+
openWorldHint: isHosted,
|
|
161
|
+
};
|
|
162
|
+
const ADDITIVE_IDEMPOTENT = { ...ADDITIVE, idempotentHint: true };
|
|
163
|
+
// May replace or remove data.
|
|
164
|
+
const DESTRUCTIVE = {
|
|
165
|
+
readOnlyHint: false,
|
|
166
|
+
destructiveHint: true,
|
|
167
|
+
idempotentHint: false,
|
|
168
|
+
openWorldHint: isHosted,
|
|
169
|
+
};
|
|
129
170
|
// `_id` comes back as a bigint, which JSON can't serialize — render it as a string.
|
|
130
171
|
const toText = (value) => JSON.stringify(value, (_k, v) => (typeof v === "bigint" ? v.toString() : v), 2);
|
|
131
172
|
const ok = (value) => ({ content: [{ type: "text", text: toText(value) }] });
|
|
@@ -168,35 +209,9 @@ const fail = (message) => ({
|
|
|
168
209
|
content: [{ type: "text", text: message }],
|
|
169
210
|
isError: true,
|
|
170
211
|
});
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
// errors, which surface when a search needs an index the table wasn't
|
|
175
|
-
// created with.
|
|
176
|
-
function errText(err) {
|
|
177
|
-
const e = err;
|
|
178
|
-
const message = e?.message ?? String(err);
|
|
179
|
-
if (/KV metadata key "inf\.fts\./.test(message)) {
|
|
180
|
-
return ("this table has no full-text index, so keyword/BM25/hybrid search is " +
|
|
181
|
-
"unavailable on it — query it with infino_sql instead, or recreate the " +
|
|
182
|
-
"table with an FTS index on the text column");
|
|
183
|
-
}
|
|
184
|
-
if (/KV metadata key "inf\.vec\./.test(message)) {
|
|
185
|
-
return ("this table has no vector index, so semantic/hybrid search is " +
|
|
186
|
-
"unavailable on it — query it with infino_sql instead, or recreate the " +
|
|
187
|
-
"table with a vector index");
|
|
188
|
-
}
|
|
189
|
-
if (e?.status === 503) {
|
|
190
|
-
return "the database is starting up (transient 503) — retry in a few seconds";
|
|
191
|
-
}
|
|
192
|
-
if (e?.status === 404) {
|
|
193
|
-
return `not found (404): ${message}`;
|
|
194
|
-
}
|
|
195
|
-
if (e?.status === 409) {
|
|
196
|
-
return `already exists (409): ${message}`;
|
|
197
|
-
}
|
|
198
|
-
return message;
|
|
199
|
-
}
|
|
212
|
+
// Error translation lives in guards.ts; this binds the connection mode so call
|
|
213
|
+
// sites only say what kind of operation failed.
|
|
214
|
+
const errText = (err, op) => translate(err, { op, hosted: isHosted });
|
|
200
215
|
// When the caller doesn't name a column, infer the searchable text column.
|
|
201
216
|
// FTS indexes require LargeUtf8, so a LargeUtf8 column is almost certainly
|
|
202
217
|
// the indexed one; plain Utf8 columns are typically ids and short labels.
|
|
@@ -215,33 +230,77 @@ function inferVectorColumn(table) {
|
|
|
215
230
|
const field = table.schema().fields.find((f) => String(f.type).toLowerCase().includes("list"));
|
|
216
231
|
return field?.name;
|
|
217
232
|
}
|
|
218
|
-
async function
|
|
233
|
+
async function prepareRows(handle, table, rows) {
|
|
234
|
+
const fields = handle.schema().fields;
|
|
235
|
+
const columns = fields.map((f) => f.name);
|
|
236
|
+
// A table created from a descriptor has no nullable columns, so a row that
|
|
237
|
+
// omits one fails inside Arrow with a message about nullability. Name the
|
|
238
|
+
// column instead. The vector column is exempt: embedRows fills it in.
|
|
239
|
+
const vecCol = inferVectorColumn(handle);
|
|
240
|
+
const required = fields.filter((f) => f.nullable === false && f.name !== vecCol).map((f) => f.name);
|
|
241
|
+
rows.forEach((doc, i) => {
|
|
242
|
+
for (const key of Object.keys(doc)) {
|
|
243
|
+
if (!columns.includes(key)) {
|
|
244
|
+
throw new Error(`document ${i}: '${key}' is not a column of this table (columns: ${columns.join(", ")})`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const missing = required.filter((c) => doc[c] == null);
|
|
248
|
+
if (missing.length > 0) {
|
|
249
|
+
throw new Error(`document ${i}: missing ${missing.map((c) => `'${c}'`).join(", ")}; every column of this table is required in each row (columns: ${columns.join(", ")})`);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
const int64 = fields.filter((f) => /int64/i.test(String(f.type))).map((f) => f.name);
|
|
253
|
+
const widened = int64.length === 0
|
|
254
|
+
? rows
|
|
255
|
+
: rows.map((doc) => {
|
|
256
|
+
const out = { ...doc };
|
|
257
|
+
for (const col of int64) {
|
|
258
|
+
if (typeof out[col] === "number")
|
|
259
|
+
out[col] = BigInt(Math.trunc(out[col]));
|
|
260
|
+
}
|
|
261
|
+
return out;
|
|
262
|
+
});
|
|
263
|
+
return embedRows(handle, widened, table);
|
|
264
|
+
}
|
|
265
|
+
// The configured embedder must produce vectors as wide as the table's vector
|
|
266
|
+
// column, or every vector written or searched is meaningless (and the engine
|
|
267
|
+
// rejects the width). Checked once per table and column, before the first
|
|
268
|
+
// embedding into or against it, so a mismatch names both numbers up front
|
|
269
|
+
// instead of surfacing as an Arrow length error.
|
|
270
|
+
const widthChecked = new Set();
|
|
271
|
+
async function assertVectorWidth(handle, table, vecCol) {
|
|
272
|
+
const key = `${table}${vecCol}`;
|
|
273
|
+
if (widthChecked.has(key))
|
|
274
|
+
return;
|
|
275
|
+
const field = handle.schema().fields.find((f) => f.name === vecCol);
|
|
276
|
+
const width = field?.type?.listSize;
|
|
277
|
+
const dim = await embedderDim();
|
|
278
|
+
if (typeof width === "number" && width !== dim) {
|
|
279
|
+
throw new Error(`the embedder produces ${dim}-dimensional vectors but '${vecCol}' in '${table}' is ${width}-dimensional; ` +
|
|
280
|
+
"set INFINO_MCP_EMBED_MODEL (and provider) to the model that built this table, or recreate the table");
|
|
281
|
+
}
|
|
282
|
+
widthChecked.add(key);
|
|
283
|
+
}
|
|
284
|
+
// When a table has a vector index, fill in a missing vector for each row by
|
|
285
|
+
// embedding its text column, every missing vector in one batched call.
|
|
286
|
+
// Returns the rows and how many were embedded.
|
|
287
|
+
async function embedRows(handle, rows, table) {
|
|
219
288
|
const vecCol = inferVectorColumn(handle);
|
|
220
289
|
if (!vecCol)
|
|
221
|
-
return rows;
|
|
290
|
+
return { rows, embedded: 0 };
|
|
222
291
|
const textCol = inferTextColumn(handle);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
// switch as infino_add_documents: off → read-only, so the default install can't
|
|
236
|
-
// write through SQL; on → any single statement (DDL/DML) is allowed.
|
|
237
|
-
function guardSql(sql, allowWrites) {
|
|
238
|
-
const stripped = sql.trim().replace(/;\s*$/, "");
|
|
239
|
-
if (stripped.includes(";"))
|
|
240
|
-
throw new Error("only a single statement is allowed");
|
|
241
|
-
if (!allowWrites && !/^(select|with)\b/i.test(stripped)) {
|
|
242
|
-
throw new Error("only read-only SELECT / WITH queries are allowed (set INFINO_MCP_ENABLE_WRITES to permit DDL/DML through SQL)");
|
|
243
|
-
}
|
|
244
|
-
return stripped;
|
|
292
|
+
const pending = [];
|
|
293
|
+
rows.forEach((doc, i) => {
|
|
294
|
+
if (doc[vecCol] == null && textCol && typeof doc[textCol] === "string")
|
|
295
|
+
pending.push(i);
|
|
296
|
+
});
|
|
297
|
+
if (pending.length === 0)
|
|
298
|
+
return { rows, embedded: 0 };
|
|
299
|
+
await assertVectorWidth(handle, table, vecCol);
|
|
300
|
+
const vectors = await embedMany(pending.map((i) => rows[i][textCol]));
|
|
301
|
+
const out = rows.slice();
|
|
302
|
+
pending.forEach((i, n) => (out[i] = { ...out[i], [vecCol]: vectors[n] }));
|
|
303
|
+
return { rows: out, embedded: pending.length };
|
|
245
304
|
}
|
|
246
305
|
// --- server ----------------------------------------------------------------
|
|
247
306
|
// Server-level instructions are returned to the client on initialize and shown
|
|
@@ -250,7 +309,8 @@ function guardSql(sql, allowWrites) {
|
|
|
250
309
|
const server = new McpServer({ name: "infino", version: "0.1.0" }, {
|
|
251
310
|
instructions: "Infino is an embedded retrieval engine for data on object storage: full-text (BM25), vector, " +
|
|
252
311
|
"hybrid, and SQL search over one copy of the data, in-process, with no separate server or managed " +
|
|
253
|
-
"service.
|
|
312
|
+
"service. Tables are stored as valid Parquet; DuckDB or pyarrow can read the same files. These tools " +
|
|
313
|
+
"retrieve from a connected catalog of tables.\n\n" +
|
|
254
314
|
"Pick a tool by the question shape:\n" +
|
|
255
315
|
"- infino_keyword_search — literal terms, identifiers, error codes, names (ranked BM25).\n" +
|
|
256
316
|
"- infino_semantic_search — meaning or paraphrase when the exact wording is unknown; its optional " +
|
|
@@ -259,11 +319,18 @@ const server = new McpServer({ name: "infino", version: "0.1.0" }, {
|
|
|
259
319
|
"- infino_sql — counts, joins, aggregates, and filtering by exact column value (structural, not relevance).\n" +
|
|
260
320
|
"- infino_token_match / infino_exact_match — unranked keyword / exact-equality filters.\n" +
|
|
261
321
|
"- infino_list_tables / infino_describe_table — discover the tables and their columns before searching.\n\n" +
|
|
262
|
-
"
|
|
263
|
-
"
|
|
322
|
+
"Writing data, in order: infino_create_database if a hosted database answers 404; infino_create_table " +
|
|
323
|
+
"with a utf8 key column, large_utf8 text columns, and vector: true for semantic search (the server sizes " +
|
|
324
|
+
"the vector column to its embedder); infino_add_documents with tens of rows per call, always including " +
|
|
325
|
+
"the key; rows without a vector are embedded from their text. To replace rows, infino_delete_documents " +
|
|
326
|
+
"by key predicate then add again; before any delete, check the predicate with infino_count or infino_sql. " +
|
|
327
|
+
"Every write is one commit and is durable when the tool returns. For a whole corpus use the infino CLI " +
|
|
328
|
+
"(infino ingest) or an SDK, not this server. There is no server-side write gate: the API key's " +
|
|
329
|
+
"capabilities decide what a hosted connection may do, and you are responsible for what you change.",
|
|
264
330
|
});
|
|
265
331
|
server.registerTool("infino_list_tables", {
|
|
266
332
|
title: "List Infino tables",
|
|
333
|
+
annotations: READ_ONLY,
|
|
267
334
|
description: "List the tables in the connected catalog. Call this first to discover what is available to search or query.",
|
|
268
335
|
inputSchema: {},
|
|
269
336
|
}, async () => {
|
|
@@ -276,6 +343,7 @@ server.registerTool("infino_list_tables", {
|
|
|
276
343
|
});
|
|
277
344
|
server.registerTool("infino_describe_table", {
|
|
278
345
|
title: "Describe an Infino table",
|
|
346
|
+
annotations: READ_ONLY,
|
|
279
347
|
description: "Return a table's column names and types — call before searching so you know which column to target and what " +
|
|
280
348
|
"fields each result row carries.",
|
|
281
349
|
inputSchema: {
|
|
@@ -293,6 +361,120 @@ server.registerTool("infino_describe_table", {
|
|
|
293
361
|
return fail(`describe_table failed: ${errText(err)}`);
|
|
294
362
|
}
|
|
295
363
|
});
|
|
364
|
+
// --- catalog management ------------------------------------------------------
|
|
365
|
+
server.registerTool("infino_create_database", {
|
|
366
|
+
title: "Create the database this server is connected to",
|
|
367
|
+
annotations: ADDITIVE_IDEMPOTENT,
|
|
368
|
+
description: "Provision the database named in the connection. On Infino Cloud this registers the database; on a " +
|
|
369
|
+
"local path or bucket the catalog root is the database, so this is a no-op success. Idempotent: an " +
|
|
370
|
+
"existing database is reported as created: false. Call it when a hosted connection answers 404.",
|
|
371
|
+
inputSchema: {},
|
|
372
|
+
}, async () => {
|
|
373
|
+
try {
|
|
374
|
+
db.createDatabase();
|
|
375
|
+
return ok({ created: true });
|
|
376
|
+
}
|
|
377
|
+
catch (err) {
|
|
378
|
+
const e = err;
|
|
379
|
+
if (e?.status === 409)
|
|
380
|
+
return ok({ created: false, note: "database already exists" });
|
|
381
|
+
return fail(`create_database failed: ${errText(err, "create")}`);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
// The scalar column types the binding's schema descriptor accepts. Full-text
|
|
385
|
+
// indexes require large_utf8, which is why the descriptor spells both string
|
|
386
|
+
// widths out instead of offering a single "string".
|
|
387
|
+
const COLUMN_TYPES = ["utf8", "large_utf8", "bool", "int32", "int64", "float32", "float64"];
|
|
388
|
+
// Name of the vector column `vector: true` adds. Fixed so the skill, the
|
|
389
|
+
// searches' column inference, and the tables the server creates all agree.
|
|
390
|
+
const VECTOR_COLUMN = "embedding";
|
|
391
|
+
server.registerTool("infino_create_table", {
|
|
392
|
+
title: "Create an Infino table",
|
|
393
|
+
annotations: ADDITIVE,
|
|
394
|
+
description: "Create a table from a {column: type} descriptor. Full-text (BM25) indexes go on the columns named in " +
|
|
395
|
+
"'fts' (default: every large_utf8 column; the index requires that type). With vector: true the server " +
|
|
396
|
+
"adds an 'embedding' column sized to its embedder and a cosine vector index on it, so semantic and hybrid " +
|
|
397
|
+
"search work and rows added without a vector are embedded from their text. Every column is required in " +
|
|
398
|
+
"every row you add, so declare only columns you will always fill. Give every table a stable key " +
|
|
399
|
+
"column of type utf8 so rows can be replaced or removed later by predicate (e.g. key = 'doc-1'); keep " +
|
|
400
|
+
"utf8 for ids and short labels and large_utf8 for the text to search, so the searches infer the right column.",
|
|
401
|
+
inputSchema: {
|
|
402
|
+
table: z.string().describe("Table name."),
|
|
403
|
+
columns: z
|
|
404
|
+
.record(z.string(), z.enum(COLUMN_TYPES))
|
|
405
|
+
.describe("Columns as {name: type}. large_utf8 for text to search; utf8 for a key, ids, and short labels."),
|
|
406
|
+
fts: z
|
|
407
|
+
.array(z.string())
|
|
408
|
+
.optional()
|
|
409
|
+
.describe("Columns to full-text index. Default: every large_utf8 column. Must be large_utf8."),
|
|
410
|
+
vector: z
|
|
411
|
+
.boolean()
|
|
412
|
+
.optional()
|
|
413
|
+
.describe("Add an 'embedding' vector column sized to the server's embedder, with a cosine index. Default false."),
|
|
414
|
+
},
|
|
415
|
+
}, async ({ table, columns, fts, vector }) => {
|
|
416
|
+
try {
|
|
417
|
+
const descriptor = { ...columns };
|
|
418
|
+
const vectorColumns = [];
|
|
419
|
+
let spec = new IndexSpec();
|
|
420
|
+
if (vector) {
|
|
421
|
+
if (VECTOR_COLUMN in descriptor) {
|
|
422
|
+
return fail(`create_table: '${VECTOR_COLUMN}' is reserved for the vector column that vector: true adds; rename it.`);
|
|
423
|
+
}
|
|
424
|
+
const dim = await embedderDim();
|
|
425
|
+
descriptor[VECTOR_COLUMN] = { vector: dim };
|
|
426
|
+
spec = spec.vector(VECTOR_COLUMN, dim, "cosine");
|
|
427
|
+
vectorColumns.push(VECTOR_COLUMN);
|
|
428
|
+
}
|
|
429
|
+
const ftsColumns = fts ??
|
|
430
|
+
Object.entries(columns)
|
|
431
|
+
.filter(([, t]) => t === "large_utf8")
|
|
432
|
+
.map(([n]) => n);
|
|
433
|
+
for (const col of ftsColumns) {
|
|
434
|
+
if (!(col in descriptor))
|
|
435
|
+
return fail(`create_table: fts column '${col}' is not in 'columns'.`);
|
|
436
|
+
if (descriptor[col] !== "large_utf8") {
|
|
437
|
+
return fail(`create_table: fts column '${col}' is ${descriptor[col]}; a full-text index requires large_utf8.`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
for (const col of ftsColumns)
|
|
441
|
+
spec = spec.fts(col);
|
|
442
|
+
const handle = db.createTable(table, descriptor, spec);
|
|
443
|
+
const schema = handle
|
|
444
|
+
.schema()
|
|
445
|
+
.fields.map((f) => ({ name: f.name, type: String(f.type) }));
|
|
446
|
+
return ok({ table, columns: schema, indexes: { fts: ftsColumns, vector: vectorColumns } });
|
|
447
|
+
}
|
|
448
|
+
catch (err) {
|
|
449
|
+
const e = err;
|
|
450
|
+
if (e?.status === 409 || /already ?exists/i.test(e?.message ?? "")) {
|
|
451
|
+
return fail(`create_table: table '${table}' already exists; inspect it with infino_describe_table.`);
|
|
452
|
+
}
|
|
453
|
+
return fail(`create_table failed: ${errText(err, "create")}`);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
server.registerTool("infino_drop_table", {
|
|
457
|
+
title: "Drop an Infino table",
|
|
458
|
+
annotations: DESTRUCTIVE,
|
|
459
|
+
description: "Drop a table from the catalog and, by default, delete its storage objects too. Pass purge: false to only " +
|
|
460
|
+
"unregister the table and leave the bytes in place. Irreversible.",
|
|
461
|
+
inputSchema: {
|
|
462
|
+
table: z.string().describe("Table to drop."),
|
|
463
|
+
purge: z
|
|
464
|
+
.boolean()
|
|
465
|
+
.optional()
|
|
466
|
+
.describe("Also delete the table's storage objects. Default true; false only unregisters the name."),
|
|
467
|
+
},
|
|
468
|
+
}, async ({ table, purge }) => {
|
|
469
|
+
try {
|
|
470
|
+
const reclaim = purge ?? true;
|
|
471
|
+
db.dropTable(table, reclaim);
|
|
472
|
+
return ok({ table, dropped: true, purged: reclaim });
|
|
473
|
+
}
|
|
474
|
+
catch (err) {
|
|
475
|
+
return fail(`drop_table failed: ${errText(err, "write")}`);
|
|
476
|
+
}
|
|
477
|
+
});
|
|
296
478
|
// Build the returned-column projection for a search hit. A caller-supplied
|
|
297
479
|
// `columns` list is honored so clients can retrieve the fields they need
|
|
298
480
|
// (e.g. a path + line range to cite), with `_id` and `score` always appended
|
|
@@ -312,6 +494,7 @@ const SCORE_KIND = {
|
|
|
312
494
|
};
|
|
313
495
|
server.registerTool("infino_semantic_search", {
|
|
314
496
|
title: "Semantic (vector) search",
|
|
497
|
+
annotations: READ_ONLY,
|
|
315
498
|
description: "Use when searching for a concept by meaning and the exact wording is unknown — this retrieves paraphrases and " +
|
|
316
499
|
"synonyms, not just literal matches. Embeds the query with a local model (no API key) and ranks a table's " +
|
|
317
500
|
"embedding column by vector similarity. Each hit carries a score that is a DISTANCE (lower is closer) plus the " +
|
|
@@ -348,6 +531,7 @@ server.registerTool("infino_semantic_search", {
|
|
|
348
531
|
if (!vecCol)
|
|
349
532
|
return fail(`semantic_search: no vector column in '${table}' — pass 'vectorColumn'.`);
|
|
350
533
|
const textCol = column ?? inferTextColumn(handle);
|
|
534
|
+
await assertVectorWidth(handle, table, vecCol);
|
|
351
535
|
const vector = await embed(query);
|
|
352
536
|
const projection = searchProjection(columns, textCol);
|
|
353
537
|
const { value: results, tookMs } = timed(() => handle.vectorSearch(vecCol, vector, k, { projection, filter }));
|
|
@@ -365,6 +549,7 @@ server.registerTool("infino_semantic_search", {
|
|
|
365
549
|
});
|
|
366
550
|
server.registerTool("infino_keyword_search", {
|
|
367
551
|
title: "Keyword (BM25) search",
|
|
552
|
+
annotations: READ_ONLY,
|
|
368
553
|
description: "Use when the query is literal terms — identifiers, error codes, product names, exact phrases — and you want " +
|
|
369
554
|
"results ranked by relevance. BM25 full-text search over a text column: ranks rows by how well the query's " +
|
|
370
555
|
"tokens (and their stems) match, each with a relevance score (higher is better) plus the columns you project " +
|
|
@@ -379,19 +564,27 @@ server.registerTool("infino_keyword_search", {
|
|
|
379
564
|
.string()
|
|
380
565
|
.optional()
|
|
381
566
|
.describe("Text column to search; inferred from the table schema when omitted."),
|
|
567
|
+
mode: z
|
|
568
|
+
.enum(["or", "and"])
|
|
569
|
+
.optional()
|
|
570
|
+
.describe("Match any query token ('or', the default) or require every token ('and')."),
|
|
571
|
+
stats: z
|
|
572
|
+
.enum(["per_superfile", "global"])
|
|
573
|
+
.optional()
|
|
574
|
+
.describe("BM25 statistics scope: 'per_superfile' (the default; each segment scored against its own statistics) or 'global' (one table-wide idf, so a table written in many small batches ranks like one corpus)."),
|
|
382
575
|
columns: z
|
|
383
576
|
.array(z.string())
|
|
384
577
|
.optional()
|
|
385
578
|
.describe("Which of the table's columns each hit returns, with full values (a projection passed straight to the engine). Defaults to the searched column; '_id' and 'score' are always included. Any column works: ['id'] for compact hits at a large k, ['id', 'text'] to get the full text alongside an id to cite, ['title', 'created_at'] for metadata. Nothing is truncated; read fewer columns or a smaller k to keep results small."),
|
|
386
579
|
},
|
|
387
|
-
}, async ({ table, query, k, column, columns }) => {
|
|
580
|
+
}, async ({ table, query, k, column, mode, stats, columns }) => {
|
|
388
581
|
try {
|
|
389
582
|
const handle = db.openTable(table);
|
|
390
583
|
const col = column ?? inferTextColumn(handle);
|
|
391
584
|
if (!col) {
|
|
392
585
|
return fail(`keyword_search: no text column found in '${table}' — pass 'column' explicitly.`);
|
|
393
586
|
}
|
|
394
|
-
const { value: results, tookMs } = timed(() => handle.bm25Search(col, query, k, { projection: searchProjection(columns, col) }));
|
|
587
|
+
const { value: results, tookMs } = timed(() => handle.bm25Search(col, query, k, { mode, stats, projection: searchProjection(columns, col) }));
|
|
395
588
|
return ok({
|
|
396
589
|
table,
|
|
397
590
|
column: col,
|
|
@@ -407,6 +600,7 @@ server.registerTool("infino_keyword_search", {
|
|
|
407
600
|
});
|
|
408
601
|
server.registerTool("infino_hybrid_search", {
|
|
409
602
|
title: "Hybrid (keyword + semantic) search",
|
|
603
|
+
annotations: READ_ONLY,
|
|
410
604
|
description: "Use when a query carries both specific terms and an intent — you want exact-term precision without giving up " +
|
|
411
605
|
"paraphrase recall. Fuses BM25 over a text column with vector similarity over the embedding column in a single " +
|
|
412
606
|
"ranking pass, so rows matching the literal terms AND the meaning rank highest; the score is the fused rank " +
|
|
@@ -417,13 +611,20 @@ server.registerTool("infino_hybrid_search", {
|
|
|
417
611
|
query: z.string().describe("Query text; matched as keyword terms AND embedded for vector similarity."),
|
|
418
612
|
k: z.number().int().positive().max(100).default(10).describe("Maximum results."),
|
|
419
613
|
column: z.string().optional().describe("Text column for the keyword half; inferred if omitted."),
|
|
420
|
-
vectorColumn: z
|
|
614
|
+
vectorColumn: z
|
|
615
|
+
.string()
|
|
616
|
+
.optional()
|
|
617
|
+
.describe("Vector column for the semantic half; inferred if omitted."),
|
|
618
|
+
mode: z
|
|
619
|
+
.enum(["or", "and"])
|
|
620
|
+
.optional()
|
|
621
|
+
.describe("Keyword half: match any query token ('or', the default) or require every token ('and')."),
|
|
421
622
|
columns: z
|
|
422
623
|
.array(z.string())
|
|
423
624
|
.optional()
|
|
424
625
|
.describe("Which of the table's columns each hit returns, with full values (a projection passed straight to the engine). Defaults to the text column; '_id' and 'score' are always included. Any column works: ['id'] for compact hits at a large k, ['id', 'text'] to get the full text alongside an id to cite, ['title', 'created_at'] for metadata. Nothing is truncated; read fewer columns or a smaller k to keep results small."),
|
|
425
626
|
},
|
|
426
|
-
}, async ({ table, query, k, column, vectorColumn, columns }) => {
|
|
627
|
+
}, async ({ table, query, k, column, vectorColumn, mode, columns }) => {
|
|
427
628
|
try {
|
|
428
629
|
const handle = db.openTable(table);
|
|
429
630
|
const textCol = column ?? inferTextColumn(handle);
|
|
@@ -432,8 +633,10 @@ server.registerTool("infino_hybrid_search", {
|
|
|
432
633
|
const vecCol = vectorColumn ?? inferVectorColumn(handle);
|
|
433
634
|
if (!vecCol)
|
|
434
635
|
return fail(`hybrid_search: no vector column in '${table}' — pass 'vectorColumn'.`);
|
|
636
|
+
await assertVectorWidth(handle, table, vecCol);
|
|
435
637
|
const vector = await embed(query);
|
|
436
638
|
const { value: results, tookMs } = timed(() => handle.hybridSearch(textCol, query, vecCol, vector, k, {
|
|
639
|
+
mode,
|
|
437
640
|
projection: searchProjection(columns, textCol),
|
|
438
641
|
}));
|
|
439
642
|
return ok({
|
|
@@ -450,6 +653,7 @@ server.registerTool("infino_hybrid_search", {
|
|
|
450
653
|
});
|
|
451
654
|
server.registerTool("infino_token_match", {
|
|
452
655
|
title: "Token match (unranked keyword filter)",
|
|
656
|
+
annotations: READ_ONLY,
|
|
453
657
|
description: "Use when you need the SET of rows containing a keyword, not a ranked order — a fast unranked keyword filter. " +
|
|
454
658
|
"Returns rows whose text column contains the token(s), matching indexed tokens and their stems. For ranked " +
|
|
455
659
|
"results use infino_keyword_search; for analytical filtering across columns use infino_sql.",
|
|
@@ -476,7 +680,14 @@ server.registerTool("infino_token_match", {
|
|
|
476
680
|
if (!col)
|
|
477
681
|
return fail(`token_match: no text column in '${table}' — pass 'column'.`);
|
|
478
682
|
const { value: rows, tookMs } = timed(() => handle.tokenMatch(col, query, { mode, projection: [col, "_id"] }));
|
|
479
|
-
return ok({
|
|
683
|
+
return ok({
|
|
684
|
+
table,
|
|
685
|
+
column: col,
|
|
686
|
+
query,
|
|
687
|
+
matched: rows.length,
|
|
688
|
+
results: rows.slice(0, limit),
|
|
689
|
+
took_ms: tookMs,
|
|
690
|
+
});
|
|
480
691
|
}
|
|
481
692
|
catch (err) {
|
|
482
693
|
return fail(`token_match failed: ${errText(err)}`);
|
|
@@ -484,6 +695,7 @@ server.registerTool("infino_token_match", {
|
|
|
484
695
|
});
|
|
485
696
|
server.registerTool("infino_exact_match", {
|
|
486
697
|
title: "Exact match (unranked exact filter)",
|
|
698
|
+
annotations: READ_ONLY,
|
|
487
699
|
description: "Use to fetch rows whose column exactly equals a value — a tag, status, or id string. Unranked exact-equality " +
|
|
488
700
|
"filter over an indexed column. For ranked text relevance use infino_keyword_search; for multi-column " +
|
|
489
701
|
"analytical filtering use infino_sql.",
|
|
@@ -506,7 +718,14 @@ server.registerTool("infino_exact_match", {
|
|
|
506
718
|
if (!col)
|
|
507
719
|
return fail(`exact_match: no column found in '${table}' — pass 'column'.`);
|
|
508
720
|
const { value: rows, tookMs } = timed(() => handle.exactMatch(col, value, { projection: [col, "_id"] }));
|
|
509
|
-
return ok({
|
|
721
|
+
return ok({
|
|
722
|
+
table,
|
|
723
|
+
column: col,
|
|
724
|
+
value,
|
|
725
|
+
matched: rows.length,
|
|
726
|
+
results: rows.slice(0, limit),
|
|
727
|
+
took_ms: tookMs,
|
|
728
|
+
});
|
|
510
729
|
}
|
|
511
730
|
catch (err) {
|
|
512
731
|
return fail(`exact_match failed: ${errText(err)}`);
|
|
@@ -514,6 +733,7 @@ server.registerTool("infino_exact_match", {
|
|
|
514
733
|
});
|
|
515
734
|
server.registerTool("infino_count", {
|
|
516
735
|
title: "Count keyword matches",
|
|
736
|
+
annotations: READ_ONLY,
|
|
517
737
|
description: "Use when you only need HOW MANY rows match a keyword query, not the rows themselves — a fast tally over a text " +
|
|
518
738
|
"column, without fetching or ranking. Cheaper than infino_keyword_search when a number is all you need (e.g. " +
|
|
519
739
|
"'how many docs mention X'). For the matching rows use infino_keyword_search or infino_token_match.",
|
|
@@ -545,23 +765,20 @@ server.registerTool("infino_count", {
|
|
|
545
765
|
});
|
|
546
766
|
server.registerTool("infino_sql", {
|
|
547
767
|
title: "SQL over Infino",
|
|
768
|
+
annotations: DESTRUCTIVE,
|
|
548
769
|
description: "Use for structural or analytical questions — counts, GROUP BY, joins, aggregates, filtering by column value — " +
|
|
549
770
|
"returning result rows. The engine's search functions are callable as table-valued relations, so a single query " +
|
|
550
771
|
"can rank AND aggregate: bm25_search('table','text_col','terms', k) — also bm25_search_prefix / token_match / " +
|
|
551
772
|
"exact_match — need no embedding. vector_search('table','vec_col', {{q}}, k) and " +
|
|
552
773
|
"hybrid_search('table','text_col','terms','vec_col', {{q}}, k) need a query vector: put a {{name}} placeholder " +
|
|
553
|
-
|
|
774
|
+
'where the vector goes and pass embed:{"name":"query text"} — the server embeds the text and substitutes the ' +
|
|
554
775
|
"vector in. Example: SELECT path, SUM(end_line - start_line + 1) AS lines FROM " +
|
|
555
776
|
"bm25_search('docs','body','error timeout', 300) GROUP BY path ORDER BY lines DESC. " +
|
|
556
|
-
|
|
557
|
-
? "Any single statement is allowed (including DDL/DML), since INFINO_MCP_ENABLE_WRITES is set."
|
|
558
|
-
: "Read-only: a single SELECT / WITH statement; DDL/DML is rejected."),
|
|
777
|
+
"Any single statement is allowed, DDL/DML included.",
|
|
559
778
|
inputSchema: {
|
|
560
|
-
query:
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
.string()
|
|
564
|
-
.describe("A single read-only SELECT or WITH statement. May use search TVFs and {{name}} vector placeholders."),
|
|
779
|
+
query: z
|
|
780
|
+
.string()
|
|
781
|
+
.describe("A single SQL statement. May use search TVFs and {{name}} vector placeholders."),
|
|
565
782
|
embed: z
|
|
566
783
|
.record(z.string(), z.string())
|
|
567
784
|
.optional()
|
|
@@ -572,90 +789,93 @@ server.registerTool("infino_sql", {
|
|
|
572
789
|
}, async ({ query, embed: embeds }) => {
|
|
573
790
|
try {
|
|
574
791
|
const sql = await applyEmbeds(query, embeds);
|
|
575
|
-
const { value: rows, tookMs } = timed(() => db.querySql(guardSql(sql
|
|
792
|
+
const { value: rows, tookMs } = timed(() => db.querySql(guardSql(sql)));
|
|
576
793
|
return ok({ rows, took_ms: tookMs });
|
|
577
794
|
}
|
|
578
795
|
catch (err) {
|
|
579
796
|
return fail(`sql failed: ${errText(err)}`);
|
|
580
797
|
}
|
|
581
798
|
});
|
|
582
|
-
//
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
|
|
799
|
+
// --- document writes ---------------------------------------------------------
|
|
800
|
+
server.registerTool("infino_add_documents", {
|
|
801
|
+
title: "Add documents to an Infino table",
|
|
802
|
+
annotations: ADDITIVE,
|
|
803
|
+
description: "Append documents (rows, as JSON objects keyed by column name) to a table; one call is one commit. " +
|
|
804
|
+
"If the table has a vector index and a document omits the vector, the server embeds its text column " +
|
|
805
|
+
"(a local model, no API key). Send tens of rows per call; for a whole corpus use the infino CLI or an SDK.",
|
|
806
|
+
inputSchema: {
|
|
807
|
+
table: z.string().describe("Table to append to."),
|
|
808
|
+
documents: z
|
|
809
|
+
.array(z.record(z.string(), z.any()))
|
|
810
|
+
.min(1)
|
|
811
|
+
.describe("Rows to append, as JSON objects keyed by column name."),
|
|
812
|
+
},
|
|
813
|
+
}, async ({ table, documents }) => {
|
|
814
|
+
try {
|
|
815
|
+
const handle = db.openTable(table);
|
|
816
|
+
const { rows, embedded } = await prepareRows(handle, table, documents);
|
|
817
|
+
const { tookMs } = timed(() => handle.append(rows));
|
|
818
|
+
return ok({
|
|
819
|
+
table,
|
|
820
|
+
appended: rows.length,
|
|
821
|
+
embedded,
|
|
822
|
+
took_ms: tookMs,
|
|
823
|
+
verify: `infino_count or a search on '${table}' shows the new rows`,
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
catch (err) {
|
|
827
|
+
return fail(`add_documents failed: ${errText(err, "write")}`);
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
server.registerTool("infino_update_documents", {
|
|
831
|
+
title: "Update documents in an Infino table",
|
|
832
|
+
annotations: DESTRUCTIVE,
|
|
833
|
+
description: "Replace the rows matching a SQL predicate with new documents, 1:1; the number of matched rows must equal " +
|
|
834
|
+
"the number of replacement documents. As with add, a row that omits its vector has it embedded from the text " +
|
|
835
|
+
"column (local model, no API key). Requires durable storage (not memory://).",
|
|
836
|
+
inputSchema: {
|
|
837
|
+
table: z.string().describe("Table to update."),
|
|
838
|
+
predicate: z
|
|
839
|
+
.string()
|
|
840
|
+
.describe("SQL predicate selecting the rows to replace, e.g. \"status = 'draft'\"."),
|
|
841
|
+
documents: z
|
|
842
|
+
.array(z.record(z.string(), z.any()))
|
|
843
|
+
.min(1)
|
|
844
|
+
.describe("Replacement rows, as JSON objects keyed by column name (one per matched row)."),
|
|
845
|
+
},
|
|
846
|
+
}, async ({ table, predicate, documents }) => {
|
|
847
|
+
try {
|
|
848
|
+
const handle = db.openTable(table);
|
|
849
|
+
const { rows, embedded } = await prepareRows(handle, table, documents);
|
|
850
|
+
const stats = handle.update(predicate, rows);
|
|
851
|
+
return ok({ table, predicate, ...stats, embedded });
|
|
852
|
+
}
|
|
853
|
+
catch (err) {
|
|
854
|
+
return fail(`update_documents failed: ${errText(err, "write")}`);
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
server.registerTool("infino_delete_documents", {
|
|
858
|
+
title: "Delete documents from an Infino table",
|
|
859
|
+
annotations: DESTRUCTIVE,
|
|
860
|
+
description: "Delete the rows matching a SQL predicate, e.g. \"status = 'spam'\". Returns how many rows matched and were " +
|
|
861
|
+
"removed. Check the predicate first with infino_count or infino_sql. Requires durable storage (not memory://).",
|
|
862
|
+
inputSchema: {
|
|
863
|
+
table: z.string().describe("Table to delete from."),
|
|
864
|
+
predicate: z.string().describe("SQL predicate selecting the rows to delete, e.g. \"status = 'spam'\"."),
|
|
865
|
+
},
|
|
866
|
+
}, async ({ table, predicate }) => {
|
|
867
|
+
try {
|
|
868
|
+
const stats = db.openTable(table).delete(predicate);
|
|
869
|
+
return ok({ table, predicate, ...stats });
|
|
870
|
+
}
|
|
871
|
+
catch (err) {
|
|
872
|
+
return fail(`delete_documents failed: ${errText(err, "write")}`);
|
|
873
|
+
}
|
|
874
|
+
});
|
|
655
875
|
// --- transport -------------------------------------------------------------
|
|
656
876
|
// stdio for desktop/CLI clients (Claude Desktop/Code, Cursor). Logs go to
|
|
657
877
|
// stderr so they never corrupt the JSON-RPC stream on stdout.
|
|
658
878
|
const transport = new StdioServerTransport();
|
|
659
879
|
await server.connect(transport);
|
|
660
880
|
console.error(`infino MCP server ready on stdio (uri: ${uri}, mode: ${isHosted ? "hosted" : "embedded"}, ` +
|
|
661
|
-
`
|
|
881
|
+
`embedder: ${embedderInfo()})`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infino-ai/mcp-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "MCP server for Infino — keyword,
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "MCP server for Infino — keyword, semantic, hybrid, and SQL retrieval for AI agents: RAG, persistent agent memory, and search over data stored as plain Parquet on object storage. Local embeddings, no API key.",
|
|
5
5
|
"mcpName": "io.github.infino-ai/mcp-server",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"homepage": "https://github.com/infino-ai/infino-mcp#readme",
|
|
@@ -26,7 +26,10 @@
|
|
|
26
26
|
"agent-memory",
|
|
27
27
|
"object-storage",
|
|
28
28
|
"embeddings",
|
|
29
|
-
"ai"
|
|
29
|
+
"ai",
|
|
30
|
+
"parquet",
|
|
31
|
+
"s3",
|
|
32
|
+
"semantic-search"
|
|
30
33
|
],
|
|
31
34
|
"type": "module",
|
|
32
35
|
"bin": {
|
|
@@ -37,7 +40,7 @@
|
|
|
37
40
|
"dist"
|
|
38
41
|
],
|
|
39
42
|
"engines": {
|
|
40
|
-
"node": ">=
|
|
43
|
+
"node": ">=20"
|
|
41
44
|
},
|
|
42
45
|
"publishConfig": {
|
|
43
46
|
"access": "public"
|
|
@@ -47,16 +50,25 @@
|
|
|
47
50
|
"watch": "tsc --watch",
|
|
48
51
|
"start": "node dist/index.js",
|
|
49
52
|
"pretest": "npm run build",
|
|
50
|
-
"test": "node --test"
|
|
53
|
+
"test": "node --test",
|
|
54
|
+
"lint": "eslint . --max-warnings 0",
|
|
55
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.mjs\" \"scripts/**/*.mjs\" eslint.config.js",
|
|
56
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.mjs\" \"scripts/**/*.mjs\" eslint.config.js",
|
|
57
|
+
"audit:gate": "node scripts/audit-gate.mjs"
|
|
51
58
|
},
|
|
52
59
|
"dependencies": {
|
|
53
60
|
"@huggingface/transformers": "^4.2.0",
|
|
54
|
-
"@infino-ai/infino": "^0.
|
|
61
|
+
"@infino-ai/infino": "^0.6.0",
|
|
55
62
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
56
|
-
"zod": "^4.4
|
|
63
|
+
"zod": "^4.5.4"
|
|
57
64
|
},
|
|
58
65
|
"devDependencies": {
|
|
66
|
+
"@eslint/js": "^10.0.1",
|
|
59
67
|
"@types/node": "^26",
|
|
60
|
-
"
|
|
68
|
+
"eslint": "^10.10.0",
|
|
69
|
+
"globals": "^17.12.0",
|
|
70
|
+
"prettier": "^3.9.6",
|
|
71
|
+
"typescript": "^6.0.3",
|
|
72
|
+
"typescript-eslint": "^8.69.0"
|
|
61
73
|
}
|
|
62
74
|
}
|