Spaces:
Running
Running
Upload 3 files
Browse files- README.md +9 -7
- app.py +57 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
| 1 |
---
|
| 2 |
-
title: Chess
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.0.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Stockfish Chess Engine - MCP Server
|
| 3 |
+
emoji: 🤖
|
| 4 |
+
colorFrom: gray
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.0.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
+
short_description: Evaluates chess positions
|
| 12 |
+
tags:
|
| 13 |
+
- building-mcp-track-consumer
|
| 14 |
+
- mcp-in-action-track-consumer
|
| 15 |
+
---
|
app.py
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# References:
|
| 2 |
+
|
| 3 |
+
# https://www.stockfish.online/docs.php (API)
|
| 4 |
+
# https://www.stockfish.online/ (FEN to image)
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import gradio.utils, requests
|
| 8 |
+
from typing import Optional, List, Dict, Any
|
| 9 |
+
|
| 10 |
+
# MCP server functions
|
| 11 |
+
|
| 12 |
+
def position_evaluation(fen):
|
| 13 |
+
"""Chess position evaluation. Get best move with continuation in UCI notation for chess position in FEN.
|
| 14 |
+
|
| 15 |
+
Args:
|
| 16 |
+
fen (str): Chess position in FEN
|
| 17 |
+
|
| 18 |
+
Returns:
|
| 19 |
+
str: Best move with continuation in UCI notation
|
| 20 |
+
"""
|
| 21 |
+
print("")
|
| 22 |
+
|
| 23 |
+
print(f"🤖 Chess position_evaluation: fen={fen}")
|
| 24 |
+
|
| 25 |
+
url = "https://stockfish.online/api/s/v2.php"
|
| 26 |
+
params = {"fen": fen, "depth": 12}
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
response = requests.get(url, params=params, timeout=10)
|
| 30 |
+
response.raise_for_status()
|
| 31 |
+
result = response.json()
|
| 32 |
+
|
| 33 |
+
print(f"🤖 Chess position_evaluation: result={result}")
|
| 34 |
+
|
| 35 |
+
return result, None
|
| 36 |
+
|
| 37 |
+
except requests.exceptions.RequestException as e:
|
| 38 |
+
return None, str(e)
|
| 39 |
+
|
| 40 |
+
# Helper functions
|
| 41 |
+
|
| 42 |
+
def _noop(*args, **kwargs):
|
| 43 |
+
pass
|
| 44 |
+
|
| 45 |
+
gradio.utils.watchfn_spaces = _noop
|
| 46 |
+
|
| 47 |
+
# Graphical user interface
|
| 48 |
+
|
| 49 |
+
mcp = gr.Interface(
|
| 50 |
+
fn=position_evaluation,
|
| 51 |
+
inputs = [gr.Textbox(label = "Forsyth-Edwards Notation (FEN)", value = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", lines=2)],
|
| 52 |
+
outputs = [gr.Textbox(label = "Evaluation", interactive = False, lines=2)],
|
| 53 |
+
title="Stockfish Chess Engine",
|
| 54 |
+
description="Chess position evaluation by top open source chess engine"
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
mcp.launch(mcp_server=True, ssr_mode=False)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
gradio==6.0.0
|