Skip to main content
Glama
liuguoping1024

SWLC MCP Server

analyze_numbers

Analyze lottery number statistics to identify hot and cold numbers for Double Color Ball, 3D Lottery, Seven Happiness Lottery, and Happy 8 games. Specify lottery type and analysis periods to get statistical insights.

Instructions

分析彩票号码统计信息,包括热号、冷号等

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
lottery_typeYes彩票类型
periodsNo分析期数

Implementation Reference

  • MCP tool handler for 'analyze_numbers': fetches historical data based on input parameters and performs analysis using the helper method, formats response text.
                elif name == "analyze_numbers":
                    lottery_type = arguments.get("lottery_type")
                    periods = arguments.get("periods", 30)
                    
                    results = await lottery_service.get_historical_data(lottery_type, periods)
                    if results:
                        analysis = lottery_service.analyze_numbers(results)
                        
                        text = f"""{lottery_type}号码分析(最近{periods}期):
    
    热门号码(前10):{' '.join(analysis.hot_numbers)}
    冷门号码(后10):{' '.join(analysis.cold_numbers)}
    
    统计信息:
    - 分析期数:{analysis.consecutive_analysis['total_periods']}期
    - 最高频号码:{analysis.consecutive_analysis['most_frequent'][0]} (出现{analysis.consecutive_analysis['most_frequent'][1]}次)
    - 最低频号码:{analysis.consecutive_analysis['least_frequent'][0]} (出现{analysis.consecutive_analysis['least_frequent'][1]}次)
    
    详细频率统计:"""
                        
                        # 添加详细频率信息
                        sorted_freq = sorted(analysis.frequency_stats.items(), key=lambda x: x[1], reverse=True)
                        for num, freq in sorted_freq[:15]:  # 显示前15个
                            text += f"\n号码 {num}: {freq}次"
                        
                        return [types.TextContent(type="text", text=text)]
                    else:
                        return [types.TextContent(type="text", text="获取数据失败,无法进行分析")]
  • Core analysis function that computes frequency statistics, hot and cold numbers from a list of lottery results.
    def analyze_numbers(self, results: List[LotteryResult]) -> LotteryAnalysis:
        """分析号码统计 - 基于传入的results进行统计,不使用数据库累积统计"""
        logger.info(f"基于{len(results)}期数据计算号码统计")
        
        # 直接从传入的results计算频率统计
        frequency = {}
        all_numbers = []
        
        for result in results:
            all_numbers.extend(result.numbers)
            if result.special_numbers:
                all_numbers.extend(result.special_numbers)
        
        # 统计频率
        for num in all_numbers:
            frequency[num] = frequency.get(num, 0) + 1
        
        # 排序找出热号和冷号
        sorted_nums = sorted(frequency.items(), key=lambda x: x[1], reverse=True)
        hot_numbers = [num for num, _ in sorted_nums[:10]]
        cold_numbers = [num for num, _ in sorted_nums[-10:]]
        
        return LotteryAnalysis(
            hot_numbers=hot_numbers,
            cold_numbers=cold_numbers,
            frequency_stats=frequency,
            consecutive_analysis={
                "total_periods": len(results),
                "most_frequent": sorted_nums[0] if sorted_nums else ("", 0),
                "least_frequent": sorted_nums[-1] if sorted_nums else ("", 0)
            }
        )
  • Registers the 'analyze_numbers' tool in MCP server's list_tools() with name, description, and input schema.
        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"]
        }
    ),
  • Pydantic model defining the structure of lottery analysis output.
    class LotteryAnalysis(BaseModel):
        """彩票分析结果"""
        hot_numbers: List[str]
        cold_numbers: List[str]
        frequency_stats: Dict[str, int]
        consecutive_analysis: Dict[str, Any]

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/liuguoping1024/swlc-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server