csmar_list_fields
Retrieve all field names from a specified table in CSMAR financial databases, enabling analysis of table structure.
Instructions
列出指定表中的所有字段
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | 表名称 |
Implementation Reference
- src/index.js:464-487 (registration)Registration of the 'csmar_list_fields' tool with the MCP server. Defines the tool name, description, input schema (table_name), and the async handler that calls initPythonClient() and client.call('list_fields', ...).
// 5. 列出字段 server.registerTool( 'csmar_list_fields', { description: '列出指定表中的所有字段', inputSchema: { table_name: z.string().describe('表名称'), }, }, async ({ table_name }) => { 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('list_fields', { table_name }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `获取字段列表错误: ${error.message}` }], isError: true }; } } ); - src/index.js:473-486 (handler)The handler function for 'csmar_list_fields'. It ensures login, initializes the Python client, calls the 'list_fields' action with the table_name parameter, and returns the result as text content.
async ({ table_name }) => { 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('list_fields', { table_name }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `获取字段列表错误: ${error.message}` }], isError: true }; } } - src/index.js:467-472 (schema)Input schema for 'csmar_list_fields' tool. Defines 'table_name' as a required string parameter using Zod validation.
{ description: '列出指定表中的所有字段', inputSchema: { table_name: z.string().describe('表名称'), }, }, - src/python_client.py:255-264 (helper)Python-side handler: CSMARClient.get_list_fields() method. Calls csmar.getListFields(table_name) from the CSMAR SDK, wraps the result in a dict with success status and field list.
def get_list_fields(self, table_name: str) -> Dict[str, Any]: try: csmar = self._ensure_csmar() fields = csmar.getListFields(table_name) if fields is None: return {"success": False, "error": "字段列表为空", "table": table_name, "fields": [], "count": 0} field_list = list(fields) if hasattr(fields, '__iter__') else [str(fields)] return {"success": True, "table": table_name, "fields": field_list, "count": len(field_list)} except Exception as e: return {"success": False, "error": f"获取字段列表失败: {str(e)}"} - src/python_client.py:309-343 (helper)Command dispatcher: handle_command() routes the 'list_fields' action to client.get_list_fields(params.get('table_name', '')).
def handle_command(command: Dict[str, Any], client: CSMARClient) -> Dict[str, Any]: action = command.get("action") params = command.get("params", {}) handlers = { "login": lambda: client.login( params.get("account", ""), params.get("pwd", ""), params.get("lang", "0") ), "list_databases": lambda: client.get_list_dbs(), "list_tables": lambda: client.get_list_tables(params.get("database_name", "")), "list_fields": lambda: client.get_list_fields(params.get("table_name", "")), "query_count": lambda: client.query_count( params.get("columns", []), params.get("condition", ""), params.get("table_name", ""), params.get("start_time"), params.get("end_time") ), "query": lambda: client.query( params.get("columns", []), params.get("condition", ""), params.get("table_name", ""), params.get("start_time"), params.get("end_time"), params.get("format", "json"), params.get("limit") ), "preview": lambda: client.preview(params.get("table_name", "")), "check_availability": lambda: { "success": True, "csmar_available": CSMAR_AVAILABLE, "client_logged_in": client.logged_in, "username": client.username, "sdk_error": _sdk_error if not CSMAR_AVAILABLE else None }, "reset": lambda: client.reset() or {"success": True, "message": "已重置"} } handler = handlers.get(action) if handler: return handler() return {"success": False, "error": f"未知动作: {action}", "supported_actions": list(handlers.keys())}