@pipeworx/mcp-deckofcards 1.0.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -0
  3. package/package.json +18 -0
  4. package/src/index.ts +163 -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,33 @@
1
+ # mcp-deckofcards
2
+
3
+ MCP server for drawing and shuffling playing cards via [Deck of Cards API](https://deckofcardsapi.com). No authentication required.
4
+
5
+ ## Tools
6
+
7
+ | Tool | Description |
8
+ |------|-------------|
9
+ | `new_deck` | Create and shuffle a new deck (or multiple decks) of playing cards |
10
+ | `draw_cards` | Draw one or more cards from an existing deck |
11
+ | `shuffle_deck` | Shuffle (or re-shuffle) an existing deck |
12
+
13
+ ## Quickstart via Pipeworx Gateway
14
+
15
+ Call any tool through the hosted gateway with zero setup:
16
+
17
+ ```bash
18
+ curl -X POST https://gateway.pipeworx.io/mcp \
19
+ -H "Content-Type: application/json" \
20
+ -d '{
21
+ "jsonrpc": "2.0",
22
+ "id": 1,
23
+ "method": "tools/call",
24
+ "params": {
25
+ "name": "deckofcards_new_deck",
26
+ "arguments": { "count": 1 }
27
+ }
28
+ }'
29
+ ```
30
+
31
+ ## License
32
+
33
+ MIT
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@pipeworx/mcp-deckofcards",
3
+ "version": "1.0.0",
4
+ "description": "MCP server for drawing and shuffling playing cards via Deck of Cards API",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
+ "files": ["src"],
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "typecheck": "tsc --noEmit"
11
+ },
12
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "deckofcards", "cards", "games"],
13
+ "author": "Pipeworx <hello@pipeworx.io>",
14
+ "license": "MIT",
15
+ "devDependencies": {
16
+ "typescript": "^5.0.0"
17
+ }
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Deck of Cards MCP — wraps deckofcardsapi.com (free, no auth)
3
+ *
4
+ * Tools:
5
+ * - new_deck: Create and shuffle a new deck of cards
6
+ * - draw_cards: Draw one or more cards from an existing deck
7
+ * - shuffle_deck: Shuffle (or re-shuffle) an existing deck
8
+ */
9
+
10
+ interface McpToolDefinition {
11
+ name: string;
12
+ description: string;
13
+ inputSchema: {
14
+ type: 'object';
15
+ properties: Record<string, unknown>;
16
+ required?: string[];
17
+ };
18
+ }
19
+
20
+ interface McpToolExport {
21
+ tools: McpToolDefinition[];
22
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
23
+ }
24
+
25
+ const BASE_URL = 'https://deckofcardsapi.com/api/deck';
26
+
27
+ type RawCard = {
28
+ code: string;
29
+ image: string;
30
+ value: string;
31
+ suit: string;
32
+ };
33
+
34
+ type RawDeckResponse = {
35
+ success: boolean;
36
+ deck_id: string;
37
+ shuffled: boolean;
38
+ remaining: number;
39
+ };
40
+
41
+ type RawDrawResponse = {
42
+ success: boolean;
43
+ deck_id: string;
44
+ cards: RawCard[];
45
+ remaining: number;
46
+ };
47
+
48
+ function formatCard(c: RawCard) {
49
+ return {
50
+ code: c.code,
51
+ value: c.value,
52
+ suit: c.suit,
53
+ image: c.image,
54
+ };
55
+ }
56
+
57
+ const tools: McpToolExport['tools'] = [
58
+ {
59
+ name: 'new_deck',
60
+ description:
61
+ 'Create and shuffle a new deck (or multiple decks) of playing cards. Returns a deck_id for subsequent draws.',
62
+ inputSchema: {
63
+ type: 'object',
64
+ properties: {
65
+ count: {
66
+ type: 'number',
67
+ description: 'Number of standard 52-card decks to combine and shuffle. Defaults to 1.',
68
+ },
69
+ },
70
+ },
71
+ },
72
+ {
73
+ name: 'draw_cards',
74
+ description:
75
+ 'Draw one or more cards from an existing deck. Requires the deck_id returned by new_deck.',
76
+ inputSchema: {
77
+ type: 'object',
78
+ properties: {
79
+ deck_id: {
80
+ type: 'string',
81
+ description: 'The deck ID returned by new_deck (e.g. "3p40paa87x90").',
82
+ },
83
+ count: {
84
+ type: 'number',
85
+ description: 'Number of cards to draw. Defaults to 1.',
86
+ },
87
+ },
88
+ required: ['deck_id'],
89
+ },
90
+ },
91
+ {
92
+ name: 'shuffle_deck',
93
+ description:
94
+ 'Shuffle (or re-shuffle) an existing deck, returning all drawn cards back into it.',
95
+ inputSchema: {
96
+ type: 'object',
97
+ properties: {
98
+ deck_id: {
99
+ type: 'string',
100
+ description: 'The deck ID to shuffle (e.g. "3p40paa87x90").',
101
+ },
102
+ },
103
+ required: ['deck_id'],
104
+ },
105
+ },
106
+ ];
107
+
108
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
109
+ switch (name) {
110
+ case 'new_deck':
111
+ return newDeck((args.count as number | undefined) ?? 1);
112
+ case 'draw_cards':
113
+ return drawCards(args.deck_id as string, (args.count as number | undefined) ?? 1);
114
+ case 'shuffle_deck':
115
+ return shuffleDeck(args.deck_id as string);
116
+ default:
117
+ throw new Error(`Unknown tool: ${name}`);
118
+ }
119
+ }
120
+
121
+ async function newDeck(count: number) {
122
+ const res = await fetch(`${BASE_URL}/new/shuffle/?deck_count=${count}`);
123
+ if (!res.ok) throw new Error(`Deck of Cards API error: ${res.status}`);
124
+
125
+ const data = (await res.json()) as RawDeckResponse;
126
+ if (!data.success) throw new Error('Deck of Cards API returned success: false');
127
+
128
+ return {
129
+ deck_id: data.deck_id,
130
+ shuffled: data.shuffled,
131
+ remaining: data.remaining,
132
+ };
133
+ }
134
+
135
+ async function drawCards(deckId: string, count: number) {
136
+ const res = await fetch(`${BASE_URL}/${encodeURIComponent(deckId)}/draw/?count=${count}`);
137
+ if (!res.ok) throw new Error(`Deck of Cards API error: ${res.status}`);
138
+
139
+ const data = (await res.json()) as RawDrawResponse;
140
+ if (!data.success) throw new Error('Deck of Cards API returned success: false');
141
+
142
+ return {
143
+ deck_id: data.deck_id,
144
+ cards: data.cards.map(formatCard),
145
+ remaining: data.remaining,
146
+ };
147
+ }
148
+
149
+ async function shuffleDeck(deckId: string) {
150
+ const res = await fetch(`${BASE_URL}/${encodeURIComponent(deckId)}/shuffle/`);
151
+ if (!res.ok) throw new Error(`Deck of Cards API error: ${res.status}`);
152
+
153
+ const data = (await res.json()) as RawDeckResponse;
154
+ if (!data.success) throw new Error('Deck of Cards API returned success: false');
155
+
156
+ return {
157
+ deck_id: data.deck_id,
158
+ shuffled: data.shuffled,
159
+ remaining: data.remaining,
160
+ };
161
+ }
162
+
163
+ export default { tools, callTool } satisfies McpToolExport;