@pipeworx/mcp-chess 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +37 -0
- package/package.json +10 -0
- package/src/index.ts +279 -0
- package/tsconfig.json +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pipeworx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @pipeworx/mcp-chess
|
|
2
|
+
|
|
3
|
+
MCP server for the [Chess.com API](https://www.chess.com/news/view/published-data-api) — player profiles, game statistics, monthly game archives, and leaderboards. Free, no auth required.
|
|
4
|
+
|
|
5
|
+
## Tools
|
|
6
|
+
|
|
7
|
+
| Tool | Description |
|
|
8
|
+
|------|-------------|
|
|
9
|
+
| `get_player` | Get a player's public profile |
|
|
10
|
+
| `get_stats` | Get ratings and win/loss/draw records across all formats |
|
|
11
|
+
| `get_games` | Get a player's games for a specific month |
|
|
12
|
+
| `get_leaderboards` | Get top-ranked players across game formats |
|
|
13
|
+
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
Add to your MCP client config:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"mcpServers": {
|
|
21
|
+
"chess": {
|
|
22
|
+
"type": "url",
|
|
23
|
+
"url": "https://gateway.pipeworx.io/chess"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## CLI Usage
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx @anthropic-ai/mcp-client https://gateway.pipeworx.io/chess
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
MIT
|
package/package.json
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chess.com MCP — wraps the Chess.com public API (free, no auth)
|
|
3
|
+
*
|
|
4
|
+
* Tools:
|
|
5
|
+
* - get_player: Get a player's public profile
|
|
6
|
+
* - get_stats: Get a player's game statistics across all formats
|
|
7
|
+
* - get_games: Get a player's games for a specific month
|
|
8
|
+
* - get_leaderboards: Get top-ranked players across game formats
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface McpToolDefinition {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
inputSchema: {
|
|
15
|
+
type: 'object';
|
|
16
|
+
properties: Record<string, unknown>;
|
|
17
|
+
required?: string[];
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface McpToolExport {
|
|
22
|
+
tools: McpToolDefinition[];
|
|
23
|
+
callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const BASE_URL = 'https://api.chess.com/pub';
|
|
27
|
+
|
|
28
|
+
// --- Raw API types ---
|
|
29
|
+
|
|
30
|
+
type RawPlayer = {
|
|
31
|
+
player_id: number;
|
|
32
|
+
username: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
title?: string;
|
|
35
|
+
followers: number;
|
|
36
|
+
country: string;
|
|
37
|
+
location?: string;
|
|
38
|
+
joined: number;
|
|
39
|
+
last_online: number;
|
|
40
|
+
is_streamer: boolean;
|
|
41
|
+
verified: boolean;
|
|
42
|
+
league?: string;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type RawRatingStats = {
|
|
46
|
+
last?: { rating: number; date: number; rd: number };
|
|
47
|
+
best?: { rating: number; date: number; game?: string };
|
|
48
|
+
record?: { win: number; loss: number; draw: number };
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type RawStats = {
|
|
52
|
+
chess_daily?: RawRatingStats;
|
|
53
|
+
chess_rapid?: RawRatingStats;
|
|
54
|
+
chess_blitz?: RawRatingStats;
|
|
55
|
+
chess_bullet?: RawRatingStats;
|
|
56
|
+
chess_960_daily?: RawRatingStats;
|
|
57
|
+
fide?: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type RawGame = {
|
|
61
|
+
url: string;
|
|
62
|
+
pgn?: string;
|
|
63
|
+
time_control: string;
|
|
64
|
+
end_time: number;
|
|
65
|
+
rated: boolean;
|
|
66
|
+
tcn?: string;
|
|
67
|
+
uuid: string;
|
|
68
|
+
initial_setup: string;
|
|
69
|
+
fen: string;
|
|
70
|
+
time_class: string;
|
|
71
|
+
rules: string;
|
|
72
|
+
white: { username: string; rating: number; result: string };
|
|
73
|
+
black: { username: string; rating: number; result: string };
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
type RawGamesResponse = {
|
|
77
|
+
games: RawGame[];
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
type RawLeaderEntry = {
|
|
81
|
+
player_id: number;
|
|
82
|
+
username: string;
|
|
83
|
+
score: number;
|
|
84
|
+
rank: number;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
type RawLeaderboards = {
|
|
88
|
+
daily?: RawLeaderEntry[];
|
|
89
|
+
daily960?: RawLeaderEntry[];
|
|
90
|
+
live_rapid?: RawLeaderEntry[];
|
|
91
|
+
live_blitz?: RawLeaderEntry[];
|
|
92
|
+
live_bullet?: RawLeaderEntry[];
|
|
93
|
+
live_bughouse?: RawLeaderEntry[];
|
|
94
|
+
live_blitz960?: RawLeaderEntry[];
|
|
95
|
+
live_threecheck?: RawLeaderEntry[];
|
|
96
|
+
live_crazyhouse?: RawLeaderEntry[];
|
|
97
|
+
live_kingofthehill?: RawLeaderEntry[];
|
|
98
|
+
lessons?: RawLeaderEntry[];
|
|
99
|
+
tactics?: RawLeaderEntry[];
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// --- Tool definitions ---
|
|
103
|
+
|
|
104
|
+
const tools: McpToolExport['tools'] = [
|
|
105
|
+
{
|
|
106
|
+
name: 'get_player',
|
|
107
|
+
description:
|
|
108
|
+
"Get a Chess.com player's public profile including name, title, followers, country, join date, and last online time.",
|
|
109
|
+
inputSchema: {
|
|
110
|
+
type: 'object',
|
|
111
|
+
properties: {
|
|
112
|
+
username: {
|
|
113
|
+
type: 'string',
|
|
114
|
+
description: 'Chess.com username (case-insensitive, e.g., "hikaru", "magnuscarlsen")',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
required: ['username'],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: 'get_stats',
|
|
122
|
+
description:
|
|
123
|
+
"Get a player's game statistics including current rating, best rating, and win/loss/draw record for daily, rapid, blitz, and bullet formats.",
|
|
124
|
+
inputSchema: {
|
|
125
|
+
type: 'object',
|
|
126
|
+
properties: {
|
|
127
|
+
username: {
|
|
128
|
+
type: 'string',
|
|
129
|
+
description: 'Chess.com username',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
required: ['username'],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: 'get_games',
|
|
137
|
+
description:
|
|
138
|
+
"Get a player's completed games for a specific month. Returns game URLs, time controls, results, and player ratings.",
|
|
139
|
+
inputSchema: {
|
|
140
|
+
type: 'object',
|
|
141
|
+
properties: {
|
|
142
|
+
username: { type: 'string', description: 'Chess.com username' },
|
|
143
|
+
year: { type: 'number', description: 'Year (e.g., 2024)' },
|
|
144
|
+
month: { type: 'number', description: 'Month as a number (1-12)' },
|
|
145
|
+
},
|
|
146
|
+
required: ['username', 'year', 'month'],
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: 'get_leaderboards',
|
|
151
|
+
description:
|
|
152
|
+
'Get the top-ranked Chess.com players across game formats including daily, rapid, blitz, and bullet.',
|
|
153
|
+
inputSchema: {
|
|
154
|
+
type: 'object',
|
|
155
|
+
properties: {},
|
|
156
|
+
required: [],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
// --- callTool dispatcher ---
|
|
162
|
+
|
|
163
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
164
|
+
switch (name) {
|
|
165
|
+
case 'get_player':
|
|
166
|
+
return getPlayer(args.username as string);
|
|
167
|
+
case 'get_stats':
|
|
168
|
+
return getStats(args.username as string);
|
|
169
|
+
case 'get_games':
|
|
170
|
+
return getGames(args.username as string, args.year as number, args.month as number);
|
|
171
|
+
case 'get_leaderboards':
|
|
172
|
+
return getLeaderboards();
|
|
173
|
+
default:
|
|
174
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// --- Tool implementations ---
|
|
179
|
+
|
|
180
|
+
async function getPlayer(username: string) {
|
|
181
|
+
const res = await fetch(`${BASE_URL}/player/${encodeURIComponent(username.toLowerCase())}`);
|
|
182
|
+
if (!res.ok) throw new Error(`Chess.com error: ${res.status}`);
|
|
183
|
+
|
|
184
|
+
const p = (await res.json()) as RawPlayer;
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
player_id: p.player_id,
|
|
188
|
+
username: p.username,
|
|
189
|
+
name: p.name ?? null,
|
|
190
|
+
title: p.title ?? null,
|
|
191
|
+
followers: p.followers,
|
|
192
|
+
country_url: p.country,
|
|
193
|
+
location: p.location ?? null,
|
|
194
|
+
joined: new Date(p.joined * 1000).toISOString(),
|
|
195
|
+
last_online: new Date(p.last_online * 1000).toISOString(),
|
|
196
|
+
is_streamer: p.is_streamer,
|
|
197
|
+
verified: p.verified,
|
|
198
|
+
league: p.league ?? null,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function formatRatingStats(stats: RawRatingStats | undefined) {
|
|
203
|
+
if (!stats) return null;
|
|
204
|
+
return {
|
|
205
|
+
current_rating: stats.last?.rating ?? null,
|
|
206
|
+
best_rating: stats.best?.rating ?? null,
|
|
207
|
+
record: stats.record
|
|
208
|
+
? { win: stats.record.win, loss: stats.record.loss, draw: stats.record.draw }
|
|
209
|
+
: null,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async function getStats(username: string) {
|
|
214
|
+
const res = await fetch(`${BASE_URL}/player/${encodeURIComponent(username.toLowerCase())}/stats`);
|
|
215
|
+
if (!res.ok) throw new Error(`Chess.com error: ${res.status}`);
|
|
216
|
+
|
|
217
|
+
const data = (await res.json()) as RawStats;
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
username,
|
|
221
|
+
fide: data.fide ?? null,
|
|
222
|
+
daily: formatRatingStats(data.chess_daily),
|
|
223
|
+
rapid: formatRatingStats(data.chess_rapid),
|
|
224
|
+
blitz: formatRatingStats(data.chess_blitz),
|
|
225
|
+
bullet: formatRatingStats(data.chess_bullet),
|
|
226
|
+
daily_960: formatRatingStats(data.chess_960_daily),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async function getGames(username: string, year: number, month: number) {
|
|
231
|
+
const mm = String(month).padStart(2, '0');
|
|
232
|
+
const res = await fetch(
|
|
233
|
+
`${BASE_URL}/player/${encodeURIComponent(username.toLowerCase())}/games/${year}/${mm}`,
|
|
234
|
+
);
|
|
235
|
+
if (!res.ok) throw new Error(`Chess.com error: ${res.status}`);
|
|
236
|
+
|
|
237
|
+
const data = (await res.json()) as RawGamesResponse;
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
username,
|
|
241
|
+
year,
|
|
242
|
+
month,
|
|
243
|
+
total_games: data.games.length,
|
|
244
|
+
games: data.games.map((g) => ({
|
|
245
|
+
url: g.url,
|
|
246
|
+
uuid: g.uuid,
|
|
247
|
+
time_class: g.time_class,
|
|
248
|
+
time_control: g.time_control,
|
|
249
|
+
rated: g.rated,
|
|
250
|
+
end_time: new Date(g.end_time * 1000).toISOString(),
|
|
251
|
+
white: { username: g.white.username, rating: g.white.rating, result: g.white.result },
|
|
252
|
+
black: { username: g.black.username, rating: g.black.rating, result: g.black.result },
|
|
253
|
+
})),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function getLeaderboards() {
|
|
258
|
+
const res = await fetch(`${BASE_URL}/leaderboards`);
|
|
259
|
+
if (!res.ok) throw new Error(`Chess.com error: ${res.status}`);
|
|
260
|
+
|
|
261
|
+
const data = (await res.json()) as RawLeaderboards;
|
|
262
|
+
|
|
263
|
+
const formatLeaders = (entries: RawLeaderEntry[] | undefined) =>
|
|
264
|
+
(entries ?? []).slice(0, 10).map((e) => ({
|
|
265
|
+
rank: e.rank,
|
|
266
|
+
username: e.username,
|
|
267
|
+
score: e.score,
|
|
268
|
+
}));
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
daily: formatLeaders(data.daily),
|
|
272
|
+
live_rapid: formatLeaders(data.live_rapid),
|
|
273
|
+
live_blitz: formatLeaders(data.live_blitz),
|
|
274
|
+
live_bullet: formatLeaders(data.live_bullet),
|
|
275
|
+
tactics: formatLeaders(data.tactics),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export default { tools, callTool } satisfies McpToolExport;
|