Tutorial 1: Understanding MCP with Haiveβs Dynamic DiscoveryΒΆ
What is MCP?ΒΆ
The Model Context Protocol (MCP) is a standardized protocol that allows AI models to interact with external tools, resources, and data sources. With Haive MCP, agents can automatically discover and integrate tools from 1900+ MCP servers at runtime, without any manual configuration.
Core ConceptsΒΆ
1. MCP ServersΒΆ
MCP servers are standalone programs that expose functionality to AI models. They can:
Provide tools (functions the AI can call)
Offer resources (data the AI can access)
Supply prompts (templates for optimal usage)
2. Transport LayersΒΆ
MCP supports multiple transport mechanisms:
stdio: Communication via standard input/output
HTTP/SSE: Web-based communication
WebSocket: Real-time bidirectional communication
3. CapabilitiesΒΆ
Each MCP server declares its capabilities:
Tools: Executable functions
Resources: Accessible data
Prompts: Predefined templates
How MCP WorksΒΆ
βββββββββββββββ MCP Protocol βββββββββββββββ
β AI Agent ββββββββββββββββββββββββΊβ MCP Server β
β (Client) β β (Provider) β
βββββββββββββββ βββββββββββββββ
β β
β 1. List available tools β
βββββββββββββββββββββββββββββββββββββββΊβ
β β
β 2. Return tool definitions β
ββββββββββββββββββββββββββββββββββββββββ
β β
β 3. Call tool with parameters β
βββββββββββββββββββββββββββββββββββββββΊβ
β β
β 4. Return tool results β
ββββββββββββββββββββββββββββββββββββββββ
Key BenefitsΒΆ
Standardization: One protocol for all integrations
Security: Controlled access to resources
Flexibility: Support for various transport methods
Extensibility: Easy to add new capabilities
Example: Filesystem ServerΒΆ
The filesystem MCP server provides tools for file operations:
{
"name": "@modelcontextprotocol/server-filesystem",
"tools": [
{
"name": "read_file",
"description": "Read contents of a file",
"inputSchema": {
"type": "object",
"properties": {
"path": { "type": "string" }
}
}
},
{
"name": "write_file",
"description": "Write contents to a file",
"inputSchema": {
"type": "object",
"properties": {
"path": { "type": "string" },
"content": { "type": "string" }
}
}
}
]
}
MCP vs Traditional APIsΒΆ
Feature |
MCP |
Traditional API |
|---|---|---|
Protocol |
Standardized |
Varies per API |
Discovery |
Built-in |
Manual documentation |
Type Safety |
JSON Schema |
Varies |
Tool Chaining |
Native support |
Custom implementation |
Error Handling |
Standardized |
API-specific |
Getting Started with Haive MCPΒΆ
With Haive MCP, the process is dramatically simplified through automatic discovery:
Create Agent: Use
EnhancedMCPAgentwith desired capabilitiesAuto-Discovery: Agent automatically finds and installs needed servers
Dynamic Integration: Tools are available instantly in your agent
Just Use: No manual configuration - tools work immediately
import asyncio
from haive.mcp.agents.enhanced_mcp_agent import EnhancedMCPAgent
from haive.core.engine.aug_llm import AugLLMConfig
async def quick_start():
# Create agent that auto-discovers tools from 1900+ servers
agent = EnhancedMCPAgent(
name="discovery_agent",
engine=AugLLMConfig(temperature=0.7),
mcp_categories=["core"], # Auto-install filesystem, database, search tools
auto_install=True
)
# Initialize - agent discovers and installs tools automatically
await agent.initialize_mcp()
# Use immediately - tools are ready!
result = await agent.arun("List files and search for Python projects")
return result
# Run the agent
asyncio.run(quick_start())
Common Use CasesΒΆ
File Operations: Read/write files, manage directories
Database Access: Query and modify databases
API Integration: Connect to external services
Data Processing: Transform and analyze data
System Control: Execute commands, manage processes
Best PracticesΒΆ
Start Simple: Begin with basic servers like filesystem
Understand Transport: Choose appropriate transport method
Handle Errors: Implement proper error handling
Security First: Never expose sensitive credentials
Monitor Usage: Track tool calls and performance
Next StepsΒΆ
Continue to Tutorial 2: Setting Up Your First MCP Server
Explore available MCP servers in the registry
Read the MCP specification for deeper understanding