# WebMCP in Practice — Find the Right Task and Update It > Add two imperative WebMCP tools to DevDesk so an agent can find tasks by project and update the right one by ID. - **Author**: Luca Del Puppo (@puppo92) — AI Native Engineer at Nearform - **Published**: Nov 19, 2026 - **Canonical URL**: https://blog.delpuppo.net/webmcp-in-practice/webmcp-imperative-tools/ - **Series**: WebMCP in Practice (Part 3 of 3) — 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/) **(Current Article)** --- In the demo, I ask the agent to move “Write release notes.” There are two cards called **Write release notes** on the DevDesk board. The one we want is `DD-104`. The other is `DD-101` and belongs to DevDesk. If we offer an action that takes a title and picks the first match, we’ve already made the wrong choice before the agent gets a say. In Part 02, we gave the agent a way to prepare a task in the existing HTML form. This time, we’ll register two JavaScript tools. One reads the board and returns matching tasks. The other updates a task whose ID the caller already knows. [Part 02 — Turn an HTML Form into an Agent Tool](https://blog.delpuppo.net/webmcp-in-practice/webmcp-declarative-forms/) ## Run DevDesk Use Node.js 26 or later and check out the branch for this chapter. If you already cloned the repository, fetch the branch and switch to it. [Part 03 demo](https://github.com/Puppo/webmcp-in-practice/tree/part-03-imperative-tools) ```sh git clone https://github.com/Puppo/webmcp-in-practice.git cd webmcp-in-practice git checkout part-03-imperative-tools npm ci npm run dev ``` Open the URL printed by Vite. The board’s manual controls work in a modern browser. For native tool discovery and invocation, follow Chrome’s current setup instructions and check that your browser or inspector can see both imperative tools. Confirm **Reset example board** if you’ve used another chapter on the same local origin and want to restore the fixtures. [Chrome’s imperative WebMCP guide](https://developer.chrome.com/docs/ai/webmcp/imperative-api) ## Find first, then change `list_tasks` accepts three optional filters. `project` matches the whole project name ignoring case, `query` matches part of the title ignoring case, and `status` matches a board status. With no filters it returns the current board. Matching tasks include their IDs alongside the project and title. [Tool definitions](https://github.com/Puppo/webmcp-in-practice/blob/part-03-imperative-tools/src/webmcp.ts) Start with this input to `list_tasks`: ```json { "query": "Write release notes" } ``` On a reset board you’ll get both release-notes tasks. If that’s all the user told you, ask which project they mean. If they said Design System, include that project in the query or use it to select the matching result. Once you have the ID, pass it to `set_task_status`: ```json { "taskId": "DD-104", "status": "done" } ``` Keeping lookup separate gives an agent a way to inspect the board before committing to an update. It also lets someone ask what’s still in progress without touching any tasks. The ID makes the update precise once the target is known. The user’s words and the lookup results still determine which target to choose. ## Register the update The tool definition describes its inputs and implements what happens when it’s called. Here’s the `set_task_status` entry from the demo’s tool array. [Source](https://github.com/Puppo/webmcp-in-practice/blob/part-03-imperative-tools/src/webmcp.ts) ```typescript { name: 'set_task_status', description: 'Update a known task by its ID. Find the task first if its identity is unclear.', inputSchema: { type: 'object', properties: { taskId: { type: 'string', description: 'The unique task ID.', }, status: { type: 'string', enum: statuses, }, }, required: ['taskId', 'status'], additionalProperties: false, }, annotations: { untrustedContentHint: true, }, async execute(input) { if (typeof input.taskId !== 'string') { return output({ error: 'Provide a task ID.' }) } const result = setTaskStatus( board.getTasks(), input.taskId, input.status, ) if (!result.ok) { return output({ error: result.message }) } board.update(result.tasks, `Updated ${result.task.title}.`) return output(result.task) }, }, ``` The schema exposes the required arguments and supported status values. The callback checks the ID type at runtime, and `setTaskStatus` checks the status and whether the ID exists. `output` wraps the result as a text content item containing JSON. At this checkpoint, a successful response returns the updated task. The page can warn when storage fails, but the tool response gives the caller no storage status yet. The page passes `document.modelContext` to the registration function. When the interface is present, the demo registers each tool with an abort signal, logs a registration rejection unless cleanup is underway, and aborts the signal when Vite disposes the module during a development update. A page that re-registers tools as its views change can use the same signal pattern to retire old definitions. [Page setup](https://github.com/Puppo/webmcp-in-practice/blob/part-03-imperative-tools/src/main.ts) · [WebMCP draft](https://webmachinelearning.github.io/webmcp/) ## Use the same board from both entry points The callback calls `board.getTasks()` at invocation time. If you change a card by hand after the tools register, the next tool call sees the current tasks. Both the dropdown and the tool call `setTaskStatus`. A successful update goes through the same page function, which updates the in-memory board, attempts to save it, and redraws the cards. [Board state](https://github.com/Puppo/webmcp-in-practice/blob/part-03-imperative-tools/src/state.ts) · [Page setup](https://github.com/Puppo/webmcp-in-practice/blob/part-03-imperative-tools/src/main.ts) > 🎬 **Watch on YouTube:** [Imperative WebMCP demo](https://www.youtube.com/watch?v=_TacFe54gP8) The video starts with a request that leaves the project and destination open: > Move the Write release notes The agent finds two cards with that title, one in **DevDesk** and one in **Design System**, and asks which one I want to move. I reply with the project and destination: > The design one to the Done column Here, “the design one” refers to the **Design System** card. The follow-up gives the agent enough information to move that card to **Done**. To check the underlying tool behavior yourself, try the two calls above and list the release-notes tasks again. On a fresh board, `DD-104` should be in **Done** and `DD-101` should still be in **To do**. Change `DD-104` by hand and list again to check that the tool reads the updated board. The automated tests exercise these handlers with a mocked model context. The video shows one run of the clarification flow. [Tool tests](https://github.com/Puppo/webmcp-in-practice/blob/part-03-imperative-tools/src/webmcp.test.ts) ![DD-104 in Done and DD-101 still in To do](/images/webmcp-in-practice/03-target.webp) *The expected board after updating DD-104. The screenshot uses the demo’s tool handler with mocked registration.* Next, we’ll see what happens when a valid ID goes stale between the two calls.