Field note · Applied AI

Giving AI agents a task manager: an MCP server with scoped tokens.

An agent that can create a task can usually delete one too. The design question is how much of that power a single token carries, and what happens when the agent gets it wrong.

Why an agent needs a real task system, not a scratch file

An AI agent can keep its to-do list in a text file. That works until a person wants to see the same list on a phone, or a second agent starts writing to it.

ClearMind is a task and notes workspace with a Model Context Protocol (MCP) server. The server does not have its own copy of the logic. Its tool catalogue runs the same shared domain operations as the apps, against the same data store, so a task created by an agent is the same record as one created by hand.

This note describes how that server is built, taken from its source and documentation: scopes, confirmation, retries and the audit record.

Tool design: small verbs, predictable results

Tools are named by area and verb: tasks_create, tasks_list, tasks_update, projects_get, notes_create. Habits, goals, calendar and the other personal areas follow one pattern of _list, _save and _delete.

Every tool declares a JSON Schema for its input and the scopes it needs. The dispatcher returns one envelope for every call. Over the REST API, success is { "ok": true, "result": … } and failure is { "ok": false, "error": { "code", "message", "data"? } }. Over MCP, the same error object comes back flagged as an error. The code is a short word such as forbidden, invalid, not_found, rate_limited or confirm_required, so an agent can branch on it without parsing prose.

Older tool names still work. tasks_complete is an alias that calls tasks_update with completed: true, so a client configured against the old names does not break.

Scopes: what a token may read, write and delete

A token carries explicit scopes. There are fourteen: read, write and delete for each of tasks, projects, notes and a group that covers habits, goals, calendar and journal among others, plus productivity:read and bulk. The settings screen offers three presets: read only, standard with no deletes, and full access.

Scopes are enforced in two places. First, a tool the token cannot use is never listed to the agent:

tools: toolManifest()
  .filter((t) => t.scopes.every((s) => auth.token.scopes.includes(s)))

Second, the dispatcher checks scopes again on every call and returns forbidden with the missing scope names. The second check is the one that counts, because a client can call a tool name it was never shown.

The token itself is shown once, when it is created. Only its SHA-256 hash is stored, so it can be revoked but not recovered. A revoked or expired token fails authentication on the next request.

Clients that support OAuth do not need a pasted token. The endpoint answers an unauthenticated request with 401 and a WWW-Authenticate header that points to its resource metadata. The user chooses permissions on a consent page, and the code is exchanged with PKCE using S256. What comes back is an ordinary scoped token that expires after 24 hours.

Destructive actions: previews and confirmation tokens

Some calls cannot be made in one step, whatever the token’s scopes. A bulk delete of tasks, a project delete, a bulk change to more than 25 tasks and a delete of more than one note all work the same way. The first call changes nothing. It returns confirm_required with a preview of what would be affected and a confirm_token. Only a second call that carries the token applies the change.

The token is not a random value held in a table. It is derived from the request:

const windowId = Math.floor(now / 300_000) - offset;
return (await sha256(`${uid}|${tool}|${[...ids].sort().join(',')}|${windowId}`)).slice(0, 16);

It binds the user, the tool and the exact set of item ids to a five-minute window. The server accepts the current window and the one before it. If the set of matching items changes between the preview and the second call, the token no longer matches and the agent gets a fresh preview.

A bulk call is capped at 200 items. The server’s instructions ask the agent to show the preview to the user before confirming. That is a request, not a control. The control is that no single call can do the damage.

Deletes are tombstones, not erasures, and tasks_restore brings deleted tasks back by id.

Idempotency for agents that retry

Agents retry. A call times out, the agent cannot tell whether it landed, and it sends the call again.

Tools that create a record accept an idempotency_key: tasks_create, inbox_capture, projects_create, sections_create, comments_create and notes_create. The key is hashed into the record’s id, so the same key always produces the same id. If a live record with that id exists, the operation returns it and writes nothing.

One catalogue, several doors

The same catalogue and dispatcher sit behind four entry points: a hosted MCP endpoint over Streamable HTTP, a local MCP server over stdio, a REST API and a command-line tool. All four use the same tokens and scopes.

The hosted endpoint is stateless. It accepts POST only and answers GET and DELETE with 405. Each request authenticates the token and builds a server bound to that user and those scopes.

Every call is written to an audit log with the agent’s name, the tool, the outcome and a summary. Records changed by an agent carry a source of mcp, api or cli and the token’s name, so the activity history shows which connection made a change.

What the boundary tolerates, and what is still open

Language models drift on argument types. The validator coerces the common cases instead of failing them: a numeric string becomes a number, "P1" becomes p1, and a single value becomes a one-item array where an array is expected. It still rejects types it cannot coerce, __proto__ and constructor keys, strings over 200,000 characters and nesting deeper than eight levels.

Two limits are recorded in the project’s own security review as open. The per-token rate limit, 60 requests a minute by default, is held in memory per server instance, so it is a soft limit. And a token can still be passed in the URL for clients that cannot send a header, which puts it in request logs outside the application. The documentation tells users to prefer OAuth or the header.

ClearMind is described on the ClearMind page, alongside our wider work on AI systems.

Contact

Tell us what you are trying to operate.

Describe the infrastructure, the workflow that costs you most, and your connectivity as it really is. The first call is with an engineer.