Maintain a living document with your agent
A resource is content your agent reads over MCP — a runbook, a conventions doc, an API cheat-sheet, a decisions log. With the management tools the agent doesn't only read it; it maintains it — adding what it learns and correcting what's gone stale, so the context it relies on gets better over time.
It's the same loop as optimizing a prompt from a session, applied to knowledge instead of instructions: use what happened this session to improve what the agent reads next time.
The loop
- Give the agent a document to work from. Create it with
create_resource— apath(its address, e.g.reference/runbook.md) and some initial content. A client whose credential can reach the resource can then read it withresources/read. - Find before you write.
grep_resourcesearches inside the resource and returns the matching lines with their line numbers and the document's currentversion— without pulling the whole file. Use it to check whether a fact is already recorded (so you don't duplicate it) and to locate where it belongs. - Record the change in place.
patch_resourceapplies targeted edits — insert a line, replace a value, add a section — sending only the change instead of re-uploading the file. Pass theversionyou just read asexpected_versionso a change someone else made in the meantime is reported as a conflict rather than being silently overwritten. - Notify subscribed consumers. When the resource changes, the server sends a best-effort
resources/updatednotification to subscribed clients, so they can pick up the new knowledge without routine polling. If a client misses the notification, its nextresources/readstill returns the current content.
Example
Your agent just discovered that the staging deploy needs a flag. Instead of only using that this session, it writes it into the runbook.
First it searches — to confirm it isn't already noted, and to read the current version:
{ "path": "reference/runbook.md", "query": "staging deploy", "ignore_case": true }
{
"path": "reference/runbook.md",
"matches": [{ "line": 24, "text": "### Staging deploy" }],
"truncated": false,
"version": 7
}
Then it inserts a note right after that heading, guarded by the version it read:
{
"path": "reference/runbook.md",
"expected_version": 7,
"edits": [
{
"after_line": 24,
"new_string": "\n> Staging deploy needs `--skip-cache`, or the CDN serves stale assets.\n"
}
]
}
{ "path": "reference/runbook.md", "id": "018f...c2a1", "version": 8 }
The next agent to read the runbook starts with that knowledge already in it.
Instruct your agent
A short standing instruction turns this into a habit:
Treat
reference/runbook.mdas our shared runbook. When you learn something durable — a gotcha, a convention, a fix — record it there instead of only using it this session. Firstgrep_resourceto check it isn't already written and to read the currentversion; thenpatch_resourceto add it, passing thatversionasexpected_version. Never re-upload the whole file.
Good to know
versionis a safety guard, not history. Every content write bumps the resource'sversion, and reading it back asexpected_versionprotects concurrent edits from clobbering each other. Unlike a prompt, a resource keeps no restorable version history — the latest content is the content. Keep your own backup if a document is precious.- Text only for
grep_resourceandpatch_resource. They work on text resources. A binary resource — an image, a PDF, an archive — is replaced as a whole withupdate_resource, passing the version read with it as the requiredexpected_version. - Small changes over MCP, large files in the dashboard. A tool call carries content as a single JSON string, so there's a per-call size cap;
patch_resourcesidesteps it for edits by sending only the diff. Seed or replace a large document in the dashboard. - Personal and team spaces. With a credential that represents you, omit
teamto work in your own space. To work in a team space, name a team the credential is bound to and allowed to manage. A userless organization credential must name such a team. Publishing to the organization catalogue stays a dashboard action. - Every call is metered — each
grep_resource,patch_resource, orcreate_resourcecounts once against your plan's tool-invocation allowance.