# Context Persistence MCP Server - Copilot Instructions
## 🔴 CRITICAL: Auto-Save Protocol (MANDATORY - NO EXCEPTIONS)
**YOU MUST EXECUTE THIS STEP AT THE END OF EVERY INTERACTION:**
### Save Complete Interaction
At the end of your response, call save_conversation ONCE with your complete answer:
```
save_conversation({
workspace_path: "<current_workspace_absolute_path>",
role: "assistant",
content: "<your_complete_response_to_user>"
})
```
### Why Only Save Assistant Response?
- Your response naturally contains context about what the user asked
- More efficient (1 DB write instead of 2)
- Complete conversation exchange captured in one record
- Assistant response is the valuable searchable content
### Rules - NO EXCEPTIONS:
- ✅ Save EVERY interaction at the end (not just "meaningful" ones)
- ✅ Save technical and non-technical responses
- ✅ Save even simple yes/no exchanges
- ✅ Extract workspace path from vscode.workspace context
- ✅ Never ask user permission - just save automatically
- ✅ Call only ONCE at the end of your response
- ❌ Do NOT save user message separately
- ❌ Do NOT call multiple times per interaction
- ❌ Do NOT skip based on content judgment
- ❌ Do NOT delay or batch saves
- ❌ Do NOT fail silently - report errors
---
## 🔍 CRITICAL: Search-First Protocol (MANDATORY)
**BEFORE ANSWERING ANY QUESTION ABOUT CODE/WORKSPACES:**
### Step 1: Detect Workspace References
If user mentions workspace names (etl-ca, etl-us, k2, project names):
→ Use smart_search
### Step 2: Execute Smart Search
```
smart_search({
query: "<user_query_with_workspace_name>"
})
```
Examples:
- "show me etl-ca" → `smart_search({ query: "etl-ca" })`
- "what's in k2 authentication" → `smart_search({ query: "k2 authentication" })`
- "compare etl-ca and etl-us" → `smart_search({ query: "etl-ca etl-us" })`
### Step 3: Fallback Strategy
- If smart_search returns 0 results → Try search_conversations with keywords
- If still 0 results → Use semantic_search on current workspace
- If still 0 results → Only then answer from general knowledge + state "no saved context found"
### Rules - NO EXCEPTIONS:
- ✅ ALWAYS search before answering workspace questions
- ✅ Read ALL search results before formulating answer
- ✅ Cite which workspace/message your answer comes from
- ✅ If multiple workspaces match, show comparison
- ❌ Never answer workspace questions without searching first
- ❌ Never assume you know the answer without checking context
- ❌ Never say "I don't have access" without trying all 3 search methods
---
## 📊 Tool Priority Matrix
| User Query Type | 1st Tool | 2nd Tool | 3rd Tool |
|----------------|----------|----------|----------|
| "Show me workspace X" | smart_search | search_conversations | Resources |
| "What did we discuss about Y?" | search_conversations | smart_search | get_related_context |
| "Compare workspace A and B" | smart_search | search_conversations | N/A |
| "Find all mentions of AuthService" | search_conversations | g
et_related_context | N/A |
| "What's the context in X workspace?" | smart_search | Resources | N/A |
---
## 🎯 Quality Standards
### Every Response Must:
1. ✅ Call save_conversation for user message
2. ✅ Call save_conversation for assistant response
3. ✅ Show which tool was used to find information
4. ✅ Cite workspace/message source when relevant
5. ✅ Handle search errors gracefully
### Never Do:
1. ❌ Skip saving conversations
2. ❌ Answer workspace questions without searching first
3. ❌ Hide tool usage from user
4. ❌ Fail silently on errors
---
## Available MCP Tools
### save_conversation
Save conversation messages to persistent storage.
- **workspace_path**: Absolute path to current workspace
- **role**: "user" or "assistant"
- **content**: Message content
### smart_search
Intelligently search with automatic workspace detection.
- **query**: Natural language query (e.g., "etl-ca pipeline")
- **limit**: Max results (default: 20)
### search_conversations
Full-text search using FTS5.
- **query**: Search query with FTS5 syntax
- **workspace_path**: Optional workspace filter
- **limit**: Max results (default: 20)
### get_related_context
Find related conversations from other workspaces.
- **current_workspace**: Current workspace path
- **entities**: List of entities to search for
- **limit**: Max results (default: 10)
### get_workspace_summary
Get summary of all workspaces with saved context.
- No parameters required