Skip to content

Commit 4fa742a

Browse files
committed
Define canonical KnowCode MCP retrieval contract
1 parent 4c530c0 commit 4fa742a

13 files changed

Lines changed: 270 additions & 304 deletions

File tree

.agent/rules/context.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22
trigger: always_on
33
---
44

5-
to determine if sufficient local context is available.
6-
When the user submits a query, use the following sources for generating the required context -
5+
Follow `docs/mcp-contract.md` for the canonical KnowCode MCP retrieval policy.
6+
Use the current chat context first. When repository context is still needed,
7+
call `retrieve_context_for_query` with `verbosity=minimal` and the smallest
8+
budget that fits the task.
79

8-
1. Check the context window of the current chat session. If you need more context,
9-
2. Use the knowcode mcp tool `retrieve_context_for_query` with the following arguments: `task_type=auto`, `max_tokens=3000`, `limit_entities=3`, `expand_deps=true`, and crucially, **`verbosity=minimal`**.
10-
3. In `minimal` mode, the tool returns a `reduction_summary` telling you what was hidden (e.g., source code or evidence). **If the returned context lacks the implementation details you need**, call the tool again with `verbosity=standard` (to get raw source code) or `verbosity=verbose` (to get evidence chunks).
11-
4. Consider using the other knowcode mcp tools (listed below) if relevant:
10+
Default starting points:
1211

13-
- `search_codebase`: Use to find code entities (functions, classes, modules) by name or pattern.
14-
- `get_entity_context`: Use to get detailed context for a specific entity (source code, docstrings, callers/callees).
15-
- `trace_calls`: Use to trace the call graph (callers or callees) for an entity up to N hops.
12+
- Locate or explain one symbol: `max_tokens=1500`, `limit_entities=1`, `expand_deps=false`.
13+
- Debug a concrete failure: `max_tokens=2000`, `limit_entities=2`, `expand_deps=true`.
14+
- Review or extend a feature area: `max_tokens=3000`, `limit_entities=2-3`, `expand_deps=true`.
1615

17-
If `sufficiency_score >= 0.88` and `context_text` is non-empty, you may answer from the retrieved context alone to maximize efficiency.
18-
If more information is needed, or if the score is low, inform the user that you do not have a satisfactory answer to the query and stop, UNLESS you haven't yet escalated your `verbosity` level to recover missing code.
16+
If `context_text` is insufficient, escalate in this order: increase breadth while
17+
staying in `minimal`, then use `standard` for implementation detail, then use
18+
`verbose` for ranking evidence. Use `diagnostic` only for retrieval debugging.
1919

20-
DO NOT use the external frontier LLMs (e.g. Gemini 3 Flash, Gemini 3 Pro, Claude Sonnet 4.5, Claud Opus 4.5, etc.) at all.
20+
Use the configured `config.sufficiency_threshold` from `aimodels.yaml` to decide
21+
whether local context is sufficient. If the score is below threshold, recover
22+
missing local context before falling back to a larger external prompt.
23+
24+
Use focused tools only after the first retrieval call:
25+
26+
- `search_codebase`: find entities by known name or pattern.
27+
- `get_entity_context`: fetch context for a specific known entity.
28+
- `trace_calls`: inspect callers or callees for a specific entity.

AGENTS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ If the codebase already addresses the problem you are about to recommend solving
1515
## Do not present uncertain claims as facts
1616

1717
If you have not verified something, say "I have not verified this." Hedging is not a weakness — unearned confidence is. When you skip verification to sound more decisive, you trade correctness for tone.
18+
19+
# KnowCode MCP Context
20+
21+
When repository context is needed, follow `docs/mcp-contract.md`. Start with `retrieve_context_for_query` using `verbosity=minimal` and the smallest budget that fits the task. Escalate verbosity or breadth only when the minimal context is insufficient.

CLAUDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ If the codebase already addresses the problem you are about to recommend solving
1515
## Do not present uncertain claims as facts
1616

1717
If you have not verified something, say "I have not verified this." Hedging is not a weakness — unearned confidence is. When you skip verification to sound more decisive, you trade correctness for tone.
18+
19+
# KnowCode MCP Context
20+
21+
When repository context is needed, follow `docs/mcp-contract.md`. Start with `retrieve_context_for_query` using `verbosity=minimal` and the smallest budget that fits the task. Escalate verbosity or breadth only when the minimal context is insufficient.

GEMINI.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ If the codebase already addresses the problem you are about to recommend solving
1515
## Do not present uncertain claims as facts
1616

1717
If you have not verified something, say "I have not verified this." Hedging is not a weakness — unearned confidence is. When you skip verification to sound more decisive, you trade correctness for tone.
18+
19+
# KnowCode MCP Context
20+
21+
When repository context is needed, follow `docs/mcp-contract.md`. Start with `retrieve_context_for_query` using `verbosity=minimal` and the smallest budget that fits the task. Escalate verbosity or breadth only when the minimal context is insufficient.

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ MCP read tools are deterministic and do not auto-run analysis.
257257
```json
258258
{
259259
"knowcode": {
260-
"command": "knowcode",
261-
"args": ["mcp-server", "--store", "/path/to/project"]
260+
"command": "uv",
261+
"args": ["run", "knowcode", "mcp-server", "--store", "/path/to/project"]
262262
}
263263
}
264264
```
@@ -272,20 +272,24 @@ pip install "knowcode[mcp]"
272272

273273
KnowCode enables token-efficient IDE agent workflows. When your IDE agent needs context, it invokes KnowCode's MCP tools to retrieve relevant code context locally *before* calling expensive external LLMs.
274274

275+
The canonical retrieval policy lives in [`docs/mcp-contract.md`](docs/mcp-contract.md).
276+
Keep agent rules pointed there instead of hard-coding separate thresholds or
277+
token budgets in each client.
278+
275279
**How It Works:**
276280
1. IDE agent receives user query
277-
2. Agent invokes `retrieve_context_for_query` via MCP
278-
3. KnowCode returns context + `sufficiency_score` (0.0-1.0)
279-
4. **Score ≥ 0.8**: Answer locally (zero external tokens)
280-
5. **Score < 0.8**: Use returned context with external LLM
281+
2. Agent invokes `retrieve_context_for_query` with `verbosity="minimal"`
282+
3. KnowCode returns compact context + `sufficiency_score` (0.0-1.0)
283+
4. If the score meets `config.sufficiency_threshold`, answer locally
284+
5. If context is insufficient, escalate verbosity or budget before falling back
281285

282286
**Antigravity Configuration (`.gemini/mcp_servers.json`):**
283287
```json
284288
{
285289
"mcpServers": {
286290
"knowcode": {
287-
"command": "knowcode",
288-
"args": ["mcp-server", "--store", "/path/to/your/project"]
291+
"command": "uv",
292+
"args": ["run", "knowcode", "mcp-server", "--store", "/path/to/your/project"]
289293
}
290294
}
291295
}

0 commit comments

Comments
 (0)