feat: Add MCP integration to enable tools from skills.sh and other MCP servers
- Added MCP client to discover and convert MCP tools to LangChain Tools - Extended configuration manager to support MCP server configurations - Updated CLI to manage MCP server configurations (list, add, remove, use) - Integrated MCP tools into the agent's tool loading system - Added documentation for MCP integration design
This commit is contained in:
1 parent
55a31278a8
commit
753c7d491e
5 files changed
+380
-11
No files matched your search
@@ -0,0 +1,50 @@
|
||||
# MCP Integration Design for LangCode Agent
|
||||
|
||||
## Section 1: MCP Client and Tool Conversion (Previously discussed and validated)
|
||||
|
||||
## Section 2: Integration with LangCode Agent Architecture (Previously discussed and validated)
|
||||
|
||||
## Section 3: Specific Implementation Details, Data Flow, and Error Handling
|
||||
|
||||
### Implementation Files to Create/Modify:
|
||||
1. **New file**: `mcp_client.py` - Contains the MCPClient class and tool conversion functions
|
||||
2. **Modified file**: `main.py` - Add `get_mcp_tools()` function and integrate MCP tools into `get_custom_tools()`
|
||||
3. **Modified file**: `config_manager.py` - Add methods to manage MCP server configurations (if not already present)
|
||||
4. **Modified file**: `config_cli.py` - Add CLI commands for MCP server management (list, add, remove, use, etc.)
|
||||
|
||||
### Data Flow:
|
||||
1. **Startup**: When the agent initializes, `get_custom_tools()` is called
|
||||
2. **MCP Tool Discovery**: `get_mcp_tools()` reads all configured MCP servers from config_manager
|
||||
3. **Server Connection**: For each MCP server, an MCPClient instance connects to the server URL
|
||||
4. **Tool Enumeration**: The client calls the MCP server's `tools/list` endpoint to get available tools
|
||||
5. **Tool Conversion**: Each tool specification is converted to a LangChain Tool with:
|
||||
- Same name and description as the MCP tool
|
||||
- A function that serializes arguments and calls the MCP server's `tools/call` endpoint
|
||||
- Proper error handling for network issues, server errors, or invalid responses
|
||||
6. **Tool Aggregation**: All MCP-derived tools are combined with existing Proxmox and provider tools
|
||||
7. **Agent Initialization**: The DeepAgent is created with the complete toolset
|
||||
|
||||
### Error Handling Strategy:
|
||||
- **Connection Failures**: If an MCP server is unreachable during startup, log a warning and continue (don't fail agent initialization)
|
||||
- **Tool Call Failures**: If a tool call to an MCP server fails, return a descriptive error message as the tool result
|
||||
- **Schema Validation**: Validate tool arguments against the MCP tool's input schema before making the call
|
||||
- **Timeouts**: Implement reasonable timeouts for MCP server connections and calls
|
||||
- **Retry Logic**: Consider implementing retry logic for transient network failures
|
||||
|
||||
### Testing Approach:
|
||||
1. **Unit Tests**:
|
||||
- Test MCPClient connection and tool listing with mock servers
|
||||
- Test tool conversion function with various tool specifications
|
||||
- Test error handling scenarios (timeouts, invalid responses, etc.)
|
||||
|
||||
2. **Integration Tests**:
|
||||
- Test with a real MCP server (could be a local test server or skills.sh if accessible)
|
||||
- Verify that tools appear in the agent's tool list and can be invoked successfully
|
||||
- Test end-to-end flows: user asks agent to use an MCP-derived tool, agent executes it correctly
|
||||
|
||||
3. **Manual Testing**:
|
||||
- Add an MCP server configuration pointing to skills.sh (if it offers MCP endpoints)
|
||||
- Verify that skills from skills.sh appear as available tools in the agent
|
||||
- Test invoking a few different skills to ensure they work correctly
|
||||
|
||||
Are these implementation details, data flow, error handling, and testing approaches correct and complete? Do you see any gaps or areas that need adjustment?
|
||||
Reference in new issue
Block a user