@infino-ai/mcp-server 0.12.0 → 0.13.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 +33 -18
- package/dist/embedding.js +55 -15
- package/dist/guards.js +64 -0
- package/dist/index.js +356 -157
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
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).
|
|
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
12
|
|
|
13
13
|
---
|
|
@@ -59,8 +59,8 @@ The server is launched by your MCP client over stdio — you don't run it direct
|
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
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
|
|
62
|
+
the `https://<host>/<database>` endpoint and supply your API key. Everything
|
|
63
|
+
else is identical:
|
|
64
64
|
|
|
65
65
|
```jsonc
|
|
66
66
|
{
|
|
@@ -86,7 +86,7 @@ For [Claude Code](https://claude.com/claude-code), this repo is also a plugin ma
|
|
|
86
86
|
/plugin install infino@infino-ai
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
On enable you'll be prompted for your **Infino data URI** (`INFINO_MCP_URI`) and
|
|
89
|
+
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
90
|
|
|
91
91
|
---
|
|
92
92
|
|
|
@@ -103,7 +103,7 @@ claude mcp add infino \
|
|
|
103
103
|
-- npx -y @infino-ai/mcp-server
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
Add more knobs with repeated `-e` flags, e.g. `-e
|
|
106
|
+
Add more knobs with repeated `-e` flags, e.g. `-e INFINO_MCP_VALIDATE=true`. Verify with:
|
|
107
107
|
|
|
108
108
|
```sh
|
|
109
109
|
claude mcp list
|
|
@@ -195,7 +195,6 @@ All configuration is via environment variables — there are no config files and
|
|
|
195
195
|
| --- | --- | --- | --- |
|
|
196
196
|
| `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
197
|
| `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
198
|
| `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
199
|
| `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
200
|
| `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 +259,7 @@ The model must match what produced the stored vectors — a mismatch yields mean
|
|
|
260
259
|
}
|
|
261
260
|
```
|
|
262
261
|
|
|
263
|
-
On a hosted connection the search, SQL, and
|
|
262
|
+
On a hosted connection the search, SQL, and write tools all
|
|
264
263
|
behave exactly as they do locally — the only difference is where the data
|
|
265
264
|
lives. Compaction and garbage collection are handled server-side, so they are
|
|
266
265
|
not exposed as client operations. Note that semantic and hybrid search still
|
|
@@ -276,21 +275,37 @@ the data.
|
|
|
276
275
|
| Tool | Arguments | What it does |
|
|
277
276
|
| --- | --- | --- |
|
|
278
277
|
| `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). |
|
|
278
|
+
| `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. |
|
|
279
|
+
| `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
280
|
| `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
281
|
| `infino_exact_match` | `table`, `value`, `column?`, `limit?` | Unranked exact-equality filter over an indexed column (tag, status, id string). |
|
|
283
282
|
| `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.
|
|
283
|
+
| `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
284
|
| `infino_list_tables` | — | List the tables in the connected catalog. |
|
|
286
285
|
| `infino_describe_table` | `table` | Column names and types for a table. |
|
|
287
|
-
| `
|
|
288
|
-
| `
|
|
289
|
-
| `
|
|
286
|
+
| `infino_create_database` | — | Provision the database the connection names (Infino Cloud); a no-op success locally. Idempotent. |
|
|
287
|
+
| `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. |
|
|
288
|
+
| `infino_drop_table` | `table`, `purge?` | Drop a table and, by default, delete its storage objects; `purge: false` only unregisters the name. |
|
|
289
|
+
| `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. |
|
|
290
|
+
| `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. |
|
|
291
|
+
| `infino_delete_documents` | `table`, `predicate` | Delete the rows matching a SQL predicate. Durable storage only. |
|
|
290
292
|
|
|
291
293
|
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
294
|
|
|
293
|
-
|
|
295
|
+
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.
|
|
296
|
+
|
|
297
|
+
### Writing data
|
|
298
|
+
|
|
299
|
+
The write path an agent follows, each step one tool call and one commit:
|
|
300
|
+
|
|
301
|
+
1. `infino_create_database` if a hosted database answers 404.
|
|
302
|
+
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.
|
|
303
|
+
3. `infino_add_documents`, tens of rows per call, always including the key. Missing vectors are embedded in one batch.
|
|
304
|
+
4. To replace rows, `infino_delete_documents` by key predicate, then add again. To remove rows, check the predicate with `infino_count` first.
|
|
305
|
+
|
|
306
|
+
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.
|
|
307
|
+
|
|
308
|
+
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
309
|
|
|
295
310
|
---
|
|
296
311
|
|
|
@@ -299,9 +314,9 @@ The engine's search table functions (`bm25_search`, `vector_search`, `hybrid_sea
|
|
|
299
314
|
This server runs locally, beside the client, and keeps data and credentials on the user's machine.
|
|
300
315
|
|
|
301
316
|
- **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.**
|
|
317
|
+
- **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
318
|
- **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
|
-
- **
|
|
319
|
+
- **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
320
|
- **Least privilege.** Point `INFINO_MCP_URI` at the narrowest dataset the task needs, and supply storage credentials scoped to that bucket/prefix.
|
|
306
321
|
|
|
307
322
|
---
|
|
@@ -320,11 +335,11 @@ If you change `INFINO_MCP_EMBED_MODEL`, the table's vector index must match the
|
|
|
320
335
|
| --- | --- |
|
|
321
336
|
| 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
337
|
| `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
|
-
|
|
|
338
|
+
| 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. |
|
|
339
|
+
| 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
340
|
| Slow first query | One-time embedding-model download (~90 MB). Subsequent runs use the cache. |
|
|
325
341
|
| 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
342
|
| 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
343
|
|
|
329
344
|
---
|
|
330
345
|
|
package/dist/embedding.js
CHANGED
|
@@ -34,8 +34,12 @@ const LOCAL_MODEL_DEFAULT = "Xenova/all-MiniLM-L6-v2";
|
|
|
34
34
|
const REMOTE_MODEL_DEFAULT = "text-embedding-3-small";
|
|
35
35
|
const MODEL = process.env.INFINO_MCP_EMBED_MODEL ??
|
|
36
36
|
(USE_REMOTE ? REMOTE_MODEL_DEFAULT : LOCAL_MODEL_DEFAULT);
|
|
37
|
-
//
|
|
38
|
-
//
|
|
37
|
+
// Batch sizes. The local pipeline runs one forward pass per call, so a batch
|
|
38
|
+
// amortizes model overhead across texts without letting the ONNX arenas grow
|
|
39
|
+
// past what a handful of documents needs. The remote size stays well inside
|
|
40
|
+
// every OpenAI-compatible provider's per-request input limit.
|
|
41
|
+
const LOCAL_BATCH = 32;
|
|
42
|
+
const REMOTE_BATCH = 100;
|
|
39
43
|
let pipe = null;
|
|
40
44
|
function getPipe() {
|
|
41
45
|
if (!pipe) {
|
|
@@ -46,8 +50,8 @@ function getPipe() {
|
|
|
46
50
|
}
|
|
47
51
|
return pipe;
|
|
48
52
|
}
|
|
49
|
-
/** Embed
|
|
50
|
-
async function
|
|
53
|
+
/** Embed up to REMOTE_BATCH texts in one OpenAI-compatible /embeddings call. */
|
|
54
|
+
async function embedRemoteBatch(texts) {
|
|
51
55
|
if (!BASE_URL) {
|
|
52
56
|
throw new Error("INFINO_MCP_EMBED_BASE_URL is required when INFINO_MCP_EMBED_PROVIDER is 'openai'.");
|
|
53
57
|
}
|
|
@@ -62,27 +66,63 @@ async function embedRemote(text) {
|
|
|
62
66
|
const res = await fetch(url, {
|
|
63
67
|
method: "POST",
|
|
64
68
|
headers,
|
|
65
|
-
body: JSON.stringify({ model: MODEL, input:
|
|
69
|
+
body: JSON.stringify({ model: MODEL, input: texts }),
|
|
66
70
|
});
|
|
67
71
|
if (!res.ok) {
|
|
68
72
|
const detail = await res.text().catch(() => "");
|
|
69
73
|
throw new Error(`embeddings request failed: HTTP ${res.status} ${detail.slice(0, 300)}`);
|
|
70
74
|
}
|
|
71
75
|
const body = (await res.json());
|
|
72
|
-
const
|
|
73
|
-
if (!Array.isArray(
|
|
74
|
-
throw new Error(
|
|
76
|
+
const data = body?.data;
|
|
77
|
+
if (!Array.isArray(data) || data.length !== texts.length) {
|
|
78
|
+
throw new Error(`embeddings response carried ${Array.isArray(data) ? data.length : 0} vectors for ${texts.length} inputs`);
|
|
75
79
|
}
|
|
76
|
-
|
|
80
|
+
// The spec orders `data` by `index`, but a provider may not; honor the
|
|
81
|
+
// index so vectors land on the text that produced them.
|
|
82
|
+
const out = new Array(texts.length);
|
|
83
|
+
data.forEach((item, position) => {
|
|
84
|
+
const at = typeof item.index === "number" ? item.index : position;
|
|
85
|
+
if (!Array.isArray(item.embedding) || at < 0 || at >= texts.length || out[at]) {
|
|
86
|
+
throw new Error("embeddings response did not contain one embedding per input");
|
|
87
|
+
}
|
|
88
|
+
out[at] = Array.from(item.embedding, Number);
|
|
89
|
+
});
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
/** Embed up to LOCAL_BATCH texts in one forward pass of the local model. */
|
|
93
|
+
async function embedLocalBatch(texts) {
|
|
94
|
+
const extractor = await getPipe();
|
|
95
|
+
// Mean-pool token vectors and L2-normalize → one sentence embedding per text,
|
|
96
|
+
// returned as an [n, dim] tensor.
|
|
97
|
+
const output = await extractor(texts, { pooling: "mean", normalize: true });
|
|
98
|
+
const dim = output.dims[output.dims.length - 1];
|
|
99
|
+
const flat = Array.from(output.data, Number);
|
|
100
|
+
return texts.map((_, i) => flat.slice(i * dim, (i + 1) * dim));
|
|
101
|
+
}
|
|
102
|
+
/** Embed many texts with the configured provider, in batches, preserving order. */
|
|
103
|
+
export async function embedMany(texts) {
|
|
104
|
+
if (texts.length === 0)
|
|
105
|
+
return [];
|
|
106
|
+
const size = USE_REMOTE ? REMOTE_BATCH : LOCAL_BATCH;
|
|
107
|
+
const run = USE_REMOTE ? embedRemoteBatch : embedLocalBatch;
|
|
108
|
+
const out = [];
|
|
109
|
+
for (let i = 0; i < texts.length; i += size) {
|
|
110
|
+
out.push(...(await run(texts.slice(i, i + size))));
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
77
113
|
}
|
|
78
114
|
/** Embed one text into a vector with the configured provider. */
|
|
79
115
|
export async function embed(text) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
116
|
+
return (await embedMany([text]))[0];
|
|
117
|
+
}
|
|
118
|
+
// The embedder's output width, learned once by embedding a short constant
|
|
119
|
+
// string. Sizes the vector column of a table the server creates, and is
|
|
120
|
+
// compared against the vector column of any table it embeds into.
|
|
121
|
+
let dim = null;
|
|
122
|
+
export function embedderDim() {
|
|
123
|
+
if (!dim)
|
|
124
|
+
dim = embed("infino").then((v) => v.length);
|
|
125
|
+
return dim;
|
|
86
126
|
}
|
|
87
127
|
/** Human-readable description of the embedder, for the startup log. */
|
|
88
128
|
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
|
|
@@ -259,11 +318,18 @@ const server = new McpServer({ name: "infino", version: "0.1.0" }, {
|
|
|
259
318
|
"- infino_sql — counts, joins, aggregates, and filtering by exact column value (structural, not relevance).\n" +
|
|
260
319
|
"- infino_token_match / infino_exact_match — unranked keyword / exact-equality filters.\n" +
|
|
261
320
|
"- infino_list_tables / infino_describe_table — discover the tables and their columns before searching.\n\n" +
|
|
262
|
-
"
|
|
263
|
-
"
|
|
321
|
+
"Writing data, in order: infino_create_database if a hosted database answers 404; infino_create_table " +
|
|
322
|
+
"with a utf8 key column, large_utf8 text columns, and vector: true for semantic search (the server sizes " +
|
|
323
|
+
"the vector column to its embedder); infino_add_documents with tens of rows per call, always including " +
|
|
324
|
+
"the key; rows without a vector are embedded from their text. To replace rows, infino_delete_documents " +
|
|
325
|
+
"by key predicate then add again; before any delete, check the predicate with infino_count or infino_sql. " +
|
|
326
|
+
"Every write is one commit and is durable when the tool returns. For a whole corpus use the infino CLI " +
|
|
327
|
+
"(infino ingest) or an SDK, not this server. There is no server-side write gate: the API key's " +
|
|
328
|
+
"capabilities decide what a hosted connection may do, and you are responsible for what you change.",
|
|
264
329
|
});
|
|
265
330
|
server.registerTool("infino_list_tables", {
|
|
266
331
|
title: "List Infino tables",
|
|
332
|
+
annotations: READ_ONLY,
|
|
267
333
|
description: "List the tables in the connected catalog. Call this first to discover what is available to search or query.",
|
|
268
334
|
inputSchema: {},
|
|
269
335
|
}, async () => {
|
|
@@ -276,6 +342,7 @@ server.registerTool("infino_list_tables", {
|
|
|
276
342
|
});
|
|
277
343
|
server.registerTool("infino_describe_table", {
|
|
278
344
|
title: "Describe an Infino table",
|
|
345
|
+
annotations: READ_ONLY,
|
|
279
346
|
description: "Return a table's column names and types — call before searching so you know which column to target and what " +
|
|
280
347
|
"fields each result row carries.",
|
|
281
348
|
inputSchema: {
|
|
@@ -293,6 +360,117 @@ server.registerTool("infino_describe_table", {
|
|
|
293
360
|
return fail(`describe_table failed: ${errText(err)}`);
|
|
294
361
|
}
|
|
295
362
|
});
|
|
363
|
+
// --- catalog management ------------------------------------------------------
|
|
364
|
+
server.registerTool("infino_create_database", {
|
|
365
|
+
title: "Create the database this server is connected to",
|
|
366
|
+
annotations: ADDITIVE_IDEMPOTENT,
|
|
367
|
+
description: "Provision the database named in the connection. On Infino Cloud this registers the database; on a " +
|
|
368
|
+
"local path or bucket the catalog root is the database, so this is a no-op success. Idempotent: an " +
|
|
369
|
+
"existing database is reported as created: false. Call it when a hosted connection answers 404.",
|
|
370
|
+
inputSchema: {},
|
|
371
|
+
}, async () => {
|
|
372
|
+
try {
|
|
373
|
+
db.createDatabase();
|
|
374
|
+
return ok({ created: true });
|
|
375
|
+
}
|
|
376
|
+
catch (err) {
|
|
377
|
+
const e = err;
|
|
378
|
+
if (e?.status === 409)
|
|
379
|
+
return ok({ created: false, note: "database already exists" });
|
|
380
|
+
return fail(`create_database failed: ${errText(err, "create")}`);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
// The scalar column types the binding's schema descriptor accepts. Full-text
|
|
384
|
+
// indexes require large_utf8, which is why the descriptor spells both string
|
|
385
|
+
// widths out instead of offering a single "string".
|
|
386
|
+
const COLUMN_TYPES = ["utf8", "large_utf8", "bool", "int32", "int64", "float32", "float64"];
|
|
387
|
+
// Name of the vector column `vector: true` adds. Fixed so the skill, the
|
|
388
|
+
// searches' column inference, and the tables the server creates all agree.
|
|
389
|
+
const VECTOR_COLUMN = "embedding";
|
|
390
|
+
server.registerTool("infino_create_table", {
|
|
391
|
+
title: "Create an Infino table",
|
|
392
|
+
annotations: ADDITIVE,
|
|
393
|
+
description: "Create a table from a {column: type} descriptor. Full-text (BM25) indexes go on the columns named in " +
|
|
394
|
+
"'fts' (default: every large_utf8 column; the index requires that type). With vector: true the server " +
|
|
395
|
+
"adds an 'embedding' column sized to its embedder and a cosine vector index on it, so semantic and hybrid " +
|
|
396
|
+
"search work and rows added without a vector are embedded from their text. Every column is required in " +
|
|
397
|
+
"every row you add, so declare only columns you will always fill. Give every table a stable key " +
|
|
398
|
+
"column of type utf8 so rows can be replaced or removed later by predicate (e.g. key = 'doc-1'); keep " +
|
|
399
|
+
"utf8 for ids and short labels and large_utf8 for the text to search, so the searches infer the right column.",
|
|
400
|
+
inputSchema: {
|
|
401
|
+
table: z.string().describe("Table name."),
|
|
402
|
+
columns: z
|
|
403
|
+
.record(z.string(), z.enum(COLUMN_TYPES))
|
|
404
|
+
.describe("Columns as {name: type}. large_utf8 for text to search; utf8 for a key, ids, and short labels."),
|
|
405
|
+
fts: z
|
|
406
|
+
.array(z.string())
|
|
407
|
+
.optional()
|
|
408
|
+
.describe("Columns to full-text index. Default: every large_utf8 column. Must be large_utf8."),
|
|
409
|
+
vector: z
|
|
410
|
+
.boolean()
|
|
411
|
+
.optional()
|
|
412
|
+
.describe("Add an 'embedding' vector column sized to the server's embedder, with a cosine index. Default false."),
|
|
413
|
+
},
|
|
414
|
+
}, async ({ table, columns, fts, vector }) => {
|
|
415
|
+
try {
|
|
416
|
+
const descriptor = { ...columns };
|
|
417
|
+
const vectorColumns = [];
|
|
418
|
+
let spec = new IndexSpec();
|
|
419
|
+
if (vector) {
|
|
420
|
+
if (VECTOR_COLUMN in descriptor) {
|
|
421
|
+
return fail(`create_table: '${VECTOR_COLUMN}' is reserved for the vector column that vector: true adds; rename it.`);
|
|
422
|
+
}
|
|
423
|
+
const dim = await embedderDim();
|
|
424
|
+
descriptor[VECTOR_COLUMN] = { vector: dim };
|
|
425
|
+
spec = spec.vector(VECTOR_COLUMN, dim, "cosine");
|
|
426
|
+
vectorColumns.push(VECTOR_COLUMN);
|
|
427
|
+
}
|
|
428
|
+
const ftsColumns = fts ?? Object.entries(columns).filter(([, t]) => t === "large_utf8").map(([n]) => n);
|
|
429
|
+
for (const col of ftsColumns) {
|
|
430
|
+
if (!(col in descriptor))
|
|
431
|
+
return fail(`create_table: fts column '${col}' is not in 'columns'.`);
|
|
432
|
+
if (descriptor[col] !== "large_utf8") {
|
|
433
|
+
return fail(`create_table: fts column '${col}' is ${descriptor[col]}; a full-text index requires large_utf8.`);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
for (const col of ftsColumns)
|
|
437
|
+
spec = spec.fts(col);
|
|
438
|
+
const handle = db.createTable(table, descriptor, spec);
|
|
439
|
+
const schema = handle
|
|
440
|
+
.schema()
|
|
441
|
+
.fields.map((f) => ({ name: f.name, type: String(f.type) }));
|
|
442
|
+
return ok({ table, columns: schema, indexes: { fts: ftsColumns, vector: vectorColumns } });
|
|
443
|
+
}
|
|
444
|
+
catch (err) {
|
|
445
|
+
const e = err;
|
|
446
|
+
if (e?.status === 409 || /already ?exists/i.test(e?.message ?? "")) {
|
|
447
|
+
return fail(`create_table: table '${table}' already exists; inspect it with infino_describe_table.`);
|
|
448
|
+
}
|
|
449
|
+
return fail(`create_table failed: ${errText(err, "create")}`);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
server.registerTool("infino_drop_table", {
|
|
453
|
+
title: "Drop an Infino table",
|
|
454
|
+
annotations: DESTRUCTIVE,
|
|
455
|
+
description: "Drop a table from the catalog and, by default, delete its storage objects too. Pass purge: false to only " +
|
|
456
|
+
"unregister the table and leave the bytes in place. Irreversible.",
|
|
457
|
+
inputSchema: {
|
|
458
|
+
table: z.string().describe("Table to drop."),
|
|
459
|
+
purge: z
|
|
460
|
+
.boolean()
|
|
461
|
+
.optional()
|
|
462
|
+
.describe("Also delete the table's storage objects. Default true; false only unregisters the name."),
|
|
463
|
+
},
|
|
464
|
+
}, async ({ table, purge }) => {
|
|
465
|
+
try {
|
|
466
|
+
const reclaim = purge ?? true;
|
|
467
|
+
db.dropTable(table, reclaim);
|
|
468
|
+
return ok({ table, dropped: true, purged: reclaim });
|
|
469
|
+
}
|
|
470
|
+
catch (err) {
|
|
471
|
+
return fail(`drop_table failed: ${errText(err, "write")}`);
|
|
472
|
+
}
|
|
473
|
+
});
|
|
296
474
|
// Build the returned-column projection for a search hit. A caller-supplied
|
|
297
475
|
// `columns` list is honored so clients can retrieve the fields they need
|
|
298
476
|
// (e.g. a path + line range to cite), with `_id` and `score` always appended
|
|
@@ -312,6 +490,7 @@ const SCORE_KIND = {
|
|
|
312
490
|
};
|
|
313
491
|
server.registerTool("infino_semantic_search", {
|
|
314
492
|
title: "Semantic (vector) search",
|
|
493
|
+
annotations: READ_ONLY,
|
|
315
494
|
description: "Use when searching for a concept by meaning and the exact wording is unknown — this retrieves paraphrases and " +
|
|
316
495
|
"synonyms, not just literal matches. Embeds the query with a local model (no API key) and ranks a table's " +
|
|
317
496
|
"embedding column by vector similarity. Each hit carries a score that is a DISTANCE (lower is closer) plus the " +
|
|
@@ -348,6 +527,7 @@ server.registerTool("infino_semantic_search", {
|
|
|
348
527
|
if (!vecCol)
|
|
349
528
|
return fail(`semantic_search: no vector column in '${table}' — pass 'vectorColumn'.`);
|
|
350
529
|
const textCol = column ?? inferTextColumn(handle);
|
|
530
|
+
await assertVectorWidth(handle, table, vecCol);
|
|
351
531
|
const vector = await embed(query);
|
|
352
532
|
const projection = searchProjection(columns, textCol);
|
|
353
533
|
const { value: results, tookMs } = timed(() => handle.vectorSearch(vecCol, vector, k, { projection, filter }));
|
|
@@ -365,6 +545,7 @@ server.registerTool("infino_semantic_search", {
|
|
|
365
545
|
});
|
|
366
546
|
server.registerTool("infino_keyword_search", {
|
|
367
547
|
title: "Keyword (BM25) search",
|
|
548
|
+
annotations: READ_ONLY,
|
|
368
549
|
description: "Use when the query is literal terms — identifiers, error codes, product names, exact phrases — and you want " +
|
|
369
550
|
"results ranked by relevance. BM25 full-text search over a text column: ranks rows by how well the query's " +
|
|
370
551
|
"tokens (and their stems) match, each with a relevance score (higher is better) plus the columns you project " +
|
|
@@ -379,19 +560,27 @@ server.registerTool("infino_keyword_search", {
|
|
|
379
560
|
.string()
|
|
380
561
|
.optional()
|
|
381
562
|
.describe("Text column to search; inferred from the table schema when omitted."),
|
|
563
|
+
mode: z
|
|
564
|
+
.enum(["or", "and"])
|
|
565
|
+
.optional()
|
|
566
|
+
.describe("Match any query token ('or', the default) or require every token ('and')."),
|
|
567
|
+
stats: z
|
|
568
|
+
.enum(["per_superfile", "global"])
|
|
569
|
+
.optional()
|
|
570
|
+
.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
571
|
columns: z
|
|
383
572
|
.array(z.string())
|
|
384
573
|
.optional()
|
|
385
574
|
.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
575
|
},
|
|
387
|
-
}, async ({ table, query, k, column, columns }) => {
|
|
576
|
+
}, async ({ table, query, k, column, mode, stats, columns }) => {
|
|
388
577
|
try {
|
|
389
578
|
const handle = db.openTable(table);
|
|
390
579
|
const col = column ?? inferTextColumn(handle);
|
|
391
580
|
if (!col) {
|
|
392
581
|
return fail(`keyword_search: no text column found in '${table}' — pass 'column' explicitly.`);
|
|
393
582
|
}
|
|
394
|
-
const { value: results, tookMs } = timed(() => handle.bm25Search(col, query, k, { projection: searchProjection(columns, col) }));
|
|
583
|
+
const { value: results, tookMs } = timed(() => handle.bm25Search(col, query, k, { mode, stats, projection: searchProjection(columns, col) }));
|
|
395
584
|
return ok({
|
|
396
585
|
table,
|
|
397
586
|
column: col,
|
|
@@ -407,6 +596,7 @@ server.registerTool("infino_keyword_search", {
|
|
|
407
596
|
});
|
|
408
597
|
server.registerTool("infino_hybrid_search", {
|
|
409
598
|
title: "Hybrid (keyword + semantic) search",
|
|
599
|
+
annotations: READ_ONLY,
|
|
410
600
|
description: "Use when a query carries both specific terms and an intent — you want exact-term precision without giving up " +
|
|
411
601
|
"paraphrase recall. Fuses BM25 over a text column with vector similarity over the embedding column in a single " +
|
|
412
602
|
"ranking pass, so rows matching the literal terms AND the meaning rank highest; the score is the fused rank " +
|
|
@@ -418,12 +608,16 @@ server.registerTool("infino_hybrid_search", {
|
|
|
418
608
|
k: z.number().int().positive().max(100).default(10).describe("Maximum results."),
|
|
419
609
|
column: z.string().optional().describe("Text column for the keyword half; inferred if omitted."),
|
|
420
610
|
vectorColumn: z.string().optional().describe("Vector column for the semantic half; inferred if omitted."),
|
|
611
|
+
mode: z
|
|
612
|
+
.enum(["or", "and"])
|
|
613
|
+
.optional()
|
|
614
|
+
.describe("Keyword half: match any query token ('or', the default) or require every token ('and')."),
|
|
421
615
|
columns: z
|
|
422
616
|
.array(z.string())
|
|
423
617
|
.optional()
|
|
424
618
|
.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
619
|
},
|
|
426
|
-
}, async ({ table, query, k, column, vectorColumn, columns }) => {
|
|
620
|
+
}, async ({ table, query, k, column, vectorColumn, mode, columns }) => {
|
|
427
621
|
try {
|
|
428
622
|
const handle = db.openTable(table);
|
|
429
623
|
const textCol = column ?? inferTextColumn(handle);
|
|
@@ -432,8 +626,10 @@ server.registerTool("infino_hybrid_search", {
|
|
|
432
626
|
const vecCol = vectorColumn ?? inferVectorColumn(handle);
|
|
433
627
|
if (!vecCol)
|
|
434
628
|
return fail(`hybrid_search: no vector column in '${table}' — pass 'vectorColumn'.`);
|
|
629
|
+
await assertVectorWidth(handle, table, vecCol);
|
|
435
630
|
const vector = await embed(query);
|
|
436
631
|
const { value: results, tookMs } = timed(() => handle.hybridSearch(textCol, query, vecCol, vector, k, {
|
|
632
|
+
mode,
|
|
437
633
|
projection: searchProjection(columns, textCol),
|
|
438
634
|
}));
|
|
439
635
|
return ok({
|
|
@@ -450,6 +646,7 @@ server.registerTool("infino_hybrid_search", {
|
|
|
450
646
|
});
|
|
451
647
|
server.registerTool("infino_token_match", {
|
|
452
648
|
title: "Token match (unranked keyword filter)",
|
|
649
|
+
annotations: READ_ONLY,
|
|
453
650
|
description: "Use when you need the SET of rows containing a keyword, not a ranked order — a fast unranked keyword filter. " +
|
|
454
651
|
"Returns rows whose text column contains the token(s), matching indexed tokens and their stems. For ranked " +
|
|
455
652
|
"results use infino_keyword_search; for analytical filtering across columns use infino_sql.",
|
|
@@ -484,6 +681,7 @@ server.registerTool("infino_token_match", {
|
|
|
484
681
|
});
|
|
485
682
|
server.registerTool("infino_exact_match", {
|
|
486
683
|
title: "Exact match (unranked exact filter)",
|
|
684
|
+
annotations: READ_ONLY,
|
|
487
685
|
description: "Use to fetch rows whose column exactly equals a value — a tag, status, or id string. Unranked exact-equality " +
|
|
488
686
|
"filter over an indexed column. For ranked text relevance use infino_keyword_search; for multi-column " +
|
|
489
687
|
"analytical filtering use infino_sql.",
|
|
@@ -514,6 +712,7 @@ server.registerTool("infino_exact_match", {
|
|
|
514
712
|
});
|
|
515
713
|
server.registerTool("infino_count", {
|
|
516
714
|
title: "Count keyword matches",
|
|
715
|
+
annotations: READ_ONLY,
|
|
517
716
|
description: "Use when you only need HOW MANY rows match a keyword query, not the rows themselves — a fast tally over a text " +
|
|
518
717
|
"column, without fetching or ranking. Cheaper than infino_keyword_search when a number is all you need (e.g. " +
|
|
519
718
|
"'how many docs mention X'). For the matching rows use infino_keyword_search or infino_token_match.",
|
|
@@ -545,6 +744,7 @@ server.registerTool("infino_count", {
|
|
|
545
744
|
});
|
|
546
745
|
server.registerTool("infino_sql", {
|
|
547
746
|
title: "SQL over Infino",
|
|
747
|
+
annotations: DESTRUCTIVE,
|
|
548
748
|
description: "Use for structural or analytical questions — counts, GROUP BY, joins, aggregates, filtering by column value — " +
|
|
549
749
|
"returning result rows. The engine's search functions are callable as table-valued relations, so a single query " +
|
|
550
750
|
"can rank AND aggregate: bm25_search('table','text_col','terms', k) — also bm25_search_prefix / token_match / " +
|
|
@@ -553,15 +753,9 @@ server.registerTool("infino_sql", {
|
|
|
553
753
|
"where the vector goes and pass embed:{\"name\":\"query text\"} — the server embeds the text and substitutes the " +
|
|
554
754
|
"vector in. Example: SELECT path, SUM(end_line - start_line + 1) AS lines FROM " +
|
|
555
755
|
"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."),
|
|
756
|
+
"Any single statement is allowed, DDL/DML included.",
|
|
559
757
|
inputSchema: {
|
|
560
|
-
query:
|
|
561
|
-
? z.string().describe("A single SQL statement. May use search TVFs and {{name}} vector placeholders.")
|
|
562
|
-
: z
|
|
563
|
-
.string()
|
|
564
|
-
.describe("A single read-only SELECT or WITH statement. May use search TVFs and {{name}} vector placeholders."),
|
|
758
|
+
query: z.string().describe("A single SQL statement. May use search TVFs and {{name}} vector placeholders."),
|
|
565
759
|
embed: z
|
|
566
760
|
.record(z.string(), z.string())
|
|
567
761
|
.optional()
|
|
@@ -572,90 +766,95 @@ server.registerTool("infino_sql", {
|
|
|
572
766
|
}, async ({ query, embed: embeds }) => {
|
|
573
767
|
try {
|
|
574
768
|
const sql = await applyEmbeds(query, embeds);
|
|
575
|
-
const { value: rows, tookMs } = timed(() => db.querySql(guardSql(sql
|
|
769
|
+
const { value: rows, tookMs } = timed(() => db.querySql(guardSql(sql)));
|
|
576
770
|
return ok({ rows, took_ms: tookMs });
|
|
577
771
|
}
|
|
578
772
|
catch (err) {
|
|
579
773
|
return fail(`sql failed: ${errText(err)}`);
|
|
580
774
|
}
|
|
581
775
|
});
|
|
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
|
-
}
|
|
776
|
+
// --- document writes ---------------------------------------------------------
|
|
777
|
+
server.registerTool("infino_add_documents", {
|
|
778
|
+
title: "Add documents to an Infino table",
|
|
779
|
+
annotations: ADDITIVE,
|
|
780
|
+
description: "Append documents (rows, as JSON objects keyed by column name) to a table; one call is one commit. " +
|
|
781
|
+
"If the table has a vector index and a document omits the vector, the server embeds its text column " +
|
|
782
|
+
"(a local model, no API key). Send tens of rows per call; for a whole corpus use the infino CLI or an SDK.",
|
|
783
|
+
inputSchema: {
|
|
784
|
+
table: z.string().describe("Table to append to."),
|
|
785
|
+
documents: z
|
|
786
|
+
.array(z.record(z.string(), z.any()))
|
|
787
|
+
.min(1)
|
|
788
|
+
.describe("Rows to append, as JSON objects keyed by column name."),
|
|
789
|
+
},
|
|
790
|
+
}, async ({ table, documents }) => {
|
|
791
|
+
try {
|
|
792
|
+
const handle = db.openTable(table);
|
|
793
|
+
const { rows, embedded } = await prepareRows(handle, table, documents);
|
|
794
|
+
const { tookMs } = timed(() => handle.append(rows));
|
|
795
|
+
return ok({
|
|
796
|
+
table,
|
|
797
|
+
appended: rows.length,
|
|
798
|
+
embedded,
|
|
799
|
+
took_ms: tookMs,
|
|
800
|
+
verify: `infino_count or a search on '${table}' shows the new rows`,
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
catch (err) {
|
|
804
|
+
return fail(`add_documents failed: ${errText(err, "write")}`);
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
server.registerTool("infino_update_documents", {
|
|
808
|
+
title: "Update documents in an Infino table",
|
|
809
|
+
annotations: DESTRUCTIVE,
|
|
810
|
+
description: "Replace the rows matching a SQL predicate with new documents, 1:1; the number of matched rows must equal " +
|
|
811
|
+
"the number of replacement documents. As with add, a row that omits its vector has it embedded from the text " +
|
|
812
|
+
"column (local model, no API key). Requires durable storage (not memory://).",
|
|
813
|
+
inputSchema: {
|
|
814
|
+
table: z.string().describe("Table to update."),
|
|
815
|
+
predicate: z
|
|
816
|
+
.string()
|
|
817
|
+
.describe("SQL predicate selecting the rows to replace, e.g. \"status = 'draft'\"."),
|
|
818
|
+
documents: z
|
|
819
|
+
.array(z.record(z.string(), z.any()))
|
|
820
|
+
.min(1)
|
|
821
|
+
.describe("Replacement rows, as JSON objects keyed by column name (one per matched row)."),
|
|
822
|
+
},
|
|
823
|
+
}, async ({ table, predicate, documents }) => {
|
|
824
|
+
try {
|
|
825
|
+
const handle = db.openTable(table);
|
|
826
|
+
const { rows, embedded } = await prepareRows(handle, table, documents);
|
|
827
|
+
const stats = handle.update(predicate, rows);
|
|
828
|
+
return ok({ table, predicate, ...stats, embedded });
|
|
829
|
+
}
|
|
830
|
+
catch (err) {
|
|
831
|
+
return fail(`update_documents failed: ${errText(err, "write")}`);
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
server.registerTool("infino_delete_documents", {
|
|
835
|
+
title: "Delete documents from an Infino table",
|
|
836
|
+
annotations: DESTRUCTIVE,
|
|
837
|
+
description: "Delete the rows matching a SQL predicate, e.g. \"status = 'spam'\". Returns how many rows matched and were " +
|
|
838
|
+
"removed. Check the predicate first with infino_count or infino_sql. Requires durable storage (not memory://).",
|
|
839
|
+
inputSchema: {
|
|
840
|
+
table: z.string().describe("Table to delete from."),
|
|
841
|
+
predicate: z
|
|
842
|
+
.string()
|
|
843
|
+
.describe("SQL predicate selecting the rows to delete, e.g. \"status = 'spam'\"."),
|
|
844
|
+
},
|
|
845
|
+
}, async ({ table, predicate }) => {
|
|
846
|
+
try {
|
|
847
|
+
const stats = db.openTable(table).delete(predicate);
|
|
848
|
+
return ok({ table, predicate, ...stats });
|
|
849
|
+
}
|
|
850
|
+
catch (err) {
|
|
851
|
+
return fail(`delete_documents failed: ${errText(err, "write")}`);
|
|
852
|
+
}
|
|
853
|
+
});
|
|
655
854
|
// --- transport -------------------------------------------------------------
|
|
656
855
|
// stdio for desktop/CLI clients (Claude Desktop/Code, Cursor). Logs go to
|
|
657
856
|
// stderr so they never corrupt the JSON-RPC stream on stdout.
|
|
658
857
|
const transport = new StdioServerTransport();
|
|
659
858
|
await server.connect(transport);
|
|
660
859
|
console.error(`infino MCP server ready on stdio (uri: ${uri}, mode: ${isHosted ? "hosted" : "embedded"}, ` +
|
|
661
|
-
`
|
|
860
|
+
`embedder: ${embedderInfo()})`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infino-ai/mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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",
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@huggingface/transformers": "^4.2.0",
|
|
54
|
-
"@infino-ai/infino": "^0.5.
|
|
54
|
+
"@infino-ai/infino": "^0.5.8",
|
|
55
55
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
56
|
-
"zod": "^4.
|
|
56
|
+
"zod": "^4.5.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/node": "^26",
|