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:
opencode committed 2026-03-21 19:01:58 +01:00
1 parent 55a31278a8
commit 753c7d491e
5 files changed
+380 -11

No files matched your search

+61
View File
@@ -72,6 +72,59 @@ def load_model_from_config():
return init_chat_model(f"openai:{model_name}")
def get_mcp_tools() -> List[Tool]:
"""
Get MCP tools from configured MCP servers
Returns:
List of MCP-derived LangChain Tool objects
"""
from mcp_client import MCPClient, get_mcp_tools_from_client
mcp_tools = []
if not CONFIG_AVAILABLE:
return mcp_tools
try:
# Get all MCP server configurations
# We'll look for configurations with provider="mcp"
all_configs = config_manager.get_configurations()
mcp_configs = {
name: config for name, config in all_configs.items()
if config.get("provider") == "mcp"
}
for name, config in mcp_configs.items():
try:
server_url = config.get("server_url")
if not server_url:
print(f"⚠️ MCP configuration '{name}' missing server_url")
continue
headers = {}
api_key = config.get("api_key")
if api_key:
headers["Authorization"] = f"Bearer {api_key}"
mcp_client = MCPClient(
server_url=server_url,
headers=headers,
timeout=config.get("timeout", 30)
)
tools = get_mcp_tools_from_client(mcp_client)
mcp_tools.extend(tools)
print(f"✅ Added {len(tools)} tools from MCP server '{name}'")
except Exception as e:
print(f"⚠️ Could not load tools from MCP server '{name}': {e}")
except Exception as e:
print(f"⚠️ Error loading MCP tools: {e}")
return mcp_tools
def get_custom_tools() -> List[Tool]:
"""
Get custom tools for the LangCode agent
@@ -111,6 +164,14 @@ def get_custom_tools() -> List[Tool]:
except Exception as e:
print(f"⚠️ Could not load provider tools: {e}")
# Add MCP tools from configured servers
try:
mcp_tools = get_mcp_tools()
custom_tools.extend(mcp_tools)
print(f"✅ Added {len(mcp_tools)} MCP tools")
except Exception as e:
print(f"⚠️ Could not load MCP tools: {e}")
return custom_tools