What is MCP?
MCP (Model Context Protocol) is an open protocol that enables AI applications to integrate with external data sources and tools. It provides:- Standardized communication - Consistent interface across extensions
- Tool discovery - Extensions expose available capabilities
- Bidirectional streaming - Efficient data transfer
- Type safety - JSON Schema validation
Protocol Overview
MCP uses JSON-RPC 2.0 over stdio (standard input/output) for communication.Message Format
Requests:Core MCP Methods
Tools
List ToolsResources
List ResourcesPrompts
List PromptsMCP in Goose
Goose uses thermcp crate for MCP implementation.
Server Implementation
Implement theServerHandler trait:
Serving the Extension
Stdio transport:Extension Manager
Goose’sExtensionManager handles MCP communication:
Testing MCP Extensions
MCP Inspector
Use the official MCP Inspector to test extensions:Integration Tests
Record and replay MCP interactions (crates/goose/tests/mcp_integration_test.rs):
Error Handling
Standard Error Codes
-32700- Parse error-32600- Invalid request-32601- Method not found-32602- Invalid params-32603- Internal error
Custom Errors
Transport Layer
MCP supports multiple transports:Stdio (Standard)
Communication over stdin/stdout:Duplex Stream (Builtin Extensions)
In-process communication:Best Practices
1. Input Validation
Validate all inputs using JSON Schema:2. Clear Descriptions
Provide detailed descriptions:3. Error Reporting
Return actionable error messages:4. Timeouts
Implement timeouts for long operations:MCP Resources
Next Steps
- Build Extensions
- Create Tools
- Learn Provider Development