Repository navigation
Description
Needs your OK: this adds an update_slots tool to the AI connector, so an assistant can change many slots in one call. Swap pipeline:proposed for pipeline:ready to have it built.
What happens
When an assistant adds a field, the signup's existing slots have no value for it. add_field's description says so: "Existing slots have no value for a new field until one is set with update_slot." update_slot (src/mcp/tools/slots.ts) changes one slot. So filling in a new field on 30 slots takes 30 tool calls, and the organizer waits through each one. Each call also runs its own policy guard, transaction and signup lock, and writes its own slot.updated row.
The same goes for any change across many slots, such as raising every shift's spots or closing one day's slots.
Adding and reordering already work in one call: add_slots takes up to 500 rows (addSlotsBulk), and reorder_slots takes the whole order. Changing slots has no bulk path, in the tools or the REST API.
Fix, in outline
- A service,
updateSlotsBulk(db, actor, signupId, { slots })insrc/services/slots.ts.slotsis 1 to 500 rows of{ slotId, values?, capacity?, status? }, eachslotIdonce. It:- opens with
withSignupWriteLock, thenlockSlotsForSignup: signup first, then slots, as the add-before and reorder paths do - refuses a
slotIdthat isn't a slot of this signup, withinvalid_inputnaming the row (slots.3.slotId) - runs
updateSlot's checks on each row: values against the fields (listFieldsForSignup, read once), capacity not below the places taken (counted once for all the slots), andslot_atfromextractSlotAtwith the signup's settings - is all or nothing: the first row that fails returns its error, with its index, and nothing is written
- writes the rows in one
UPDATE … FROMa JSON array, aswriteSlotOrderdoes - records one
slot.updatedrow,{ slotIds, changed, bulk: true }, and aslot.rescheduledrow for each slot whose time moved, asupdateSlotdoes. The time-change emails and the reminders' settle check read those by slot (src/jobs/slot-changes.ts,src/jobs/notify-rules.ts). - returns the slots in the order given
- opens with
- A tool,
update_slots, insrc/mcp/tools/slots.ts:- input
{ signupId, slots: [...] }; each row isupdate_slot's schema withoutsortOrder, strict, plusslotId - scope
signups:write,destructiveHint: true - returns
{ slots }throughslotOut - its description says what it does: changes several slots of one signup in one call, by the same rules as
update_slot, and changes nothing if any row is refused
- input
- Point to it.
add_field's description namesupdate_slotsfor filling in a new field. Add the tool toTOOLSinsrc/mcp/tools/index.ts.
Choices this makes
- A new tool, not an array on
update_slot.update_slot's input stays as it is, so calls from existing clients keep working. The tool list grows from 18 to 19. - Values replace, as
update_slot's do. A row'svaluesreplaces all of that slot's values, so an assistant filling in one field sends the others too. Merging would save tokens, but then two tools would treat the samevaluesdifferently. - All or nothing. A partial success would leave the assistant working out which rows to send again.
- Up to 500 rows, the same cap as
add_slots. - One
slot.updatedrow per call, asadd_slotswrites oneslot.created.slot.rescheduledstays one per slot. - Tools only. No REST endpoint: the Build tab saves one slot at a time and has no use for one.
Watch for
- Tool descriptions say what a tool does, never what the model should do.
src/mcp/registry.test.tsfails on the usual phrasings, and the Claude connectors directory checks this. - The roster test in
registry.test.tsspells out every tool name. Addupdate_slotsthere. instructions.tsgets one more name in its closing tools line. That line sits after the 2048-byte part, so its size test should still pass. Run it.- The MCP body cap is 1,000,000 bytes (
MAX_BODY_BYTESinsrc/app/api/mcp/route.ts), enough for 500 rows of values. That route is on the high-risk list, so don't change it. docs/telemetry.mddocumentsslot.updated. Add the bulk payload.- Evals. A follow-up case in
evals/mcp/followup-evals.json("add a Location field and fill it in") that expectsupdate_slotswould show whether assistants find it.pnpm eval:mcpisn't a CI gate. - CHANGELOG line under Added.
Done when
- A DB test:
update_slotsfills in a new field on 30 slots in one call, andget_signupshows the values. - A DB test: one row with a value that doesn't fit its field, or a
slotIdfrom another signup, changes nothing and names the row. - A DB test: moving two slots to a new date writes one
slot.rescheduledrow for each. pnpm lint && pnpm typecheck && pnpm knip && pnpm test && pnpm test:dbpass.
Split out of #245 (its first part) for the pipeline, and checked against src/mcp/tools/slots.ts, src/mcp/tools/fields.ts, src/mcp/tools/index.ts, src/mcp/registry.test.ts, src/mcp/instructions.ts, src/services/slots.ts and src/app/api/mcp/route.ts on main at 2d4fdfe. https://claude.ai/code/session_016YZ9SUWWJa1udHCjU5fUma
Activity