Skip to content

Commit eab9113

Browse files
committed
Add comprehensive MCP workflow test plan and E2E integration tests
- Introduced a detailed test plan for the MCP workflow in `test_mcp_workflow.md`, covering various query types and expected sufficiency scores. - Implemented E2E tests for IDE agent integration in `test_usecase2_ide_integration.py`, simulating high and low sufficiency scenarios, and verifying local answer usage versus LLM fallback. - Created a verification script `verify_mcp_connection.sh` to check MCP server status, configuration, knowledge store, and semantic index.
1 parent ef89a8a commit eab9113

20 files changed

Lines changed: 1357 additions & 30 deletions

.agent/rules/context.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
trigger: always_on
3+
---
4+
5+
Always call the tool `retrieve_context_for_query` before answering to determine if sufficient local context is available.
6+
Use `task_type=auto`, `max_tokens=3000`, `limit_entities=3`, `expand_deps=true`.
7+
8+
In addition to context retrieval, you have access to specialized KnowCode tools:
9+
- `search_codebase`: Use to find code entities (functions, classes, modules) by name or pattern.
10+
- `get_entity_context`: Use to get detailed context for a specific entity (source code, docstrings, callers/callees).
11+
- `trace_calls`: Use to trace the call graph (callers or callees) for an entity up to N hops.
12+
13+
If `sufficiency_score >= 0.88` and `context_text` is non-empty, you may answer from the retrieved context alone to maximize efficiency.
14+
If more information is needed, or if the score is low, use the other KnowCode tools or proceed with a full LLM answer.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,6 @@ __marimo__/
208208
knowcode_knowledge.json
209209
CHANGELOG.md
210210
docs_test/
211-
aimodels.yaml
211+
#aimodels.yaml
212212
.knowcode/
213213

KnowCode.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Entity:
134134
id: UUID
135135
kind: function | class | module | config_key | feature_flag | api_endpoint
136136
source_location: Location
137-
embeddings: vector (1536d)
137+
embeddings: vector (Nd - e.g. 1024d for VoyageAI, 1536d for OpenAI)
138138
confidence: float (0.0-1.0)
139139
provenance: static_analysis | runtime_trace | llm_inference | human_annotation
140140
created_at: timestamp

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,34 @@ knowcode mcp-server [--store <path>] [--config <path>]
237237
pip install "knowcode[mcp]"
238238
```
239239

240+
## IDE Agent Integration
241+
242+
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.
243+
244+
**How It Works:**
245+
1. IDE agent receives user query
246+
2. Agent invokes `retrieve_context_for_query` via MCP
247+
3. KnowCode returns context + `sufficiency_score` (0.0-1.0)
248+
4. **Score ≥ 0.8**: Answer locally (zero external tokens)
249+
5. **Score < 0.8**: Use returned context with external LLM
250+
251+
**Antigravity Configuration (`.gemini/mcp_servers.json`):**
252+
```json
253+
{
254+
"mcpServers": {
255+
"knowcode": {
256+
"command": "knowcode",
257+
"args": ["mcp-server", "--store", "/path/to/your/project"]
258+
}
259+
}
260+
}
261+
```
262+
263+
**Token Savings:**
264+
- Simple "locate" queries → **100% savings** (answered locally)
265+
- Code explanations → **60-80% savings** (precise context only)
266+
267+
240268
## Supported Languages (MVP)
241269

242270
- **Python** (.py) - Full AST parsing (Supports Python 3.9 - 3.12)

README_MCP.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# MCP Setup - Quick Reference
2+
3+
## ✅ What We Fixed
4+
5+
1. **MCP Configuration Path Issue**
6+
- **Problem**: Used `"command": "knowcode"` (not in PATH)
7+
- **Solution**: Changed to `"/home/deeog/Desktop/KnowCode/.venv/bin/knowcode"`
8+
- **File**: `/home/deeog/.gemini/mcp_servers.json`
9+
10+
## 📋 Current Status
11+
12+
### ✅ Ready
13+
- [x] MCP configuration file updated with absolute path
14+
- [x] Knowledge store exists (1.1M, 1 day old)
15+
- [x] KnowCode CLI working (v0.2.1)
16+
- [x] Virtual environment configured
17+
- [x] Agent rules defined in `.agent/context.md`
18+
19+
### ⚠️ Needs Attention
20+
- [ ] **Semantic index missing** - Will use lexical search only
21+
- [ ] **Knowledge store is 1 day old** - Consider re-analyzing
22+
23+
### 🔄 Next Actions Required
24+
1. **Stop the manual MCP server** (Ctrl+C in terminal)
25+
2. **Restart Antigravity IDE**
26+
3. **Test the workflow** (see test_mcp_workflow.md)
27+
28+
## 🎯 Expected Workflow After Restart
29+
30+
```
31+
User asks: "How does search work in KnowCode?"
32+
33+
Agent calls: retrieve_context_for_query(
34+
query="How does search work in KnowCode?",
35+
task_type="auto",
36+
max_tokens=3000,
37+
limit_entities=3,
38+
expand_deps=true
39+
)
40+
41+
KnowCode MCP Server returns:
42+
{
43+
"context_text": "...",
44+
"sufficiency_score": 0.92,
45+
"evidence": [...],
46+
...
47+
}
48+
49+
Agent checks: sufficiency_score >= 0.88?
50+
51+
YES → Answer from context_text only (no external LLM)
52+
NO → Use external LLM (Claude Sonnet 4.5)
53+
```
54+
55+
## 📁 Files Created
56+
57+
1. **`verify_mcp_connection.sh`** - Check MCP setup status
58+
2. **`test_mcp_workflow.md`** - Test questions after restart
59+
3. **`docs/MCP_SETUP.md`** - Complete setup documentation
60+
4. **`README_MCP.md`** - This quick reference (you are here)
61+
62+
## 🚀 Quick Commands
63+
64+
### Check MCP Status
65+
```bash
66+
./verify_mcp_connection.sh
67+
```
68+
69+
### Check MCP Server Process
70+
```bash
71+
ps aux | grep "knowcode mcp-server"
72+
```
73+
74+
### View MCP Configuration
75+
```bash
76+
cat ~/.gemini/mcp_servers.json
77+
```
78+
79+
### Rebuild Knowledge Store (if needed)
80+
```bash
81+
source .venv/bin/activate
82+
knowcode analyze . -o .
83+
```
84+
85+
**Note:** This automatically rebuilds both the knowledge store AND the semantic index!
86+
87+
## 🐛 Troubleshooting
88+
89+
### MCP Tool Not Available After Restart?
90+
91+
1. Check server is running:
92+
```bash
93+
ps aux | grep "knowcode mcp-server"
94+
```
95+
96+
2. Check configuration:
97+
```bash
98+
cat ~/.gemini/mcp_servers.json
99+
```
100+
101+
3. Restart IDE again
102+
103+
### Low Sufficiency Scores?
104+
105+
1. Verify index exists (should be created by analyze):
106+
```bash
107+
ls -la knowcode_index/
108+
```
109+
110+
2. If missing, re-run analyze (it will rebuild the index):
111+
```bash
112+
knowcode analyze . -o .
113+
```
114+
115+
3. Increase token budget in `.agent/context.md`:
116+
```markdown
117+
Use max_tokens=6000, limit_entities=5
118+
```
119+
120+
## 📊 Success Metrics
121+
122+
After setup, you should see:
123+
- ✅ 70%+ queries with `sufficiency_score >= 0.88`
124+
- ✅ Faster responses for codebase questions
125+
- ✅ 50%+ reduction in external LLM token usage
126+
- ✅ Accurate answers from local context
127+
128+
## 📚 Documentation
129+
130+
- **Full Setup Guide**: `docs/MCP_SETUP.md`
131+
- **Test Plan**: `test_mcp_workflow.md`
132+
- **KnowCode Docs**: `README.md`
133+
134+
## 🎓 Key Concepts
135+
136+
**Sufficiency Score**: Confidence that retrieved context is enough to answer the query
137+
- `>= 0.88` → Answer locally
138+
- `< 0.88` → Use external LLM
139+
140+
**Retrieval Modes**:
141+
- **Semantic**: Uses embeddings + vector search (better)
142+
- **Lexical**: Uses keyword matching (fallback)
143+
144+
**Dependency Expansion**: Includes related code (callees, callers) for complete context
145+
146+
## ⚡ Performance Tips
147+
148+
1. **Build semantic index** - Much better than lexical
149+
2. **Keep knowledge store updated** - Re-analyze after major changes
150+
3. **Tune parameters** - Adjust max_tokens and limit_entities
151+
4. **Monitor scores** - Track sufficiency_score distribution
152+
153+
## 🔒 Security Notes
154+
155+
- MCP server runs **locally** (no external data transmission)
156+
- Knowledge store contains your **source code** (keep secure)
157+
- Embeddings may be sent to **external providers** (VoyageAI, OpenAI)
158+
- Store API keys in `.env` (never commit)
159+
160+
## 🎉 You're Almost There!
161+
162+
Just need to:
163+
1. Stop the manual MCP server (Ctrl+C)
164+
2. Restart Antigravity IDE
165+
3. Ask a test question
166+
167+
Good luck! 🚀
168+
169+
---
170+
171+
*Last updated: 2026-01-13*

aimodels.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ embedding_models:
1919
eval_models:
2020
- name: voyage-code-3
2121
provider: voyageai
22-
api_key_env: VOYAGE_API_KEY_1
22+
# api_key_env: VOYAGE_API_KEY_1
2323
tokens_free_tier_limit: 200000000
2424

2525
# Configuration

check_mcp_server.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# Check if KnowCode MCP server is running
3+
4+
echo "=== Checking for KnowCode MCP Server ==="
5+
echo ""
6+
7+
# Method 1: Check for knowcode mcp-server process
8+
echo "1. Checking for 'knowcode mcp-server' process:"
9+
ps aux | grep -E "knowcode.*mcp-server" | grep -v grep
10+
if [ $? -eq 0 ]; then
11+
echo " ✓ KnowCode MCP server is RUNNING"
12+
else
13+
echo " ✗ KnowCode MCP server is NOT running"
14+
fi
15+
16+
echo ""
17+
18+
# Method 2: Check for any knowcode process
19+
echo "2. Checking for any 'knowcode' process:"
20+
ps aux | grep "knowcode" | grep -v grep
21+
if [ $? -eq 0 ]; then
22+
echo " ✓ Found knowcode process(es)"
23+
else
24+
echo " ✗ No knowcode processes found"
25+
fi
26+
27+
echo ""
28+
29+
# Method 3: Check for Python processes that might be running knowcode
30+
echo "3. Checking for Python processes with 'knowcode' or 'mcp':"
31+
ps aux | grep -E "python.*knowcode|python.*mcp" | grep -v grep
32+
33+
echo ""
34+
echo "=== MCP Server Configuration Check ==="
35+
36+
# Check if MCP config exists
37+
if [ -f "$HOME/.gemini/mcp_servers.json" ]; then
38+
echo "✓ Found MCP config: $HOME/.gemini/mcp_servers.json"
39+
echo "Content:"
40+
cat "$HOME/.gemini/mcp_servers.json" | jq '.' 2>/dev/null || cat "$HOME/.gemini/mcp_servers.json"
41+
else
42+
echo "✗ MCP config not found at: $HOME/.gemini/mcp_servers.json"
43+
fi
44+
45+
echo ""
46+
echo "=== Knowledge Store Check ==="
47+
if [ -f "knowcode_knowledge.json" ]; then
48+
echo "✓ Knowledge store exists: $(pwd)/knowcode_knowledge.json"
49+
echo " Size: $(du -h knowcode_knowledge.json | cut -f1)"
50+
else
51+
echo "✗ Knowledge store not found: $(pwd)/knowcode_knowledge.json"
52+
echo " Run: knowcode analyze src/"
53+
fi

0 commit comments

Comments
 (0)