@pipeworx/mcp-colorapi 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 +36 -0
- package/package.json +10 -0
- package/src/index.ts +165 -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,36 @@
|
|
|
1
|
+
# @pipeworx/mcp-colorapi
|
|
2
|
+
|
|
3
|
+
MCP server for [The Color API](https://www.thecolorapi.com) — identify colors by hex, generate color schemes, and convert between RGB/HSL/HSV/CMYK formats. Free, no auth required.
|
|
4
|
+
|
|
5
|
+
## Tools
|
|
6
|
+
|
|
7
|
+
| Tool | Description |
|
|
8
|
+
|------|-------------|
|
|
9
|
+
| `identify_color` | Get color name, all formats, and contrast info for a hex value |
|
|
10
|
+
| `generate_scheme` | Generate a harmonious color scheme (monochrome, analogic, complement, triad, quad) |
|
|
11
|
+
| `convert_color` | Convert an RGB color to all other formats |
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
Add to your MCP client config:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"mcpServers": {
|
|
20
|
+
"colorapi": {
|
|
21
|
+
"type": "url",
|
|
22
|
+
"url": "https://gateway.pipeworx.io/colorapi"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## CLI Usage
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx @anthropic-ai/mcp-client https://gateway.pipeworx.io/colorapi
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
MIT
|
package/package.json
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color API MCP — wraps thecolorapi.com (free, no auth)
|
|
3
|
+
*
|
|
4
|
+
* Tools:
|
|
5
|
+
* - identify_color: Get color name, formats, and contrast info for a hex value
|
|
6
|
+
* - generate_scheme: Generate a color scheme from a hex value and mode
|
|
7
|
+
* - convert_color: Convert an RGB color to all other formats
|
|
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://www.thecolorapi.com';
|
|
26
|
+
|
|
27
|
+
type RawColor = {
|
|
28
|
+
hex: { value: string; clean: string };
|
|
29
|
+
rgb: { r: number; g: number; b: number; value: string };
|
|
30
|
+
hsl: { h: number; s: number; l: number; value: string };
|
|
31
|
+
hsv: { h: number; s: number; v: number; value: string };
|
|
32
|
+
cmyk: { c: number; m: number; y: number; k: number; value: string };
|
|
33
|
+
name: { value: string; closest_named_hex: string; exact_match_name: boolean };
|
|
34
|
+
contrast: { value: string };
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type RawSchemeResponse = {
|
|
38
|
+
mode: string;
|
|
39
|
+
count: number;
|
|
40
|
+
colors: RawColor[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function formatColor(c: RawColor) {
|
|
44
|
+
return {
|
|
45
|
+
name: c.name.value,
|
|
46
|
+
exact_name_match: c.name.exact_match_name,
|
|
47
|
+
closest_named_hex: c.name.closest_named_hex,
|
|
48
|
+
hex: c.hex.value,
|
|
49
|
+
rgb: c.rgb.value,
|
|
50
|
+
hsl: c.hsl.value,
|
|
51
|
+
hsv: c.hsv.value,
|
|
52
|
+
cmyk: c.cmyk.value,
|
|
53
|
+
contrast: c.contrast.value,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const tools: McpToolExport['tools'] = [
|
|
58
|
+
{
|
|
59
|
+
name: 'identify_color',
|
|
60
|
+
description:
|
|
61
|
+
'Identify a color by its hex value. Returns the color name, all format representations (RGB, HSL, HSV, CMYK), and contrast info.',
|
|
62
|
+
inputSchema: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties: {
|
|
65
|
+
hex: {
|
|
66
|
+
type: 'string',
|
|
67
|
+
description: 'Hex color value without the # prefix (e.g. "FF5733").',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
required: ['hex'],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'generate_scheme',
|
|
75
|
+
description:
|
|
76
|
+
'Generate a color scheme from a seed hex color. Returns a set of harmonious colors based on the chosen mode.',
|
|
77
|
+
inputSchema: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: {
|
|
80
|
+
hex: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
description: 'Seed hex color value without the # prefix (e.g. "FF5733").',
|
|
83
|
+
},
|
|
84
|
+
mode: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
description:
|
|
87
|
+
'Color scheme mode. One of: monochrome, analogic, complement, triad, quad. Defaults to "monochrome".',
|
|
88
|
+
},
|
|
89
|
+
count: {
|
|
90
|
+
type: 'number',
|
|
91
|
+
description: 'Number of colors to return (1-10, default 5).',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
required: ['hex'],
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'convert_color',
|
|
99
|
+
description:
|
|
100
|
+
'Convert an RGB color to all other color formats (hex, HSL, HSV, CMYK) and get its closest color name.',
|
|
101
|
+
inputSchema: {
|
|
102
|
+
type: 'object',
|
|
103
|
+
properties: {
|
|
104
|
+
r: { type: 'number', description: 'Red channel (0-255).' },
|
|
105
|
+
g: { type: 'number', description: 'Green channel (0-255).' },
|
|
106
|
+
b: { type: 'number', description: 'Blue channel (0-255).' },
|
|
107
|
+
},
|
|
108
|
+
required: ['r', 'g', 'b'],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
114
|
+
switch (name) {
|
|
115
|
+
case 'identify_color':
|
|
116
|
+
return identifyColor(args.hex as string);
|
|
117
|
+
case 'generate_scheme':
|
|
118
|
+
return generateScheme(
|
|
119
|
+
args.hex as string,
|
|
120
|
+
(args.mode as string | undefined) ?? 'monochrome',
|
|
121
|
+
(args.count as number | undefined) ?? 5,
|
|
122
|
+
);
|
|
123
|
+
case 'convert_color':
|
|
124
|
+
return convertColor(args.r as number, args.g as number, args.b as number);
|
|
125
|
+
default:
|
|
126
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function identifyColor(hex: string) {
|
|
131
|
+
const clean = hex.replace(/^#/, '');
|
|
132
|
+
const res = await fetch(`${BASE_URL}/id?hex=${encodeURIComponent(clean)}`);
|
|
133
|
+
if (!res.ok) throw new Error(`Color API error: ${res.status}`);
|
|
134
|
+
const data = (await res.json()) as RawColor;
|
|
135
|
+
return formatColor(data);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function generateScheme(hex: string, mode: string, count: number) {
|
|
139
|
+
const clean = hex.replace(/^#/, '');
|
|
140
|
+
const safeCount = Math.min(10, Math.max(1, count));
|
|
141
|
+
const params = new URLSearchParams({
|
|
142
|
+
hex: clean,
|
|
143
|
+
mode,
|
|
144
|
+
count: String(safeCount),
|
|
145
|
+
});
|
|
146
|
+
const res = await fetch(`${BASE_URL}/scheme?${params}`);
|
|
147
|
+
if (!res.ok) throw new Error(`Color API error: ${res.status}`);
|
|
148
|
+
const data = (await res.json()) as RawSchemeResponse;
|
|
149
|
+
return {
|
|
150
|
+
seed_hex: `#${clean}`,
|
|
151
|
+
mode: data.mode,
|
|
152
|
+
count: data.count,
|
|
153
|
+
colors: data.colors.map(formatColor),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function convertColor(r: number, g: number, b: number) {
|
|
158
|
+
const params = new URLSearchParams({ rgb: `rgb(${r},${g},${b})` });
|
|
159
|
+
const res = await fetch(`${BASE_URL}/id?${params}`);
|
|
160
|
+
if (!res.ok) throw new Error(`Color API error: ${res.status}`);
|
|
161
|
+
const data = (await res.json()) as RawColor;
|
|
162
|
+
return formatColor(data);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default { tools, callTool } satisfies McpToolExport;
|