Model Context Protocol (MCP) in AgenticGoKit β
Navigation: Documentation Home β Tutorials β MCP (Tools)
Overview β
The Model Context Protocol (MCP) is a powerful framework within AgenticGoKit that enables agents to interact with external tools, APIs, and services. MCP bridges the gap between language models and the outside world, allowing agents to perform actions beyond text generation.
With MCP, agents can search the web, access databases, call APIs, manipulate files, perform calculations, and much more. This capability transforms agents from simple text processors into powerful assistants that can take meaningful actions.
Key Concepts β
What is MCP? β
MCP (Model Context Protocol) is a standardized interface for connecting language models to external tools and capabilities. It defines:
- Tool Registration: How tools are defined and registered with the system
- Tool Discovery: How agents discover available tools
- Tool Invocation: How agents call tools and receive results
- Tool Response Handling: How tool results are processed and incorporated into agent responses
MCP Architecture β
βββββββββββββββ βββββββββββββββββ βββββββββββββββ
β β β β β β
β Agent ββββββΆβ MCP Manager ββββββΆβ Tool β
β β β β β β
βββββββββββββββ βββββββββββββββββ βββββββββββββββ
β² β β
β βΌ βΌ
β βββββββββββββββββ βββββββββββββββ
ββββββββββββββββ Tool Result ββββββ External β
β Processor β β Service β
βββββββββββββββββ βββββββββββββββ
Tool Types β
AgenticGoKit supports various types of tools:
- Built-in Tools: Core functionality provided by the framework
- Custom Tools: User-defined tools for specific use cases
- API Tools: Wrappers around external APIs and services
- Stateful Tools: Tools that maintain state between invocations
- Composite Tools: Tools composed of multiple sub-tools
Why Use MCP? β
MCP provides several key benefits:
- Extended Capabilities: Enables agents to perform actions beyond text generation
- Modularity: Tools can be developed and maintained independently
- Flexibility: Mix and match tools based on specific requirements
- Standardization: Consistent interface for all tool interactions
- Security: Controlled access to external systems
MCP vs. Function Calling β
MCP is similar to function calling in LLMs but provides additional capabilities:
Feature | MCP | Function Calling |
---|---|---|
Tool Discovery | Dynamic | Static |
Tool Registration | Runtime | Design time |
Tool Composition | Supported | Limited |
State Management | Built-in | Manual |
Error Handling | Comprehensive | Basic |
Security Controls | Fine-grained | Limited |
Getting Started with MCP β
To start using MCP in AgenticGoKit, you'll need to:
- Create Tools: Define the tools your agents will use
- Register Tools: Make tools available to the MCP manager
- Configure Agents: Set up agents to use MCP
- Handle Tool Results: Process and incorporate tool outputs
The following tutorials will guide you through these steps in detail:
- Tool Development - Creating custom tools
- Tool Integration - Integrating tools with agents
- Advanced Tool Patterns - Complex tool usage patterns
Example: Simple MCP Setup β
package main
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/kunalkushwaha/agenticgokit/core"
)
func main() {
// Initialize MCP for tool discovery
core.QuickStartMCP()
// Create LLM provider
provider, err := core.NewOpenAIAdapter(
os.Getenv("OPENAI_API_KEY"),
"gpt-3.5-turbo",
1000,
0.7,
)
if err != nil {
log.Fatalf("Failed to create provider: %v", err)
}
// Create agent with MCP tools
agent := core.NewLLMAgent("assistant", provider).
WithSystemPrompt("You are a helpful assistant with access to tools. Use them when needed.").
WithTools([]string{"calculator", "weather"}) // Tools discovered via MCP
// Create agents map
agents := map[string]core.AgentHandler{
"assistant": agent,
}
// Create runner
runner, _ := core.NewRunnerFromConfig("agentflow.toml")
// Start runner
ctx := context.Background()
if err := runner.Start(ctx); err != nil {
log.Fatalf("Failed to start runner: %v", err)
}
defer runner.Stop()
// Create event with user query
event := core.NewEvent("assistant", map[string]interface{}{
"message": "What's 25 * 16 and what's the weather in New York?",
})
event.SetMetadata(core.RouteMetadataKey, "assistant")
// Emit the event
if err := runner.Emit(event); err != nil {
log.Fatalf("Failed to emit event: %v", err)
}
// Wait for processing
time.Sleep(5 * time.Second)
fmt.Println("MCP tool integration complete!")
}
Next Steps β
Now that you understand the basics of MCP, proceed to the following tutorials to learn more:
- Tool Development - Learn how to create custom tools
- Tool Integration - Integrate tools with your agents
- Advanced Tool Patterns - Explore complex tool usage patterns
Further Reading β
- API Reference: MCP
- Examples: Tool Usage
- Advanced Patterns - Advanced multi-agent patterns