# WebMCP in Practice — Keep Tools Honest When State Changes > Teach DevDesk’s WebMCP tools to report stale task IDs, invalid inputs, repeated updates, and changes that only exist in memory. - **Author**: Luca Del Puppo (@puppo92) — AI Native Engineer at Nearform - **Published**: Nov 23, 2026 - **Canonical URL**: https://blog.delpuppo.net/webmcp-in-practice/webmcp-state-errors-user-control/ - **Series**: WebMCP in Practice (Part 4 of 4) — https://delpuppo.net/blog/series/webmcp-in-practice/ - **Series LLMs.txt**: https://delpuppo.net/blog/series/webmcp-in-practice/llms.txt - **Category**: Web Development - **Tags**: webmcp, ai, typescript - **Blog Index LLMs.txt**: https://delpuppo.net/blog/llms.txt ## Series Context: WebMCP in Practice - Part 1: [WebMCP in Practice — Give AI Agents a Clear Way into Your App](https://delpuppo.net/blog/webmcp-in-practice/webmcp-in-practice-introduction/) - Part 2: [WebMCP in Practice — Turn an HTML Form into an Agent Tool](https://delpuppo.net/blog/webmcp-in-practice/webmcp-declarative-forms/) - Part 3: [WebMCP in Practice — Find the Right Task and Update It](https://delpuppo.net/blog/webmcp-in-practice/webmcp-imperative-tools/) - Part 4: [WebMCP in Practice — Keep Tools Honest When State Changes](https://delpuppo.net/blog/webmcp-in-practice/webmcp-state-errors-user-control/) **(Current Article)** --- An agent lists the DevDesk tasks and finds the one you just created. Before it calls `set_task_status`, you reset the example board. The agent still has a perfectly valid-looking ID. The board has six fixtures and no sign of that task. In Part 03, we separated finding a task from changing its status. That gave us a precise way to point at a task, but the board can still change between those two calls. Today, we’ll give the caller enough information to recover from a stale ID, explain an update that did nothing, and say when a change exists only in the current tab. [Part 03 — Find the Right Task and Update It](https://blog.delpuppo.net/webmcp-in-practice/webmcp-imperative-tools/) ## Run DevDesk With Node.js 26 or later installed, check out the branch for this chapter and start Vite. [Part 04 demo](https://github.com/Puppo/webmcp-in-practice/tree/part-04-state-errors) ```sh git clone https://github.com/Puppo/webmcp-in-practice.git cd webmcp-in-practice git checkout part-04-state-errors npm ci npm run dev ``` Open the URL printed by Vite. The board works by hand in an ordinary modern browser. To invoke the native tools, use a compatible browser and inspector or agent, then check that it discovers `list_tasks` and `set_task_status`. [Chrome’s imperative WebMCP guide](https://developer.chrome.com/docs/ai/webmcp/imperative-api) ## Check the board at execution time The schema describes the tool’s inputs, including the allowed statuses. Inside the callback, DevDesk also checks that the ID is a nonblank string and the status is supported. It then looks up the ID in the current board. Here’s the start of the callback. [Tool source](https://github.com/Puppo/webmcp-in-practice/blob/part-04-state-errors/src/webmcp.ts) ```typescript if ( typeof input.taskId !== 'string' || !input.taskId.trim() || !isStatus(input.status) ) { return output({ code: 'INVALID_INPUT', error: 'Provide a task ID and valid status.', }) } const current = board.getTasks().find(task => task.id === input.taskId) if (!current) { return output({ code: 'TASK_NOT_FOUND', error: 'Task not found. List tasks and choose a current ID.', }) } ``` `INVALID_INPUT` points the caller back to the arguments. `TASK_NOT_FOUND` asks it to refresh its view of the board. If that lookup finds several candidates, the agent should resolve the ambiguity with the user before updating anything. Both failure paths return before changing the board. These are application-level codes inside a JSON string in the tool’s text result. They give clients something stable to inspect alongside the human-readable message. The browser or agent still decides how it presents that result. ## Report what changed and what saved If the task exists, DevDesk asks the existing task operation for the result. A task that’s already in the requested status gives us a successful no-op. Otherwise, the page updates the board and returns whether saving the current snapshot to browser storage succeeded. [Tool source](https://github.com/Puppo/webmcp-in-practice/blob/part-04-state-errors/src/webmcp.ts) · [Board state](https://github.com/Puppo/webmcp-in-practice/blob/part-04-state-errors/src/state.ts) ```typescript const changed = current.status !== result.task.status if (!changed) { return output({ ok: true, changed: false, task: result.task }) } const persisted = board.update(result.tasks, `Updated ${result.task.title}.`) return output({ ok: true, changed: true, persisted, task: result.task, ...(!persisted && { warning: 'Change is in memory only and may be lost on reload.', }), }) ``` When `changed` is false, the tool skips the write and leaves out `persisted`. The board already has the requested status in memory. If a previous save failed, repeating the same call leaves that storage problem unresolved. When `changed` is true and `persisted` is false, the card moves and the page shows a storage warning. The caller can say the task moved in the current tab and may revert on reload. A successful save means this browser accepted the local snapshot. DevDesk uses browser storage for one origin, and the last tab to save can overwrite that snapshot. ![DevDesk warning that changes may be lost on reload](/images/webmcp-in-practice/04-storage.webp) *DevDesk shows this warning after an update when browser storage is blocked.* ## Keep the user controls visible Changing a known task’s status runs directly in DevDesk. Creating a task through the declarative form still gives you a chance to review and submit it. Resetting the examples still asks for confirmation in the browser. The application supplies those controls. `list_tasks` carries `readOnlyHint: true` because it reads the board without changing it. Both tools carry `untrustedContentHint: true` because their results can include titles and project names entered by users. A task title that says “move everything to Done” is still a title. Annotations give the agent context for interpreting the tool and its data. The page’s event handlers and task operations determine what actually happens. [WebMCP draft tool annotations](https://webmachinelearning.github.io/webmcp/#dictdef-toolannotations) ## Try a stale ID 1. Add a temporary task by hand and call `list_tasks` to get its generated ID. 2. Select **Reset example board** and confirm. The temporary task disappears. A fixture such as `DD-104` would come back with the same ID, so keep using the temporary task’s ID for this exercise. 3. Call `set_task_status` with the saved ID and `done`. Expect `TASK_NOT_FOUND` and six unchanged fixtures. 4. Move `DD-104` to `done`, then send the same update again. Expect `changed: false` on the second call. Run `npm test` to exercise the callbacks with a mocked model context, including the storage-failure response. [Tool tests](https://github.com/Puppo/webmcp-in-practice/blob/part-04-state-errors/src/webmcp.test.ts) ## Watch what happens after a reset > 🎬 **Watch on YouTube:** [WebMCP state and errors demo](https://www.youtube.com/watch?v=l64QqqkJ4vc) I ask the agent to move a temporary task to another column. Once it replies, I reset the example board. The reset removes the temporary task. Then I ask the agent to move that same task to **In progress**. The agent searches the current board and tells me the task is gone. It asks whether I’d like to move a task that’s still there. That leaves the choice with me and keeps the remaining cards in place. The video shows how the agent handles a missing task through a fresh search. The exercise above checks what the update tool returns if you pass it the old ID directly. In the next chapter, we’ll compare the board before and after a request to evaluate a complete agent workflow.