replace_knowledge
The CodePanel MCP tool that replaces a repository's review rules and notes from an edited document, and refuses a stale copy.
On this page›
replace_knowledge replaces a repository's review rules and notes with what the ## Rules and ## Notes sections of an edited document contain. Send back the whole document get_knowledge returned, with its version comment: a copy older than the stored knowledge is refused. It needs repo and markdown, and the repos:write scope.
When to call it
- After editing the document
get_knowledgereturned. Dedupe, shorten, fix a stale rule, turn one off by adding(disabled)to its heading. - Not to add one rule. Anything you leave out of
## Rulesand## Notesis deleted, so a call with a single rule would remove all the others. Start from a freshget_knowledge. - Not for learnings, verdicts or account rules. Those sections are read-only context and are ignored on the way back.
Inputs
| Input | Type | Required | Description |
|---|---|---|---|
repo |
string | yes | Repository as owner/name |
markdown |
string | yes | The complete edited document, in the format get_knowledge returned |
It writes: the server marks it readOnlyHint: false and destructiveHint: true (it can change what is already there), so a client that asks before writes asks here.
The document's format is the one get_knowledge writes. Each ### heading is one entry. A rule is matched by its name, so renaming a rule removes the old one and adds a new one. A note has no name: an unchanged note (same type and text) keeps its row and its source, and any other note is replaced. Note headings are one of custom_rules, conventions, patterns or architecture.
How a stale copy fails
The document's <!-- knowledge-version: … --> line is a short hash of the repository's rules (name, text, whether enabled) and notes (type, text) at the moment you read it. On replace, the server computes the hash of what is stored now. If the two differ, nothing changes and you get:
CodePanel: The knowledge changed since this copy was read. Read it again, redo the edit and replace.
Someone edited a rule in the dashboard, or another agent replaced the knowledge, between your read and your write. Call get_knowledge again, apply your edit to that copy, and send it. Without the line at all, the call is refused too (the message begins Keep the <!-- knowledge-version: … --> line from the document you read), because a copy with no version could be any age.
A document that doesn't parse is also refused with the reason, and nothing changes. The check protects rules and notes only: ratings and learnings change without invalidating your copy, because they aren't part of what you replace.
What it returns
Counts for each of rules and notes: added, updated and removed. A rule whose text or enabled state changed counts as updated; a rule or note you left out counts as removed. The change takes effect on the next review.
Examples
These responses come from a test account on a local backend. The markdown string is trimmed to its edited parts and its opening: the call sent the whole document, with the version line and every section get_knowledge returned.
Turn a rule on
The document was read with ### Tests beside code (disabled). The only edit is that heading, now without (disabled):
{
"repo": "codepanel-dev/web-app",
"markdown": "# CodePanel knowledge: codepanel-dev/web-app\n\n<!-- knowledge-version: a0286f9f -->\n\n... ## Rules\n\n### Named exports only\nComponents and modules use named exports; no default exports.\n\n### Tests beside code\nA test file sits next to the module it tests, named *.test.ts.\n\n## Notes\n\n### architecture\nVite + React frontend in src/components and src/routes; the API lives in src/server and runs in the same Node process.\n\n### conventions\nData fetching goes through hooks in src/hooks; components never call fetch directly.\n\n ..."
}
{
"notes": {
"added": 0,
"removed": 0,
"updated": 0
},
"rules": {
"added": 0,
"removed": 0,
"updated": 1
}
}
Sending the old copy again
The same document, still carrying knowledge-version: a0286f9f and the rule still marked (disabled), was sent again after the edit above. The rules had changed, so the tool returned an error:
CodePanel: The knowledge changed since this copy was read. Read it again, redo the edit and replace.
The same step without MCP
| Surface | Form |
|---|---|
| CLI | codepanel knowledge set <owner/name> <file>, or - to read stdin (CLI) |
| HTTP API | POST /knowledge with repo and markdown |
The dashboard's Knowledge tab has the same editor.
What the server tells your agent
The description your agent reads when it lists the tools:
Replace a repository's review rules and notes with what the
## Rulesand## Notessections ofmarkdowncontain. Send the whole document get_knowledge returned, edited: anything you leave out of those two sections is removed, so this is how you dedupe and compact. Each###heading is one entry; a rule heading ending in(disabled)is kept but not used. Other sections (verdicts, headers) are ignored. Returns counts of rules and notes added, updated and removed; an error says what did not parse and nothing changes. Changes take effect on the next review.
Related
get_knowledge: read the document you edit.add_learning: the way to add a learning, which this tool ignores.- Read and rewrite from an agent: the sections and who can edit each.
- MCP server: install, sign-in and every other tool.