get_database_info
Retrieve local database statistics for Shanghai lottery games including Double Color Ball, 3D Lottery, and Seven Happiness Lottery to support winning number analysis and queries.
Instructions
获取本地数据库统计信息
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/swlc_mcp/server.py:1469-1495 (handler)MCP tool handler implementation for 'get_database_info'. Retrieves database information using lottery_service.db.get_database_info(), formats the record counts and last sync times into a text response.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:1207-1215 (schema)Input schema definition for the 'get_database_info' tool in the list_tools() method, which registers the tool with MCP server. No input parameters required.types.Tool( 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 the SQLite database for record counts in lottery result tables and last sync times from sync_logs table.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 {}
- src/swlc_mcp/server.py:1028-1280 (registration)The list_tools() method decorated with @server.list_tools() registers all MCP tools including 'get_database_info' by returning the list of Tool objects with schemas.@server.list_tools() async def list_tools() -> List[types.Tool]: """列出所有可用工具""" return [ types.Tool( name="get_latest_ssq", description="获取双色球最新开奖结果", inputSchema={ "type": "object", "properties": {}, "required": [] } ), types.Tool( name="get_latest_3d", description="获取福彩3D最新开奖结果", inputSchema={ "type": "object", "properties": {}, "required": [] } ), types.Tool( name="get_latest_qlc", description="获取七乐彩最新开奖结果", inputSchema={ "type": "object", "properties": {}, "required": [] } ), types.Tool( name="get_latest_kl8", description="获取快乐8最新开奖结果", inputSchema={ "type": "object", "properties": {}, "required": [] } ), types.Tool( name="get_historical_data", description="获取指定彩票类型的历史开奖数据", inputSchema={ "type": "object", "properties": { "lottery_type": { "type": "string", "enum": ["双色球", "福彩3D", "七乐彩", "快乐8"], "description": "彩票类型" }, "periods": { "type": "integer", "minimum": 1, "maximum": 1000, "default": 10, "description": "获取期数" } }, "required": ["lottery_type"] } ), types.Tool( name="analyze_numbers", description="分析彩票号码统计信息,包括热号、冷号等", inputSchema={ "type": "object", "properties": { "lottery_type": { "type": "string", "enum": ["双色球", "福彩3D", "七乐彩", "快乐8"], "description": "彩票类型" }, "periods": { "type": "integer", "minimum": 5, "maximum": 1000, "default": 30, "description": "分析期数" } }, "required": ["lottery_type"] } ), types.Tool( name="analyze_seq_numbers", description="分析号码连续出现概率(滑窗),返回理论值与实测值", inputSchema={ "type": "object", "properties": { "lottery_type": { "type": "string", "enum": ["双色球", "福彩3D", "七乐彩", "快乐8"], "description": "彩票类型" }, "periods": { "type": "integer", "minimum": 5, "maximum": 1000, "default": 100, "description": "分析期数" }, "sequence_length": { "type": "integer", "minimum": 1, "maximum": 10, "default": 2, "description": "连续期数" } }, "required": ["lottery_type"] } ), types.Tool( name="generate_random_numbers", description="生成随机彩票号码推荐", inputSchema={ "type": "object", "properties": { "lottery_type": { "type": "string", "enum": ["双色球", "福彩3D", "七乐彩", "快乐8"], "description": "彩票类型" }, "count": { "type": "integer", "minimum": 1, "maximum": 10, "default": 1, "description": "生成组数" } }, "required": ["lottery_type"] } ), types.Tool( name="sync_lottery_data", description="同步指定彩票类型的最新数据到本地数据库", inputSchema={ "type": "object", "properties": { "lottery_type": { "type": "string", "enum": ["双色球", "福彩3D", "七乐彩", "快乐8"], "description": "彩票类型" }, "periods": { "type": "integer", "minimum": 1, "maximum": 50, "default": 10, "description": "同步期数" } }, "required": ["lottery_type"] } ), types.Tool( name="force_sync_data", description="强制同步指定彩票类型的最新数据到本地数据库", inputSchema={ "type": "object", "properties": { "lottery_type": { "type": "string", "enum": ["双色球", "福彩3D", "七乐彩", "快乐8"], "description": "彩票类型" }, "periods": { "type": "integer", "minimum": 1, "maximum": 1000, "default": 20, "description": "同步期数" } }, "required": ["lottery_type"] } ), types.Tool( name="get_database_info", description="获取本地数据库统计信息", inputSchema={ "type": "object", "properties": {}, "required": [] } ), types.Tool( name="predict_lottery", description="预测彩票号码,基于历史数据生成预测结果", inputSchema={ "type": "object", "properties": { "lottery_type": { "type": "string", "enum": ["双色球", "福彩3D", "七乐彩", "快乐8"], "description": "彩票类型" }, "method": { "type": "string", "enum": ["rule"], "default": "rule", "description": "预测方法" }, "count": { "type": "integer", "minimum": 1, "maximum": 20, "default": 5, "description": "预测组数" }, "strategy": { "type": "string", "enum": ["all", "balanced", "cold_recovery", "hot_focus", "interval_balance", "contrarian"], "default": "all", "description": "预测策略" } }, "required": ["lottery_type"] } ), types.Tool( name="backtest_lottery", description="回测预测算法,评估预测准确性", inputSchema={ "type": "object", "properties": { "lottery_type": { "type": "string", "enum": ["双色球", "福彩3D", "七乐彩", "快乐8"], "description": "彩票类型" }, "window_size": { "type": "integer", "minimum": 50, "maximum": 500, "default": 100, "description": "窗口大小(训练数据期数)" }, "step": { "type": "integer", "minimum": 10, "maximum": 100, "default": 50, "description": "步长(每次移动的期数)" } }, "required": ["lottery_type"] } ) ]