@mdeleon23/wardrowbe-mcp 0.3.1 → 0.4.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 +4 -4
- package/dist/cli.js +1 -1
- package/dist/server.d.ts +3 -1
- package/dist/server.js +2 -2
- package/dist/tools.d.ts +3 -1
- package/dist/tools.js +36 -21
- package/dist/uploads.d.ts +2 -5
- package/dist/uploads.js +9 -5
- package/package.json +1 -1
- package/skill/SKILL.md +6 -11
package/README.md
CHANGED
|
@@ -161,9 +161,9 @@ curl -s -X POST https://<host>:8080/uploads \
|
|
|
161
161
|
--data-binary @blue-shirt.jpg
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
There is no MCP tool for sending image bytes, because the model would have to write the whole photo out as base64.
|
|
165
165
|
|
|
166
|
-
`
|
|
166
|
+
Over stdio, the server runs on your own machine, so it offers `upload_photo_from_path` instead. Give it an absolute path to a photo (`.jpg`, `.jpeg`, `.png`, `.webp`, `.heic`, `.heif`, up to 15 MB). The server reads the file itself and returns an `upload_id` for `add_item`. The tool is not offered over HTTP, because it would let a remote caller read files off the server. `/uploads` is HTTP only.
|
|
167
167
|
|
|
168
168
|
## Tools
|
|
169
169
|
|
|
@@ -176,8 +176,8 @@ An agent can also do the whole thing through MCP with the `upload_photo` tool, w
|
|
|
176
176
|
| `suggest_outfit` | `POST /outfits/suggest` | Rate limited to about 10 per minute per user. |
|
|
177
177
|
| `accept_outfit` | `POST /outfits/{id}/accept` | |
|
|
178
178
|
| `reject_outfit` | `POST /outfits/{id}/reject` | |
|
|
179
|
-
| `
|
|
180
|
-
| `add_item` | `POST /items` | Takes an `upload_id` from `
|
|
179
|
+
| `upload_photo_from_path` | `POST /uploads` (in-process) | stdio only. Reads a photo from an absolute local path and returns an `upload_id`. |
|
|
180
|
+
| `add_item` | `POST /items` | Takes an `upload_id` from `upload_photo_from_path` (stdio) or `POST /uploads` (HTTP). Wardrowbe detects the type unless you pass one. |
|
|
181
181
|
| `get_analytics` | `GET /analytics` | `days` from 7 to 365. |
|
|
182
182
|
| `get_wardrobe_summary` | `GET /analytics` | Counts, insights, most and never worn items. Good first call. |
|
|
183
183
|
| `get_most_worn_items` | `GET /analytics` | Up to 5 items, from the same trend window. |
|
package/dist/cli.js
CHANGED
|
@@ -64,7 +64,7 @@ async function serve() {
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
// stdio: stdout carries MCP frames, so diagnostics go to stderr only.
|
|
67
|
-
const server = createServer(config);
|
|
67
|
+
const server = createServer(config, fetch, undefined, { localFiles: true });
|
|
68
68
|
await server.connect(new StdioServerTransport());
|
|
69
69
|
console.error(`${SERVER_NAME} ${SERVER_VERSION} running on stdio`);
|
|
70
70
|
}
|
package/dist/server.d.ts
CHANGED
|
@@ -4,4 +4,6 @@ import { type UploadStore } from "./uploads.js";
|
|
|
4
4
|
export declare const SERVER_NAME = "wardrowbe-mcp";
|
|
5
5
|
export declare const SERVER_VERSION = "0.3.0";
|
|
6
6
|
/** Builds an MCP server with all Wardrowbe tools registered against the configured instance. */
|
|
7
|
-
export declare function createServer(config: Config, fetchFn?: typeof fetch, uploads?: UploadStore
|
|
7
|
+
export declare function createServer(config: Config, fetchFn?: typeof fetch, uploads?: UploadStore, options?: {
|
|
8
|
+
localFiles?: boolean;
|
|
9
|
+
}): McpServer;
|
package/dist/server.js
CHANGED
|
@@ -49,11 +49,11 @@ function registerSkill(server) {
|
|
|
49
49
|
}, (uri) => ({ contents: [{ uri: uri.toString(), mimeType: "text/markdown", text: skillText }] }));
|
|
50
50
|
}
|
|
51
51
|
/** Builds an MCP server with all Wardrowbe tools registered against the configured instance. */
|
|
52
|
-
export function createServer(config, fetchFn = fetch, uploads = sharedUploads) {
|
|
52
|
+
export function createServer(config, fetchFn = fetch, uploads = sharedUploads, options = {}) {
|
|
53
53
|
const tokens = new TokenProvider(config, fetchFn, Date.now, signInHooks(config));
|
|
54
54
|
const client = new WardrowbeClient(config, tokens, fetchFn);
|
|
55
55
|
const server = new McpServer({ name: SERVER_NAME, version: SERVER_VERSION });
|
|
56
|
-
registerTools(server, client, uploads);
|
|
56
|
+
registerTools(server, client, uploads, options);
|
|
57
57
|
registerSkill(server);
|
|
58
58
|
return server;
|
|
59
59
|
}
|
package/dist/tools.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import type { WardrowbeClient } from "./client.js";
|
|
3
3
|
import { type UploadStore } from "./uploads.js";
|
|
4
4
|
/** Registers the Wardrowbe tools on an MCP server. */
|
|
5
|
-
export declare function registerTools(server: McpServer, client: WardrowbeClient, uploads?: UploadStore
|
|
5
|
+
export declare function registerTools(server: McpServer, client: WardrowbeClient, uploads?: UploadStore, options?: {
|
|
6
|
+
localFiles?: boolean;
|
|
7
|
+
}): void;
|
package/dist/tools.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { readFile, stat } from "node:fs/promises";
|
|
2
|
+
import { basename, extname, isAbsolute } from "node:path";
|
|
1
3
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
4
|
+
import { IMAGE_EXTENSIONS, MAX_UPLOAD_BYTES, UPLOAD_TTL_MS, sharedUploads, } from "./uploads.js";
|
|
3
5
|
const uuid = z.string().uuid().describe("Item or outfit UUID");
|
|
4
6
|
const isoDate = z
|
|
5
7
|
.string()
|
|
@@ -17,7 +19,7 @@ async function run(fn) {
|
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
/** Registers the Wardrowbe tools on an MCP server. */
|
|
20
|
-
export function registerTools(server, client, uploads = sharedUploads) {
|
|
22
|
+
export function registerTools(server, client, uploads = sharedUploads, options = {}) {
|
|
21
23
|
server.registerTool("list_items", {
|
|
22
24
|
title: "List wardrobe items",
|
|
23
25
|
description: "List items in the user's wardrobe. Filter by type, status, favorites, or items that need washing.",
|
|
@@ -90,27 +92,40 @@ export function registerTools(server, client, uploads = sharedUploads) {
|
|
|
90
92
|
days: z.number().int().min(7).max(365).optional().describe("Trend window, 7 to 365 days"),
|
|
91
93
|
},
|
|
92
94
|
}, ({ days }) => run(() => client.get("/analytics", { days: days ?? 30 })));
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
if (options.localFiles) {
|
|
96
|
+
// Only for stdio, where the server runs on the user's own machine. Over HTTP this would let
|
|
97
|
+
// a remote caller read files off the server, so it is not registered there.
|
|
98
|
+
server.registerTool("upload_photo_from_path", {
|
|
99
|
+
title: "Upload a photo from a local file",
|
|
100
|
+
description: `Read an image file from this computer and stage it for add_item, without the image passing through the model. Pass an absolute path to a ${Object.keys(IMAGE_EXTENSIONS).join(", ")} file. Returns an upload_id for add_item. The id is good for 10 minutes and works once.`,
|
|
101
|
+
inputSchema: {
|
|
102
|
+
path: z.string().min(1).describe("Absolute path to the photo on this computer"),
|
|
103
|
+
},
|
|
104
|
+
}, ({ path }) => run(async () => {
|
|
105
|
+
if (!isAbsolute(path))
|
|
106
|
+
throw new Error("Pass an absolute path to the photo.");
|
|
107
|
+
const contentType = IMAGE_EXTENSIONS[extname(path).toLowerCase()];
|
|
108
|
+
if (!contentType) {
|
|
109
|
+
throw new Error(`Unsupported file type. Use one of: ${Object.keys(IMAGE_EXTENSIONS).join(", ")}.`);
|
|
110
|
+
}
|
|
111
|
+
const info = await stat(path).catch(() => {
|
|
112
|
+
throw new Error(`No file found at ${path}.`);
|
|
113
|
+
});
|
|
114
|
+
if (!info.isFile())
|
|
115
|
+
throw new Error(`${path} is not a file.`);
|
|
116
|
+
if (info.size > MAX_UPLOAD_BYTES) {
|
|
117
|
+
throw new Error(`The photo is larger than ${MAX_UPLOAD_BYTES / 1024 / 1024} MB.`);
|
|
118
|
+
}
|
|
119
|
+
const bytes = await readFile(path);
|
|
120
|
+
if (bytes.length === 0)
|
|
121
|
+
throw new Error("The file is empty.");
|
|
122
|
+
const upload_id = uploads.put({ bytes, contentType, filename: basename(path) });
|
|
123
|
+
return { upload_id, expires_in_seconds: UPLOAD_TTL_MS / 1000 };
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
111
126
|
server.registerTool("add_item", {
|
|
112
127
|
title: "Add a wardrobe item",
|
|
113
|
-
description: "Add a new item to the wardrobe from a photo. The photo must first be
|
|
128
|
+
description: "Add a new item to the wardrobe from a photo. The photo must first be staged, which returns an upload_id: with upload_photo_from_path when it is available (stdio), otherwise by sending the raw image bytes to the server's POST /uploads endpoint with the same Bearer key. Pass that id here. Wardrowbe detects the type and colors unless skip_ai is true or you pass them.",
|
|
114
129
|
inputSchema: {
|
|
115
130
|
upload_id: z.string().uuid().describe("upload_id returned when the photo was uploaded"),
|
|
116
131
|
type: z.string().optional().describe("Item type, e.g. top, bottom, shoes. Detected if omitted."),
|
package/dist/uploads.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/** Image types Wardrowbe accepts. HEIC is what iPhones produce by default. */
|
|
2
2
|
export declare const ALLOWED_IMAGE_TYPES: string[];
|
|
3
|
+
/** Maps file extensions to the image types above, for reading photos from disk. */
|
|
4
|
+
export declare const IMAGE_EXTENSIONS: Record<string, string>;
|
|
3
5
|
/** Largest photo the upload endpoint accepts. Phone photos are often 3 to 8 MB. */
|
|
4
6
|
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
7
|
export declare const UPLOAD_TTL_MS: number;
|
|
11
8
|
/** Caps how many photos can wait at once, so a flood of uploads cannot fill memory. */
|
|
12
9
|
export declare const MAX_PENDING_UPLOADS = 50;
|
package/dist/uploads.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
/** Image types Wardrowbe accepts. HEIC is what iPhones produce by default. */
|
|
3
3
|
export const ALLOWED_IMAGE_TYPES = ["image/jpeg", "image/png", "image/webp", "image/heic", "image/heif"];
|
|
4
|
+
/** Maps file extensions to the image types above, for reading photos from disk. */
|
|
5
|
+
export const IMAGE_EXTENSIONS = {
|
|
6
|
+
".jpg": "image/jpeg",
|
|
7
|
+
".jpeg": "image/jpeg",
|
|
8
|
+
".png": "image/png",
|
|
9
|
+
".webp": "image/webp",
|
|
10
|
+
".heic": "image/heic",
|
|
11
|
+
".heif": "image/heif",
|
|
12
|
+
};
|
|
4
13
|
/** Largest photo the upload endpoint accepts. Phone photos are often 3 to 8 MB. */
|
|
5
14
|
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
15
|
export const UPLOAD_TTL_MS = 10 * 60_000;
|
|
12
16
|
/** Caps how many photos can wait at once, so a flood of uploads cannot fill memory. */
|
|
13
17
|
export const MAX_PENDING_UPLOADS = 50;
|
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED
|
@@ -18,23 +18,18 @@ Use these tools to help the user with their own wardrobe. Wardrowbe stores each
|
|
|
18
18
|
| Log a day's wear or a wash | `log_wear`, `log_wash` |
|
|
19
19
|
| Remove an item from suggestions without deleting it | `archive_item` |
|
|
20
20
|
| Bring an archived item back | `restore_item` |
|
|
21
|
-
| Add a new item | `
|
|
21
|
+
| Add a new item | `upload_photo_from_path` if you have it, then `add_item` (see below) |
|
|
22
22
|
| Get or respond to outfit suggestions | `suggest_outfit`, `accept_outfit`, `reject_outfit` |
|
|
23
23
|
|
|
24
24
|
## Adding an item from a photo
|
|
25
25
|
|
|
26
|
-
|
|
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.
|
|
26
|
+
Photos don't go through MCP tools as image data. The server stages the photo and returns an `upload_id`.
|
|
30
27
|
|
|
31
|
-
|
|
28
|
+
1. Ask the user for a photo of the item, or the path to it on their computer.
|
|
29
|
+
2. If you have `upload_photo_from_path`, call it with the absolute path. Otherwise the app (or a shell tool, if you have one) sends the raw image bytes to `POST /uploads` on the server with the same Bearer key, and `Content-Type` set to the image type. Either way you get an `upload_id`.
|
|
30
|
+
3. 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.
|
|
32
31
|
|
|
33
|
-
|
|
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.
|
|
32
|
+
If you have neither `upload_photo_from_path` nor a way to reach `/uploads`, don't try to paste the image into a tool call. Ask the user to add the photo from the app, then use the `upload_id` it gives you.
|
|
38
33
|
|
|
39
34
|
An `upload_id` works once and expires after 10 minutes. If `add_item` says the upload was not found, upload the photo again.
|
|
40
35
|
|