mcp.transport #
fn new_http_transport #
fn new_http_transport(config HttpConfig) Transport
new_http_transport creates a new HTTP transport instance
fn new_stdio_transport #
fn new_stdio_transport() Transport
new_stdio_transport creates a new STDIO transport instance
interface Transport #
interface Transport {
mut:
// start begins listening for requests and handling them with the provided JSON-RPC handler.
// This method should block and run the transport's main loop.
//
// Parameters:
// - handler: The JSON-RPC handler that processes MCP protocol messages
//
// Returns:
// - An error if the transport fails to start or encounters a fatal error
start(handler &jsonrpc.Handler) !
// send transmits a response back to the client.
// The implementation depends on the transport type (stdout for STDIO, HTTP response, etc.)
//
// Parameters:
// - response: The JSON-RPC response string to send to the client
send(response string)
}
Transport defines the interface for different MCP transport mechanisms. This abstraction allows MCP servers to work with multiple transport protocols (STDIO, HTTP, WebSocket, etc.) without changing the core MCP logic.
enum HttpMode #
enum HttpMode {
jsonrpc_only // Only JSON-RPC over HTTP endpoint
rest_only // Only REST API endpoints
both // Both JSON-RPC and REST endpoints
}
HttpMode defines which HTTP protocols the server should support
enum TransportMode #
enum TransportMode {
stdio // Standard input/output transport (current default)
http // HTTP/REST transport (new)
}
TransportMode defines the available transport types
struct Context #
struct Context {
veb.Context
}
Context represents the HTTP request context
struct HttpApp #
struct HttpApp {
pub mut:
transport &HttpTransport = unsafe { nil }
}
HttpApp is the VEB application struct that handles HTTP requests
fn (HttpApp) handle_jsonrpc #
fn (mut app HttpApp) handle_jsonrpc(mut ctx Context) veb.Result
JSON-RPC over HTTP endpoint Handles POST requests to /jsonrpc with JSON-RPC 2.0 protocol
fn (HttpApp) health #
fn (mut app HttpApp) health(mut ctx Context) veb.Result
Health check endpoint
fn (HttpApp) options #
fn (mut app HttpApp) options(mut ctx Context) veb.Result
CORS preflight handler
fn (HttpApp) list_tools #
fn (mut app HttpApp) list_tools(mut ctx Context) veb.Result
List all available tools
fn (HttpApp) call_tool #
fn (mut app HttpApp) call_tool(mut ctx Context, tool_name string) veb.Result
Call a specific tool
fn (HttpApp) list_resources #
fn (mut app HttpApp) list_resources(mut ctx Context) veb.Result
List all available resources
fn (HttpApp) handle_sse #
fn (mut app HttpApp) handle_sse(mut ctx Context) veb.Result
SSE endpoint for streaming MCP communication
struct HttpConfig #
struct HttpConfig {
pub:
port int = 8080 // Port to listen on
host string = 'localhost' // Host to bind to
protocol HttpMode = .both // Which HTTP protocols to support
}
HttpConfig holds HTTP-specific configuration
struct HttpTransport #
struct HttpTransport {
pub:
port int = 8080
host string = 'localhost'
mode HttpMode = .both
mut:
handler &jsonrpc.Handler = unsafe { nil }
}
HttpTransport implements the Transport interface for HTTP communication. It provides both JSON-RPC over HTTP and REST API endpoints for MCP servers.
fn (HttpTransport) start #
fn (mut t HttpTransport) start(handler &jsonrpc.Handler) !
start implements the Transport interface for HTTP communication. It starts a VEB web server with the appropriate endpoints based on the configured mode.
fn (HttpTransport) send #
fn (mut t HttpTransport) send(response string)
send implements the Transport interface for HTTP communication.
Note: For HTTP, responses are sent directly in the request handlers, so this method is not used in the same way as STDIO transport.
struct StdioTransport #
struct StdioTransport {
mut:
handler &jsonrpc.Handler = unsafe { nil }
}
StdioTransport implements the Transport interface for standard input/output communication. This is the original MCP transport method where the server reads JSON-RPC requests from stdin and writes responses to stdout. This transport is used for process-to-process communication.
fn (StdioTransport) start #
fn (mut t StdioTransport) start(handler &jsonrpc.Handler) !
start implements the Transport interface for STDIO communication. It reads JSON-RPC messages from stdin, processes them with the handler, and sends responses to stdout.
fn (StdioTransport) send #
fn (mut t StdioTransport) send(response string)
send implements the Transport interface for STDIO communication. It writes the response to stdout and flushes the output buffer.
struct TransportConfig #
struct TransportConfig {
pub:
mode TransportMode = .stdio
http HttpConfig
}
TransportConfig holds configuration for different transport types