get_database_info
Retrieve local database statistics from the SWLC MCP Server to access and analyze lottery information, including winning numbers for games like Double Color Ball and Seven Happiness Lottery.
Instructions
获取本地数据库统计信息
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/swlc_mcp/server.py:1225-1251 (handler)MCP tool handler implementation for 'get_database_info' that retrieves database stats via the helper method and returns formatted text content.elif name == "get_database_info": try: info = lottery_service.db.get_database_info() text_lines = ["本地数据库统计信息:\n"] # 各表记录数 text_lines.append("各彩票类型记录数:") for table, count in info.items(): if table != 'last_sync': lottery_name = { 'ssq_results': '双色球', 'fucai3d_results': '福彩3D', 'qilecai_results': '七乐彩', 'kuaile8_results': '快乐8' }.get(table, table) text_lines.append(f"- {lottery_name}: {count}期") # 最新同步时间 if 'last_sync' in info and info['last_sync']: text_lines.append("\n最新同步时间:") for lottery_type, sync_time in info['last_sync'].items(): text_lines.append(f"- {lottery_type}: {sync_time}") return [types.TextContent(type="text", text="\n".join(text_lines))] except Exception as e: return [types.TextContent(type="text", text=f"获取数据库信息失败:{str(e)}")]
- src/swlc_mcp/server.py:1049-1056 (registration)Tool registration in the MCP server's list_tools() method, defining name, description, and empty input schema.name="get_database_info", description="获取本地数据库统计信息", inputSchema={ "type": "object", "properties": {}, "required": [] } )
- src/swlc_mcp/database.py:518-546 (helper)Core helper method in LotteryDatabase class that queries SQLite for record counts across lottery tables and last sync times.def get_database_info(self) -> Dict[str, Any]: """获取数据库统计信息""" try: with sqlite3.connect(self.db_path) as conn: cursor = conn.cursor() info = {} # 统计各表记录数 tables = ['ssq_results', 'fucai3d_results', 'qilecai_results', 'kuaile8_results'] for table in tables: cursor.execute(f"SELECT COUNT(*) FROM {table}") count = cursor.fetchone()[0] info[table] = count # 获取最新同步时间 cursor.execute(""" SELECT lottery_type, MAX(sync_date) FROM sync_logs GROUP BY lottery_type """) sync_info = {row[0]: row[1] for row in cursor.fetchall()} info['last_sync'] = sync_info return info except Exception as e: logger.error(f"获取数据库信息失败: {e}") return {}