What is MCP?
The Model Context Protocol is a standardized protocol that enables AI agents to interact with external tools and services through a consistent interface. MCP works by:- Exposing tools and prompts as API endpoints
- Defining tool schemas in JSON Schema format
- Supporting multiple transport mechanisms (stdio, SSE)
- Providing a marketplace of ready-to-use servers
- Standardization: Connect to any MCP-compliant server without custom integrations
- Ecosystem: Access hundreds of pre-built servers from the MCP Marketplace and DockerHub
- Flexibility: Support for multiple transport protocols (stdio, SSE)
- Easy Integration: Automatic tool registration and conversion to Koog’s tool interface
Installation
Add the MCP integration dependency:gradle
Quick Start
Connect to an MCP server and create an agent with its tools:Transport Types
MCP supports different transport mechanisms for communication:Standard Input/Output (stdio)
Use stdio transport when the MCP server runs as a separate process:Server-Sent Events (SSE)
Use SSE transport when the MCP server runs as a web service:Configuration Options
Custom Client Configuration
Customize the MCP client name and version:Using an Existing MCP Client
Connect with a pre-configured MCP client:Examples
Google Maps Integration
Connect to the Google Maps MCP server for geographic data:examples/simple-examples/src/main/kotlin/ai/koog/agents/example/mcp/GoogleMapsMcpClient.kt:21
Playwright Browser Automation
Connect to the Playwright MCP server for web automation:Ktor Integration
Use MCP in a Ktor application:examples/simple-examples/src/main/kotlin/ai/koog/agents/example/ktor/KtorIntegrationExample.kt:72
Core Components
McpToolRegistryProvider
The main entry point for creating tool registries from MCP servers:fromTransport(): Create registry from a transportfromSseUrl(): Create registry from SSE URLfromClient(): Create registry from existing MCP clientdefaultStdioTransport(): Create stdio transportdefaultSseTransport(): Create SSE transport
agents/agents-mcp/src/commonMain/kotlin/ai/koog/agents/mcp/McpToolRegistryProvider.kt:29
McpTool
Bridge between Koog’s Tool interface and the MCP SDK. Automatically created when tools are retrieved from an MCP server. Source:agents/agents-mcp/src/commonMain/kotlin/ai/koog/agents/mcp/McpTool.kt
McpToolDescriptorParser
Parses tool definitions from the MCP SDK to Koog’s tool descriptor format. Handles JSON Schema conversion automatically. Source:agents/agents-mcp/src/commonMain/kotlin/ai/koog/agents/mcp/McpToolDefinitionParser.kt
Finding MCP Servers
Discover ready-to-use MCP servers:- MCP Marketplace: Browse hundreds of community-built servers
- MCP DockerHub: Official Docker images
- Popular Servers:
- Google Maps: Geographic data and mapping
- Playwright: Browser automation
- Filesystem: File operations
- GitHub: Repository interactions
- Slack: Team communication
Platform Support
- JVM: Full support (stdio and SSE)
- JS: Full support (stdio and SSE)
- Native: Planned
Common Use Cases
- Geographic Data: Connect to mapping services for location-based features
- Web Automation: Control browsers for testing and data extraction
- File Operations: Access filesystem tools for document processing
- API Integration: Connect to external services without custom tool code
- Testing: Use mock MCP servers for unit testing
Best Practices
-
Process Management: Always destroy MCP processes when done:
-
Error Handling: Handle connection failures gracefully:
-
Tool Validation: List tools before using them:
Next Steps
- Explore the MCP Marketplace for available servers
- Check out example implementations
- Learn about Agent Client Protocol for bidirectional communication
- See Spring Boot integration for enterprise applications