remove
Delete data from a specified collection in UniCloudDB-MCP using JQL query conditions. Execute precise removal operations with standardized database interfaces.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | 集合名称 | |
| where | Yes | 查询条件 (JQL格式) |
Implementation Reference
- database.js:308-322 (handler)The main handler function for the 'remove' MCP tool. It destructures the input parameters, calls the removeFromDatabase helper, and formats the response as MCP content or error.async function handleRemoveTool(params, dbUrl) { const { collection, where } = params; try { const result = await removeFromDatabase(collection, where, dbUrl); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; } catch (error) { return { content: [{ type: 'text', text: error.message }], isError: true, }; } }
- database.js:183-219 (helper)Core helper function that performs the actual database removal by sending a POST request to the uniCloud DB service with JQL delete operation.async function removeFromDatabase(collection, where, dbUrl = DEFAULT_DB_URL) { try { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT); // 使用传入的dbUrl或默认URL const targetUrl = dbUrl || DEFAULT_DB_URL; // console.log('删除操作使用URL:', targetUrl); const response = await fetch(targetUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ operation: { collection, action: 'delete', where, }, }), signal: controller.signal, }); clearTimeout(timeoutId); const result = await response.json(); if (result.code !== 0) { throw new Error(result.msg || '删除失败'); } return result.data; } catch (error) { if (error.name === 'AbortError') { throw new Error(`删除超时: 请求超过${REQUEST_TIMEOUT}毫秒`); } throw new Error(`删除错误: ${error.message}`); } }
- database.js:414-421 (schema)Tool definition object including the Zod schema for input parameters (collection and where condition in JQL format). This is returned by getToolDefinitions.removeTool: { name: 'remove', params: { collection: z.string().describe('集合名称'), where: z.record(z.any()).describe('查询条件 (JQL格式)'), }, handler: (params) => handleRemoveTool(params, dbServiceUrl), },
- index.js:52-56 (registration)Registration of the 'remove' tool with the MCP server using the definition from database.js.server.tool( tools.removeTool.name, tools.removeTool.params, tools.removeTool.handler );