csmar_query_count
Count records in a CSMAR database table that satisfy specified conditions including columns, time range, and custom query criteria.
Instructions
查询满足条件的记录数量
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | 表名称 | |
| columns | No | 字段列表 | |
| condition | No | 查询条件 | |
| start_time | No | 开始时间 | |
| end_time | No | 结束时间 |
Implementation Reference
- src/index.js:549-556 (schema)Input schema definition for csmar_query_count tool, describing the required table_name and optional columns, condition, start_time, end_time parameters.
description: '查询满足条件的记录数量', inputSchema: { table_name: z.string().describe('表名称'), columns: z.array(z.string()).optional().describe('字段列表'), condition: z.string().optional().describe('查询条件'), start_time: z.string().optional().describe('开始时间'), end_time: z.string().optional().describe('结束时间'), }, - src/index.js:546-572 (registration)Registration of the 'csmar_query_count' tool with the MCP server, including description, input schema, and handler.
server.registerTool( 'csmar_query_count', { description: '查询满足条件的记录数量', inputSchema: { table_name: z.string().describe('表名称'), columns: z.array(z.string()).optional().describe('字段列表'), condition: z.string().optional().describe('查询条件'), start_time: z.string().optional().describe('开始时间'), end_time: z.string().optional().describe('结束时间'), }, }, async ({ table_name, columns = [], condition = '', start_time, end_time }) => { try { const loginResult = await ensureLogin(); if (!loginResult.success) { return { content: [{ type: 'text', text: JSON.stringify(loginResult, null, 2) }], isError: true }; } const client = await initPythonClient(); const result = await client.call('query_count', { table_name, columns, condition, start_time, end_time }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `查询数量错误: ${error.message}` }], isError: true }; } } ); - src/index.js:558-571 (handler)Handler function for csmar_query_count that ensures login, initializes the Python client, and calls 'query_count' action on the Python client.
async ({ table_name, columns = [], condition = '', start_time, end_time }) => { try { const loginResult = await ensureLogin(); if (!loginResult.success) { return { content: [{ type: 'text', text: JSON.stringify(loginResult, null, 2) }], isError: true }; } const client = await initPythonClient(); const result = await client.call('query_count', { table_name, columns, condition, start_time, end_time }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `查询数量错误: ${error.message}` }], isError: true }; } } - src/python_client.py:266-282 (helper)Python helper method 'query_count' on CSMARClient that calls the CSMAR SDK's queryCount method and returns the result.
def query_count(self, columns: list, condition: str, table_name: str, start_time: Optional[str] = None, end_time: Optional[str] = None) -> Dict[str, Any]: try: csmar = self._ensure_csmar() count = csmar.queryCount(columns, condition, table_name, start_time, end_time) return {"success": True, "table": table_name, "count": int(count) if count else 0} except Exception as e: return {"success": False, "error": f"查询数量失败: {str(e)}"} def query(self, columns: list, condition: str, table_name: str, start_time: Optional[str] = None, end_time: Optional[str] = None, format: str = "json", limit: Optional[int] = None) -> Dict[str, Any]: try: csmar = self._ensure_csmar() if format == "dataframe": data = csmar.query_df(columns, condition, table_name, start_time, end_time) result = data.to_dict('records') if hasattr(data, 'to_dict') else data - src/python_client.py:320-323 (helper)Command dispatch registration mapping the 'query_count' action string to the Python client's query_count method.
"query_count": lambda: client.query_count( params.get("columns", []), params.get("condition", ""), params.get("table_name", ""), params.get("start_time"), params.get("end_time") ),