返回市场
国际象棋支持mcp

国际象棋支持mcp

作者:danilop3 星标更新:2025-08-14

项目介绍

国际象棋支持MCP服务器

这是一个管理国际象棋游戏状态的MCP服务器,适用于LLMs/代理。它故意不建议走法。相反,它提供了以下工具:

  • 创建/重置游戏
  • 添加一步(UCI)
  • 列出所有走法
  • 获取最后N步
  • 机器友好的棋盘JSON(方格到棋子映射)在get_status()
  • 检查走法是否合法
  • 获取状态(FEN,轮到谁,是否将军,游戏是否结束,结果)

要求

  • Python 3.13+
  • uv 包管理器

直接从GitHub运行(无需本地检出)

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

通用MCP配置(类似Inspector风格):

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

Claude Desktop mcpServers示例:

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

首次运行时,uvx会解析并构建包,这可能需要更长时间;后续运行将使用缓存。

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

使用uv run与stdio(无硬编码路径)。示例通用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_numberhalfmove_clockply_countlast_move_ucilast_move_sanwho_moved_last;将军标志;is_game_over;当游戏结束时的result;以及用于机器推理的pieces映射。
  • add_move(uci: str) → 如果合法则应用一步(例如,e2e4g1f3,升变如e7e8q)。返回{ accepted, status },成功时还返回movesmoves_detailed。失败时返回{ accepted:false, reason:"illegal"|"parse_error", expected_turn? }status反映未改变的位置。
  • is_legal(uci: str) → 检查当前位置下UCI走法的合法性。
  • list_moves() → 到目前为止所有UCI走法。
  • list_moves_detailed() → 所有走法,包括plysideucisan
  • last_moves(n: int=1) → 最后N步UCI走法。
  • last_moves_detailed(n: int=1) → 最后N步走法,包括plysideucisan
  • board_ascii() → ASCII棋盘(可选,面向人类)。正常API返回机器友好的JSON在status.pieces中。

API设计说明

  • 走法始终以UCI提供(例如,e2e4g1f3,升变e7e8q)。服务器从位置推断轮到哪一方;发送走法时您不需要指定白/黑。
  • get_status().side_to_move告诉模型轮到谁。who_moved_lastlast_move_ucilast_move_san有助于上下文。
  • 提供详细的走法列表在单独的*_detailed工具中,以保持基本列表简单且向后兼容。

注意事项

  • 服务器维护一个内存中的游戏。
  • 服务器不提供提示或最佳走法。

开发

  • 运行测试:
uv run pytest -q