@mdeleon23/wardrowbe-mcp 0.1.0 → 0.2.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 CHANGED
@@ -76,6 +76,26 @@ npx -y @mdeleon23/wardrowbe-mcp
76
76
 
77
77
  Register the server at `http://<host>:8080/mcp` with the header `Authorization: Bearer <MCP_API_KEY>`. `GET /` returns a small info response without auth.
78
78
 
79
+ ### Adding items from photos
80
+
81
+ Photos go to the server directly, not through the AI, so the model never has to handle image bytes:
82
+
83
+ 1. The app uploads the photo to `POST /uploads` with the same Bearer key. Send the raw image as the body, with `Content-Type` set to `image/jpeg`, `image/png`, `image/webp`, or `image/heic`. Optionally set `X-Filename` (URL-encoded).
84
+ 2. The response is `{"upload_id": "...", "expires_in_seconds": 600}`.
85
+ 3. The agent calls `add_item` with that `upload_id`. The upload is used once and then deleted. Uploads over 15 MB are refused, and uploads expire after 10 minutes.
86
+
87
+ ```bash
88
+ curl -s -X POST https://<host>:8080/uploads \
89
+ -H "Authorization: Bearer <MCP_API_KEY>" \
90
+ -H "Content-Type: image/jpeg" \
91
+ -H "X-Filename: blue-shirt.jpg" \
92
+ --data-binary @blue-shirt.jpg
93
+ ```
94
+
95
+ An agent can also do the whole thing through MCP with the `upload_photo` tool, which takes the photo as base64 (up to 300 KB) and returns an `upload_id` for `add_item`. The model has to write the image out in full, so keep photos small for this route. Full-size phone photos should go through `/uploads`.
96
+
97
+ `add_item` works over stdio too, as long as the `upload_id` came from `upload_photo` in the same server process. `/uploads` is HTTP only.
98
+
79
99
  ## Tools
80
100
 
81
101
  | Tool | Wardrowbe endpoint | Notes |
@@ -87,7 +107,18 @@ Register the server at `http://<host>:8080/mcp` with the header `Authorization:
87
107
  | `suggest_outfit` | `POST /outfits/suggest` | Rate limited to about 10 per minute per user. |
88
108
  | `accept_outfit` | `POST /outfits/{id}/accept` | |
89
109
  | `reject_outfit` | `POST /outfits/{id}/reject` | |
110
+ | `upload_photo` | `POST /uploads` (in-process) | Takes a small photo as base64 (up to 300 KB) and returns an `upload_id`. |
111
+ | `add_item` | `POST /items` | Takes an `upload_id` from `upload_photo` or `/uploads`. Wardrowbe detects the type unless you pass one. |
90
112
  | `get_analytics` | `GET /analytics` | `days` from 7 to 365. |
113
+ | `get_wardrobe_summary` | `GET /analytics` | Counts, insights, most and never worn items. Good first call. |
114
+ | `get_most_worn_items` | `GET /analytics` | Up to 5 items, from the same trend window. |
115
+ | `get_items_to_wash` | `GET /items?needs_wash=true` | Items worn since their last wash. |
116
+ | `archive_item` | `POST /items/{id}/archive` | Hides an item from suggestions. Reversible. Takes an optional `reason`. |
117
+ | `restore_item` | `POST /items/{id}/restore` | Brings an archived item back. |
118
+
119
+ ## Skill
120
+
121
+ The server publishes `skill://wardrowbe-skill/SKILL.md` as an MCP resource. It explains which tool to use for each task, how to add an item from a photo (including re-encoding large photos), and how archiving works. Clients that install skills pick it up automatically. The source is in [`skill/SKILL.md`](skill/SKILL.md).
91
122
 
92
123
  ## Development
93
124
 
package/dist/client.d.ts CHANGED
@@ -46,5 +46,7 @@ export declare class WardrowbeClient {
46
46
  constructor(config: Config, tokens: TokenProvider, fetchFn?: FetchFn);
47
47
  get<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
48
48
  post<T>(path: string, body?: unknown): Promise<T>;
49
+ /** Sends a multipart form, such as an item with its photo. The boundary header is set by fetch. */
50
+ postForm<T>(path: string, form: FormData): Promise<T>;
49
51
  private request;
50
52
  }
package/dist/client.js CHANGED
@@ -157,6 +157,10 @@ export class WardrowbeClient {
157
157
  post(path, body) {
158
158
  return this.request("POST", path, { body });
159
159
  }
160
+ /** Sends a multipart form, such as an item with its photo. The boundary header is set by fetch. */
161
+ postForm(path, form) {
162
+ return this.request("POST", path, { form });
163
+ }
160
164
  async request(method, path, opts) {
161
165
  const url = new URL(`${this.config.wardrowbeUrl}/api/v1${path}`);
162
166
  for (const [k, v] of Object.entries(opts.query ?? {})) {
@@ -169,7 +173,10 @@ export class WardrowbeClient {
169
173
  Accept: "application/json",
170
174
  };
171
175
  const init = { method, headers };
172
- if (opts.body !== undefined) {
176
+ if (opts.form) {
177
+ init.body = opts.form;
178
+ }
179
+ else if (opts.body !== undefined) {
173
180
  headers["Content-Type"] = "application/json";
174
181
  init.body = JSON.stringify(opts.body);
175
182
  }
package/dist/http.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import { type IncomingMessage, type ServerResponse } from "node:http";
2
2
  import type { Config } from "./config.js";
3
+ import { type UploadStore } from "./uploads.js";
3
4
  /** Constant-time check of the Bearer token, so the comparison doesn't leak the key by timing. */
4
5
  export declare function isAuthorized(header: string | undefined, apiKey: string): boolean;
5
- /** Serves the MCP endpoint at /mcp over Streamable HTTP, stateless, behind a Bearer API key. */
6
- export declare function createMcpHttpServer(config: Config): import("http").Server<typeof IncomingMessage, typeof ServerResponse>;
6
+ /**
7
+ * Serves the MCP endpoint at /mcp over Streamable HTTP, stateless, behind a Bearer API key.
8
+ * Also serves POST /uploads, where the app sends a photo before asking the agent to add it.
9
+ */
10
+ export declare function createMcpHttpServer(config: Config, uploads?: UploadStore): import("http").Server<typeof IncomingMessage, typeof ServerResponse>;
package/dist/http.js CHANGED
@@ -2,6 +2,7 @@ import { createServer as createHttpServer } from "node:http";
2
2
  import { timingSafeEqual } from "node:crypto";
3
3
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
4
4
  import { createServer, SERVER_NAME, SERVER_VERSION } from "./server.js";
5
+ import { ALLOWED_IMAGE_TYPES, MAX_UPLOAD_BYTES, sharedUploads, UPLOAD_TTL_MS, UploadError, } from "./uploads.js";
5
6
  /** Constant-time check of the Bearer token, so the comparison doesn't leak the key by timing. */
6
7
  export function isAuthorized(header, apiKey) {
7
8
  const match = /^Bearer (.+)$/.exec(header ?? "");
@@ -15,18 +16,98 @@ function sendJson(res, status, body) {
15
16
  res.writeHead(status, { "Content-Type": "application/json" });
16
17
  res.end(JSON.stringify(body));
17
18
  }
18
- /** Serves the MCP endpoint at /mcp over Streamable HTTP, stateless, behind a Bearer API key. */
19
- export function createMcpHttpServer(config) {
19
+ /** Reads the body, or returns "too-large" if it goes past the limit. The rest is drained so the response can be sent. */
20
+ function readBody(req, limit) {
21
+ return new Promise((resolve, reject) => {
22
+ const chunks = [];
23
+ let size = 0;
24
+ let tooLarge = false;
25
+ req.on("data", (chunk) => {
26
+ size += chunk.length;
27
+ if (size > limit) {
28
+ tooLarge = true;
29
+ return;
30
+ }
31
+ if (!tooLarge)
32
+ chunks.push(chunk);
33
+ });
34
+ req.on("end", () => resolve(tooLarge ? "too-large" : Buffer.concat(chunks)));
35
+ req.on("error", reject);
36
+ });
37
+ }
38
+ /** Keeps just a safe file name: no folders, no control characters, at most 200 characters. */
39
+ function sanitizeFilename(header) {
40
+ const raw = Array.isArray(header) ? header[0] : header;
41
+ let name = raw ?? "";
42
+ try {
43
+ name = decodeURIComponent(name);
44
+ }
45
+ catch {
46
+ // Keep the raw value if it isn't valid percent-encoding.
47
+ }
48
+ name = name
49
+ .split(/[\\/]/)
50
+ .pop()
51
+ .replace(/[\u0000-\u001f\u007f]/g, "")
52
+ .trim()
53
+ .slice(0, 200);
54
+ return name || "photo.jpg";
55
+ }
56
+ /**
57
+ * POST /uploads takes the raw photo bytes (Content-Type image/*, optional X-Filename header) and
58
+ * returns an upload_id. The add_item tool then uses that id, so the photo never passes through the model.
59
+ */
60
+ async function handleUpload(req, res, uploads) {
61
+ const contentType = (req.headers["content-type"] ?? "").split(";")[0].trim().toLowerCase();
62
+ if (!ALLOWED_IMAGE_TYPES.includes(contentType)) {
63
+ sendJson(res, 415, { error: `Send the photo as one of: ${ALLOWED_IMAGE_TYPES.join(", ")}` });
64
+ return;
65
+ }
66
+ const declared = Number(req.headers["content-length"]);
67
+ if (Number.isFinite(declared) && declared > MAX_UPLOAD_BYTES) {
68
+ sendJson(res, 413, { error: `Photo is larger than ${MAX_UPLOAD_BYTES / 1024 / 1024} MB` });
69
+ return;
70
+ }
71
+ const body = await readBody(req, MAX_UPLOAD_BYTES);
72
+ if (body === "too-large") {
73
+ sendJson(res, 413, { error: `Photo is larger than ${MAX_UPLOAD_BYTES / 1024 / 1024} MB` });
74
+ return;
75
+ }
76
+ if (body.length === 0) {
77
+ sendJson(res, 400, { error: "The request had no photo data" });
78
+ return;
79
+ }
80
+ try {
81
+ const upload_id = uploads.put({
82
+ bytes: body,
83
+ contentType,
84
+ filename: sanitizeFilename(req.headers["x-filename"]),
85
+ });
86
+ sendJson(res, 201, { upload_id, expires_in_seconds: UPLOAD_TTL_MS / 1000 });
87
+ }
88
+ catch (err) {
89
+ if (err instanceof UploadError) {
90
+ sendJson(res, 429, { error: err.message });
91
+ return;
92
+ }
93
+ throw err;
94
+ }
95
+ }
96
+ /**
97
+ * Serves the MCP endpoint at /mcp over Streamable HTTP, stateless, behind a Bearer API key.
98
+ * Also serves POST /uploads, where the app sends a photo before asking the agent to add it.
99
+ */
100
+ export function createMcpHttpServer(config, uploads = sharedUploads) {
20
101
  const apiKey = config.apiKey;
21
102
  if (!apiKey)
22
103
  throw new Error("MCP_API_KEY is required for the http transport");
23
104
  return createHttpServer(async (req, res) => {
24
105
  const url = new URL(req.url ?? "/", "http://localhost");
25
106
  if (url.pathname === "/" && req.method === "GET") {
26
- sendJson(res, 200, { name: SERVER_NAME, version: SERVER_VERSION, endpoint: "/mcp" });
107
+ sendJson(res, 200, { name: SERVER_NAME, version: SERVER_VERSION, endpoint: "/mcp", uploads: "/uploads" });
27
108
  return;
28
109
  }
29
- if (url.pathname !== "/mcp") {
110
+ if (url.pathname !== "/mcp" && url.pathname !== "/uploads") {
30
111
  sendJson(res, 404, { error: "not found" });
31
112
  return;
32
113
  }
@@ -35,8 +116,17 @@ export function createMcpHttpServer(config) {
35
116
  sendJson(res, 401, { error: "unauthorized" });
36
117
  return;
37
118
  }
119
+ if (url.pathname === "/uploads") {
120
+ if (req.method !== "POST") {
121
+ res.setHeader("Allow", "POST");
122
+ sendJson(res, 405, { error: "method not allowed" });
123
+ return;
124
+ }
125
+ await handleUpload(req, res, uploads);
126
+ return;
127
+ }
38
128
  // Stateless: a fresh server and transport per request, so no session state is kept between calls.
39
- const server = createServer(config);
129
+ const server = createServer(config, fetch, uploads);
40
130
  const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
41
131
  res.on("close", () => {
42
132
  void transport.close();
package/dist/server.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import type { Config } from "./config.js";
3
+ import { type UploadStore } from "./uploads.js";
3
4
  export declare const SERVER_NAME = "wardrowbe-mcp";
4
- export declare const SERVER_VERSION = "0.1.0";
5
+ export declare const SERVER_VERSION = "0.2.0";
5
6
  /** Builds an MCP server with all Wardrowbe tools registered against the configured instance. */
6
- export declare function createServer(config: Config, fetchFn?: typeof fetch): McpServer;
7
+ export declare function createServer(config: Config, fetchFn?: typeof fetch, uploads?: UploadStore): McpServer;
package/dist/server.js CHANGED
@@ -1,19 +1,21 @@
1
+ import { readFileSync } from "node:fs";
1
2
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
3
  import { WardrowbeClient, TokenProvider } from "./client.js";
3
4
  import { DEFAULT_LOGIN_PORT, runLogin } from "./login.js";
4
5
  import { registerTools } from "./tools.js";
5
6
  import { TokenStore } from "./token-store.js";
7
+ import { sharedUploads } from "./uploads.js";
6
8
  export const SERVER_NAME = "wardrowbe-mcp";
7
- export const SERVER_VERSION = "0.1.0";
8
- /**
9
- * Sign-in for the OIDC path: the stored refresh token, and a browser sign-in when there is none.
10
- * The browser sign-in only runs on the first tool call that needs it, not at startup.
11
- */
9
+ export const SERVER_VERSION = "0.2.0";
12
10
  /**
13
11
  * Module-level, because the HTTP transport builds a server per request. Only one browser sign-in
14
12
  * runs at a time: concurrent callers share it, since the callback port can be bound only once.
15
13
  */
16
14
  let pendingSignIn;
15
+ /**
16
+ * Sign-in for the OIDC path: the stored refresh token, and a browser sign-in when there is none.
17
+ * The browser sign-in only runs on the first tool call that needs it, not at startup.
18
+ */
17
19
  function signInHooks(config) {
18
20
  if (!config.oidc)
19
21
  return {};
@@ -35,11 +37,23 @@ function signInHooks(config) {
35
37
  },
36
38
  };
37
39
  }
40
+ /** Agent guidance, shipped in the package. Works from src/ (tests) and dist/ (published build). */
41
+ const SKILL_URI = "skill://wardrowbe-skill/SKILL.md";
42
+ const skillText = readFileSync(new URL("../skill/SKILL.md", import.meta.url), "utf8");
43
+ /** Exposes SKILL.md as an MCP resource, so clients that install skills pick it up. */
44
+ function registerSkill(server) {
45
+ server.registerResource("wardrowbe-skill", SKILL_URI, {
46
+ title: "Wardrowbe skill",
47
+ description: "How to use the Wardrowbe tools: choosing a tool, adding items from photos, archiving.",
48
+ mimeType: "text/markdown",
49
+ }, (uri) => ({ contents: [{ uri: uri.toString(), mimeType: "text/markdown", text: skillText }] }));
50
+ }
38
51
  /** Builds an MCP server with all Wardrowbe tools registered against the configured instance. */
39
- export function createServer(config, fetchFn = fetch) {
52
+ export function createServer(config, fetchFn = fetch, uploads = sharedUploads) {
40
53
  const tokens = new TokenProvider(config, fetchFn, Date.now, signInHooks(config));
41
54
  const client = new WardrowbeClient(config, tokens, fetchFn);
42
55
  const server = new McpServer({ name: SERVER_NAME, version: SERVER_VERSION });
43
- registerTools(server, client);
56
+ registerTools(server, client, uploads);
57
+ registerSkill(server);
44
58
  return server;
45
59
  }
package/dist/tools.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import type { WardrowbeClient } from "./client.js";
3
+ import { type UploadStore } from "./uploads.js";
3
4
  /** Registers the Wardrowbe tools on an MCP server. */
4
- export declare function registerTools(server: McpServer, client: WardrowbeClient): void;
5
+ export declare function registerTools(server: McpServer, client: WardrowbeClient, uploads?: UploadStore): void;
package/dist/tools.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { ALLOWED_IMAGE_TYPES, MAX_TOOL_UPLOAD_BYTES, sharedUploads, } from "./uploads.js";
2
3
  const uuid = z.string().uuid().describe("Item or outfit UUID");
3
4
  const isoDate = z
4
5
  .string()
@@ -16,7 +17,7 @@ async function run(fn) {
16
17
  }
17
18
  }
18
19
  /** Registers the Wardrowbe tools on an MCP server. */
19
- export function registerTools(server, client) {
20
+ export function registerTools(server, client, uploads = sharedUploads) {
20
21
  server.registerTool("list_items", {
21
22
  title: "List wardrobe items",
22
23
  description: "List items in the user's wardrobe. Filter by type, status, favorites, or items that need washing.",
@@ -89,4 +90,94 @@ export function registerTools(server, client) {
89
90
  days: z.number().int().min(7).max(365).optional().describe("Trend window, 7 to 365 days"),
90
91
  },
91
92
  }, ({ days }) => run(() => client.get("/analytics", { days: days ?? 30 })));
93
+ server.registerTool("upload_photo", {
94
+ title: "Upload a photo",
95
+ description: `Upload a photo of a clothing item so add_item can use it. Pass the image as base64. Keep it small: the limit is ${MAX_TOOL_UPLOAD_BYTES / 1024} KB, so use a reduced-size image. Returns an upload_id for add_item. The id is good for 10 minutes and works once.`,
96
+ inputSchema: {
97
+ image_base64: z.string().min(1).describe("The image bytes, base64-encoded, without a data: prefix"),
98
+ mime_type: z.enum(ALLOWED_IMAGE_TYPES).describe("Image type"),
99
+ filename: z.string().max(200).optional().describe("File name, e.g. blue-shirt.jpg"),
100
+ },
101
+ }, ({ image_base64, mime_type, filename }) => run(async () => {
102
+ const bytes = Buffer.from(image_base64, "base64");
103
+ if (bytes.length === 0)
104
+ throw new Error("The image_base64 value decoded to no data.");
105
+ if (bytes.length > MAX_TOOL_UPLOAD_BYTES) {
106
+ throw new Error(`The photo is ${Math.round(bytes.length / 1024)} KB, over the ${MAX_TOOL_UPLOAD_BYTES / 1024} KB limit for upload_photo. Send a smaller image.`);
107
+ }
108
+ const upload_id = uploads.put({ bytes, contentType: mime_type, filename: filename ?? "photo.jpg" });
109
+ return { upload_id, expires_in_seconds: 600 };
110
+ }));
111
+ server.registerTool("add_item", {
112
+ title: "Add a wardrobe item",
113
+ description: "Add a new item to the wardrobe from a photo. The photo must first be uploaded to the server's upload endpoint, which returns an upload_id. Pass that id here. Wardrowbe detects the type and colors unless skip_ai is true or you pass them.",
114
+ inputSchema: {
115
+ upload_id: z.string().uuid().describe("upload_id returned when the photo was uploaded"),
116
+ type: z.string().optional().describe("Item type, e.g. top, bottom, shoes. Detected if omitted."),
117
+ subtype: z.string().optional(),
118
+ name: z.string().max(100).optional(),
119
+ brand: z.string().max(100).optional(),
120
+ notes: z.string().max(1000).optional(),
121
+ colors: z.string().optional().describe("Comma-separated color names"),
122
+ primary_color: z.string().optional(),
123
+ favorite: z.boolean().optional(),
124
+ skip_ai: z.boolean().optional().describe("Skip AI tagging and use only the fields given"),
125
+ },
126
+ }, ({ upload_id, ...fields }) => run(async () => {
127
+ const photo = uploads.take(upload_id);
128
+ const form = new FormData();
129
+ const bytes = new Uint8Array(photo.bytes);
130
+ form.append("image", new Blob([bytes], { type: photo.contentType }), photo.filename);
131
+ for (const [key, value] of Object.entries(fields)) {
132
+ if (value !== undefined)
133
+ form.append(key, String(value));
134
+ }
135
+ return client.postForm("/items", form);
136
+ }));
137
+ server.registerTool("get_wardrobe_summary", {
138
+ title: "Wardrobe summary",
139
+ description: "A short overview of the wardrobe: item counts, the insights Wardrowbe has noticed, and the most and least worn items. Good first call when a user asks how their wardrobe is doing.",
140
+ inputSchema: {
141
+ days: z.number().int().min(7).max(365).optional().describe("Trend window, 7 to 365 days"),
142
+ },
143
+ }, ({ days }) => run(async () => {
144
+ const analytics = await client.get("/analytics", { days: days ?? 30 });
145
+ return {
146
+ wardrobe: analytics.wardrobe,
147
+ insights: analytics.insights,
148
+ most_worn: analytics.most_worn,
149
+ never_worn: analytics.never_worn,
150
+ };
151
+ }));
152
+ server.registerTool("get_most_worn_items", {
153
+ title: "Most worn items",
154
+ description: "The items worn most often in the trend window. Wardrowbe returns at most 5.",
155
+ inputSchema: {
156
+ limit: z.number().int().min(1).max(5).optional().describe("How many items, up to 5"),
157
+ days: z.number().int().min(7).max(365).optional().describe("Trend window, 7 to 365 days"),
158
+ },
159
+ }, ({ limit, days }) => run(async () => {
160
+ const analytics = await client.get("/analytics", { days: days ?? 30 });
161
+ return { items: analytics.most_worn.slice(0, limit ?? 5) };
162
+ }));
163
+ server.registerTool("get_items_to_wash", {
164
+ title: "Items to wash",
165
+ description: "Items worn since their last wash, so they are due for washing.",
166
+ inputSchema: {
167
+ limit: z.number().int().min(1).max(100).optional().describe("How many items to return"),
168
+ },
169
+ }, ({ limit }) => run(() => client.get("/items", { needs_wash: true, page_size: limit ?? 20 })));
170
+ server.registerTool("archive_item", {
171
+ title: "Archive an item",
172
+ description: "Archive an item so it is left out of outfit suggestions. It stays in the wardrobe and can be restored. Use this for items that are worn out, given away, or out of season.",
173
+ inputSchema: {
174
+ item_id: uuid,
175
+ reason: z.string().max(200).optional().describe("Why the item is archived, e.g. worn out"),
176
+ },
177
+ }, ({ item_id, reason }) => run(() => client.post(`/items/${item_id}/archive`, reason === undefined ? {} : { reason })));
178
+ server.registerTool("restore_item", {
179
+ title: "Restore an archived item",
180
+ description: "Bring an archived item back into the active wardrobe and outfit suggestions.",
181
+ inputSchema: { item_id: uuid },
182
+ }, ({ item_id }) => run(() => client.post(`/items/${item_id}/restore`)));
92
183
  }
@@ -0,0 +1,36 @@
1
+ /** Image types Wardrowbe accepts. HEIC is what iPhones produce by default. */
2
+ export declare const ALLOWED_IMAGE_TYPES: string[];
3
+ /** Largest photo the upload endpoint accepts. Phone photos are often 3 to 8 MB. */
4
+ export declare const MAX_UPLOAD_BYTES: number;
5
+ /**
6
+ * Largest photo the upload_photo tool accepts. The model has to write the whole image as base64
7
+ * inside the tool call, so this stays small. Full-size photos go through POST /uploads.
8
+ */
9
+ export declare const MAX_TOOL_UPLOAD_BYTES: number;
10
+ export declare const UPLOAD_TTL_MS: number;
11
+ /** Caps how many photos can wait at once, so a flood of uploads cannot fill memory. */
12
+ export declare const MAX_PENDING_UPLOADS = 50;
13
+ export interface PendingUpload {
14
+ bytes: Buffer;
15
+ contentType: string;
16
+ filename: string;
17
+ }
18
+ export declare class UploadError extends Error {
19
+ }
20
+ /**
21
+ * Holds photos from the upload endpoint until a tool uses them. Each id works once, and entries
22
+ * expire after UPLOAD_TTL_MS. Kept in memory, so uploads are lost if the server restarts.
23
+ */
24
+ export declare class UploadStore {
25
+ private readonly now;
26
+ private readonly ttlMs;
27
+ private readonly entries;
28
+ constructor(now?: () => number, ttlMs?: number);
29
+ /** Stores a photo and returns its id. */
30
+ put(upload: PendingUpload): string;
31
+ /** Returns the photo and removes it, so each id is used only once. */
32
+ take(id: string): PendingUpload;
33
+ private sweep;
34
+ }
35
+ /** Shared by every HTTP request, since the HTTP transport builds a server per request. */
36
+ export declare const sharedUploads: UploadStore;
@@ -0,0 +1,57 @@
1
+ import { randomUUID } from "node:crypto";
2
+ /** Image types Wardrowbe accepts. HEIC is what iPhones produce by default. */
3
+ export const ALLOWED_IMAGE_TYPES = ["image/jpeg", "image/png", "image/webp", "image/heic", "image/heif"];
4
+ /** Largest photo the upload endpoint accepts. Phone photos are often 3 to 8 MB. */
5
+ export const MAX_UPLOAD_BYTES = 15 * 1024 * 1024;
6
+ /**
7
+ * Largest photo the upload_photo tool accepts. The model has to write the whole image as base64
8
+ * inside the tool call, so this stays small. Full-size photos go through POST /uploads.
9
+ */
10
+ export const MAX_TOOL_UPLOAD_BYTES = 300 * 1024;
11
+ export const UPLOAD_TTL_MS = 10 * 60_000;
12
+ /** Caps how many photos can wait at once, so a flood of uploads cannot fill memory. */
13
+ export const MAX_PENDING_UPLOADS = 50;
14
+ export class UploadError extends Error {
15
+ }
16
+ /**
17
+ * Holds photos from the upload endpoint until a tool uses them. Each id works once, and entries
18
+ * expire after UPLOAD_TTL_MS. Kept in memory, so uploads are lost if the server restarts.
19
+ */
20
+ export class UploadStore {
21
+ now;
22
+ ttlMs;
23
+ entries = new Map();
24
+ constructor(now = Date.now, ttlMs = UPLOAD_TTL_MS) {
25
+ this.now = now;
26
+ this.ttlMs = ttlMs;
27
+ }
28
+ /** Stores a photo and returns its id. */
29
+ put(upload) {
30
+ this.sweep();
31
+ if (this.entries.size >= MAX_PENDING_UPLOADS) {
32
+ throw new UploadError("Too many photos are waiting to be added. Try again in a few minutes.");
33
+ }
34
+ const id = randomUUID();
35
+ this.entries.set(id, { ...upload, expiresAt: this.now() + this.ttlMs });
36
+ return id;
37
+ }
38
+ /** Returns the photo and removes it, so each id is used only once. */
39
+ take(id) {
40
+ this.sweep();
41
+ const entry = this.entries.get(id);
42
+ if (!entry) {
43
+ throw new UploadError(`Upload ${id} was not found. It may have expired or already been used. Upload the photo again.`);
44
+ }
45
+ this.entries.delete(id);
46
+ return { bytes: entry.bytes, contentType: entry.contentType, filename: entry.filename };
47
+ }
48
+ sweep() {
49
+ const now = this.now();
50
+ for (const [id, entry] of this.entries) {
51
+ if (entry.expiresAt <= now)
52
+ this.entries.delete(id);
53
+ }
54
+ }
55
+ }
56
+ /** Shared by every HTTP request, since the HTTP transport builds a server per request. */
57
+ export const sharedUploads = new UploadStore();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdeleon23/wardrowbe-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "MCP server for the Wardrowbe wardrobe API. Runs over stdio (npx) or Streamable HTTP.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,6 +10,7 @@
10
10
  "types": "dist/index.d.ts",
11
11
  "files": [
12
12
  "dist",
13
+ "skill",
13
14
  "README.md"
14
15
  ],
15
16
  "scripts": {
package/skill/SKILL.md ADDED
@@ -0,0 +1,49 @@
1
+ ---
2
+ name: wardrowbe
3
+ description: Manage a Wardrowbe wardrobe through MCP tools. Use it to browse and add items, log wear and washes, archive or restore items, check wardrobe stats, and handle outfit suggestions.
4
+ ---
5
+
6
+ # Wardrowbe wardrobe
7
+
8
+ Use these tools to help the user with their own wardrobe. Wardrowbe stores each item with a photo, a type, colors, and wear and wash history.
9
+
10
+ ## Choosing a tool
11
+
12
+ | The user wants to... | Use |
13
+ | --- | --- |
14
+ | See how the wardrobe is doing | `get_wardrobe_summary` |
15
+ | Find or look at items | `list_items`, then `get_item` for details |
16
+ | Know what needs washing | `get_items_to_wash` |
17
+ | Know what they wear most | `get_most_worn_items` |
18
+ | Log a day's wear or a wash | `log_wear`, `log_wash` |
19
+ | Remove an item from suggestions without deleting it | `archive_item` |
20
+ | Bring an archived item back | `restore_item` |
21
+ | Add a new item | `upload_photo`, then `add_item` (see below) |
22
+ | Get or respond to outfit suggestions | `suggest_outfit`, `accept_outfit`, `reject_outfit` |
23
+
24
+ ## Adding an item from a photo
25
+
26
+ 1. Ask the user for a photo of the item.
27
+ 2. Make sure the photo is under 300 KB before calling `upload_photo`. Phone photos usually aren't, so re-encode them first (see below).
28
+ 3. Call `upload_photo` with the image as base64 and its MIME type. It returns an `upload_id`.
29
+ 4. Call `add_item` with that `upload_id`. Pass `type`, `name`, `colors`, or `brand` only if the user gave them. Otherwise leave them out and Wardrowbe detects them.
30
+
31
+ ### Re-encoding a large photo
32
+
33
+ Shrink the photo before encoding it to base64. Resize the longest side to 512 pixels and save it as JPEG at quality 70. Most clothing photos come out well under 300 KB this way. If the result is still over the limit, lower the quality in steps of 10, down to 50.
34
+
35
+ A reduced photo is fine for adding the item. Once the item is added, tell the user they can upload a full-resolution photo later from the app if they want a sharper image.
36
+
37
+ If you have no tool to resize or re-encode images, don't send the original. Tell the user the photo is too large and ask for a smaller one, or ask them to use the app, which can upload full-size photos.
38
+
39
+ An `upload_id` works once and expires after 10 minutes. If `add_item` says the upload was not found, upload the photo again.
40
+
41
+ ## Archiving
42
+
43
+ Archive is reversible. Prefer it over anything destructive. When an item is archived, it stays in the wardrobe and can be restored, but it's left out of outfit suggestions. Confirm with the user before archiving an item they didn't name.
44
+
45
+ ## Reading results
46
+
47
+ - Tool results are JSON. Summarize them for the user rather than dumping the raw fields.
48
+ - `get_most_worn_items` returns at most 5 items.
49
+ - Errors come back as tool errors with Wardrowbe's message. Read the message and tell the user what went wrong. Retry only if the fix is clear, such as a wrong ID.