@mdeleon23/wardrowbe-mcp 0.3.0 → 0.3.1

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.
Files changed (3) hide show
  1. package/README.md +100 -31
  2. package/dist/client.js +22 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -6,31 +6,106 @@ Requires Node.js 20 or newer.
6
6
 
7
7
  ## Quick start
8
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.
9
+ You need:
10
+
11
+ - Node.js 20 or newer
12
+ - Your Wardrowbe URL, for example `https://wardrowbe.example.com`
13
+ - An OIDC identity provider that runs Wardrowbe sign-in. Pocket ID works.
14
+
15
+ Setup has four steps: create an OIDC client, get a refresh token, add the server to your MCP client, and check that it works.
16
+
17
+ ### Step 1: Create an OIDC client
18
+
19
+ In your identity provider:
20
+
21
+ 1. Create a client. A **public** client uses PKCE and has no secret. A **confidential** client has a client secret. Both work. If yours is confidential, you'll set `OIDC_CLIENT_SECRET` in steps 2 and 3.
22
+ 2. Allow the scopes `openid profile email offline_access`. `offline_access` is required. Without it the provider returns no refresh token.
23
+ 3. Add the redirect URI `http://localhost:8765/callback` exactly as written.
24
+ 4. Note two values: the issuer URL (for example `https://pocket.example.com`) and the client ID (for example `wardrowbe`).
25
+
26
+ ### Step 2: Get a refresh token
27
+
28
+ Run this on a computer with a web browser. It can be your laptop, even if the MCP server runs somewhere else. Port `8765` must be free.
29
+
30
+ Run it from a folder outside any project, such as your home directory. Running it inside a clone of this repository fails with `sh: wardrowbe-mcp: command not found`.
31
+
32
+ If your client is confidential, set the secret in your shell first. `read -s` keeps it out of your shell history and off the command line. Type the secret when prompted and press Enter. Skip this for a public client.
33
+
34
+ ```bash
35
+ read -s OIDC_CLIENT_SECRET && export OIDC_CLIENT_SECRET
36
+ ```
37
+
38
+ Then run the login. It reads `OIDC_CLIENT_SECRET` from the environment automatically.
39
+
40
+ ```bash
41
+ cd ~
42
+ npx -y @mdeleon23/wardrowbe-mcp@0.3.0 login \
43
+ --issuer https://pocket.example.com \
44
+ --client-id wardrowbe \
45
+ > refresh-token.txt
46
+ chmod 600 refresh-token.txt
47
+ ```
48
+
49
+ The command pins `@0.3.0`, the release this step was checked against. You can drop the pin to use the latest release.
50
+
51
+ 1. The command prints progress messages to your terminal and tries to open the provider's sign-in page in your browser. If the browser doesn't open, copy the URL from the terminal into a browser yourself.
52
+ 2. Sign in and approve the request.
53
+ 3. The browser then redirects to `localhost:8765`. The terminal prints `Refresh token printed to stdout`. If you see an error instead, see [Troubleshooting](#troubleshooting).
54
+ 4. `refresh-token.txt` now contains the token. Treat it like a password.
55
+
56
+ ### Step 3: Add the server to your MCP client
57
+
58
+ For Claude Desktop or Claude Code, add this to your MCP config. Replace `<refresh-token>` with the contents of `refresh-token.txt`:
59
+
60
+ ```json
61
+ {
62
+ "mcpServers": {
63
+ "wardrowbe": {
64
+ "command": "npx",
65
+ "args": ["-y", "@mdeleon23/wardrowbe-mcp"],
66
+ "env": {
67
+ "WARDROWBE_URL": "https://wardrowbe.example.com",
68
+ "OIDC_ISSUER_URL": "https://pocket.example.com",
69
+ "OIDC_CLIENT_ID": "wardrowbe",
70
+ "OIDC_REFRESH_TOKEN": "<refresh-token>"
71
+ }
72
+ }
73
+ }
74
+ }
75
+ ```
76
+
77
+ Save the config, then delete `refresh-token.txt`. The token now lives only in your MCP config.
78
+
79
+ If you use a confidential client, also add `"OIDC_CLIENT_SECRET": "<client-secret>"` to `env`. Use the same secret as in step 2. The server needs it to refresh the token, so a token from a confidential client won't work without it.
31
80
 
32
81
  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
82
 
83
+ ### Step 4: Check that it works
84
+
85
+ Restart your MCP client, then ask it to call `get_wardrobe_summary`. It should return your item counts without asking you to sign in. If it reports a token or sign-in error, see [Troubleshooting](#troubleshooting).
86
+
87
+ ## Troubleshooting
88
+
89
+ **"The identity provider returned no refresh_token"**
90
+ The client doesn't allow `offline_access`. Enable that scope on the client, then repeat step 2.
91
+
92
+ **`sh: wardrowbe-mcp: command not found`**
93
+ You ran step 2 from inside a project folder, most likely this repository. Run it from another folder, such as your home directory.
94
+
95
+ **`Token exchange failed (HTTP 401: invalid_client)`**
96
+ The client is confidential, and `OIDC_CLIENT_SECRET` is missing or wrong at login. Set the secret as shown in step 2, then run the login again.
97
+
98
+ **Port 8765 is in use, or the browser redirect never arrives**
99
+ Another program is using port `8765`. Stop it, then repeat step 2. The redirect URI must still be `http://localhost:8765/callback`.
100
+
101
+ **"OIDC refresh failed" or "The refresh token may be expired or revoked"**
102
+ The token is no longer valid. Repeat step 2, then replace `OIDC_REFRESH_TOKEN` in your MCP config with the new token and restart the client.
103
+
104
+ If your provider rotates refresh tokens, the server saves each new token to `WARDROWBE_TOKEN_FILE`. At startup, though, `OIDC_REFRESH_TOKEN` takes priority over that file. If sign-in worked before and fails after a restart, repeat step 2 and update the config.
105
+
106
+ **A tool call starts a browser sign-in, or fails without one**
107
+ The server can start a browser sign-in by itself the first time a tool needs a token, but that path has not been reliable. Don't rely on it. Complete step 2 ahead of time and set `OIDC_REFRESH_TOKEN`.
108
+
34
109
  ## Configuration
35
110
 
36
111
  | Variable | Required | Default | Purpose |
@@ -40,7 +115,7 @@ To use a plain access token instead, set `WARDROWBE_TOKEN` in place of the `OIDC
40
115
  | `OIDC_ISSUER_URL` | or token | | OIDC issuer, e.g. `https://pocket.example.com`. |
41
116
  | `OIDC_CLIENT_ID` | with OIDC | | OIDC client ID. |
42
117
  | `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). |
118
+ | `OIDC_REFRESH_TOKEN` | no | | Refresh token from step 2 of the Quick start. Takes priority over the saved one. |
44
119
  | `WARDROWBE_TOKEN_FILE` | no | `~/.config/wardrowbe-mcp/refresh-token.json` | Where the refresh token is saved. |
45
120
  | `MCP_TRANSPORT` | no | `stdio` | `stdio` or `http`. |
46
121
  | `MCP_BIND_HOST` | no | `127.0.0.1` | Address for HTTP. Use `0.0.0.0` in containers. |
@@ -49,15 +124,9 @@ To use a plain access token instead, set `WARDROWBE_TOKEN` in place of the `OIDC
49
124
 
50
125
  ## How sign-in works
51
126
 
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
- ```
127
+ The server turns the refresh token into a short-lived access token before each batch of calls. It takes the refresh token from `OIDC_REFRESH_TOKEN` if you set it, and otherwise from `WARDROWBE_TOKEN_FILE`. If the provider issues a new refresh token, the server saves it to that file.
59
128
 
60
- Then set `OIDC_REFRESH_TOKEN` to the contents of `refresh-token.txt`, and delete the file.
129
+ Step 2 of the Quick start is the supported way to get a refresh token. This works on headless hosts and in containers too: sign in on any machine with a browser, then pass the token in with `OIDC_REFRESH_TOKEN`.
61
130
 
62
131
  ## HTTP transport
63
132
 
package/dist/client.js CHANGED
@@ -49,10 +49,22 @@ export class TokenProvider {
49
49
  if (!oidc)
50
50
  throw new Error("No OIDC configuration");
51
51
  const idToken = await this.refreshIdToken(oidc);
52
+ const claims = jwtClaims(idToken);
53
+ // Wardrowbe's /auth/sync requires external_id and display_name next to the id token.
54
+ if (typeof claims.sub !== "string" || !claims.sub) {
55
+ throw new Error("The ID token has no sub claim, so Wardrowbe cannot identify the user.");
56
+ }
57
+ const email = typeof claims.email === "string" ? claims.email : undefined;
58
+ const name = [claims.name, claims.preferred_username, email?.split("@")[0]].find((v) => typeof v === "string" && v.trim() !== "");
52
59
  const res = await this.fetchFn(`${this.config.wardrowbeUrl}/api/v1/auth/sync`, {
53
60
  method: "POST",
54
61
  headers: { "Content-Type": "application/json", Accept: "application/json" },
55
- body: JSON.stringify({ id_token: idToken }),
62
+ body: JSON.stringify({
63
+ id_token: idToken,
64
+ external_id: claims.sub,
65
+ email,
66
+ display_name: name ?? "User",
67
+ }),
56
68
  });
57
69
  const body = (await parseJson(res));
58
70
  if (!res.ok || !body?.access_token) {
@@ -207,15 +219,20 @@ function describe(body, res) {
207
219
  return res.statusText || "request failed";
208
220
  }
209
221
  /** Milliseconds until a JWT's exp claim, or undefined when it has none. Signature is not checked. */
210
- function jwtTtlMs(jwt, now) {
222
+ /** Reads the claims from a JWT's payload. The signature is not checked; Wardrowbe verifies it. */
223
+ function jwtClaims(jwt) {
211
224
  const payload = jwt.split(".")[1];
212
225
  if (!payload)
213
- return undefined;
226
+ return {};
214
227
  try {
215
228
  const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
216
- return typeof claims.exp === "number" ? claims.exp * 1000 - now() : undefined;
229
+ return claims && typeof claims === "object" ? claims : {};
217
230
  }
218
231
  catch {
219
- return undefined;
232
+ return {};
220
233
  }
221
234
  }
235
+ function jwtTtlMs(jwt, now) {
236
+ const exp = jwtClaims(jwt).exp;
237
+ return typeof exp === "number" ? exp * 1000 - now() : undefined;
238
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdeleon23/wardrowbe-mcp",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "MCP server for the Wardrowbe wardrobe API. Runs over stdio (npx) or Streamable HTTP.",
5
5
  "type": "module",
6
6
  "bin": {