UNPKG

@iflow-mcp/chess-mcp

Version:

A Model Context Protocol (MCP) server that provides an interactive chess game experience using MCP-UI. This server exposes chess game functionality through MCP tools and provides a web-based chessboard interface for playing games.

19 lines (18 loc) 675 B
import { writeFile, readFile, mkdir } from "node:fs/promises"; import { existsSync } from "node:fs"; import { Chess } from "chess.js"; export async function saveGame(sessionId, game) { // Ensure games directory exists if (!existsSync("./games")) { await mkdir("./games", { recursive: true }); } await writeFile(`./games/${sessionId}.json`, JSON.stringify(game.fen(), null, 2)); } export async function loadGame(sessionId) { if (!existsSync(`./games/${sessionId}.json`) || !sessionId) { return null; } const data = await readFile(`./games/${sessionId}.json`, "utf-8"); const fen = JSON.parse(data); return new Chess(fen); }