UNPKG

mira-app-server

Version:

Mira Server - standalone server application using mira-app-core

66 lines 2.65 kB
"use strict"; /** * database 模块工具 * * 服务端的数据库路由都需要 libraryId 查询参数(每个素材库独立 SQLite DB), * 这里通过 HttpClient 直接拼查询串调用。 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.registerDatabaseTools = registerDatabaseTools; const zod_1 = require("zod"); const helpers_1 = require("../helpers"); function registerDatabaseTools(mcp, ctx) { mcp.registerTool('db_tables', { description: '列出素材库的所有数据表(名称+行数)', inputSchema: { libraryId: zod_1.z.string() }, }, async (args) => { return (0, helpers_1.run)(async () => { const client = ctx.getClient(); return await client .getHttpClient() .get(`/api/database/tables?libraryId=${encodeURIComponent(args.libraryId)}`); }); }); mcp.registerTool('db_schema', { description: '查看指定表的列结构', inputSchema: { libraryId: zod_1.z.string(), table: zod_1.z.string().describe('表名'), }, }, async (args) => { return (0, helpers_1.run)(async () => { const client = ctx.getClient(); return await client .getHttpClient() .get(`/api/database/tables/${encodeURIComponent(args.table)}/schema?libraryId=${encodeURIComponent(args.libraryId)}`); }); }); mcp.registerTool('db_data', { description: '查看指定表的行数据', inputSchema: { libraryId: zod_1.z.string(), table: zod_1.z.string(), limit: zod_1.z.number().optional().describe('限制返回行数'), }, }, async (args) => { return (0, helpers_1.run)(async () => { const client = ctx.getClient(); const data = await client .getHttpClient() .get(`/api/database/tables/${encodeURIComponent(args.table)}/data?libraryId=${encodeURIComponent(args.libraryId)}`); return args.limit ? data.slice(0, args.limit) : data; }); }); mcp.registerTool('db_info', { description: '查看素材库所有表的基本信息(名称+行数)', inputSchema: { libraryId: zod_1.z.string() }, }, async (args) => { return (0, helpers_1.run)(async () => { const client = ctx.getClient(); return await client .getHttpClient() .get(`/api/database/tables?libraryId=${encodeURIComponent(args.libraryId)}`); }); }); } //# sourceMappingURL=database.js.map