Skip to content

Commit d373349

Browse files
committed
feat: Initial working version
1 parent 6b8b16f commit d373349

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
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 = "0.2.2"
7+
version = "1.0.0"
88
authors = [
99
{ name="Stephan Botes", email="stephanbotes@gmail.com" },
1010
]

stockfish_mcp/__init__.py

Whitespace-only changes.

stockfish_mcp/__main__.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import argparse
2-
import os
3-
import platform
4-
import sys
5-
from importlib import resources
62
import shutil
7-
from .mcp_server import mcp, game
3+
from . import mcp_server
84
from .chess_logic import ChessGame
95

106
def main():
@@ -21,9 +17,8 @@ def main():
2117
if not stockfish_path:
2218
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.")
2319

24-
global game
25-
game = ChessGame(stockfish_path=stockfish_path, skill_level=10)
26-
mcp.run()
20+
mcp_server.game = ChessGame(stockfish_path=stockfish_path, skill_level=10)
21+
mcp_server.mcp.run()
2722

2823
if __name__ == "__main__":
2924
main()

stockfish_mcp/bin/.gitkeep

Whitespace-only changes.

stockfish_mcp/chess_logic.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ def get_game_result(self):
9292
return "Game in progress"
9393

9494
def reset_game(self):
95-
"""Resets the board to the starting position."""
95+
"""Resets the board to the starting position and re-randomizes the engine color."""
9696
self.board.reset()
9797
self.moves = []
98+
self.engine_color = random.choice([chess.WHITE, chess.BLACK])
99+
if self.engine_color == chess.WHITE:
100+
self.make_engine_move_internal()
98101

99102
def get_moves(self):
100103
"""Returns the list of moves made so far."""

stockfish_mcp/mcp_server.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from fastmcp import FastMCP
22
from .chess_logic import ChessGame
33

4-
mcp = FastMCP("chess")
4+
mcp = FastMCP("stockfish")
55

6-
# Global game state will be initialized in the main block
6+
# Global game state will be initialized in the main entrypoint
77
game = None
88

99
@mcp.tool
@@ -54,10 +54,8 @@ def reset_game(skill_level: int = 10) -> str:
5454
The engine will be randomly assigned White or Black.
5555
Returns the initial board state.
5656
"""
57-
global game
58-
# The stockfish path is now part of the game instance
59-
stockfish_path = game.stockfish_path
60-
game = ChessGame(stockfish_path=stockfish_path, skill_level=skill_level)
57+
game.reset_game()
58+
game.stockfish.set_skill_level(skill_level)
6159
initial_state = game.get_board_state()
6260
initial_md = game.get_board_markdown()
6361
engine_color = "White" if game.engine_color == 1 else "Black"

0 commit comments

Comments
 (0)