feat: support H2 file connections

This commit is contained in:
t8y2 committed 2026-06-08 20:09:27 +08:00
1 parent 7a2ed233be
commit 9dfc2ba294
19 files changed
+499 -66

No files matched your search

+47 -3
View File
@@ -138,8 +138,22 @@ test("mongodb describe table returns inferred document fields", async () => {
...backend,
findConnection: async () => mongoConnection,
describeTable: async () => [
{ name: "_id", data_type: "object", is_nullable: false, column_default: null, is_primary_key: true, comment: null },
{ name: "name", data_type: "string", is_nullable: false, column_default: null, is_primary_key: false, comment: null },
{
name: "_id",
data_type: "object",
is_nullable: false,
column_default: null,
is_primary_key: true,
comment: null,
},
{
name: "name",
data_type: "string",
is_nullable: false,
column_default: null,
is_primary_key: false,
comment: null,
},
],
};
const server = createDbxMcpServer(scopedBackend, { isWebMode: true });
@@ -159,7 +173,11 @@ test("mongodb execute query formats shell-style find results", async () => {
const scopedBackend: Backend = {
...backend,
findConnection: async () => mongoConnection,
executeQuery: async () => ({ columns: ["_id", "meta", "missing"], rows: [{ _id: "1", meta: { name: "demo" }, missing: null }], row_count: 1 }),
executeQuery: async () => ({
columns: ["_id", "meta", "missing"],
rows: [{ _id: "1", meta: { name: "demo" }, missing: null }],
row_count: 1,
}),
};
const server = createDbxMcpServer(scopedBackend, { isWebMode: true });
@@ -186,6 +204,32 @@ test("connection lookup failures include a stable MCP error code", async () => {
assert.match(result.content[0].text, /missing/);
});
test("add connection accepts H2 file paths without a port", async () => {
let added: Omit<ConnectionConfig, "id"> | undefined;
const scopedBackend: Backend = {
...backend,
findConnection: async () => undefined,
addConnection: async (config) => {
added = config;
return { id: "h2-file", ...config };
},
};
const server = createDbxMcpServer(scopedBackend, { isWebMode: true });
const result = await (server as any)._registeredTools.dbx_add_connection.handler({
name: "h2-local",
db_type: "h2",
host: "/data/app.mv.db",
username: "sa",
password: "",
});
assert.equal(result.isError, undefined);
assert.equal(added?.db_type, "h2");
assert.equal(added?.host, "/data/app.mv.db");
assert.equal(added?.port, 0);
});
test("SQL safety failures include a stable MCP error code", async () => {
const server = createDbxMcpServer(backend, { isWebMode: true });