Skip to content

Commit bbd0f0c

Browse files
committed
fix: Initialize game at startup and on reset
1 parent d373349 commit bbd0f0c

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "stockfish-mcp"
7-
version = "1.0.0"
7+
version = "1.0.2"
88
authors = [
99
{ name="Stephan Botes", email="stephanbotes@gmail.com" },
1010
]

stockfish_mcp/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def main():
1717
if not stockfish_path:
1818
parser.error("Stockfish executable not found. Please install Stockfish and ensure it is in your PATH, or provide the path using the --stockfish-path argument.")
1919

20+
mcp_server.STOCKFISH_PATH = stockfish_path
21+
# Initialize the first game
2022
mcp_server.game = ChessGame(stockfish_path=stockfish_path, skill_level=10)
2123
mcp_server.mcp.run()
2224

stockfish_mcp/mcp_server.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
mcp = FastMCP("stockfish")
55

6-
# Global game state will be initialized in the main entrypoint
6+
# Global game state
77
game = None
8+
STOCKFISH_PATH = None
89

910
@mcp.tool
1011
def get_board_state() -> str:
@@ -54,11 +55,14 @@ def reset_game(skill_level: int = 10) -> str:
5455
The engine will be randomly assigned White or Black.
5556
Returns the initial board state.
5657
"""
57-
game.reset_game()
58-
game.stockfish.set_skill_level(skill_level)
58+
global game
59+
if not STOCKFISH_PATH:
60+
return "Error: Stockfish path not configured. The server must be started with the --stockfish-path argument."
61+
62+
game = ChessGame(stockfish_path=STOCKFISH_PATH, skill_level=skill_level)
5963
initial_state = game.get_board_state()
6064
initial_md = game.get_board_markdown()
61-
engine_color = "White" if game.engine_color == 1 else "Black"
65+
engine_color = "White" if game.engine_color == chess.WHITE else "Black"
6266
moves = game.get_moves()
6367
moves_str = ", ".join(moves)
6468
return f"Game reset with skill level {skill_level}. Engine is playing as {engine_color}.\n\n**Initial board:**\nFEN: `{initial_state['fen']}`\n{initial_md}\n\nMoves: {moves_str}"

0 commit comments

Comments
 (0)