MCP Client Configuration
Configure MCP (Model Context Protocol) client connections to external MCP servers
MCP Client Configuration
SmartRAG supports connecting to external MCP (Model Context Protocol) servers to extend query capabilities with external tools and data sources.
Overview
The MCP Client feature allows SmartRAG to:
- Connect to external MCP servers
- Discover and use tools provided by MCP servers
- Integrate MCP tool results with RAG responses
- Query multiple MCP servers simultaneously
Configuration
Enable MCP Client
Add the following to your appsettings.json:
{
"SmartRAG": {
"Features": {
"EnableMcpSearch": true
},
"McpServers": [
{
"ServerId": "example-server",
"Endpoint": "https://mcp.example.com/api",
"AutoConnect": true,
"TimeoutSeconds": 30,
"Headers": {
"Authorization": "Bearer your-token-here"
}
}
]
}
}
Configuration Properties
Features.EnableMcpSearch
- Type:
bool - Default:
false - Description: Enables or disables MCP Client functionality. When enabled, SmartRAG will query connected MCP servers during search operations.
McpServers
- Type:
List<McpServerConfig> - Default: Empty list
- Description: List of MCP server configurations
McpServerConfig Properties
| Property | Type | Required | Description |
|---|---|---|---|
ServerId |
string |
Yes | Unique identifier for the server |
Endpoint |
string |
Yes | Server endpoint URL (HTTP/HTTPS) |
AutoConnect |
bool |
No | Whether to automatically connect on startup (default: true) |
TimeoutSeconds |
int |
No | Connection timeout in seconds (default: 30) |
Headers |
Dictionary<string, string> |
No | Optional HTTP headers for authentication or custom configuration |
Programmatic Configuration
You can also configure MCP servers programmatically:
services.AddSmartRag(configuration, options =>
{
options.Features.EnableMcpSearch = true;
options.McpServers.Add(new McpServerConfig
{
ServerId = "example-server",
Endpoint = "https://mcp.example.com/api",
AutoConnect = true,
TimeoutSeconds = 30,
Headers = new Dictionary<string, string>
{
{ "Authorization", "Bearer your-token" }
}
});
});
Initialization
After building the service provider, initialize MCP connections:
var serviceProvider = services.BuildServiceProvider();
await serviceProvider.InitializeSmartRagAsync();
This will automatically connect to all servers with AutoConnect: true.
Usage
Once configured, MCP tools are automatically integrated into query responses. When you query SmartRAG, it will:
- Query connected MCP servers for relevant tools
- Execute tools that match the query
- Merge MCP results with document and database results
- Include MCP sources in the response
Example Response
{
"Query": "What is the weather today?",
"Answer": "The weather today is sunny with a temperature of 22°C...",
"Sources": [
{
"SourceType": "MCP",
"FileName": "weather-server:get_weather",
"RelevantContent": "Temperature: 22°C, Condition: Sunny",
"RelevanceScore": 1.0
}
]
}
Troubleshooting
Connection Failures
If MCP servers fail to connect:
- Check the endpoint URL is correct
- Verify network connectivity
- Ensure authentication headers are valid
- Check server logs for errors
Tool Discovery Issues
If tools are not discovered:
- Verify the server implements the MCP protocol correctly
- Check that the
tools/listmethod is available - Review server documentation for tool naming conventions