fix(mcp): pass request database to backend

This commit is contained in:
t8y2 committed 2026-05-20 11:09:54 +08:00
1 parent bd727c32d0
commit 8d041b438b
2 files changed
+36 -8

No files matched your search

+20
View File
@@ -33,3 +33,23 @@ test("creates an MCP server without starting stdio transport", () => {
assert.equal(typeof server.connect, "function");
});
test("execute query scopes the connection to the requested database", async () => {
let usedDatabase = "";
const scopedBackend: Backend = {
...backend,
executeQuery: async (config) => {
usedDatabase = config.database || "";
return { columns: ["total"], rows: [{ total: 1 }], row_count: 1 };
},
};
const server = createDbxMcpServer(scopedBackend, { isWebMode: true });
await (server as any)._registeredTools.dbx_execute_query.handler({
connection_name: "local",
database: "stores_demo",
sql: "SELECT FIRST 1 tabname FROM systables",
});
assert.equal(usedDatabase, "stores_demo");
});