Skip to content

Commit ce18355

Browse files
committed
feat: Convert project to PyPI package
1 parent 56d2d1c commit ce18355

File tree

12 files changed

+154
-108
lines changed

12 files changed

+154
-108
lines changed

.github/workflows/publish-mcp.yml

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,76 @@
1-
name: Publish to MCP Registry
1+
name: Publish to PyPI and MCP Registry
22

33
on:
44
push:
55
tags:
6-
- 'v*' # Triggers on version tags like v1.0.0
6+
- 'v*'
77

88
jobs:
9+
build_wheels:
10+
name: Build wheels on ${{ matrix.os }}
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, windows-latest, macos-latest]
15+
include:
16+
- os: ubuntu-latest
17+
cibw_build: "*-manylinux_x86_64"
18+
- os: windows-latest
19+
cibw_build: "*-win_amd64"
20+
- os: macos-latest
21+
cibw_build: "*-macosx_x86_64 *-macosx_arm64"
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v3
28+
with:
29+
python-version: '3.x'
30+
31+
- name: Download Stockfish
32+
run: |
33+
mkdir -p stockfish_mcp/bin
34+
if [ "$RUNNER_OS" == "Linux" ]; then
35+
curl -L "https://github.com/official-stockfish/Stockfish/releases/latest/download/stockfish-ubuntu-x86-64-avx2.tar" | tar -x -C stockfish_mcp/bin --strip-components=1
36+
elif [ "$RUNNER_OS" == "Windows" ]; then
37+
curl -L "https://github.com/official-stockfish/Stockfish/releases/latest/download/stockfish-windows-x86-64-avx2.zip" -o stockfish.zip
38+
unzip stockfish.zip -d stockfish_mcp/bin
39+
elif [ "$RUNNER_OS" == "macOS" ]; then
40+
curl -L "https://github.com/official-stockfish/Stockfish/releases/latest/download/stockfish-macos-x86-64.tar" | tar -x -C stockfish_mcp/bin --strip-components=1
41+
fi
42+
shell: bash
43+
44+
- name: Build wheels
45+
uses: pypa/cibuildwheel@v2.16.2
46+
env:
47+
CIBW_BUILD: ${{ matrix.cibw_build }}
48+
49+
- name: Store wheel
50+
uses: actions/upload-artifact@v4
51+
with:
52+
path: ./wheelhouse/*.whl
53+
954
publish:
55+
name: Publish to PyPI and MCP Registry
56+
needs: build_wheels
1057
runs-on: ubuntu-latest
1158
permissions:
12-
contents: read
13-
packages: write
14-
id-token: write # Required for OIDC authentication
59+
id-token: write
1560

1661
steps:
17-
- name: Checkout repository
18-
uses: actions/checkout@v3
62+
- uses: actions/checkout@v3
1963

20-
- name: Log in to the GitHub Container Registry
21-
uses: docker/login-action@v2
64+
- name: Download all wheels
65+
uses: actions/download-artifact@v4
2266
with:
23-
registry: ghcr.io
24-
username: ${{ github.actor }}
25-
password: ${{ secrets.GITHUB_TOKEN }}
67+
path: dist/
2668

27-
- name: Build and push Docker image
28-
uses: docker/build-push-action@v4
69+
- name: Publish to PyPI
70+
uses: pypa/gh-action-pypi-publish@release/v1
2971
with:
30-
context: .
31-
push: true
32-
tags: ghcr.io/stepbot/stockfish-mcp:${{ github.ref_name }}
33-
labels: io.modelcontextprotocol.server.name=io.github.stepbot/stockfish-mcp
72+
user: __token__
73+
password: ${{ secrets.PYPI_API_TOKEN }}
3474

3575
- name: Install MCP Publisher
3676
run: |

Dockerfile

Lines changed: 0 additions & 31 deletions
This file was deleted.

README.md

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,29 @@
11
# Stockfish MCP Server
22

3-
This project implements a simple MCP (Model Context Protocol) server that allows an LLM to play chess against the Stockfish engine.
3+
<!-- mcp-name: io.github.stepbot/stockfish-mcp -->
44

5-
## Features
5+
A Stockfish server for the Model Context Protocol. This package allows a Large Language Model to play chess against the Stockfish engine.
66

7-
- Play a game of chess against Stockfish.
8-
- Get the board state in FEN and Markdown format.
9-
- Make moves using UCI notation.
10-
- Reset the game with a specific skill level for the engine.
7+
## Installation
118

12-
## Installation from Registry
9+
Install the package from PyPI:
1310

14-
You can install and run this server directly from the MCP registry using an MCP-compatible client. Update your `mcp_settings.json` to include the following server configuration:
15-
16-
```json
17-
{
18-
"mcpServers": {
19-
"chess": {
20-
"package": "io.github.stepbot/stockfish-mcp@v0.1.3"
21-
}
22-
}
23-
}
11+
```bash
12+
pip install stockfish-mcp
2413
```
2514

26-
Your client will automatically download and manage the server package.
27-
28-
## Local Development Setup
29-
30-
1. **Clone the repository:**
31-
```bash
32-
git clone <repository-url>
33-
cd StockfishMcp
34-
```
35-
36-
2. **Install `uv`:**
37-
If you don't have `uv` installed, you can install it with:
38-
```powershell
39-
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
40-
```
41-
After installation, you may need to add the installation directory (usually `C:\Users\<YourUser>\.local\bin` on Windows) to your system's PATH and restart your terminal.
42-
43-
3. **Download Stockfish:**
44-
You need to download the Stockfish engine separately. You can find it on the [official Stockfish website](https://stockfishchess.org/download/).
15+
## Usage
4516

46-
4. **Configure the MCP Server:**
47-
To use this server, you must add an entry for it in your global `mcp_settings.json` file. This file tells your MCP client how to launch the server.
17+
Run the server from the command line:
4818

49-
An example configuration is provided in `mcp_settings.example.json`. You should copy this configuration into your `mcp_settings.json` file and update the following paths:
50-
- The path to the `mcp_server.py` script in this project.
51-
- The path to your downloaded Stockfish executable for the `--stockfish-path` argument.
19+
```bash
20+
stockfish-mcp
21+
```
5222

53-
## Usage
23+
You can also provide a path to a custom Stockfish executable:
5424

55-
The server is managed by your MCP client and will be launched using `uv`. `uv` will automatically handle the virtual environment and dependencies from `requirements.txt`. The MCP client will pass the `--stockfish-path` argument to the server on startup.
25+
```bash
26+
stockfish-mcp --stockfish-path /path/to/your/stockfish
5627

5728
## Example
5829

pyproject.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "stockfish-mcp"
7+
version = "0.2.0"
8+
authors = [
9+
{ name="Stephan Botes", email="stephanbotes@gmail.com" },
10+
]
11+
description = "A Stockfish MCP server"
12+
readme = "README.md"
13+
requires-python = ">=3.8"
14+
classifiers = [
15+
"Programming Language :: Python :: 3",
16+
"License :: OSI Approved :: MIT License",
17+
"Operating System :: OS Independent",
18+
]
19+
dependencies = [
20+
"fastmcp",
21+
"chess",
22+
"stockfish",
23+
]
24+
25+
[project.scripts]
26+
stockfish-mcp = "stockfish_mcp.__main__:main"

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

server.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-10-17/server.schema.json",
33
"name": "io.github.stepbot/stockfish-mcp",
44
"title": "Stockfish MCP",
5-
"description": "An MCP server for playing chess against Stockfish.",
5+
"description": "A Stockfish MCP server to allow an LLM to play chess against Stockfish",
66
"version": "__VERSION__",
77
"packages": [
88
{
9-
"registryType": "oci",
10-
"identifier": "ghcr.io/stepbot/stockfish-mcp:__VERSION__",
9+
"registryType": "pypi",
10+
"identifier": "stockfish-mcp",
11+
"version": "__VERSION__",
1112
"transport": {
1213
"type": "stdio"
1314
}

setup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
packages=["stockfish_mcp", "stockfish_mcp.bin"],
5+
include_package_data=True,
6+
package_data={
7+
"stockfish_mcp.bin": ["*"],
8+
},
9+
)

stockfish_mcp/__init__.py

Whitespace-only changes.

stockfish_mcp/__main__.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import argparse
2+
import os
3+
import platform
4+
import sys
5+
from .mcp_server import mcp, game
6+
from .chess_logic import ChessGame
7+
8+
def get_stockfish_path():
9+
"""
10+
Determines the path to the correct Stockfish binary based on the OS and architecture.
11+
"""
12+
system = platform.system()
13+
machine = platform.machine()
14+
15+
base_path = os.path.join(os.path.dirname(__file__), 'bin')
16+
17+
if system == "Linux":
18+
return os.path.join(base_path, "stockfish-ubuntu-x86-64-avx2")
19+
elif system == "Windows":
20+
return os.path.join(base_path, "stockfish-windows-x86-64-avx2.exe")
21+
elif system == "Darwin": # macOS
22+
if machine == "arm64":
23+
return os.path.join(base_path, "stockfish-macos-arm64")
24+
else:
25+
return os.path.join(base_path, "stockfish-macos-x86-64")
26+
27+
raise OSError("Unsupported operating system")
28+
29+
30+
def main():
31+
parser = argparse.ArgumentParser(description="Run the Chess MCP server.")
32+
parser.add_argument("--stockfish-path", help="Path to a custom Stockfish executable.")
33+
args = parser.parse_args()
34+
35+
stockfish_path = args.stockfish_path if args.stockfish_path else get_stockfish_path()
36+
37+
global game
38+
game = ChessGame(stockfish_path=stockfish_path, skill_level=10)
39+
mcp.run()
40+
41+
if __name__ == "__main__":
42+
main()

stockfish_mcp/bin/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)