slab-mcp 0.1.2 → 0.3.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.
Files changed (59) hide show
  1. package/README.md +190 -107
  2. package/dist/client.d.ts +34 -13
  3. package/dist/client.js +99 -59
  4. package/dist/config.d.ts +7 -2
  5. package/dist/config.js +30 -7
  6. package/dist/context.d.ts +8 -12
  7. package/dist/context.js +7 -29
  8. package/dist/credentials.d.ts +33 -0
  9. package/dist/credentials.js +77 -0
  10. package/dist/errors.js +6 -2
  11. package/dist/format.d.ts +2 -0
  12. package/dist/format.js +7 -1
  13. package/dist/index.js +4 -2
  14. package/dist/prompts/index.js +31 -6
  15. package/dist/resources/index.d.ts +2 -1
  16. package/dist/resources/index.js +4 -3
  17. package/dist/tools/args.d.ts +18 -0
  18. package/dist/tools/args.js +26 -0
  19. package/dist/tools/catalog.d.ts +21 -6
  20. package/dist/tools/catalog.js +88 -47
  21. package/dist/tools/chases.d.ts +28 -0
  22. package/dist/tools/chases.js +72 -0
  23. package/dist/tools/collection.d.ts +26 -18
  24. package/dist/tools/collection.js +113 -82
  25. package/dist/tools/community.d.ts +16 -3
  26. package/dist/tools/community.js +110 -50
  27. package/dist/tools/filters.d.ts +6 -0
  28. package/dist/tools/filters.js +6 -0
  29. package/dist/tools/index.js +2 -0
  30. package/dist/tools/lines.d.ts +20 -0
  31. package/dist/tools/lines.js +31 -0
  32. package/dist/tools/meta.js +5 -4
  33. package/dist/tools/pricing.d.ts +21 -16
  34. package/dist/tools/pricing.js +167 -63
  35. package/dist/tools/writes.d.ts +43 -47
  36. package/dist/tools/writes.js +65 -29
  37. package/dist/types.d.ts +48 -77
  38. package/dist/types.js +6 -6
  39. package/dist/version.d.ts +13 -0
  40. package/dist/version.js +16 -0
  41. package/package.json +14 -5
  42. package/dist/client.js.map +0 -1
  43. package/dist/config.js.map +0 -1
  44. package/dist/context.js.map +0 -1
  45. package/dist/errors.js.map +0 -1
  46. package/dist/format.js.map +0 -1
  47. package/dist/index.js.map +0 -1
  48. package/dist/prompts/index.js.map +0 -1
  49. package/dist/resources/index.js.map +0 -1
  50. package/dist/tools/catalog.js.map +0 -1
  51. package/dist/tools/collection.js.map +0 -1
  52. package/dist/tools/community.js.map +0 -1
  53. package/dist/tools/filters.js.map +0 -1
  54. package/dist/tools/index.js.map +0 -1
  55. package/dist/tools/meta.js.map +0 -1
  56. package/dist/tools/pricing.js.map +0 -1
  57. package/dist/tools/types.js.map +0 -1
  58. package/dist/tools/writes.js.map +0 -1
  59. package/dist/types.js.map +0 -1
package/README.md CHANGED
@@ -1,23 +1,29 @@
1
1
  # slab-mcp
2
2
 
3
- An [MCP](https://modelcontextprotocol.io) server for the [slab](https://app.slab.dev-jeb.com)
4
- trading-card API. It runs locally on your machine and gives an AI agent — Claude Code, Claude
5
- Desktop, Cursor, or anything else that speaks MCP — the ability to search the card catalog, read
6
- pricing, and (if you turn it on) manage your collection.
3
+ An [MCP](https://modelcontextprotocol.io) server for [slab](https://collection.slab.dev-jeb.com), the
4
+ hockey card collection site. It gives an AI agent (Claude Code, Claude Desktop, Cursor, or anything
5
+ else that speaks MCP) slab's catalog, prices and community, and the user's own collection:
7
6
 
8
- Ask your agent *"what are my three most valuable rookies, and is any of them worth grading?"* and it
9
- has the tools to actually answer.
7
+ - *"What's a PSA 10 Bedard Young Guns worth, and what have they actually sold for this month?"*
8
+ - *"Show me every parallel of Celebrini's Young Guns and how rare each one is."*
9
+ - *"Is my Schaefer worth grading?"*
10
+ - *"What's my collection worth, and what's on my want list?"*
11
+ - *"What's hot in hockey cards right now?"*
10
12
 
11
- **Read-only by default.** Write tools are not registered at all unless you opt in.
13
+ Every card is catalogued down to the exact parallel (over 550,000 printings), and every price is a
14
+ median of real sales with the count it rests on, so the agent can say how sure a number is.
15
+
16
+ It runs on your machine, uses **your slab API key**, and talks to **the slab API and nothing else**.
17
+ It is **read-only by default**: the write tools are not registered unless you turn them on.
12
18
 
13
19
  ## Prerequisites
14
20
 
15
21
  - **Node.js 20+** ([nodejs.org](https://nodejs.org))
16
- - A **slab API key** ([app.slab.dev-jeb.com](https://app.slab.dev-jeb.com) → Account → API Keys)
22
+ - A **slab API key**: sign in at [app.slab.dev-jeb.com](https://app.slab.dev-jeb.com) → Account → API Keys. Accounts are free.
17
23
 
18
24
  ## Install
19
25
 
20
- Once published, no install step is needed — your MCP client runs it with `npx`.
26
+ Your MCP client runs it with `npx`; there is nothing else to install.
21
27
 
22
28
  ### Claude Code
23
29
 
@@ -43,7 +49,7 @@ Add this to the client's MCP config (`claude_desktop_config.json` for Claude Des
43
49
  }
44
50
  ```
45
51
 
46
- Restart the client. You should see a `slab` server with 8 tools.
52
+ Restart the client. You should see a `slab` server with 16 tools (23 with writes on).
47
53
 
48
54
  ### From source
49
55
 
@@ -57,20 +63,107 @@ npm run build
57
63
  Then point your client at `node /absolute/path/to/slab-community/slab-mcp/dist/index.js` instead of
58
64
  the `npx` command.
59
65
 
66
+ ## Tools
67
+
68
+ **Read** (always available)
69
+
70
+ | Tool | What it answers |
71
+ |---|---|
72
+ | `search_cards` | Find cards: player, set, team, rookie, autograph, parallel, print run, honors. The entry point. |
73
+ | `get_card_pricing` | What one printing is worth at each grade, the sales behind it, its value series, which serials have surfaced. |
74
+ | `get_rainbow` | Every printing of a card (base and parallels) with print runs, pack odds and values. |
75
+ | `get_grading_desk` | What a card sells for raw and at each grade, by grading company. |
76
+ | `search_sets` | Find a product, with its release date, size, sales seen and hobby box price. |
77
+ | `get_set_detail` | A product's sealed prices (box, case, blaster…) and its most valuable cards. |
78
+ | `search_collection` | The user's copies, with cost basis, value and a summary. |
79
+ | `get_dashboard` | Collection totals, make-up, most valuable, rarest, hardest pulls, value over time. |
80
+ | `get_collection_sets` | The user's collection by set: copies, printings, value. |
81
+ | `get_targets` | The user's want list, with values and what they've found. |
82
+ | `search_chases` / `get_chase` | Checklists collectors follow (a player's rookies, a team, award winners), with the user's progress. |
83
+ | `get_community` | Card of the day, most wanted, community favorite, hottest players, most valuable, rarest owned, records. |
84
+ | `get_market_index` | How the hockey card market moved each month beyond what card age explains. |
85
+ | `get_vocab` | Every value the API accepts, live from the catalog. |
86
+ | `explain_metrics` | What a slab number means, in slab's own words. |
87
+
88
+ **Write** (only when `SLAB_MCP_WRITE=1`)
89
+
90
+ | Tool | What it does |
91
+ |---|---|
92
+ | `add_copy` | Record a card the user owns. |
93
+ | `update_copy` | Change a copy: grade, favorite, status, or record a sale. |
94
+ | `remove_copy` | Delete a copy record. Destructive, no undo. |
95
+ | `log_break` | Log a sealed product that was opened, so pulls get a real cost basis. |
96
+ | `log_lot` | Log a multi-card purchase, same idea. |
97
+ | `add_target` / `remove_target` | Add a card to the want list, or take one off. |
98
+
99
+ Three **resources** give the agent reference material without a tool call: `slab://vocab`,
100
+ `slab://glossary` and `slab://openapi` (the full API contract), all read live from the API.
101
+ Four **prompts** appear in your client's slash menu: `appraise-collection`, `research-player`,
102
+ `grading-decision` and `whats-hot`.
103
+
60
104
  ## Configuration
61
105
 
62
- Every setting is an environment variable, set in your MCP client's `env` block. There is no config
63
- file and no way to pass credentials as a tool argument — the model on the other end never sees your
64
- key.
106
+ Every setting is an environment variable in your MCP client's `env` block. There is no config file
107
+ and no way to pass a credential as a tool argument, so the model never sees your key.
65
108
 
66
109
  | Variable | Required | Default | Description |
67
110
  |---|---|---|---|
68
- | `SLAB_API_KEY` | Yes | — | Your slab API key. |
69
- | `SLAB_API_URL` | No | `https://api.slab.dev-jeb.com` | Override for local development. |
70
- | `SLAB_COLLECTOR` | No | your account's default | Collector UUID to act as. |
111
+ | `SLAB_API_KEY` | one of these two | — | Your slab API key, literally. |
112
+ | `SLAB_API_KEY_COMMAND` | one of these two | — | A command that *prints* the key. See [Handling the API key](#handling-the-api-key). |
113
+ | `SLAB_API_URL` | No | `https://api.slab.dev-jeb.com` | Override for local development. Must be https (http only for localhost). |
114
+ | `SLAB_COLLECTOR` | No | your account's default | Collector UUID to act as, for an account with several. |
71
115
  | `SLAB_MCP_WRITE` | No | `0` | Set to `1` to register the write tools. |
72
116
  | `SLAB_MCP_TIMEOUT_MS` | No | `30000` | Per-request HTTP timeout. |
73
117
 
118
+ ### Handling the API key
119
+
120
+ Pasting the key straight into your MCP client config works, and for CI or a container it is the
121
+ right answer. On a workstation there is a better one, for a reason specific to agents.
122
+
123
+ The usual objection to a key in a config file is plaintext-at-rest — but `~/.claude.json` is already
124
+ `0600`, so the OS is not the weak point. The weak point is that **the agent can read its own
125
+ config**. Ask Claude Code to debug a flaky MCP server and a perfectly reasonable next step is to
126
+ read that file, at which point a live credential is in a transcript, in scrollback, and in whatever
127
+ that conversation gets pasted into. Nothing was breached; the key leaked sideways through ordinary
128
+ use.
129
+
130
+ So prefer `SLAB_API_KEY_COMMAND`, which holds an *instruction* instead of a credential:
131
+
132
+ ```bash
133
+ # store the key once, in the OS keychain
134
+ security add-generic-password -s slab-mcp -a "$USER" -w # macOS; prompts for the key
135
+
136
+ claude mcp add slab -s user \
137
+ -e SLAB_API_KEY_COMMAND='security find-generic-password -s slab-mcp -w' \
138
+ -- npx -y slab-mcp
139
+ ```
140
+
141
+ Now `~/.claude.json` contains a lookup command, and the secret lives behind the OS keychain. The
142
+ same seam works with anything that prints a secret to stdout:
143
+
144
+ | Backend | Command |
145
+ |---|---|
146
+ | macOS Keychain | `security find-generic-password -s slab-mcp -w` |
147
+ | 1Password | `op read "op://Private/slab/credential"` |
148
+ | pass | `pass show slab/api-key` |
149
+ | Vault | `vault kv get -field=key secret/slab` |
150
+
151
+ slab-mcp depends on none of them — it runs whatever you give it and reads stdout, so a backend it
152
+ has never heard of works too.
153
+
154
+ Two more things worth doing, both of which slab already supports:
155
+
156
+ - **Mint a dedicated key for the MCP** and name it (slab portal → Account → API Keys). Keys carry
157
+ a label and `last_used_dt` and revoke individually, so an agent-held key can be killed without
158
+ disturbing your CLI or scripts, and you can see when it was last used.
159
+ - **Leave writes off** unless you need them. A read-only key-holder cannot damage your collection
160
+ regardless of what the agent is talked into.
161
+
162
+ Notes: if both variables are set, `SLAB_API_KEY` wins — explicit beats indirect, and the startup log
163
+ names the source (never the value) so a forgotten shell export shadowing your keychain is visible
164
+ rather than a mystery 401. Don't inline a secret in the command itself; a failing command is echoed
165
+ back in the error so you can debug it.
166
+
74
167
  ### Enabling writes
75
168
 
76
169
  ```json
@@ -80,79 +173,68 @@ key.
80
173
  }
81
174
  ```
82
175
 
83
- With this off, the five write tools are never registered, so the agent cannot call them — that is a
84
- stronger guarantee than telling it not to. With it on, each write tool declares the MCP annotations
85
- (`readOnlyHint`, `destructiveHint`) that let your client prompt you before it runs. Whether your
86
- client actually prompts is up to your client; the annotations only make it possible.
176
+ With this off, the seven write tools are never registered, so the agent cannot call them: a stronger
177
+ guarantee than telling it not to. With it on, each write tool declares the MCP annotations
178
+ (`readOnlyHint`, `destructiveHint`) that let your client ask you before it runs. Whether your client
179
+ actually asks is up to your client.
87
180
 
88
- ## Tools
181
+ ## Only the slab API
89
182
 
90
- **Read** (always available)
183
+ slab-mcp is a client of the slab API and nothing more. Each of these is held by a test in
184
+ `tests/boundary.test.ts` or `tests/client.test.ts`, so a later change can't quietly undo it:
91
185
 
92
- | Tool | What it does |
93
- |---|---|
94
- | `search_cards` | Search the catalog. The entry point — most other tools take a UUID from here. |
95
- | `search_sets` | Find a product/release. |
96
- | `get_set_detail` | A set's sealed prices and its most valuable cards. |
97
- | `get_card_pricing` | Fair market value, the individual sales behind it, and the daily series. |
98
- | `search_collection` | Search your own copies, with a financial summary. |
99
- | `get_dashboard` | Collection totals, top cards, and portfolio history. |
100
- | `get_community` | Public leaderboards and activity. |
101
- | `get_vocab` | Every value the API accepts, live from the catalog. |
102
- | `explain_metrics` | What a slab number means, in slab's own words. |
186
+ - **One network door.** Only `src/client.ts` makes requests, and only to `SLAB_API_URL`. The source
187
+ names no other host.
188
+ - **The key stays in one header.** It goes in `x-api-key` on each request, over https, and is never
189
+ a tool argument, never in a tool result, and never in an error. Requests refuse redirects, so the
190
+ key is never replayed to another host.
191
+ - **A model can't steer a request.** Every id argument must be a UUID, and every id is encoded as a
192
+ single path segment, so `../../account/keys/…` passed as a copy id is refused, not a request to
193
+ another route.
194
+ - **No retried writes.** Reads ride out a brief outage (two retries, honouring `Retry-After`); a
195
+ write is sent once, because a create that timed out may have landed.
196
+ - **The only local command it runs** is your `SLAB_API_KEY_COMMAND`, once, to read the key.
103
197
 
104
- **Write** (only when `SLAB_MCP_WRITE=1`)
198
+ ## How the tools are designed
105
199
 
106
- | Tool | What it does |
107
- |---|---|
108
- | `add_copy` | Record a card you own. |
109
- | `update_copy` | Change a copy, including recording a sale. |
110
- | `remove_copy` | Delete a copy record. Destructive, no undo. |
111
- | `log_break` | Log a sealed product you opened, so pulls get a real cost basis. |
112
- | `log_lot` | Log a multi-card purchase, same idea. |
200
+ **Task-shaped, not endpoint-shaped.** The slab API has 84 routes; this server exposes 23 tools. Each
201
+ answers a question a person asks, folding several endpoints where that's the natural unit:
202
+ `get_card_pricing` is `/market` + `/comps` + `/price-history` + `/serials`, because "what's it worth"
203
+ is one question.
113
204
 
114
- ## Resources and prompts
205
+ **Results are formatted, not dumped.** A tool result is spent out of the agent's context window, so
206
+ results render one entity per line with a labelled id first (`card:`, `copy:`, `set:`, `chase:`,
207
+ `target:`): the id is what the agent carries to the next call, and a copy id fed to a card tool is a
208
+ 404. Every paged result says how many rows exist.
115
209
 
116
- Three **resources** let an agent pull reference material without spending a tool call:
117
- `slab://vocab` (every accepted value), `slab://glossary` (what each metric means), and
118
- `slab://openapi` (the full API contract). All three are served from the live API rather than
119
- copied into this repo, so they can't go stale.
210
+ **Nothing enumerable or explanatory is written down here.** `get_vocab` serves accepted values (the
211
+ catalog grows with every set) and `explain_metrics` serves what a number means. Responses that embed
212
+ their own glossary render it beside the numbers, so the agent uses slab's wording instead of
213
+ inventing its own.
120
214
 
121
- Three **prompts** show up in your client's slash menu as starting points:
122
- `appraise-collection`, `research-player`, and `grading-decision`.
215
+ Two rules from the slab data model are written into the tool descriptions, because getting them
216
+ wrong produces a confident false statement about someone's money:
123
217
 
124
- ## How the tools are designed
218
+ - **A price is an appraisal, not a ticker.** A fair market value is a median of the trailing 90 days
219
+ of sales, so the difference between two of them is how the *appraisal* drifted, not what the
220
+ market did. What happened in a window comes from counting the sales.
221
+ - **The collection's value series is as-of.** It steps up when the user buys a card, so the
222
+ difference between two points mixes purchases with price movement and is not a return.
223
+
224
+ ## Staying in step with the API
125
225
 
126
- Two decisions explain most of the code, and are worth knowing before you extend it.
127
-
128
- **Task-shaped, not endpoint-shaped.** The slab API has ~46 routes; this server exposes 13 tools.
129
- Mapping routes 1:1 would put 46 schemas into the agent's context on every single request and make
130
- tool selection worse, not better. Each tool here answers a question a person actually asks, folding
131
- several endpoints where that's the natural unit — `get_card_pricing` is `/market` + `/comps` +
132
- `/price-history`, because "what's it worth" is one question.
133
-
134
- **Results are formatted, not dumped.** A tool result is spent out of the agent's context window. A
135
- raw search page is tens of thousands of tokens of JSON, mostly nulls and repeated keys. Results here
136
- render one entity per line with the UUID first, and every paged result says how many rows exist so
137
- the agent knows whether it has seen everything.
138
-
139
- **Nothing enumerable or explanatory is written down here.** slab serves both, so this server asks:
140
- `get_vocab` for values (statuses, sort keys, and the live catalog dimensions that grow with every
141
- seeded set) and `explain_metrics` for what a number means. No tool description lists a brand, team,
142
- attribute, or finish, and none writes its own definition of `priced_coverage` — a copy in this repo
143
- would rot, and a hand-written gloss would drift from what the portal and CLI show the same user.
144
- Tools that report figures point the agent at `explain_metrics`, responses that embed their own
145
- glossary render it inline, and a test fails the build if a metric-bearing tool stops doing either.
146
-
147
- Two rules from the slab data model are written into the tool descriptions rather than left to the
148
- agent to figure out, because getting them wrong produces a confident false statement about someone's
149
- money:
150
-
151
- - **Prices are appraisals, not tickers.** A fair market value is a trimmed median of the trailing 90
152
- days, so differencing two snapshots measures how the *appraisal* drifted — not what the market did
153
- over that window. Real market movement comes from counting comps.
154
- - **The portfolio series is as-of.** It steps up when you buy a card, so differencing two points
155
- mixes purchases with price movement and is not a return.
226
+ The response types are not hand-written. `src/generated/api.ts` is generated from the API's own
227
+ OpenAPI spec (`api/openapi.json`), and every tool reads responses through those types, so a field the
228
+ API renames fails `npm run typecheck`. The tests' sample responses are typed the same way, and each
229
+ tool's test checks the value actually appears in what it renders.
230
+
231
+ ```bash
232
+ npm run api:sync # re-read the live spec, regenerate the types; then typecheck and test
233
+ npm run api:check # exit 1 if the live spec differs from the committed snapshot
234
+ ```
235
+
236
+ CI does this every Monday against the live API (`.github/workflows/slab-mcp.yml`); with a
237
+ `SLAB_API_KEY` repository secret it also runs the live smoke test.
156
238
 
157
239
  ## Extending it
158
240
 
@@ -163,55 +245,55 @@ src/
163
245
  tools/
164
246
  index.ts <- THE REGISTRY: read tools, write tools, registration loop
165
247
  types.ts <- the ToolModule contract + annotation presets
248
+ args.ts <- shared inputs: UUIDs, dates, the collector, grade keys
166
249
  filters.ts <- the shared card filter grammar, defined once
167
- catalog.ts collection.ts pricing.ts writes.ts meta.ts
250
+ lines.ts <- one entity on one line
251
+ catalog.ts pricing.ts collection.ts chases.ts community.ts meta.ts writes.ts
168
252
  resources/index.ts <- add a resource: one entry in RESOURCES
169
253
  prompts/index.ts <- add a prompt: one entry in PROMPTS
170
- client.ts <- HTTP, auth, timeouts, error shapes. Knows nothing about cards.
254
+ client.ts <- the one network door: paths, auth, timeouts, retries
255
+ types.ts <- wire types by name, aliases into generated/api.ts
171
256
  index.ts <- wiring only. Adding a tool never touches this file.
172
257
  ```
173
258
 
174
- To add a tool:
175
-
176
259
  ```ts
177
260
  export const getMyThing = defineTool({
178
261
  name: 'get_my_thing',
179
262
  title: 'Get my thing',
180
263
  description: 'When to call this, and what the numbers mean. Name the tool that produces any UUID this one takes.',
181
264
  inputSchema: z.object({
182
- thing_uuid: z.string().describe('Thing UUID, from search_things.'),
265
+ thing_uuid: uuid('Thing UUID, from search_things.'),
183
266
  }),
184
267
  annotations: READ_ONLY, // or CREATES / UPDATES / DELETES
185
268
  mutates: false, // true puts it behind SLAB_MCP_WRITE
186
269
  async handler(input, ctx) {
187
- const thing = await ctx.client.request<Thing>('GET', `/things/${input.thing_uuid}`);
270
+ const thing = await ctx.client.request<Thing>('GET', api`/things/${input.thing_uuid}`);
188
271
  return text(`...`);
189
272
  },
190
273
  });
191
274
  ```
192
275
 
193
- Then add it to the array in `tools/index.ts`. That's it — registration, argument validation, error
194
- handling, and the write gate are all handled by the loop.
195
-
196
- `mutates` and `annotations` are required, not optional, because a write tool that looks read-only
197
- gets no confirmation prompt from the host. `npm test` enforces that they agree, along with the
198
- things prose can't check for itself: unique snake_case names, a description substantial enough to
199
- route on, a `.describe()` on every input field, destructive tools marked destructive, and no tool
200
- description that hardcodes a live catalog vocabulary or calls appraisal drift a market move.
276
+ Then add it to the array in `tools/index.ts`, a typed sample response in `tests/render.test.ts`, and
277
+ a call in `scripts/smoke.mjs`. `npm test` enforces the rest: unique snake_case names, descriptions
278
+ substantial enough to route on, a `.describe()` on every input, `mutates` agreeing with
279
+ `readOnlyHint`, destructive tools marked destructive, UUID-only id arguments, `api\`…\`` for every
280
+ path, and no tool description that hardcodes a catalog vocabulary or calls appraisal drift a market
281
+ move.
201
282
 
202
283
  ## Development
203
284
 
204
285
  ```bash
205
286
  npm install
206
- npm run dev # run against the API without building
207
- npm test # offline: no network, no key, no server
208
- npm run typecheck
287
+ npm run dev # run against the API without building
288
+ npm test # offline: no network, no key, no server
289
+ npm run typecheck # sources and tests
209
290
  npm run build
291
+ SLAB_API_KEY=... npm run smoke # build, then call every read tool against the live API
210
292
  ```
211
293
 
212
- **Never write to stdout.** In a stdio MCP server, stdout is the protocol — one stray `console.log`
294
+ **Never write to stdout.** In a stdio MCP server, stdout is the protocol: one stray `console.log`
213
295
  corrupts the JSON-RPC stream and the client drops the connection with an error that points nowhere
214
- near the cause. Diagnostics go to stderr, which your client surfaces as the server's log.
296
+ near the cause. Diagnostics go to stderr, which your client shows as the server's log.
215
297
 
216
298
  To inspect the server by hand:
217
299
 
@@ -252,10 +334,11 @@ Two remaining one-time steps:
252
334
  After that, releasing is:
253
335
 
254
336
  ```bash
255
- # bump "version" in slab-mcp/package.json, then:
256
- git commit -am "slab-mcp 0.1.1"
257
- git tag slab-mcp-v0.1.1
258
- git push origin main slab-mcp-v0.1.1
337
+ # bump "version" in slab-mcp/package.json, run the live smoke test, then:
338
+ SLAB_API_KEY=... npm run smoke
339
+ git commit -am "slab-mcp 0.3.1"
340
+ git tag slab-mcp-v0.3.1
341
+ git push origin main slab-mcp-v0.3.1
259
342
  ```
260
343
 
261
344
  The tag is namespaced per tool, so each directory in this repo releases on its own schedule. The
@@ -264,11 +347,11 @@ workflow re-runs typecheck, tests, and build, and refuses to publish if the tag
264
347
 
265
348
  ## Limits and caveats
266
349
 
267
- - Read-only unless you opt in, and it acts for exactly one collector.
268
- - No caching. Every tool call is a live request; `slab://openapi` is large, so fetch it deliberately.
269
- - stdio transport only. It is meant to run on your machine next to your agent, not to be hosted.
270
- - Tool inputs cover the well-trodden subset of slab's filter grammar. The full contract is always
271
- `GET /openapi.json` — if this server and the spec disagree, the spec is right.
350
+ - Read-only unless you opt in, and it acts for one collector at a time.
351
+ - No caching: every tool call is a live request. `slab://openapi` is large; fetch it deliberately.
352
+ - stdio transport only. It runs on your machine next to your agent; it is not a hosted service.
353
+ - Tool inputs cover the well-trodden part of slab's filter grammar. The full contract is always
354
+ `GET /openapi.json`; if this server and the spec disagree, the spec is right.
272
355
 
273
356
  ## License
274
357
 
package/dist/client.d.ts CHANGED
@@ -1,28 +1,49 @@
1
1
  /**
2
- * Thin typed HTTP client for the slab API.
2
+ * The one door to the network.
3
3
  *
4
- * Deliberately dumb: it knows about auth, timeouts, and error shapes, and
5
- * nothing about cards. Endpoint knowledge lives in the tool modules, so adding
6
- * an endpoint never means touching this file.
4
+ * Nothing else in this server calls `fetch` (a test holds that), so everything slab-mcp sends goes
5
+ * to the slab API at `config.apiUrl`, with the key in one header, and nowhere else:
7
6
  *
8
- * The response types are declared structurally in `types.ts` rather thanß
9
- * generated, because a generated client would have to be regenerated to stay
10
- * honest. `GET /openapi.json` is the authoritative contract and is exposed to
11
- * the model as a resource — see src/resources/index.ts.
7
+ * - Paths are built with `api\`...\``, which percent-encodes every interpolated value as ONE path
8
+ * segment. A model-supplied id can't climb out of its route: `../../account/keys/x` becomes
9
+ * `..%2F..%2Faccount%2Fkeys%2Fx`, a 404, instead of a DELETE on an API key.
10
+ * - Redirects are refused, so the key is never replayed to another host.
11
+ * - Reads retry a transient failure (network, 429, 502-504) twice, honouring Retry-After. Writes
12
+ * never retry: a POST that timed out may have landed, and a second one adds a second copy.
12
13
  *
13
- * deploy
14
+ * It knows nothing about cards. Endpoint knowledge lives in the tool modules; the response types
15
+ * come from the API's own spec (`types.ts`).
14
16
  */
15
17
  import type { Config } from './config.js';
18
+ /** A path on the slab API, built only by `api`. */
19
+ export type ApiPath = string & {
20
+ readonly __apiPath: unique symbol;
21
+ };
22
+ /** `api\`/cards/${uuid}/market\``: each interpolated value becomes one encoded path segment. */
23
+ export declare function api(strings: TemplateStringsArray, ...values: Array<string | number>): ApiPath;
16
24
  export interface RequestOptions {
17
25
  /** JSON request body. Undefined keys are stripped before sending. */
18
26
  body?: unknown;
19
27
  /** Query parameters. Undefined/null values are dropped. */
20
28
  query?: Record<string, string | number | boolean | undefined | null>;
29
+ /**
30
+ * A POST that only reads (every `/search` route) may retry like a GET. Never set this on a
31
+ * write: a retried create is a duplicate.
32
+ */
33
+ read?: boolean;
34
+ }
35
+ /** Seams for tests: the network and the clock. */
36
+ export interface ClientDeps {
37
+ fetch?: typeof fetch;
38
+ sleep?: (ms: number) => Promise<void>;
21
39
  }
22
40
  export declare class SlabClient {
23
41
  private readonly config;
24
- constructor(config: Config);
25
- request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
26
- /** Fetch a public document verbatim (used by the resource handlers). */
27
- raw(path: string): Promise<string>;
42
+ private readonly fetch;
43
+ private readonly sleep;
44
+ constructor(config: Config, deps?: ClientDeps);
45
+ request<T>(method: string, path: ApiPath, options?: RequestOptions): Promise<T>;
46
+ /** A document verbatim (the resources: /vocab, /glossary, /openapi.json). */
47
+ raw(path: ApiPath): Promise<string>;
48
+ private send;
28
49
  }