@mdeleon23/wardrowbe-mcp 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mjrealm
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 CHANGED
@@ -1,3 +1,100 @@
1
- # Temporary Holding Version
1
+ # wardrowbe-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An [MCP](https://modelcontextprotocol.io) server for [Wardrowbe](https://github.com/Anyesh/wardrowbe), the self-hosted wardrobe app. It lets any MCP client list and inspect items, log wear and washes, suggest outfits, and check analytics.
4
+
5
+ Requires Node.js 20 or newer.
6
+
7
+ ## Quick start
8
+
9
+ You need your Wardrowbe URL and an OIDC client for Wardrowbe. Pocket ID works.
10
+
11
+ 1. In your IdP, create a public client with PKCE. Allow the scopes `openid profile email offline_access`, and add the redirect URI `http://localhost:8765/callback`.
12
+ 2. Add the server to your MCP client. For Claude Desktop or Claude Code:
13
+
14
+ ```json
15
+ {
16
+ "mcpServers": {
17
+ "wardrowbe": {
18
+ "command": "npx",
19
+ "args": ["-y", "@mdeleon23/wardrowbe-mcp"],
20
+ "env": {
21
+ "WARDROWBE_URL": "https://wardrowbe.example.com",
22
+ "OIDC_ISSUER_URL": "https://pocket.example.com",
23
+ "OIDC_CLIENT_ID": "wardrowbe"
24
+ }
25
+ }
26
+ }
27
+ }
28
+ ```
29
+
30
+ 3. Call `list_items` from your client. The first time, your browser opens for sign-in. After that, the refresh token is saved and you won't be asked again.
31
+
32
+ To use a plain access token instead, set `WARDROWBE_TOKEN` in place of the `OIDC_*` variables. It expires, so OIDC is better for regular use.
33
+
34
+ ## Configuration
35
+
36
+ | Variable | Required | Default | Purpose |
37
+ | --- | --- | --- | --- |
38
+ | `WARDROWBE_URL` | yes | | Base URL of your Wardrowbe instance. |
39
+ | `WARDROWBE_TOKEN` | or OIDC | | A Wardrowbe access token (JWT). |
40
+ | `OIDC_ISSUER_URL` | or token | | OIDC issuer, e.g. `https://pocket.example.com`. |
41
+ | `OIDC_CLIENT_ID` | with OIDC | | OIDC client ID. |
42
+ | `OIDC_CLIENT_SECRET` | no | | Only for confidential clients. |
43
+ | `OIDC_REFRESH_TOKEN` | no | | Use this refresh token instead of the saved one. For headless hosts (see below). |
44
+ | `WARDROWBE_TOKEN_FILE` | no | `~/.config/wardrowbe-mcp/refresh-token.json` | Where the refresh token is saved. |
45
+ | `MCP_TRANSPORT` | no | `stdio` | `stdio` or `http`. |
46
+ | `MCP_BIND_HOST` | no | `127.0.0.1` | Address for HTTP. Use `0.0.0.0` in containers. |
47
+ | `MCP_PORT` | no | `8080` | Port for HTTP. |
48
+ | `MCP_API_KEY` | http only | | Bearer key that clients send to `/mcp`. |
49
+
50
+ ## How sign-in works
51
+
52
+ With OIDC set, the server signs in through your browser the first time a tool needs a token. It catches the redirect on `localhost:8765`, then saves the refresh token to `WARDROWBE_TOKEN_FILE` with owner-only permissions. Later runs reuse it. If the token is revoked, the server signs in once more.
53
+
54
+ The browser sign-in needs a browser on the same machine as the server. On a headless host or in a container, sign in elsewhere and pass the token in:
55
+
56
+ ```bash
57
+ npx -y @mdeleon23/wardrowbe-mcp login --issuer https://pocket.example.com --client-id wardrowbe > refresh-token.txt
58
+ ```
59
+
60
+ Then set `OIDC_REFRESH_TOKEN` to the contents of `refresh-token.txt`, and delete the file.
61
+
62
+ ## HTTP transport
63
+
64
+ For MCPHub or any client that connects to a URL:
65
+
66
+ ```bash
67
+ MCP_TRANSPORT=http \
68
+ MCP_BIND_HOST=0.0.0.0 \
69
+ MCP_API_KEY="$(openssl rand -hex 32)" \
70
+ WARDROWBE_URL=https://wardrowbe.example.com \
71
+ OIDC_ISSUER_URL=https://pocket.example.com \
72
+ OIDC_CLIENT_ID=wardrowbe \
73
+ OIDC_REFRESH_TOKEN=<refresh-token> \
74
+ npx -y @mdeleon23/wardrowbe-mcp
75
+ ```
76
+
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
+
79
+ ## Tools
80
+
81
+ | Tool | Wardrowbe endpoint | Notes |
82
+ | --- | --- | --- |
83
+ | `list_items` | `GET /items` | Filter by type, status, favorites, needs wash, search. Paginated. |
84
+ | `get_item` | `GET /items/{id}` | |
85
+ | `log_wear` | `POST /items/{id}/wear` | Defaults to today. |
86
+ | `log_wash` | `POST /items/{id}/wash` | Defaults to today. |
87
+ | `suggest_outfit` | `POST /outfits/suggest` | Rate limited to about 10 per minute per user. |
88
+ | `accept_outfit` | `POST /outfits/{id}/accept` | |
89
+ | `reject_outfit` | `POST /outfits/{id}/reject` | |
90
+ | `get_analytics` | `GET /analytics` | `days` from 7 to 365. |
91
+
92
+ ## Development
93
+
94
+ ```bash
95
+ npm install
96
+ npm run build
97
+ npm test
98
+ ```
99
+
100
+ Written against Wardrowbe 1.13.x. If Wardrowbe changes its endpoints, update `src/tools.ts`.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from "node:util";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { ConfigError, loadConfig } from "./config.js";
5
+ import { createMcpHttpServer } from "./http.js";
6
+ import { runLogin } from "./login.js";
7
+ import { createServer, SERVER_NAME, SERVER_VERSION } from "./server.js";
8
+ const USAGE = `Usage:
9
+ wardrowbe-mcp Run the MCP server (stdio, or http if MCP_TRANSPORT=http)
10
+ wardrowbe-mcp login [options] One-time sign-in. Prints a refresh token to stdout.
11
+
12
+ Login options (each can also come from the environment):
13
+ --issuer <url> OIDC issuer, e.g. https://pocket.example.com (OIDC_ISSUER_URL)
14
+ --client-id <id> OIDC client ID (OIDC_CLIENT_ID)
15
+ --client-secret <s> Only for confidential clients (OIDC_CLIENT_SECRET)
16
+ --port <n> Localhost port for the redirect. Default 8765.
17
+ `;
18
+ async function login(argv) {
19
+ const { values } = parseArgs({
20
+ args: argv,
21
+ options: {
22
+ issuer: { type: "string" },
23
+ "client-id": { type: "string" },
24
+ "client-secret": { type: "string" },
25
+ port: { type: "string" },
26
+ help: { type: "boolean", short: "h" },
27
+ },
28
+ strict: true,
29
+ });
30
+ if (values.help) {
31
+ process.stderr.write(USAGE);
32
+ return;
33
+ }
34
+ const issuer = values.issuer ?? process.env.OIDC_ISSUER_URL;
35
+ const clientId = values["client-id"] ?? process.env.OIDC_CLIENT_ID;
36
+ const clientSecret = values["client-secret"] ?? process.env.OIDC_CLIENT_SECRET;
37
+ if (!issuer || !clientId) {
38
+ throw new ConfigError("login needs --issuer and --client-id (or OIDC_ISSUER_URL and OIDC_CLIENT_ID)");
39
+ }
40
+ const port = Number(values.port ?? "8765");
41
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
42
+ throw new ConfigError(`--port must be a port number, got "${values.port}"`);
43
+ }
44
+ const result = await runLogin({ issuerUrl: issuer, clientId, clientSecret, port });
45
+ // The token goes to stdout alone, so `wardrowbe-mcp login > token.txt` captures just the value.
46
+ process.stdout.write(`${result.refreshToken}\n`);
47
+ process.stderr.write([
48
+ "",
49
+ "Refresh token printed to stdout. Store it as a secret, not in the repo.",
50
+ "Set these for the MCP server:",
51
+ ` OIDC_ISSUER_URL=${issuer}`,
52
+ ` OIDC_CLIENT_ID=${clientId}`,
53
+ " OIDC_REFRESH_TOKEN=<the value above>",
54
+ "",
55
+ ].join("\n"));
56
+ }
57
+ async function serve() {
58
+ const config = loadConfig(process.env);
59
+ if (config.transport === "http") {
60
+ const httpServer = createMcpHttpServer(config);
61
+ httpServer.listen(config.port, config.host, () => {
62
+ console.error(`${SERVER_NAME} ${SERVER_VERSION} listening on http://${config.host}:${config.port}/mcp`);
63
+ });
64
+ return;
65
+ }
66
+ // stdio: stdout carries MCP frames, so diagnostics go to stderr only.
67
+ const server = createServer(config);
68
+ await server.connect(new StdioServerTransport());
69
+ console.error(`${SERVER_NAME} ${SERVER_VERSION} running on stdio`);
70
+ }
71
+ async function main() {
72
+ const [command, ...rest] = process.argv.slice(2);
73
+ if (command === "login") {
74
+ await login(rest);
75
+ return;
76
+ }
77
+ if (command === "--help" || command === "-h") {
78
+ process.stderr.write(USAGE);
79
+ return;
80
+ }
81
+ await serve();
82
+ }
83
+ main().catch((err) => {
84
+ const message = err instanceof Error ? err.message : String(err);
85
+ console.error(`${SERVER_NAME}: ${message}`);
86
+ process.exit(err instanceof ConfigError ? 2 : 1);
87
+ });
@@ -0,0 +1,50 @@
1
+ import type { Config } from "./config.js";
2
+ import type { TokenStore } from "./token-store.js";
3
+ export type FetchFn = typeof fetch;
4
+ /** How the OIDC path gets a refresh token when it has none: from disk, or from a browser sign-in. */
5
+ export interface SignInHooks {
6
+ store?: TokenStore;
7
+ /** Runs the browser sign-in and resolves with a refresh token. */
8
+ signIn?: () => Promise<string>;
9
+ }
10
+ export declare class WardrowbeApiError extends Error {
11
+ readonly status: number;
12
+ readonly detail: string;
13
+ constructor(status: number, detail: string);
14
+ }
15
+ /**
16
+ * Provides a Wardrowbe access token. With a static token it returns that. With OIDC it
17
+ * exchanges the refresh token for an id token, then trades that id token at /auth/sync for
18
+ * a Wardrowbe access token, caching the result until shortly before it expires.
19
+ */
20
+ export declare class TokenProvider {
21
+ private readonly config;
22
+ private readonly fetchFn;
23
+ private readonly now;
24
+ private readonly hooks;
25
+ private accessToken?;
26
+ private expiresAt;
27
+ private refreshToken?;
28
+ private inflight?;
29
+ constructor(config: Config, fetchFn?: FetchFn, now?: () => number, hooks?: SignInHooks);
30
+ getToken(): Promise<string>;
31
+ private exchange;
32
+ private refreshIdToken;
33
+ /** Current refresh token: the in-memory one, then the stored one, then a fresh browser sign-in. */
34
+ private currentRefreshToken;
35
+ /** Runs the browser sign-in and keeps the resulting refresh token. */
36
+ private signIn;
37
+ private refresh;
38
+ /** Keeps a refresh token in memory and in the store. A failed write is logged, not fatal. */
39
+ private remember;
40
+ }
41
+ /** Thin JSON client for the Wardrowbe REST API. */
42
+ export declare class WardrowbeClient {
43
+ private readonly config;
44
+ private readonly tokens;
45
+ private readonly fetchFn;
46
+ constructor(config: Config, tokens: TokenProvider, fetchFn?: FetchFn);
47
+ get<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
48
+ post<T>(path: string, body?: unknown): Promise<T>;
49
+ private request;
50
+ }
package/dist/client.js ADDED
@@ -0,0 +1,214 @@
1
+ export class WardrowbeApiError extends Error {
2
+ status;
3
+ detail;
4
+ constructor(status, detail) {
5
+ super(`Wardrowbe API ${status}: ${detail}`);
6
+ this.status = status;
7
+ this.detail = detail;
8
+ }
9
+ }
10
+ /** Refresh this long before the access token expires, so a call never starts with a dead token. */
11
+ const EXPIRY_MARGIN_MS = 60_000;
12
+ /** Used when an access token has no exp claim. */
13
+ const FALLBACK_TTL_MS = 5 * 60_000;
14
+ /**
15
+ * Provides a Wardrowbe access token. With a static token it returns that. With OIDC it
16
+ * exchanges the refresh token for an id token, then trades that id token at /auth/sync for
17
+ * a Wardrowbe access token, caching the result until shortly before it expires.
18
+ */
19
+ export class TokenProvider {
20
+ config;
21
+ fetchFn;
22
+ now;
23
+ hooks;
24
+ accessToken;
25
+ expiresAt = 0;
26
+ refreshToken;
27
+ inflight;
28
+ constructor(config, fetchFn = fetch, now = Date.now, hooks = {}) {
29
+ this.config = config;
30
+ this.fetchFn = fetchFn;
31
+ this.now = now;
32
+ this.hooks = hooks;
33
+ this.refreshToken = config.oidc?.refreshToken;
34
+ }
35
+ async getToken() {
36
+ if (this.config.staticToken)
37
+ return this.config.staticToken;
38
+ if (this.accessToken && this.now() < this.expiresAt - EXPIRY_MARGIN_MS) {
39
+ return this.accessToken;
40
+ }
41
+ // Share one in-flight exchange so concurrent tool calls don't each refresh the token.
42
+ this.inflight ??= this.exchange().finally(() => {
43
+ this.inflight = undefined;
44
+ });
45
+ return this.inflight;
46
+ }
47
+ async exchange() {
48
+ const oidc = this.config.oidc;
49
+ if (!oidc)
50
+ throw new Error("No OIDC configuration");
51
+ const idToken = await this.refreshIdToken(oidc);
52
+ const res = await this.fetchFn(`${this.config.wardrowbeUrl}/api/v1/auth/sync`, {
53
+ method: "POST",
54
+ headers: { "Content-Type": "application/json", Accept: "application/json" },
55
+ body: JSON.stringify({ id_token: idToken }),
56
+ });
57
+ const body = (await parseJson(res));
58
+ if (!res.ok || !body?.access_token) {
59
+ throw new WardrowbeApiError(res.status, `auth/sync failed: ${describe(body, res)}`);
60
+ }
61
+ this.accessToken = body.access_token;
62
+ const ttl = jwtTtlMs(body.access_token, this.now);
63
+ this.expiresAt = this.now() + (ttl ?? FALLBACK_TTL_MS);
64
+ return this.accessToken;
65
+ }
66
+ async refreshIdToken(oidc) {
67
+ const discovery = await this.fetchFn(`${oidc.issuerUrl}/.well-known/openid-configuration`, {
68
+ headers: { Accept: "application/json" },
69
+ });
70
+ const meta = (await parseJson(discovery));
71
+ if (!discovery.ok || !meta?.token_endpoint) {
72
+ throw new Error(`OIDC discovery failed at ${oidc.issuerUrl} (HTTP ${discovery.status})`);
73
+ }
74
+ const first = await this.refresh(meta.token_endpoint, oidc, await this.currentRefreshToken(oidc));
75
+ if (first.ok)
76
+ return first.idToken;
77
+ // The issuer rejected the token, so it has expired or been revoked. Sign in again once.
78
+ // Server errors are not a sign of a bad token, so they are reported as they are.
79
+ const rejected = first.status === 400 || first.status === 401;
80
+ if (!rejected || !this.hooks.signIn) {
81
+ throw new Error(`OIDC refresh failed (HTTP ${first.status}). The refresh token may be expired or revoked.`);
82
+ }
83
+ const second = await this.refresh(meta.token_endpoint, oidc, await this.signIn(oidc));
84
+ if (second.ok)
85
+ return second.idToken;
86
+ throw new Error(`OIDC refresh failed after signing in again (HTTP ${second.status}).`);
87
+ }
88
+ /** Current refresh token: the in-memory one, then the stored one, then a fresh browser sign-in. */
89
+ async currentRefreshToken(oidc) {
90
+ if (this.refreshToken)
91
+ return this.refreshToken;
92
+ const stored = await this.hooks.store?.load(oidc.issuerUrl, oidc.clientId);
93
+ if (stored) {
94
+ this.refreshToken = stored;
95
+ return stored;
96
+ }
97
+ return this.signIn(oidc);
98
+ }
99
+ /** Runs the browser sign-in and keeps the resulting refresh token. */
100
+ async signIn(oidc) {
101
+ if (!this.hooks.signIn) {
102
+ throw new Error("No refresh token is available. Set OIDC_REFRESH_TOKEN, or run `wardrowbe-mcp login`.");
103
+ }
104
+ const token = await this.hooks.signIn();
105
+ await this.remember(oidc, token);
106
+ return token;
107
+ }
108
+ async refresh(tokenEndpoint, oidc, refreshToken) {
109
+ const form = new URLSearchParams({
110
+ grant_type: "refresh_token",
111
+ refresh_token: refreshToken,
112
+ client_id: oidc.clientId,
113
+ });
114
+ if (oidc.clientSecret)
115
+ form.set("client_secret", oidc.clientSecret);
116
+ const res = await this.fetchFn(tokenEndpoint, {
117
+ method: "POST",
118
+ headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
119
+ body: form,
120
+ });
121
+ const tokens = (await parseJson(res));
122
+ if (!res.ok || !tokens?.id_token)
123
+ return { ok: false, status: res.status };
124
+ // Some issuers rotate refresh tokens. Keep the newest one so the next run can use it.
125
+ if (tokens.refresh_token)
126
+ await this.remember(oidc, tokens.refresh_token);
127
+ return { ok: true, idToken: tokens.id_token };
128
+ }
129
+ /** Keeps a refresh token in memory and in the store. A failed write is logged, not fatal. */
130
+ async remember(oidc, refreshToken) {
131
+ this.refreshToken = refreshToken;
132
+ const store = this.hooks.store;
133
+ if (!store)
134
+ return;
135
+ try {
136
+ await store.save({ issuerUrl: oidc.issuerUrl, clientId: oidc.clientId, refreshToken });
137
+ }
138
+ catch (err) {
139
+ const message = err instanceof Error ? err.message : String(err);
140
+ console.error(`wardrowbe-mcp: could not save the refresh token to ${store.path}: ${message}`);
141
+ }
142
+ }
143
+ }
144
+ /** Thin JSON client for the Wardrowbe REST API. */
145
+ export class WardrowbeClient {
146
+ config;
147
+ tokens;
148
+ fetchFn;
149
+ constructor(config, tokens, fetchFn = fetch) {
150
+ this.config = config;
151
+ this.tokens = tokens;
152
+ this.fetchFn = fetchFn;
153
+ }
154
+ get(path, query) {
155
+ return this.request("GET", path, { query });
156
+ }
157
+ post(path, body) {
158
+ return this.request("POST", path, { body });
159
+ }
160
+ async request(method, path, opts) {
161
+ const url = new URL(`${this.config.wardrowbeUrl}/api/v1${path}`);
162
+ for (const [k, v] of Object.entries(opts.query ?? {})) {
163
+ if (v !== undefined)
164
+ url.searchParams.set(k, String(v));
165
+ }
166
+ const token = await this.tokens.getToken();
167
+ const headers = {
168
+ Authorization: `Bearer ${token}`,
169
+ Accept: "application/json",
170
+ };
171
+ const init = { method, headers };
172
+ if (opts.body !== undefined) {
173
+ headers["Content-Type"] = "application/json";
174
+ init.body = JSON.stringify(opts.body);
175
+ }
176
+ const res = await this.fetchFn(url, init);
177
+ const body = await parseJson(res);
178
+ if (!res.ok)
179
+ throw new WardrowbeApiError(res.status, describe(body, res));
180
+ return body;
181
+ }
182
+ }
183
+ async function parseJson(res) {
184
+ const text = await res.text();
185
+ if (!text)
186
+ return undefined;
187
+ try {
188
+ return JSON.parse(text);
189
+ }
190
+ catch {
191
+ return undefined;
192
+ }
193
+ }
194
+ function describe(body, res) {
195
+ const detail = body?.detail;
196
+ if (typeof detail === "string")
197
+ return detail;
198
+ if (detail !== undefined)
199
+ return JSON.stringify(detail).slice(0, 300);
200
+ return res.statusText || "request failed";
201
+ }
202
+ /** Milliseconds until a JWT's exp claim, or undefined when it has none. Signature is not checked. */
203
+ function jwtTtlMs(jwt, now) {
204
+ const payload = jwt.split(".")[1];
205
+ if (!payload)
206
+ return undefined;
207
+ try {
208
+ const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
209
+ return typeof claims.exp === "number" ? claims.exp * 1000 - now() : undefined;
210
+ }
211
+ catch {
212
+ return undefined;
213
+ }
214
+ }
@@ -0,0 +1,24 @@
1
+ export type Transport = "stdio" | "http";
2
+ export interface Config {
3
+ wardrowbeUrl: string;
4
+ /** Static access token for the Wardrowbe API (JWT). Optional when OIDC is configured. */
5
+ staticToken?: string;
6
+ oidc?: {
7
+ issuerUrl: string;
8
+ clientId: string;
9
+ clientSecret?: string;
10
+ /** Explicit refresh token. When absent, the stored one is used, or the browser sign-in runs. */
11
+ refreshToken?: string;
12
+ };
13
+ /** Where the refresh token is kept between runs. Set only when OIDC is configured. */
14
+ tokenFile?: string;
15
+ transport: Transport;
16
+ host: string;
17
+ port: number;
18
+ /** Required for the http transport. Clients send it as a Bearer token. */
19
+ apiKey?: string;
20
+ }
21
+ export declare class ConfigError extends Error {
22
+ }
23
+ /** Parses config from environment variables. Pure, so it is easy to test. */
24
+ export declare function loadConfig(env: NodeJS.ProcessEnv): Config;
package/dist/config.js ADDED
@@ -0,0 +1,61 @@
1
+ import { defaultTokenFile } from "./token-store.js";
2
+ export class ConfigError extends Error {
3
+ }
4
+ /** Parses config from environment variables. Pure, so it is easy to test. */
5
+ export function loadConfig(env) {
6
+ const wardrowbeUrl = (env.WARDROWBE_URL ?? "").trim().replace(/\/+$/, "");
7
+ if (!wardrowbeUrl) {
8
+ throw new ConfigError("WARDROWBE_URL is required (e.g. https://wardrowbe.example.com)");
9
+ }
10
+ try {
11
+ new URL(wardrowbeUrl);
12
+ }
13
+ catch {
14
+ throw new ConfigError(`WARDROWBE_URL is not a valid URL: ${wardrowbeUrl}`);
15
+ }
16
+ const staticToken = env.WARDROWBE_TOKEN?.trim() || undefined;
17
+ const oidcIssuer = env.OIDC_ISSUER_URL?.trim();
18
+ const oidcClient = env.OIDC_CLIENT_ID?.trim();
19
+ // OIDC_REFRESH_TOKEN is optional. Without it, the server signs in through the browser and stores the result.
20
+ const oidcRefresh = env.OIDC_REFRESH_TOKEN?.trim() || undefined;
21
+ let oidc;
22
+ let tokenFile;
23
+ if (oidcIssuer || oidcClient || oidcRefresh) {
24
+ if (!oidcIssuer || !oidcClient) {
25
+ throw new ConfigError("OIDC needs OIDC_ISSUER_URL and OIDC_CLIENT_ID");
26
+ }
27
+ oidc = {
28
+ issuerUrl: oidcIssuer.replace(/\/+$/, ""),
29
+ clientId: oidcClient,
30
+ clientSecret: env.OIDC_CLIENT_SECRET?.trim() || undefined,
31
+ refreshToken: oidcRefresh,
32
+ };
33
+ tokenFile = env.WARDROWBE_TOKEN_FILE?.trim() || defaultTokenFile(env);
34
+ }
35
+ if (!staticToken && !oidc) {
36
+ throw new ConfigError("Set WARDROWBE_TOKEN, or OIDC_ISSUER_URL and OIDC_CLIENT_ID to sign in with your identity provider");
37
+ }
38
+ const transport = (env.MCP_TRANSPORT?.trim() || "stdio");
39
+ if (transport !== "stdio" && transport !== "http") {
40
+ throw new ConfigError(`MCP_TRANSPORT must be "stdio" or "http", got "${transport}"`);
41
+ }
42
+ const port = Number(env.MCP_PORT ?? "8080");
43
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
44
+ throw new ConfigError(`MCP_PORT must be a port number, got "${env.MCP_PORT}"`);
45
+ }
46
+ const apiKey = env.MCP_API_KEY?.trim() || undefined;
47
+ if (transport === "http" && !apiKey) {
48
+ throw new ConfigError("MCP_API_KEY is required for the http transport");
49
+ }
50
+ return {
51
+ wardrowbeUrl,
52
+ staticToken,
53
+ oidc,
54
+ tokenFile,
55
+ transport,
56
+ // Bind to loopback unless the caller opts in. Container deployments set MCP_BIND_HOST=0.0.0.0.
57
+ host: env.MCP_BIND_HOST?.trim() || "127.0.0.1",
58
+ port,
59
+ apiKey,
60
+ };
61
+ }
package/dist/http.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { type IncomingMessage, type ServerResponse } from "node:http";
2
+ import type { Config } from "./config.js";
3
+ /** Constant-time check of the Bearer token, so the comparison doesn't leak the key by timing. */
4
+ 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>;
package/dist/http.js ADDED
@@ -0,0 +1,48 @@
1
+ import { createServer as createHttpServer } from "node:http";
2
+ import { timingSafeEqual } from "node:crypto";
3
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
4
+ import { createServer, SERVER_NAME, SERVER_VERSION } from "./server.js";
5
+ /** Constant-time check of the Bearer token, so the comparison doesn't leak the key by timing. */
6
+ export function isAuthorized(header, apiKey) {
7
+ const match = /^Bearer (.+)$/.exec(header ?? "");
8
+ if (!match)
9
+ return false;
10
+ const given = Buffer.from(match[1]);
11
+ const expected = Buffer.from(apiKey);
12
+ return given.length === expected.length && timingSafeEqual(given, expected);
13
+ }
14
+ function sendJson(res, status, body) {
15
+ res.writeHead(status, { "Content-Type": "application/json" });
16
+ res.end(JSON.stringify(body));
17
+ }
18
+ /** Serves the MCP endpoint at /mcp over Streamable HTTP, stateless, behind a Bearer API key. */
19
+ export function createMcpHttpServer(config) {
20
+ const apiKey = config.apiKey;
21
+ if (!apiKey)
22
+ throw new Error("MCP_API_KEY is required for the http transport");
23
+ return createHttpServer(async (req, res) => {
24
+ const url = new URL(req.url ?? "/", "http://localhost");
25
+ if (url.pathname === "/" && req.method === "GET") {
26
+ sendJson(res, 200, { name: SERVER_NAME, version: SERVER_VERSION, endpoint: "/mcp" });
27
+ return;
28
+ }
29
+ if (url.pathname !== "/mcp") {
30
+ sendJson(res, 404, { error: "not found" });
31
+ return;
32
+ }
33
+ if (!isAuthorized(req.headers.authorization, apiKey)) {
34
+ res.setHeader("WWW-Authenticate", "Bearer");
35
+ sendJson(res, 401, { error: "unauthorized" });
36
+ return;
37
+ }
38
+ // Stateless: a fresh server and transport per request, so no session state is kept between calls.
39
+ const server = createServer(config);
40
+ const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
41
+ res.on("close", () => {
42
+ void transport.close();
43
+ void server.close();
44
+ });
45
+ await server.connect(transport);
46
+ await transport.handleRequest(req, res);
47
+ });
48
+ }
@@ -0,0 +1,5 @@
1
+ export { loadConfig, ConfigError, type Config, type Transport } from "./config.js";
2
+ export { WardrowbeClient, TokenProvider, WardrowbeApiError } from "./client.js";
3
+ export { createServer, SERVER_NAME, SERVER_VERSION } from "./server.js";
4
+ export { registerTools } from "./tools.js";
5
+ export { createMcpHttpServer, isAuthorized } from "./http.js";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { loadConfig, ConfigError } from "./config.js";
2
+ export { WardrowbeClient, TokenProvider, WardrowbeApiError } from "./client.js";
3
+ export { createServer, SERVER_NAME, SERVER_VERSION } from "./server.js";
4
+ export { registerTools } from "./tools.js";
5
+ export { createMcpHttpServer, isAuthorized } from "./http.js";
@@ -0,0 +1,32 @@
1
+ export interface Pkce {
2
+ verifier: string;
3
+ challenge: string;
4
+ }
5
+ /** Creates a PKCE verifier and its S256 challenge (RFC 7636). */
6
+ export declare function createPkce(): Pkce;
7
+ /** S256 code challenge for a verifier. */
8
+ export declare function challengeFor(verifier: string): string;
9
+ export interface LoginOptions {
10
+ issuerUrl: string;
11
+ clientId: string;
12
+ clientSecret?: string;
13
+ port: number;
14
+ fetchFn?: typeof fetch;
15
+ /** Opens the authorize URL. Defaults to the platform browser opener. Failures are ignored. */
16
+ openBrowser?: (url: string) => void;
17
+ /** Receives human-readable progress. Defaults to stderr. */
18
+ log?: (message: string) => void;
19
+ /** How long to wait for the browser sign-in to come back. */
20
+ timeoutMs?: number;
21
+ }
22
+ export interface LoginResult {
23
+ refreshToken: string;
24
+ idToken?: string;
25
+ }
26
+ /** Localhost port for the sign-in redirect. Register `http://localhost:8765/callback` with the IdP. */
27
+ export declare const DEFAULT_LOGIN_PORT = 8765;
28
+ /**
29
+ * Runs the one-time sign-in: opens the browser at the issuer's authorize endpoint with PKCE and
30
+ * `offline_access`, catches the redirect on localhost, and exchanges the code for a refresh token.
31
+ */
32
+ export declare function runLogin(opts: LoginOptions): Promise<LoginResult>;
package/dist/login.js ADDED
@@ -0,0 +1,140 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { createServer } from "node:http";
3
+ import { spawn } from "node:child_process";
4
+ /** Creates a PKCE verifier and its S256 challenge (RFC 7636). */
5
+ export function createPkce() {
6
+ const verifier = randomBytes(32).toString("base64url");
7
+ return { verifier, challenge: challengeFor(verifier) };
8
+ }
9
+ /** S256 code challenge for a verifier. */
10
+ export function challengeFor(verifier) {
11
+ return createHash("sha256").update(verifier).digest("base64url");
12
+ }
13
+ const CALLBACK_PATH = "/callback";
14
+ const DEFAULT_TIMEOUT_MS = 5 * 60_000;
15
+ /** Localhost port for the sign-in redirect. Register `http://localhost:8765/callback` with the IdP. */
16
+ export const DEFAULT_LOGIN_PORT = 8765;
17
+ /**
18
+ * Runs the one-time sign-in: opens the browser at the issuer's authorize endpoint with PKCE and
19
+ * `offline_access`, catches the redirect on localhost, and exchanges the code for a refresh token.
20
+ */
21
+ export async function runLogin(opts) {
22
+ const fetchFn = opts.fetchFn ?? fetch;
23
+ const log = opts.log ?? ((m) => console.error(m));
24
+ const issuer = opts.issuerUrl.replace(/\/+$/, "");
25
+ const discovery = await fetchFn(`${issuer}/.well-known/openid-configuration`, {
26
+ headers: { Accept: "application/json" },
27
+ });
28
+ const meta = (await discovery.json().catch(() => undefined));
29
+ if (!discovery.ok || !meta?.authorization_endpoint || !meta.token_endpoint) {
30
+ throw new Error(`OIDC discovery failed at ${issuer} (HTTP ${discovery.status})`);
31
+ }
32
+ const { verifier, challenge } = createPkce();
33
+ const state = randomBytes(16).toString("base64url");
34
+ const redirectUri = `http://localhost:${opts.port}${CALLBACK_PATH}`;
35
+ const authorizeUrl = new URL(meta.authorization_endpoint);
36
+ authorizeUrl.search = new URLSearchParams({
37
+ response_type: "code",
38
+ client_id: opts.clientId,
39
+ redirect_uri: redirectUri,
40
+ scope: "openid profile email offline_access",
41
+ code_challenge: challenge,
42
+ code_challenge_method: "S256",
43
+ state,
44
+ }).toString();
45
+ const code = await waitForCode({
46
+ port: opts.port,
47
+ state,
48
+ timeoutMs: opts.timeoutMs ?? DEFAULT_TIMEOUT_MS,
49
+ onListening: () => {
50
+ log(`Sign in with your identity provider. If no browser opens, visit:\n ${authorizeUrl}`);
51
+ (opts.openBrowser ?? openInBrowser)(authorizeUrl.toString());
52
+ },
53
+ });
54
+ const form = new URLSearchParams({
55
+ grant_type: "authorization_code",
56
+ code,
57
+ redirect_uri: redirectUri,
58
+ client_id: opts.clientId,
59
+ code_verifier: verifier,
60
+ });
61
+ if (opts.clientSecret)
62
+ form.set("client_secret", opts.clientSecret);
63
+ const res = await fetchFn(meta.token_endpoint, {
64
+ method: "POST",
65
+ headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
66
+ body: form,
67
+ });
68
+ const tokens = (await res.json().catch(() => undefined));
69
+ if (!res.ok || !tokens) {
70
+ throw new Error(`Token exchange failed (HTTP ${res.status}${tokens?.error ? `: ${tokens.error}` : ""})`);
71
+ }
72
+ if (!tokens.refresh_token) {
73
+ throw new Error("The identity provider returned no refresh_token. Allow the offline_access scope for this client and sign in again.");
74
+ }
75
+ return { refreshToken: tokens.refresh_token, idToken: tokens.id_token };
76
+ }
77
+ /** Starts a localhost listener and resolves with the authorization code from the redirect. */
78
+ function waitForCode(opts) {
79
+ return new Promise((resolve, reject) => {
80
+ let server;
81
+ const timer = setTimeout(() => {
82
+ server?.close();
83
+ reject(new Error("Timed out waiting for the browser sign-in"));
84
+ }, opts.timeoutMs);
85
+ server = createServer((req, res) => {
86
+ const url = new URL(req.url ?? "/", "http://localhost");
87
+ if (url.pathname !== CALLBACK_PATH) {
88
+ res.writeHead(404).end("not found");
89
+ return;
90
+ }
91
+ const error = url.searchParams.get("error");
92
+ const code = url.searchParams.get("code");
93
+ const state = url.searchParams.get("state");
94
+ if (error) {
95
+ res.writeHead(400, { "Content-Type": "text/plain" }).end(`Sign-in failed: ${error}`);
96
+ finish(new Error(`Sign-in failed: ${error}`));
97
+ return;
98
+ }
99
+ if (!code || state !== opts.state) {
100
+ res.writeHead(400, { "Content-Type": "text/plain" }).end("Invalid sign-in response");
101
+ finish(new Error("Sign-in response had a missing code or a mismatched state"));
102
+ return;
103
+ }
104
+ res
105
+ .writeHead(200, { "Content-Type": "text/html" })
106
+ .end("<h1>Signed in</h1><p>You can close this tab and return to the terminal.</p>");
107
+ finish(undefined, code);
108
+ });
109
+ function finish(err, code) {
110
+ clearTimeout(timer);
111
+ server?.close();
112
+ if (err)
113
+ reject(err);
114
+ else
115
+ resolve(code);
116
+ }
117
+ server.on("error", (err) => {
118
+ clearTimeout(timer);
119
+ reject(err);
120
+ });
121
+ server.listen(opts.port, "127.0.0.1", () => opts.onListening());
122
+ });
123
+ }
124
+ /** Opens a URL in the default browser without blocking. Errors are ignored; the URL is printed too. */
125
+ function openInBrowser(url) {
126
+ const command = process.platform === "darwin"
127
+ ? "open"
128
+ : process.platform === "win32"
129
+ ? "cmd"
130
+ : "xdg-open";
131
+ const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
132
+ try {
133
+ const child = spawn(command, args, { stdio: "ignore", detached: true });
134
+ child.on("error", () => { });
135
+ child.unref();
136
+ }
137
+ catch {
138
+ // The URL is already printed for the user to open by hand.
139
+ }
140
+ }
@@ -0,0 +1,6 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { Config } from "./config.js";
3
+ export declare const SERVER_NAME = "wardrowbe-mcp";
4
+ export declare const SERVER_VERSION = "0.1.0";
5
+ /** Builds an MCP server with all Wardrowbe tools registered against the configured instance. */
6
+ export declare function createServer(config: Config, fetchFn?: typeof fetch): McpServer;
package/dist/server.js ADDED
@@ -0,0 +1,45 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { WardrowbeClient, TokenProvider } from "./client.js";
3
+ import { DEFAULT_LOGIN_PORT, runLogin } from "./login.js";
4
+ import { registerTools } from "./tools.js";
5
+ import { TokenStore } from "./token-store.js";
6
+ 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
+ */
12
+ /**
13
+ * Module-level, because the HTTP transport builds a server per request. Only one browser sign-in
14
+ * runs at a time: concurrent callers share it, since the callback port can be bound only once.
15
+ */
16
+ let pendingSignIn;
17
+ function signInHooks(config) {
18
+ if (!config.oidc)
19
+ return {};
20
+ const oidc = config.oidc;
21
+ return {
22
+ store: config.tokenFile ? new TokenStore(config.tokenFile) : undefined,
23
+ signIn: () => {
24
+ pendingSignIn ??= runLogin({
25
+ issuerUrl: oidc.issuerUrl,
26
+ clientId: oidc.clientId,
27
+ clientSecret: oidc.clientSecret,
28
+ port: DEFAULT_LOGIN_PORT,
29
+ })
30
+ .then((result) => result.refreshToken)
31
+ .finally(() => {
32
+ pendingSignIn = undefined;
33
+ });
34
+ return pendingSignIn;
35
+ },
36
+ };
37
+ }
38
+ /** Builds an MCP server with all Wardrowbe tools registered against the configured instance. */
39
+ export function createServer(config, fetchFn = fetch) {
40
+ const tokens = new TokenProvider(config, fetchFn, Date.now, signInHooks(config));
41
+ const client = new WardrowbeClient(config, tokens, fetchFn);
42
+ const server = new McpServer({ name: SERVER_NAME, version: SERVER_VERSION });
43
+ registerTools(server, client);
44
+ return server;
45
+ }
@@ -0,0 +1,20 @@
1
+ /** What the server keeps between runs so it doesn't have to sign in again. */
2
+ export interface StoredRefreshToken {
3
+ issuerUrl: string;
4
+ clientId: string;
5
+ refreshToken: string;
6
+ }
7
+ /** Default location: $XDG_CONFIG_HOME/wardrowbe-mcp/refresh-token.json, or ~/.config/... */
8
+ export declare function defaultTokenFile(env: NodeJS.ProcessEnv): string;
9
+ /**
10
+ * Persists the OIDC refresh token to a file readable only by the current user. Entries are keyed
11
+ * by issuer and client ID, so a changed config never reuses a token from another IdP.
12
+ */
13
+ export declare class TokenStore {
14
+ readonly path: string;
15
+ constructor(path: string);
16
+ /** Returns the stored refresh token for this issuer and client, or undefined if there is none. */
17
+ load(issuerUrl: string, clientId: string): Promise<string | undefined>;
18
+ /** Writes the token atomically: a temp file is renamed over the old one, so a crash never leaves a partial file. */
19
+ save(entry: StoredRefreshToken): Promise<void>;
20
+ }
@@ -0,0 +1,49 @@
1
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
2
+ import { homedir } from "node:os";
3
+ import { dirname, join } from "node:path";
4
+ /** Default location: $XDG_CONFIG_HOME/wardrowbe-mcp/refresh-token.json, or ~/.config/... */
5
+ export function defaultTokenFile(env) {
6
+ const base = env.XDG_CONFIG_HOME?.trim() || join(homedir(), ".config");
7
+ return join(base, "wardrowbe-mcp", "refresh-token.json");
8
+ }
9
+ /**
10
+ * Persists the OIDC refresh token to a file readable only by the current user. Entries are keyed
11
+ * by issuer and client ID, so a changed config never reuses a token from another IdP.
12
+ */
13
+ export class TokenStore {
14
+ path;
15
+ constructor(path) {
16
+ this.path = path;
17
+ }
18
+ /** Returns the stored refresh token for this issuer and client, or undefined if there is none. */
19
+ async load(issuerUrl, clientId) {
20
+ let raw;
21
+ try {
22
+ raw = await readFile(this.path, "utf8");
23
+ }
24
+ catch (err) {
25
+ if (err.code === "ENOENT")
26
+ return undefined;
27
+ throw err;
28
+ }
29
+ let entry;
30
+ try {
31
+ entry = JSON.parse(raw);
32
+ }
33
+ catch {
34
+ // A corrupt file is treated as missing; the next sign-in overwrites it.
35
+ return undefined;
36
+ }
37
+ if (entry.issuerUrl !== issuerUrl || entry.clientId !== clientId || !entry.refreshToken) {
38
+ return undefined;
39
+ }
40
+ return entry.refreshToken;
41
+ }
42
+ /** Writes the token atomically: a temp file is renamed over the old one, so a crash never leaves a partial file. */
43
+ async save(entry) {
44
+ await mkdir(dirname(this.path), { recursive: true, mode: 0o700 });
45
+ const tmp = `${this.path}.tmp`;
46
+ await writeFile(tmp, `${JSON.stringify(entry, null, 2)}\n`, { mode: 0o600 });
47
+ await rename(tmp, this.path);
48
+ }
49
+ }
@@ -0,0 +1,4 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { WardrowbeClient } from "./client.js";
3
+ /** Registers the Wardrowbe tools on an MCP server. */
4
+ export declare function registerTools(server: McpServer, client: WardrowbeClient): void;
package/dist/tools.js ADDED
@@ -0,0 +1,92 @@
1
+ import { z } from "zod";
2
+ const uuid = z.string().uuid().describe("Item or outfit UUID");
3
+ const isoDate = z
4
+ .string()
5
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "Use YYYY-MM-DD")
6
+ .describe("Date as YYYY-MM-DD");
7
+ /** Wraps a tool body so API errors come back as tool errors the model can read, not crashes. */
8
+ async function run(fn) {
9
+ try {
10
+ const result = await fn();
11
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
12
+ }
13
+ catch (err) {
14
+ const message = err instanceof Error ? err.message : String(err);
15
+ return { content: [{ type: "text", text: message }], isError: true };
16
+ }
17
+ }
18
+ /** Registers the Wardrowbe tools on an MCP server. */
19
+ export function registerTools(server, client) {
20
+ server.registerTool("list_items", {
21
+ title: "List wardrobe items",
22
+ description: "List items in the user's wardrobe. Filter by type, status, favorites, or items that need washing.",
23
+ inputSchema: {
24
+ type: z.string().optional().describe("Item type, e.g. top, bottom, shoes"),
25
+ subtype: z.string().optional(),
26
+ colors: z.string().optional().describe("Comma-separated color names"),
27
+ status: z.string().optional(),
28
+ favorite: z.boolean().optional(),
29
+ needs_wash: z.boolean().optional(),
30
+ search: z.string().optional(),
31
+ page: z.number().int().min(1).optional(),
32
+ page_size: z.number().int().min(1).optional(),
33
+ },
34
+ }, (args) => run(() => client.get("/items", args)));
35
+ server.registerTool("get_item", {
36
+ title: "Get a wardrobe item",
37
+ description: "Get full details for one wardrobe item, including its wear and wash status.",
38
+ inputSchema: { item_id: uuid },
39
+ }, ({ item_id }) => run(() => client.get(`/items/${item_id}`)));
40
+ server.registerTool("log_wear", {
41
+ title: "Log an item as worn",
42
+ description: "Record that an item was worn. Defaults to today in the user's timezone when worn_at is omitted.",
43
+ inputSchema: {
44
+ item_id: uuid,
45
+ worn_at: isoDate.optional(),
46
+ occasion: z.string().optional(),
47
+ notes: z.string().optional(),
48
+ },
49
+ }, ({ item_id, ...body }) => run(() => client.post(`/items/${item_id}/wear`, body)));
50
+ server.registerTool("log_wash", {
51
+ title: "Log an item as washed",
52
+ description: "Record that an item was washed. Defaults to today in the user's timezone when washed_at is omitted.",
53
+ inputSchema: {
54
+ item_id: uuid,
55
+ washed_at: isoDate.optional(),
56
+ method: z.string().max(50).optional(),
57
+ notes: z.string().optional(),
58
+ },
59
+ }, ({ item_id, ...body }) => run(() => client.post(`/items/${item_id}/wash`, body)));
60
+ server.registerTool("suggest_outfit", {
61
+ title: "Suggest an outfit",
62
+ description: "Ask Wardrowbe to suggest an outfit from the wardrobe. Rate limited to about 10 requests per minute per user.",
63
+ inputSchema: {
64
+ occasion: z.string().optional(),
65
+ time_of_day: z.string().optional(),
66
+ exclude_items: z.array(uuid).optional(),
67
+ include_items: z.array(uuid).optional(),
68
+ },
69
+ }, (args) => run(() => client.post("/outfits/suggest", {
70
+ occasion: args.occasion,
71
+ time_of_day: args.time_of_day,
72
+ exclude_items: args.exclude_items ?? [],
73
+ include_items: args.include_items ?? [],
74
+ })));
75
+ server.registerTool("accept_outfit", {
76
+ title: "Accept an outfit",
77
+ description: "Mark a suggested outfit as accepted.",
78
+ inputSchema: { outfit_id: uuid },
79
+ }, ({ outfit_id }) => run(() => client.post(`/outfits/${outfit_id}/accept`)));
80
+ server.registerTool("reject_outfit", {
81
+ title: "Reject an outfit",
82
+ description: "Mark a suggested outfit as rejected, so it is not suggested again.",
83
+ inputSchema: { outfit_id: uuid },
84
+ }, ({ outfit_id }) => run(() => client.post(`/outfits/${outfit_id}/reject`)));
85
+ server.registerTool("get_analytics", {
86
+ title: "Wardrobe analytics",
87
+ description: "Get wardrobe analytics, including trends over a chosen window of days.",
88
+ inputSchema: {
89
+ days: z.number().int().min(7).max(365).optional().describe("Trend window, 7 to 365 days"),
90
+ },
91
+ }, ({ days }) => run(() => client.get("/analytics", { days: days ?? 30 })));
92
+ }
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@mdeleon23/wardrowbe-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "MCP server for the Wardrowbe wardrobe API. Runs over stdio (npx) or Streamable HTTP.",
5
+ "type": "module",
6
+ "bin": {
7
+ "wardrowbe-mcp": "dist/cli.js"
8
+ },
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "files": [
12
+ "dist",
13
+ "README.md"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.json",
17
+ "typecheck": "tsc -p tsconfig.json --noEmit",
18
+ "test": "vitest run",
19
+ "prepack": "npm run build"
20
+ },
21
+ "engines": {
22
+ "node": ">=20"
23
+ },
24
+ "keywords": [
25
+ "mcp",
26
+ "model-context-protocol",
27
+ "wardrobe",
28
+ "wardrowbe"
29
+ ],
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/mjrealm/wardrowbe-mcp.git"
34
+ },
35
+ "homepage": "https://github.com/mjrealm/wardrowbe-mcp#readme",
36
+ "bugs": {
37
+ "url": "https://github.com/mjrealm/wardrowbe-mcp/issues"
38
+ },
39
+ "dependencies": {
40
+ "@modelcontextprotocol/sdk": "^1.32.2",
41
+ "zod": "^4.6.7"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^24.0.0",
45
+ "typescript": "^5.9.0",
46
+ "vitest": "^4.0.0"
47
+ }
48
+ }