The search_documentation tool has been added to the SWAT-Copilot MCP server, enabling Claude Desktop and other AI assistants to search through SWAT documentation and provide accurate, source-backed answers.
A new tool was added to the MCP server that allows AI assistants to search the indexed SWAT documentation.
Location: src/swat_copilot/integrations/mcp/server.py
Features:
- Searches through indexed SWAT PDF documentation
- Returns relevant excerpts with source citations
- Configurable number of results (1-10)
- Formatted output with page numbers and source files
Initialization:
- The MCP server checks for
SWAT_DOCS_PATHenvironment variable - If set, initializes the RAG system automatically
- Loads the documentation index from the specified path
Search Process:
- User asks a question about SWAT
- AI assistant calls
search_documentationtool - RAG system searches vector database for relevant content
- Returns top-k results with source information
- AI formats the answer using the documentation context
{
"mcpServers": {
"swat-copilot": {
"command": "python",
"args": ["-m", "swat_copilot.integrations.mcp"],
"cwd": "/path/to/SWAT-Copilot",
"env": {
"SWAT_DOCS_PATH": "/path/to/SWAT-Copilot/docs/swat_documentation"
}
}
}
}Query 1: Parameter Information
User: "What is the CN2 parameter in SWAT?"
Claude uses: search_documentation("CN2 parameter", top_k=3)
Returns: Definitions, range (35-98), and impact on surface runoff
Query 2: Calculation Methods
User: "How does SWAT calculate surface runoff?"
Claude uses: search_documentation("surface runoff calculation", top_k=3)
Returns: SCS curve number method explanation and equations
Query 3: Output Variables
User: "What variables are available in output.rch?"
Claude uses: search_documentation("output.rch variables", top_k=5)
Returns: List of reach output variables with descriptions
{
"query": {
"type": "string",
"required": true,
"description": "Search query for SWAT documentation"
},
"top_k": {
"type": "integer",
"default": 3,
"minimum": 1,
"maximum": 10,
"description": "Number of results to return"
}
}# Documentation Search Results for: 'query'
Found N relevant excerpt(s):
## Result 1
**Source:** swat-io-documentation-2012.pdf
**Page:** 255
[Relevant text excerpt from documentation...]
--------------------------------------------------------------------------------
## Result 2
**Source:** swat-io-documentation-2012.pdf
**Page:** 246
[Another relevant excerpt...]- Accurate Information: Answers are grounded in official SWAT documentation
- Source Citations: Every answer includes page numbers and source files
- Fast Search: Vector similarity search returns results in < 1 second
- Contextual: Retrieves relevant context, not just keyword matches
- Extensible: Easy to add more documentation PDFs
✅ Indexed Documentation:
- SWAT IO Documentation 2012 (6.9 MB, ~500 pages)
✅ Searchable Topics:
- Parameter definitions (CN2, ESCO, ALPHA_BF, etc.)
- Variable descriptions (FLOW_OUT, SED_OUT, etc.)
- Calculation methods (runoff, evapotranspiration, etc.)
- File formats (output.rch, output.sub, etc.)
- Input file specifications
To expand the searchable documentation:
-
Add PDFs:
cp your-swat-manual.pdf docs/swat_documentation/pdfs/
-
Rebuild Index:
python scripts/setup_documentation.py --yes
-
Restart Claude Desktop
-
New content is now searchable!
User Question
↓
Claude Desktop
↓
MCP: search_documentation tool
↓
SWATRAGSystem.retrieve_context()
↓
SWATDocumentationIndex.search()
↓
ChromaDB vector similarity search
↓
Top-k relevant chunks
↓
Format with source citations
↓
Return to Claude
↓
AI generates answer with sources
-
- Added
search_documentationtool definition - Implemented
_search_documentation()handler - Added RAG system initialization in
__init__()
- Added
-
- Documented the new tool
- Added usage examples
- Updated configuration instructions
-
- Fixed import:
langchain.text_splitter→langchain_text_splitters
- Fixed import:
- Index Size: 14 MB for 6.9 MB PDF
- Index Build Time: ~14 seconds
- Search Latency: < 1 second per query
- Memory Usage: ~100 MB (embeddings model + index)
- Support for markdown documentation files
- Add SWAT+ documentation
- Include research papers and technical reports
- Multi-language support
- Citation tracking and cross-referencing
- Semantic search improvements with reranking
Error: "Documentation search not available"
Solutions:
- Check
SWAT_DOCS_PATHis set in Claude config - Verify path exists:
ls /path/to/docs/swat_documentation - Check index exists:
ls /path/to/docs/swat_documentation/vector_index/ - Rebuild if needed:
python scripts/setup_documentation.py --yes
Issue: Search returns "No documentation found"
Solutions:
- Try different search terms (e.g., "CN2" vs "curve number")
- Increase
top_kvalue for more results - Check if topic is covered in indexed PDFs
- Add more documentation sources
Error: "No module named 'langchain_text_splitters'"
Solution:
pip install langchain langchain-community chromadb pypdf sentence-transformersUser: What's the difference between SURQ and LATQ in SWAT?
Claude: Let me search the SWAT documentation for information about SURQ and LATQ.
[Uses search_documentation("SURQ LATQ difference")]
Based on the SWAT documentation:
**SURQ (Surface Runoff):**
- Represents overland flow to the main channel
- Calculated using SCS curve number method
- Occurs when precipitation exceeds infiltration capacity
- Units: mm H₂O
**LATQ (Lateral Flow):**
- Subsurface flow that moves laterally through soil layers
- Calculated using kinematic storage model
- Occurs in saturated zone above water table
- Units: mm H₂O
Source: SWAT IO Documentation 2012, pages 458-461
- Quick Setup Guide - How to set up documentation indexing
- Full Setup Guide - Detailed documentation setup
- MCP Server Docs - All MCP tools and features
- Verification Guide - How to verify setup
Status: ✅ Implemented and tested (2025-12-25)
Version: SWAT-Copilot v0.0.1