Daniel LightRAG MCP Server
A comprehensive MCP server that provides full integration with LightRAG API, offering 22 tools across document management, querying, knowledge graph operations, and system management.
README
Daniel LightRAG MCP Server
A comprehensive MCP (Model Context Protocol) server that provides full integration with LightRAG API, offering 22 tools across 4 categories for complete document management, querying, knowledge graph operations, and system management.
Features
- Document Management: 8 tools for inserting, uploading, scanning, retrieving, and deleting documents
- Query Operations: 2 tools for text queries with regular and streaming responses
- Knowledge Graph: 7 tools for accessing, checking, updating, and deleting entities and relations
- System Management: 5 tools for health checks, status monitoring, and cache management
Quick Start
-
Install the server:
pip install -e . -
Start LightRAG server (ensure it's running on http://localhost:9621)
-
Configure your MCP client (e.g., Claude Desktop):
{ "mcpServers": { "daniel-lightrag": { "command": "python", "args": ["-m", "daniel_lightrag_mcp"] } } } -
Test the connection: Use the
get_healthtool to verify everything is working.
Installation
# Basic installation
pip install -e .
# With development dependencies
pip install -e ".[dev]"
Usage
Command Line
Start the MCP server:
daniel-lightrag-mcp
Environment Variables
Configure the server with environment variables:
export LIGHTRAG_BASE_URL="http://localhost:9621"
export LIGHTRAG_API_KEY="your-api-key" # Optional
export LIGHTRAG_TIMEOUT="30" # Optional
export LOG_LEVEL="INFO" # Optional
daniel-lightrag-mcp
Configuration
The server expects LightRAG to be running on http://localhost:9621 by default. Make sure your LightRAG server is started before running this MCP server.
For detailed configuration options, see CONFIGURATION_GUIDE.md.
Available Tools (22 Total)
Document Management Tools (8 tools)
insert_text
Insert text content into LightRAG.
Parameters:
text(required): Text content to insert
Example:
{
"text": "This is important information about machine learning algorithms and their applications in modern AI systems."
}
insert_texts
Insert multiple text documents into LightRAG.
Parameters:
texts(required): Array of text documents with optional title and metadata
Example:
{
"texts": [
{
"title": "AI Overview",
"content": "Artificial Intelligence is transforming industries...",
"metadata": {"category": "technology", "author": "researcher"}
},
{
"content": "Machine learning algorithms require large datasets..."
}
]
}
upload_document
Upload a document file to LightRAG.
Parameters:
file_path(required): Path to the file to upload
Example:
{
"file_path": "/path/to/document.pdf"
}
scan_documents
Scan for new documents in LightRAG.
Parameters: None
Example:
{}
get_documents
Retrieve all documents from LightRAG.
Parameters: None
Example:
{}
get_documents_paginated
Retrieve documents with pagination.
Parameters:
page(required): Page number (1-based)page_size(required): Number of documents per page (1-100)
Example:
{
"page": 1,
"page_size": 20
}
delete_document
Delete a specific document by ID.
Parameters:
document_id(required): ID of the document to delete
Example:
{
"document_id": "doc_12345"
}
clear_documents
Clear all documents from LightRAG.
Parameters: None
Example:
{}
Query Tools (2 tools)
query_text
Query LightRAG with text.
Parameters:
query(required): Query textmode(optional): Query mode - "naive", "local", "global", or "hybrid" (default: "hybrid")only_need_context(optional): Whether to only return context without generation (default: false)
Example:
{
"query": "What are the main concepts in machine learning?",
"mode": "hybrid",
"only_need_context": false
}
query_text_stream
Stream query results from LightRAG.
Parameters:
query(required): Query textmode(optional): Query mode - "naive", "local", "global", or "hybrid" (default: "hybrid")only_need_context(optional): Whether to only return context without generation (default: false)
Example:
{
"query": "Explain the evolution of artificial intelligence",
"mode": "global"
}
Knowledge Graph Tools (7 tools)
get_knowledge_graph
Retrieve the knowledge graph from LightRAG.
Parameters: None
Example:
{}
get_graph_labels
Get labels from the knowledge graph.
Parameters: None
Example:
{}
check_entity_exists
Check if an entity exists in the knowledge graph.
Parameters:
entity_name(required): Name of the entity to check
Example:
{
"entity_name": "Machine Learning"
}
update_entity
Update an entity in the knowledge graph.
Parameters:
entity_id(required): ID of the entity to updateproperties(required): Properties to update
Example:
{
"entity_id": "entity_123",
"properties": {
"description": "Updated description for machine learning",
"category": "AI Technology"
}
}
update_relation
Update a relation in the knowledge graph.
Parameters:
relation_id(required): ID of the relation to updateproperties(required): Properties to update
Example:
{
"relation_id": "rel_456",
"properties": {
"strength": 0.9,
"type": "implements"
}
}
delete_entity
Delete an entity from the knowledge graph.
Parameters:
entity_id(required): ID of the entity to delete
Example:
{
"entity_id": "entity_789"
}
delete_relation
Delete a relation from the knowledge graph.
Parameters:
relation_id(required): ID of the relation to delete
Example:
{
"relation_id": "rel_101"
}
System Management Tools (5 tools)
get_pipeline_status
Get the pipeline status from LightRAG.
Parameters: None
Example:
{}
get_track_status
Get track status by ID.
Parameters:
track_id(required): ID of the track to get status for
Example:
{
"track_id": "track_abc123"
}
get_document_status_counts
Get document status counts.
Parameters: None
Example:
{}
clear_cache
Clear LightRAG cache.
Parameters: None
Example:
{}
get_health
Check LightRAG server health.
Parameters: None
Example:
{}
Example Workflows
Complete Document Management Workflow
-
Check server health:
{"tool": "get_health", "arguments": {}} -
Insert documents:
{ "tool": "insert_texts", "arguments": { "texts": [ { "title": "AI Research Paper", "content": "Recent advances in transformer architectures have shown remarkable improvements in natural language understanding tasks...", "metadata": {"category": "research", "year": 2024} } ] } } -
Query the knowledge base:
{ "tool": "query_text", "arguments": { "query": "What are the recent advances in transformer architectures?", "mode": "hybrid" } } -
Explore the knowledge graph:
{"tool": "get_knowledge_graph", "arguments": {}} -
Check entity existence:
{ "tool": "check_entity_exists", "arguments": {"entity_name": "transformer architectures"} }
Knowledge Graph Management Workflow
-
Get current graph structure:
{"tool": "get_knowledge_graph", "arguments": {}} -
Get available labels:
{"tool": "get_graph_labels", "arguments": {}} -
Update entity properties:
{ "tool": "update_entity", "arguments": { "entity_id": "transformer_arch_001", "properties": { "description": "Advanced neural network architecture for sequence processing", "applications": ["NLP", "computer vision", "speech recognition"], "year_introduced": 2017 } } } -
Update relation properties:
{ "tool": "update_relation", "arguments": { "relation_id": "rel_improves_002", "properties": { "improvement_factor": 2.5, "confidence": 0.92, "evidence": "Multiple benchmark studies" } } }
System Monitoring Workflow
-
Check overall health:
{"tool": "get_health", "arguments": {}} -
Monitor pipeline status:
{"tool": "get_pipeline_status", "arguments": {}} -
Check document processing status:
{"tool": "get_document_status_counts", "arguments": {}} -
Track specific operations:
{ "tool": "get_track_status", "arguments": {"track_id": "upload_batch_001"} } -
Clear cache when needed:
{"tool": "clear_cache", "arguments": {}}
Error Handling
The server provides comprehensive error handling with detailed error messages:
- Connection Errors: When LightRAG server is unreachable
- Authentication Errors: When API key is invalid or missing
- Validation Errors: When input parameters are invalid
- API Errors: When LightRAG API returns errors
- Timeout Errors: When requests exceed timeout limits
- Server Errors: When LightRAG server returns 5xx status codes
All errors include:
- Error type and message
- HTTP status code (when applicable)
- Timestamp
- Tool name that caused the error
- Additional context data when available
Error Response Format
{
"tool": "insert_text",
"error_type": "LightRAGConnectionError",
"message": "Failed to connect to LightRAG server at http://localhost:9621",
"timestamp": 1703123456.789,
"status_code": null,
"response_data": {}
}
Common Error Scenarios
Connection Errors
{
"error_type": "LightRAGConnectionError",
"message": "Connection refused to http://localhost:9621",
"status_code": null
}
Validation Errors
{
"error_type": "LightRAGValidationError",
"message": "Missing required arguments for query_text: ['query']",
"validation_errors": [
{
"loc": ["query"],
"msg": "field required",
"type": "value_error.missing"
}
]
}
API Errors
{
"error_type": "LightRAGAPIError",
"message": "Document not found",
"status_code": 404,
"response_data": {
"detail": "Document with ID 'doc_123' does not exist"
}
}
Troubleshooting
Quick Diagnostics
-
Check LightRAG Server Status:
curl http://localhost:9621/health -
Test MCP Server:
python -m daniel_lightrag_mcp & sleep 2 pkill -f daniel_lightrag_mcp -
Verify Installation:
python -c "import daniel_lightrag_mcp; print('OK')"
Common Issues
Server Won't Start
- Check Python version: Requires Python 3.8+
- Verify dependencies: Run
pip install -e . - Check port availability: Ensure no conflicts on stdio
Connection Refused
- LightRAG not running: Start LightRAG server first
- Wrong URL: Verify
LIGHTRAG_BASE_URLenvironment variable - Firewall blocking: Check firewall settings for port 9621
Authentication Failed
- Missing API key: Set
LIGHTRAG_API_KEYenvironment variable - Invalid key: Verify API key with LightRAG server
- Key format: Ensure key format matches LightRAG expectations
Timeout Errors
- Increase timeout: Set
LIGHTRAG_TIMEOUT=60environment variable - Check server load: Verify LightRAG server performance
- Network latency: Test direct API calls with curl
Tool Not Found
- Restart MCP client: Reload server configuration
- Check tool name: Verify exact tool name spelling
- Server registration: Ensure all 22 tools are listed
Debug Mode
Enable detailed logging:
export LOG_LEVEL=DEBUG
python -m daniel_lightrag_mcp
Getting Help
- Check server logs for detailed error messages
- Test individual tools with minimal examples
- Verify LightRAG server is responding correctly
- Review the Configuration Guide for setup details
Development
Install development dependencies:
pip install -e ".[dev]"
Run tests:
pytest
Run tests with coverage:
pytest --cov=src/daniel_lightrag_mcp --cov-report=html
Format code:
black src/ tests/
isort src/ tests/
License
MIT License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。