daily-color 3.0.0 → 4.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.
- package/README.md +64 -0
- package/bin/daily-color-mcp.js +458 -0
- package/bin/dailycolor.js +2 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -96,6 +96,57 @@ dailycolor --help # all the options
|
|
|
96
96
|
dailycolor --version
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
+
### For your AI
|
|
100
|
+
|
|
101
|
+
daily-color comes with an [MCP](https://modelcontextprotocol.io) server, so an AI assistant can look up the color of any day and the colors that go with it. It has:
|
|
102
|
+
|
|
103
|
+
- A tool, `get_daily_colors`, which the AI uses when it wants colors. It takes an optional `date` (like `2027-01-01`, today if left out) and `days` (up to 31 days in a row).
|
|
104
|
+
- Resources, which you can attach to a conversation yourself: `daily-color://today`, or any day, like `daily-color://2027-01-01`. Apps that subscribe to `daily-color://today` hear when it changes at midnight.
|
|
105
|
+
- A prompt, `theme_from_daily_color`, which asks for a website color theme made from a day's colors. It takes an optional `date`, and `mode` (`light` or `dark`, or leave it out for both). In Claude Code it's the `/mcp__daily-color__theme_from_daily_color` command.
|
|
106
|
+
|
|
107
|
+
Apps that support it can suggest dates and modes as you type them.
|
|
108
|
+
|
|
109
|
+
In Claude Code:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
claude mcp add daily-color -- npx -y -p daily-color daily-color-mcp
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
In Claude Desktop (Settings → Developer → Edit Config) or Cursor (`~/.cursor/mcp.json`):
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{
|
|
119
|
+
"mcpServers": {
|
|
120
|
+
"daily-color": {
|
|
121
|
+
"command": "npx",
|
|
122
|
+
"args": ["-y", "-p", "daily-color", "daily-color-mcp"]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
In VS Code (`.vscode/mcp.json`):
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"servers": {
|
|
133
|
+
"daily-color": {
|
|
134
|
+
"type": "stdio",
|
|
135
|
+
"command": "npx",
|
|
136
|
+
"args": ["-y", "-p", "daily-color", "daily-color-mcp"]
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Then ask something like "What's today's color, and what goes with it?" or "Give me the colors for next week".
|
|
143
|
+
|
|
144
|
+
To try the server out by hand, open it in the MCP Inspector:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
npx @modelcontextprotocol/inspector node bin/daily-color-mcp.js
|
|
148
|
+
```
|
|
149
|
+
|
|
99
150
|
Just want to see today's color?
|
|
100
151
|
|
|
101
152
|
There is a demo on [www.druewilding.com/daily-color](https://www.druewilding.com/daily-color/)
|
|
@@ -112,6 +163,19 @@ Install dependencies:
|
|
|
112
163
|
npm install
|
|
113
164
|
```
|
|
114
165
|
|
|
166
|
+
See the demo page at [localhost:6766](http://localhost:6766):
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
npm run dev
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Make the pictures in the day's color: the one that shows when someone shares the page, and the home screen icons for phones. It needs Chrome, and the site makes new ones every day when it deploys:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
npm run images # today's
|
|
176
|
+
npm run images -- --date 2027-01-01 # another day's
|
|
177
|
+
```
|
|
178
|
+
|
|
115
179
|
Run tests:
|
|
116
180
|
|
|
117
181
|
```bash
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// An MCP (Model Context Protocol) server that lets an AI look up daily colors.
|
|
4
|
+
//
|
|
5
|
+
// MCP is JSON-RPC 2.0. With the stdio transport, the AI app starts this file
|
|
6
|
+
// as a child process and the two talk over stdin and stdout, one JSON message
|
|
7
|
+
// per line. Anything else printed to stdout would break the conversation, so
|
|
8
|
+
// logs go to stderr.
|
|
9
|
+
//
|
|
10
|
+
// A session goes like this:
|
|
11
|
+
// 1. The client sends "initialize". We agree on a protocol version and say
|
|
12
|
+
// what we can do (our "capabilities": here, just tools).
|
|
13
|
+
// 2. The client sends "notifications/initialized". Notifications have no
|
|
14
|
+
// id and never get a reply.
|
|
15
|
+
// 3. The client asks "tools/list" to learn what tools there are, and shows
|
|
16
|
+
// their names, descriptions and input schemas to the model.
|
|
17
|
+
// 4. When the model wants a tool, the client sends "tools/call".
|
|
18
|
+
//
|
|
19
|
+
// Tools are one of three things a server can offer:
|
|
20
|
+
// - Tools are for the model: it decides when to call them.
|
|
21
|
+
// - Resources are for the app: data it can read by URI and put in front of
|
|
22
|
+
// the model, like attaching a file. Here, daily-color://2027-01-01.
|
|
23
|
+
// - Prompts are for the user: ready-made requests they pick from a menu,
|
|
24
|
+
// often as a slash command. Here, a theme made from the day's colors.
|
|
25
|
+
//
|
|
26
|
+
// Most messages are requests from the client with a reply from us. Two
|
|
27
|
+
// things here go further:
|
|
28
|
+
// - Subscriptions: the client can subscribe to a resource, and we send it
|
|
29
|
+
// a notification when that resource changes. daily-color://today changes
|
|
30
|
+
// at midnight.
|
|
31
|
+
// - Completions: while the user types a prompt argument or fills in a
|
|
32
|
+
// resource template, the client can ask us for suggestions.
|
|
33
|
+
|
|
34
|
+
import { readFileSync } from "node:fs";
|
|
35
|
+
import { createInterface } from "node:readline";
|
|
36
|
+
|
|
37
|
+
import { getDailyPalette } from "../index.js";
|
|
38
|
+
|
|
39
|
+
const { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
40
|
+
|
|
41
|
+
// Newest first. We answer in the client's version when we know it, and
|
|
42
|
+
// otherwise offer our newest and let the client decide whether to carry on.
|
|
43
|
+
const PROTOCOL_VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
|
|
44
|
+
|
|
45
|
+
const MAX_DAYS = 31;
|
|
46
|
+
const MAX_COMPLETIONS = 100; // the most the protocol allows in one reply
|
|
47
|
+
|
|
48
|
+
// The tests set this to see what happens at midnight without waiting for it
|
|
49
|
+
const CLOCK_OFFSET = process.env.DAILY_COLOR_MCP_NOW ? new Date(process.env.DAILY_COLOR_MCP_NOW) - Date.now() : 0;
|
|
50
|
+
const now = () => new Date(Date.now() + CLOCK_OFFSET);
|
|
51
|
+
|
|
52
|
+
// Standard JSON-RPC error codes
|
|
53
|
+
const PARSE_ERROR = -32700;
|
|
54
|
+
const INVALID_REQUEST = -32600;
|
|
55
|
+
const METHOD_NOT_FOUND = -32601;
|
|
56
|
+
const INVALID_PARAMS = -32602;
|
|
57
|
+
const RESOURCE_NOT_FOUND = -32002; // MCP's own code, for resources/read
|
|
58
|
+
|
|
59
|
+
const HEX = { type: "string", pattern: "^#[0-9a-f]{6}$" };
|
|
60
|
+
const PAIR = { type: "array", items: HEX, minItems: 2, maxItems: 2 };
|
|
61
|
+
|
|
62
|
+
const DAY_SCHEMA = {
|
|
63
|
+
type: "object",
|
|
64
|
+
properties: {
|
|
65
|
+
date: { type: "string", description: "The day, as YYYY-MM-DD" },
|
|
66
|
+
color: { ...HEX, description: "The day's color" },
|
|
67
|
+
contrast: { ...HEX, description: "Black or white, whichever is easier to read on the day's color" },
|
|
68
|
+
complementary: { ...HEX, description: "Opposite the day's color on the color wheel" },
|
|
69
|
+
splitComplementary: { ...PAIR, description: "Either side of the complementary color" },
|
|
70
|
+
analogous: { ...PAIR, description: "Next to the day's color on the color wheel" },
|
|
71
|
+
triadic: { ...PAIR, description: "A third of the way round the color wheel each way" },
|
|
72
|
+
tetradic: {
|
|
73
|
+
type: "array",
|
|
74
|
+
items: HEX,
|
|
75
|
+
minItems: 3,
|
|
76
|
+
maxItems: 3,
|
|
77
|
+
description: "With the day's color, a square round the color wheel",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
required: ["date", "color", "contrast", "complementary", "splitComplementary", "analogous", "triadic", "tetradic"],
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// What the model sees. The descriptions matter: they are how the model
|
|
84
|
+
// decides when to use the tool and what to pass it.
|
|
85
|
+
const TOOLS = [
|
|
86
|
+
{
|
|
87
|
+
name: "get_daily_colors",
|
|
88
|
+
title: "Daily colors",
|
|
89
|
+
description:
|
|
90
|
+
"Get the daily color for a date, and the colors that go with it (complementary, split-complementary, " +
|
|
91
|
+
"analogous, triadic and tetradic), as hex codes. Every date has its own color, the same for everyone. " +
|
|
92
|
+
"The matching colors keep the day's color's lightness and strength. Use `days` to get several days in a row.",
|
|
93
|
+
inputSchema: {
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
date: {
|
|
97
|
+
type: "string",
|
|
98
|
+
pattern: "^\\d{4}-\\d{2}-\\d{2}$",
|
|
99
|
+
description: "The day, as YYYY-MM-DD. Leave it out for today.",
|
|
100
|
+
},
|
|
101
|
+
days: {
|
|
102
|
+
type: "integer",
|
|
103
|
+
minimum: 1,
|
|
104
|
+
maximum: MAX_DAYS,
|
|
105
|
+
default: 1,
|
|
106
|
+
description: "How many days to get, starting at `date`",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
additionalProperties: false,
|
|
110
|
+
},
|
|
111
|
+
outputSchema: {
|
|
112
|
+
type: "object",
|
|
113
|
+
properties: { days: { type: "array", items: DAY_SCHEMA } },
|
|
114
|
+
required: ["days"],
|
|
115
|
+
},
|
|
116
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false },
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
// Something wrong with what we were asked for, like a date that doesn't
|
|
121
|
+
// exist. Each kind of request reports it in its own way.
|
|
122
|
+
class ArgumentError extends Error {}
|
|
123
|
+
|
|
124
|
+
// One day's colors, the same for the tool, the resources and the prompt
|
|
125
|
+
function colorsFor(day) {
|
|
126
|
+
return { date: formatDate(day), ...getDailyPalette(day) };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getDailyColors({ date, days = 1, ...rest } = {}) {
|
|
130
|
+
const unknown = Object.keys(rest);
|
|
131
|
+
if (unknown.length) throw new ArgumentError(`Unknown argument: ${unknown.join(", ")}`);
|
|
132
|
+
if (!Number.isInteger(days) || days < 1 || days > MAX_DAYS) {
|
|
133
|
+
throw new ArgumentError(`"days" must be a whole number from 1 to ${MAX_DAYS}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const start = date === undefined ? today() : parseDate(date);
|
|
137
|
+
const result = [];
|
|
138
|
+
for (let i = 0; i < days; i++) {
|
|
139
|
+
result.push(colorsFor(new Date(start.getFullYear(), start.getMonth(), start.getDate() + i)));
|
|
140
|
+
}
|
|
141
|
+
return { days: result };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// "Today" is the day where this server runs, which is where its user is
|
|
145
|
+
function today() {
|
|
146
|
+
const time = now();
|
|
147
|
+
return new Date(time.getFullYear(), time.getMonth(), time.getDate());
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// A day where you are, not UTC midnight. A day that doesn't exist, like
|
|
151
|
+
// 2027-02-30, would roll over into the next month, and Date reads years 0 to
|
|
152
|
+
// 99 as 1900 to 1999, so the day has to come back as it went in.
|
|
153
|
+
function parseDate(value) {
|
|
154
|
+
const m = typeof value === "string" && /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
155
|
+
const day = m && new Date(+m[1], +m[2] - 1, +m[3]);
|
|
156
|
+
if (!day || day.getFullYear() !== +m[1] || day.getMonth() !== +m[2] - 1) {
|
|
157
|
+
throw new ArgumentError(`"${value}" isn't a date like 2027-01-01`);
|
|
158
|
+
}
|
|
159
|
+
return day;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function formatDate(day) {
|
|
163
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
164
|
+
return `${day.getFullYear()}-${pad(day.getMonth() + 1)}-${pad(day.getDate())}`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function callTool({ name, arguments: args } = {}) {
|
|
168
|
+
if (name !== "get_daily_colors") throw rpcError(INVALID_PARAMS, `Unknown tool: ${name}`);
|
|
169
|
+
try {
|
|
170
|
+
const structured = getDailyColors(args ?? {});
|
|
171
|
+
return {
|
|
172
|
+
// Clients that don't read structuredContent still get the same thing as text
|
|
173
|
+
content: [{ type: "text", text: JSON.stringify(structured, null, 2) }],
|
|
174
|
+
structuredContent: structured,
|
|
175
|
+
};
|
|
176
|
+
} catch (error) {
|
|
177
|
+
// A tool's own failures are results with isError, not protocol errors,
|
|
178
|
+
// so the model sees the message and can try again
|
|
179
|
+
if (!(error instanceof ArgumentError)) throw error;
|
|
180
|
+
return { content: [{ type: "text", text: error.message }], isError: true };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Resources. "today" is listed as it is; any other day comes from the
|
|
185
|
+
// template, which tells the app how to make a URI for itself.
|
|
186
|
+
const RESOURCES = [
|
|
187
|
+
{
|
|
188
|
+
uri: "daily-color://today",
|
|
189
|
+
name: "today",
|
|
190
|
+
title: "Today's colors",
|
|
191
|
+
description: "Today's color and the colors that go with it",
|
|
192
|
+
mimeType: "application/json",
|
|
193
|
+
},
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
const RESOURCE_TEMPLATES = [
|
|
197
|
+
{
|
|
198
|
+
uriTemplate: "daily-color://{date}",
|
|
199
|
+
name: "day",
|
|
200
|
+
title: "A day's colors",
|
|
201
|
+
description: "The color for a date (YYYY-MM-DD) and the colors that go with it",
|
|
202
|
+
mimeType: "application/json",
|
|
203
|
+
},
|
|
204
|
+
];
|
|
205
|
+
|
|
206
|
+
// The day a resource URI is for, or a RESOURCE_NOT_FOUND error
|
|
207
|
+
function resourceDay(uri) {
|
|
208
|
+
const m = /^daily-color:\/\/(.+)$/.exec(uri ?? "");
|
|
209
|
+
try {
|
|
210
|
+
if (!m) throw new ArgumentError(`There's no resource at ${uri}`);
|
|
211
|
+
return m[1] === "today" ? today() : parseDate(m[1]);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (error instanceof ArgumentError) throw rpcError(RESOURCE_NOT_FOUND, error.message);
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function readResource({ uri } = {}) {
|
|
219
|
+
const colors = colorsFor(resourceDay(uri));
|
|
220
|
+
return { contents: [{ uri, mimeType: "application/json", text: JSON.stringify(colors, null, 2) }] };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Subscriptions. Only daily-color://today ever changes, but subscribing to
|
|
224
|
+
// a particular day is allowed too: it just never sends anything.
|
|
225
|
+
const subscriptions = new Set();
|
|
226
|
+
|
|
227
|
+
function subscribe({ uri } = {}) {
|
|
228
|
+
resourceDay(uri); // so a URI that doesn't exist is an error
|
|
229
|
+
subscriptions.add(uri);
|
|
230
|
+
return {};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function unsubscribe({ uri } = {}) {
|
|
234
|
+
subscriptions.delete(uri);
|
|
235
|
+
return {};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Wakes up at midnight, and tells the client today's colors have changed if
|
|
239
|
+
// it subscribed to them. Timers can wake a little early, and a computer that
|
|
240
|
+
// sleeps can make them late, so it checks the date when it wakes, and never
|
|
241
|
+
// sleeps more than an hour at a time.
|
|
242
|
+
let lastDay = formatDate(today());
|
|
243
|
+
|
|
244
|
+
function watchTheDate() {
|
|
245
|
+
const time = now();
|
|
246
|
+
const midnight = new Date(time.getFullYear(), time.getMonth(), time.getDate() + 1);
|
|
247
|
+
const timer = setTimeout(
|
|
248
|
+
() => {
|
|
249
|
+
const day = formatDate(today());
|
|
250
|
+
if (day !== lastDay) {
|
|
251
|
+
lastDay = day;
|
|
252
|
+
if (subscriptions.has("daily-color://today")) {
|
|
253
|
+
send({ jsonrpc: "2.0", method: "notifications/resources/updated", params: { uri: "daily-color://today" } });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
watchTheDate();
|
|
257
|
+
},
|
|
258
|
+
Math.min(midnight - time + 10, 60 * 60 * 1000)
|
|
259
|
+
);
|
|
260
|
+
timer.unref(); // so the server still stops when the client goes away
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Prompts. Their arguments are always strings, filled in by the user.
|
|
264
|
+
const PROMPTS = [
|
|
265
|
+
{
|
|
266
|
+
name: "theme_from_daily_color",
|
|
267
|
+
title: "Theme from the daily color",
|
|
268
|
+
description:
|
|
269
|
+
"Make a website color theme, as CSS custom properties, from a day's color and the colors that go with it",
|
|
270
|
+
arguments: [
|
|
271
|
+
{ name: "date", description: "The day, as YYYY-MM-DD. Leave it out for today.", required: false },
|
|
272
|
+
{ name: "mode", description: '"light", "dark", or leave it out for both', required: false },
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
];
|
|
276
|
+
|
|
277
|
+
const MODES = {
|
|
278
|
+
light: "a light theme",
|
|
279
|
+
dark: "a dark theme",
|
|
280
|
+
both: "a light theme, and a dark one inside @media (prefers-color-scheme: dark)",
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
function getPrompt({ name, arguments: args } = {}) {
|
|
284
|
+
if (name !== "theme_from_daily_color") throw rpcError(INVALID_PARAMS, `Unknown prompt: ${name}`);
|
|
285
|
+
// Apps often send "" for an argument the user left blank
|
|
286
|
+
const date = args?.date || undefined;
|
|
287
|
+
const mode = args?.mode || "both";
|
|
288
|
+
if (!MODES[mode]) throw rpcError(INVALID_PARAMS, '"mode" must be "light" or "dark", or left out for both');
|
|
289
|
+
|
|
290
|
+
let day;
|
|
291
|
+
try {
|
|
292
|
+
day = date === undefined ? today() : parseDate(date);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
throw error instanceof ArgumentError ? rpcError(INVALID_PARAMS, error.message) : error;
|
|
295
|
+
}
|
|
296
|
+
const colors = colorsFor(day);
|
|
297
|
+
const uri = `daily-color://${colors.date}`;
|
|
298
|
+
|
|
299
|
+
return {
|
|
300
|
+
description: `A theme from the color for ${colors.date}`,
|
|
301
|
+
messages: [
|
|
302
|
+
{
|
|
303
|
+
role: "user",
|
|
304
|
+
content: {
|
|
305
|
+
type: "text",
|
|
306
|
+
text:
|
|
307
|
+
`Make a website color theme from the daily color for ${colors.date}, which is ${colors.color}. ` +
|
|
308
|
+
"It and the colors that go with it are attached.\n\n" +
|
|
309
|
+
`Write it as CSS custom properties on :root, for ${MODES[mode]}: background, surface, text, ` +
|
|
310
|
+
"muted text, primary, accent and border. Keep the day's character, but tint the background " +
|
|
311
|
+
"and surface only faintly with its hue rather than using colors at full strength. Text, muted " +
|
|
312
|
+
"text and primary must each reach at least 4.5:1 contrast with the background (WCAG AA), so " +
|
|
313
|
+
"make colors darker or lighter where they need it. Afterwards, say in a sentence or two which " +
|
|
314
|
+
"of the day's colors went where.",
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
// An embedded resource: the data travels with the prompt, so the
|
|
319
|
+
// model doesn't need to call a tool to see it
|
|
320
|
+
role: "user",
|
|
321
|
+
content: {
|
|
322
|
+
type: "resource",
|
|
323
|
+
resource: { uri, mimeType: "application/json", text: JSON.stringify(colors, null, 2) },
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
],
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// The server's icon, for apps that show one: a dot of today's color, with a
|
|
331
|
+
// faint ring so a pale one still shows. It's sent as a data: URI, so there's
|
|
332
|
+
// nothing to host.
|
|
333
|
+
function icon() {
|
|
334
|
+
const { color, contrast } = getDailyPalette(today());
|
|
335
|
+
const svg =
|
|
336
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><circle cx="16" cy="16" r="14.5" ' +
|
|
337
|
+
`fill="${color}" stroke="${contrast}" stroke-opacity="0.35" stroke-width="2"/></svg>`;
|
|
338
|
+
return {
|
|
339
|
+
src: `data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`,
|
|
340
|
+
mimeType: "image/svg+xml",
|
|
341
|
+
sizes: ["any"],
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const METHODS = {
|
|
346
|
+
initialize: ({ protocolVersion } = {}) => ({
|
|
347
|
+
protocolVersion: PROTOCOL_VERSIONS.includes(protocolVersion) ? protocolVersion : PROTOCOL_VERSIONS[0],
|
|
348
|
+
capabilities: { tools: {}, resources: { subscribe: true }, prompts: {}, completions: {} },
|
|
349
|
+
serverInfo: { name: "daily-color", title: "Daily color", version, icons: [icon()] },
|
|
350
|
+
instructions:
|
|
351
|
+
"Look up the color of any day, and the colors that go with it, with get_daily_colors. " +
|
|
352
|
+
"The same colors are resources at daily-color://YYYY-MM-DD and daily-color://today.",
|
|
353
|
+
}),
|
|
354
|
+
ping: () => ({}),
|
|
355
|
+
"tools/list": () => ({ tools: TOOLS }),
|
|
356
|
+
"tools/call": callTool,
|
|
357
|
+
"resources/list": () => ({ resources: RESOURCES }),
|
|
358
|
+
"resources/templates/list": () => ({ resourceTemplates: RESOURCE_TEMPLATES }),
|
|
359
|
+
"resources/read": readResource,
|
|
360
|
+
"resources/subscribe": subscribe,
|
|
361
|
+
"resources/unsubscribe": unsubscribe,
|
|
362
|
+
"prompts/list": () => ({ prompts: PROMPTS }),
|
|
363
|
+
"prompts/get": getPrompt,
|
|
364
|
+
"completion/complete": getCompletions,
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// Completions. The client tells us what the user has typed so far, and we
|
|
368
|
+
// suggest whole values that start with it.
|
|
369
|
+
const complete = (values, typed) => {
|
|
370
|
+
const matches = [...new Set(values)].filter((value) => value.startsWith(typed));
|
|
371
|
+
return {
|
|
372
|
+
completion: {
|
|
373
|
+
values: matches.slice(0, MAX_COMPLETIONS),
|
|
374
|
+
total: matches.length,
|
|
375
|
+
hasMore: matches.length > MAX_COMPLETIONS,
|
|
376
|
+
},
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// The coming year, and once a year is typed, every day of that year too
|
|
381
|
+
function dateSuggestions(typed) {
|
|
382
|
+
const start = today();
|
|
383
|
+
const days = Array.from(
|
|
384
|
+
{ length: 365 },
|
|
385
|
+
(_, i) => new Date(start.getFullYear(), start.getMonth(), start.getDate() + i)
|
|
386
|
+
);
|
|
387
|
+
const year = /^\d{4}/.exec(typed);
|
|
388
|
+
if (year) {
|
|
389
|
+
for (let day = new Date(+year[0], 0, 1); day.getFullYear() === +year[0]; day.setDate(day.getDate() + 1)) {
|
|
390
|
+
days.push(new Date(day));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return days.map(formatDate);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function getCompletions({ ref = {}, argument = {} } = {}) {
|
|
397
|
+
const { name, value = "" } = argument;
|
|
398
|
+
|
|
399
|
+
if (ref.type === "ref/prompt" && ref.name === "theme_from_daily_color") {
|
|
400
|
+
if (name === "mode") return complete(["light", "dark"], value);
|
|
401
|
+
if (name === "date") return complete(dateSuggestions(value), value);
|
|
402
|
+
} else if (ref.type === "ref/resource" && ref.uri === "daily-color://{date}") {
|
|
403
|
+
if (name === "date") return complete(["today", ...dateSuggestions(value)], value);
|
|
404
|
+
} else {
|
|
405
|
+
throw rpcError(INVALID_PARAMS, `Nothing to complete for ${ref.name ?? ref.uri}`);
|
|
406
|
+
}
|
|
407
|
+
return complete([], value); // an argument we have no suggestions for
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function rpcError(code, message) {
|
|
411
|
+
return Object.assign(new Error(message), { code });
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Works out the reply to one message, or null for a notification
|
|
415
|
+
function handle(message) {
|
|
416
|
+
if (message === null || typeof message !== "object" || Array.isArray(message) || message.jsonrpc !== "2.0") {
|
|
417
|
+
return { jsonrpc: "2.0", id: null, error: { code: INVALID_REQUEST, message: "Not a JSON-RPC 2.0 message" } };
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const { id, method, params } = message;
|
|
421
|
+
const isNotification = id === undefined;
|
|
422
|
+
|
|
423
|
+
// Replies to requests we never send, and notifications we don't need
|
|
424
|
+
// (like notifications/initialized), are fine to ignore
|
|
425
|
+
if (isNotification || method === undefined) return null;
|
|
426
|
+
|
|
427
|
+
try {
|
|
428
|
+
const run = METHODS[method];
|
|
429
|
+
if (!run) throw rpcError(METHOD_NOT_FOUND, `Unknown method: ${method}`);
|
|
430
|
+
if (params !== undefined && (params === null || typeof params !== "object" || Array.isArray(params))) {
|
|
431
|
+
throw rpcError(INVALID_PARAMS, "params must be an object");
|
|
432
|
+
}
|
|
433
|
+
return { jsonrpc: "2.0", id, result: run(params) };
|
|
434
|
+
} catch (error) {
|
|
435
|
+
const code = error.code ?? -32603; // Internal error
|
|
436
|
+
if (code === -32603) console.error(error);
|
|
437
|
+
return { jsonrpc: "2.0", id, error: { code, message: error.message } };
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function send(reply) {
|
|
442
|
+
if (reply) process.stdout.write(JSON.stringify(reply) + "\n");
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const lines = createInterface({ input: process.stdin });
|
|
446
|
+
lines.on("line", (line) => {
|
|
447
|
+
if (!line.trim()) return;
|
|
448
|
+
let message;
|
|
449
|
+
try {
|
|
450
|
+
message = JSON.parse(line);
|
|
451
|
+
} catch {
|
|
452
|
+
send({ jsonrpc: "2.0", id: null, error: { code: PARSE_ERROR, message: "That wasn't valid JSON" } });
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
send(handle(message));
|
|
456
|
+
});
|
|
457
|
+
watchTheDate();
|
|
458
|
+
console.error(`daily-color MCP server ${version} is running on stdio`);
|
package/bin/dailycolor.js
CHANGED
|
@@ -74,7 +74,8 @@ for (let i = 0; i < args.length; i++) {
|
|
|
74
74
|
function parseDate(value) {
|
|
75
75
|
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value || "");
|
|
76
76
|
const day = m && new Date(+m[1], +m[2] - 1, +m[3]);
|
|
77
|
-
if (!day || day.
|
|
77
|
+
if (!day || day.getFullYear() !== +m[1] || day.getMonth() !== +m[2] - 1)
|
|
78
|
+
fail(`"${value ?? ""}" isn't a date like 2027-01-01`);
|
|
78
79
|
return day;
|
|
79
80
|
}
|
|
80
81
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "daily-color",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Provides a unique hex code each day",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"color",
|
|
7
7
|
"daily",
|
|
8
8
|
"date",
|
|
9
9
|
"hash",
|
|
10
|
-
"hex color"
|
|
10
|
+
"hex color",
|
|
11
|
+
"mcp",
|
|
12
|
+
"model context protocol"
|
|
11
13
|
],
|
|
12
14
|
"homepage": "https://github.com/druewilding/daily-color#readme",
|
|
13
15
|
"bugs": {
|
|
@@ -23,6 +25,7 @@
|
|
|
23
25
|
],
|
|
24
26
|
"main": "index.js",
|
|
25
27
|
"bin": {
|
|
28
|
+
"daily-color-mcp": "bin/daily-color-mcp.js",
|
|
26
29
|
"dailycolor": "bin/dailycolor.js"
|
|
27
30
|
},
|
|
28
31
|
"repository": {
|
|
@@ -31,17 +34,20 @@
|
|
|
31
34
|
},
|
|
32
35
|
"type": "module",
|
|
33
36
|
"scripts": {
|
|
37
|
+
"dev": "serve --listen 6766",
|
|
34
38
|
"format": "prettier --write .",
|
|
35
39
|
"format:check": "prettier --check .",
|
|
40
|
+
"images": "node scripts/images.js",
|
|
36
41
|
"lint": "eslint --fix",
|
|
37
42
|
"lint:check": "eslint",
|
|
38
43
|
"package:lint": "npx npm-package-json-lint .",
|
|
39
44
|
"prepublishOnly": "npm run webpack",
|
|
40
|
-
"test": "node --test test
|
|
45
|
+
"test": "node --test \"test/*.js\"",
|
|
41
46
|
"webpack": "npx webpack"
|
|
42
47
|
},
|
|
43
48
|
"devDependencies": {
|
|
44
49
|
"eslint-config-plus-prettier": "5.0.0",
|
|
50
|
+
"serve": "14.2.8",
|
|
45
51
|
"webpack": "5.113.0",
|
|
46
52
|
"webpack-cli": "7.3.1"
|
|
47
53
|
},
|