Skip to main content
Glama

get_puzzle

Retrieve complete details of a 'Turtle Soup' puzzle by specifying its title, enabling users to access full puzzle content for gameplay or reference.

Instructions

获取一个谜题的完整内容

Args: puzzle_title: 海龟汤的标题 Returns: 选择结果信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
puzzle_titleYes

Implementation Reference

  • The handler function for the 'get_puzzle' tool. It takes a puzzle_title string parameter, looks up the puzzle in the global puzzles dictionary, and returns its string representation or an error message if not found.
    def get_puzzle(puzzle_title: str) -> str: """获取一个谜题的完整内容 Args: puzzle_title: 海龟汤的标题 Returns: 选择结果信息 """ try: puzzle=puzzles[puzzle_title] return str(puzzle) except KeyError: return "找不到该谜题"
  • The @mcp.tool() decorator registers the get_puzzle function as an MCP tool.
    def get_puzzle(puzzle_title: str) -> str:
  • Pydantic model used to structure puzzle data, which is loaded and used by the get_puzzle tool.
    class Puzzle(BaseModel): title: str content: str
  • Helper function that loads puzzle files into the global puzzles dictionary, enabling the get_puzzle tool.
    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("警告:未找到任何谜题文件") # 初始化时加载谜题

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