国际象棋状态管理服务器

一个为LLMs/agents设计的国际象棋游戏状态管理服务器,提供创建/重置游戏、添加移动、检查移动合法性等功能。

  • by danilop
  • Python
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 danilop/chess-support-mcp

使用说明

国际象棋支持MCP服务器

为LLM/代理管理国际象棋游戏状态的MCP服务器。它故意不建议采取行动。相反,它提供了以下工具:

  • 创建/重置游戏
  • 添加移动(UCI)
  • 列出所有动作
  • 获取最后N个动作
  • 机器友好的板JSON(方形到块的映射) get_status()
  • 检查搬家是否合法
  • 获取状态(FEN、轮到谁、检查、游戏结束、结果)

需求

  • Python 3.13+
  • uv包管理器

直接从GitHub通过uvx运行(无需本地结账)

您可以使用以下命令运行此MCP服务器而无需克隆 uvx 使用Git URL。用您的仓库信息和可选的标签/提交替换占位符。

通用MCP配置(检查器样式):

{
  "servers": {
    "chess-support-mcp": {
      "transport": {
        "type": "stdio",
        "command": "uvx",
        "args": [
          "--from",
          "git+https://github.com/danilop/chess-support-mcp.git",
          "chess-support-mcp"
        ]
      }
    }
  }
}

克劳德桌面 mcpServers 例子:

{
  "mcpServers": {
    "chess-support-mcp": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/danilop/chess-support-mcp.git",
        "chess-support-mcp"
      ]
    }
  }
}

第一次运行可能需要更长的时间 uvx 解析并构建包;后续运行使用缓存。

配置为本地MCP服务器(JSON)

使用stdio uv run (没有硬编码路径)。通用JSON配置示例:

{
  "servers": {
    "chess-support-mcp": {
      "transport": {
        "type": "stdio",
        "command": "uv",
        "args": ["run", "chess-support-mcp"]
      }
    }
  }
}

使用占位符并通过以下方式设置工作目录,在不硬编码特定路径的情况下包含项目的本地路径 cwd (首选),或通过 --project:

选项A(首选:设置工作目录):

{
  "servers": {
    "chess-support-mcp": {
      "transport": {
        "type": "stdio",
        "command": "uv",
        "args": ["run", "chess-support-mcp"],
        "cwd": "<ABSOLUTE_PATH_TO_PROJECT>"
      }
    }
  }
}

选项B(使用uv的项目标志):

{
  "servers": {
    "chess-support-mcp": {
      "transport": {
        "type": "stdio",
        "command": "uv",
        "args": ["run", "--project", "<ABSOLUTE_PATH_TO_PROJECT>", "chess-support-mcp"]
      }
    }
  }
}

Claude Desktop配置(在JSON设置中),使用 mcpServers:

{
  "mcpServers": {
    "chess-support-mcp": {
      "command": "uv",
      "args": ["run", "chess-support-mcp"],
      "cwd": "<ABSOLUTE_PATH_TO_PROJECT>"
    }
  }
}

工具(方法)

  • create_or_reset_game() → 重置到初始位置。退货 status (与 pieces 地图),以及 moves.
  • get_status() → 归还FEN; side_to_move (白色/黑色); fullmove_number; halfmove_clock; ply_count; last_move_uci; last_move_san; who_moved_last;检查旗帜; is_game_over; result 当结束时;以及a pieces 机器推理地图。
  • add_move(uci: str) → 如果合法,请采取行动(例如。, e2e4, g1f3,推广类 e7e8q).退货 { accepted, status } 关于成功 moves 和 moves_detailed.故障返回 { accepted:false, reason:"illegal"|"parse_error", expected_turn? } 随着 status 反映了不变的立场。
  • is_legal(uci: str) → 检查UCI在当前位置移动的合法性。
  • list_moves() → 到目前为止,UCI的所有动作。
  • list_moves_detailed() → 所有动作 ply, side, uci, san.
  • last_moves(n: int=1) → 最后一个N在UCI移动。
  • last_moves_detailed(n: int=1) → 最后N移动 ply, side, uci, san.
  • board_ascii() → ASCII板(可选,以人为本)。正常的API返回机器友好的JSON status.pieces.

API设计说明

  • 在UCI中总是提供移动(例如。, e2e4, g1f3,促销活动 e7e8q).服务器推断侧从位置移动;发送移动时,您永远不会指定白色/黑色。
  • get_status().side_to_move 告诉该轮到谁了。 who_moved_last, last_move_uci,以及 last_move_san 帮助上下文。
  • 详细的搬家清单单独提供 *_detailed 保持基本列表简单和向后兼容的工具。

备注

  • 服务器维护一个内存游戏。
  • 服务器不提供提示或最佳操作。

发展

  • 运行测试:
uv run pytest -q