Model Context Protocol (MCP) Implementation
This module provides a V language implementation of the Model Context Protocol (MCP) specification. MCP is a protocol designed to standardize communication between AI models and their context providers.
Overview
The MCP module implements a server that communicates using the Standard Input/Output (stdio) transport as described in the MCP transport specification. This allows for standardized communication between AI models and tools or applications that provide context to these models.
Key Components
- Server: The main MCP server struct that handles JSON-RPC requests and responses
- Model Configuration: Structures representing client and server capabilities according to the MCP specification
- Handlers: Implementation of MCP protocol handlers, including initialization
- Factory: Functions to create and configure an MCP server
Features
- Full implementation of the MCP protocol version 2024-11-05
- JSON-RPC based communication
- Support for client-server capability negotiation
- Logging capabilities
- Resource management
Usage
To create a new MCP server:
import freeflowuniverse.herolib.schemas.jsonrpc
import freeflowuniverse.herolib.mcp
// Define custom handlers if needed
handlers := {
'custom_method': my_custom_handler
}
// Create server configuration
config := mcp.ServerConfiguration{
// Configure server capabilities as needed
}
// Create and start the server
mut server := mcp.new_server(handlers, config)!
server.start()!