Skip to main content
Glama
wangyafu
by wangyafu

list_puzzles_tool

Discover all available puzzles on the Haiguitang MCP Server's 'Turtle Soup' game by using this tool to retrieve a comprehensive list for enhanced gameplay experience.

Instructions

列出所有可用的谜题

    Returns:
        谜题列表
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'list_puzzles_tool' tool. It is decorated with @mcp.tool() for registration and implements the logic to list all loaded puzzles by iterating over the global 'puzzles' dictionary and formatting them into a string list.
    @mcp.tool()
    def list_puzzles_tool() -> str:
        """列出所有可用的谜题
    
        Returns:
            谜题列表
        """
        puzzle_list = []
        for puzzle_id, puzzle in puzzles.items():
            puzzle_list.append(f"- {puzzle_id}")
        return "可用谜题列表:\n" + "\n".join(puzzle_list)
  • The @mcp.tool() decorator registers the list_puzzles_tool function as an MCP tool.
    @mcp.tool()
  • The load_puzzles function populates the global 'puzzles' dictionary used by list_puzzles_tool by searching for .md files in various directories and parsing them into Puzzle objects.
    def load_puzzles():
        # 获取当前脚本所在目录
        current_dir = os.path.dirname(os.path.abspath(__file__))
        base_dir = os.path.dirname(current_dir)  # 获取上一级目录
    
        # 查找多个可能的路径
        puzzle_paths = [
            os.path.join(current_dir, "puzzles", "*.md"),  # app/puzzles/*.md
            os.path.join(base_dir, "haiguitang-mcp", "puzzles", "*.md"),  # 项目根目录/app/puzzles/*.md
            os.path.join(base_dir, "puzzles", "*.md"),  # 项目根目录/puzzles/*.md
            os.path.join(base_dir, "*.md"),  # 项目根目录/*.md
        ]
    
        for path_pattern in puzzle_paths:
            print(f"正在搜索路径: {path_pattern}")
            puzzle_files = glob.glob(path_pattern)
            for file_path in puzzle_files:
                puzzle_title = os.path.basename(file_path).replace(".md", "")
                if "README" in puzzle_title:
                    continue
                try:
                    with open(file_path, "r", encoding="utf-8") as f:
                        content = f.read()
    
    
                    # 创建谜题对象
                    puzzle = Puzzle(
                        title=puzzle_title,
                        content=content
                    )
                    puzzles[puzzle_title] = puzzle
                    print(f"已加载谜题: {puzzle_title}")
                except Exception as e:
                    print(f"加载谜题 {puzzle_title} 失败: {str(e)}")
    
        if not puzzles:
            print("警告:未找到任何谜题文件")
    
    # 初始化时加载谜题
Install Server

Other Tools

Related Tools

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/wangyafu/haiguitangmcp'

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