(params: DatabaseQueryParams)
| 20 | |
| 21 | // 执行数据库查询的函数 |
| 22 | export async function executeDatabaseQuery(params: DatabaseQueryParams): Promise<DatabaseQueryResult> { |
| 23 | try { |
| 24 | const { stmt, limit, offset } = params; |
| 25 | |
| 26 | // 构建查询语句(如果需要分页) |
| 27 | let queryStmt = stmt.trim(); |
| 28 | if (limit !== undefined) { |
| 29 | queryStmt += ` LIMIT ${limit}`; |
| 30 | } |
| 31 | if (offset !== undefined) { |
| 32 | queryStmt += ` OFFSET ${offset}`; |
| 33 | } |
| 34 | |
| 35 | const result = await makeSiYuanRequest<DatabaseQueryResult>({ |
| 36 | endpoint: 'query/sql', |
| 37 | data: { stmt: queryStmt }, |
| 38 | }); |
| 39 | |
| 40 | return result; |
| 41 | } catch (error) { |
| 42 | logger.error('Database query execution failed', { stmt: params.stmt, error }); |
| 43 | throw error; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // 注册数据库查询工具 |
| 48 | export function registerDatabaseQueryTool(server: McpServer) { |
no test coverage detected