Documentation
¶
Index ¶
- func CreateTestServerExecutable(outputPath string) error
- func FindConfigFile(projectRoot string) (string, error)
- func GetConfigPath(projectRoot string) (string, bool)
- func IsNotification(data []byte) bool
- func IsRequest(data []byte) bool
- func IsResponse(data []byte) bool
- func ParseMessage(data []byte) (interface{}, error)
- func WriteTestServerToFile(filename string) error
- type CallToolRequest
- type CallToolResult
- type Client
- func (c *Client) CallTool(ctx context.Context, toolName string, arguments map[string]interface{}) (*CallToolResult, error)
- func (c *Client) Close() error
- func (c *Client) ConnectToServers(ctx context.Context) error
- func (c *Client) GetTools() []tools.Tool
- func (c *Client) GetToolsByServer() map[string][]tools.Tool
- type ClientCapabilities
- type ClientInfo
- type Config
- type Connectable
- type Content
- type Error
- type HTTPTransport
- type InitializeRequest
- type InitializeResult
- type ListToolsRequest
- type ListToolsResult
- type LoggingCapability
- type MCPTool
- type Notification
- type PromptsCapability
- type Request
- type ResourcesCapability
- type Response
- type SSETransport
- type SamplingCapability
- type ServerCapabilities
- type ServerConfig
- type ServerConnection
- type ServerInfo
- type StdioTransport
- type TestMCPServer
- type Tool
- type ToolSchema
- type ToolSchemaProperty
- type ToolsCapability
- type Transport
- type TransportFactory
- type TransportType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTestServerExecutable ¶
CreateTestServerExecutable creates a standalone executable for the test MCP server
func FindConfigFile ¶
FindConfigFile looks for .mcp.json files in project and user scope
func GetConfigPath ¶
GetConfigPath returns the path to the MCP configuration file if it exists
func IsNotification ¶
IsNotification checks if the message is a notification
func ParseMessage ¶
ParseMessage parses a JSON message into the appropriate type
func WriteTestServerToFile ¶
WriteTestServerToFile writes a simple test server to a file for subprocess execution
Types ¶
type CallToolRequest ¶
type CallToolRequest struct {
Name string `json:"name"`
Arguments map[string]interface{} `json:"arguments"`
}
CallToolRequest represents a tool execution request
type CallToolResult ¶
CallToolResult represents the result of a tool execution
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an MCP client that can connect to MCP servers
func NewMCPClientFromConfig ¶
NewMCPClientFromConfig creates an MCP client by discovering and loading configuration files
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, toolName string, arguments map[string]interface{}) (*CallToolResult, error)
CallTool executes an MCP tool
func (*Client) ConnectToServers ¶
ConnectToServers connects to all configured MCP servers
type ClientCapabilities ¶
type ClientCapabilities struct {
Experimental map[string]interface{} `json:"experimental,omitempty"`
Sampling *SamplingCapability `json:"sampling,omitempty"`
}
ClientCapabilities describes what the client supports
type ClientInfo ¶
ClientInfo contains information about the client
type Config ¶
type Config struct {
McpServers map[string]ServerConfig `json:"mcpServers"`
}
Config represents the structure of .mcp.json configuration files
func LoadConfig ¶
LoadConfig loads MCP configuration from a .mcp.json file
func LoadProjectConfig ¶
LoadProjectConfig loads MCP configuration from a specific project directory
func LoadUserConfig ¶
LoadUserConfig loads MCP configuration from user-scoped locations
type Connectable ¶
Connectable is an optional interface for transports that need explicit connection
type Error ¶
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
Error represents a JSON-RPC 2.0 error
type HTTPTransport ¶
type HTTPTransport struct {
// contains filtered or unexported fields
}
HTTPTransport implements MCP communication over HTTP
func NewHTTPTransport ¶
func NewHTTPTransport(baseURL string, headers map[string]string) *HTTPTransport
NewHTTPTransport creates a new HTTP transport
func (*HTTPTransport) Connect ¶
func (t *HTTPTransport) Connect(ctx context.Context) error
Connect establishes the HTTP connection (no-op for HTTP)
func (*HTTPTransport) IsConnected ¶
func (t *HTTPTransport) IsConnected() bool
IsConnected returns true if the HTTP transport is connected
type InitializeRequest ¶
type InitializeRequest struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities ClientCapabilities `json:"capabilities"`
ClientInfo ClientInfo `json:"clientInfo"`
}
InitializeRequest is sent to establish a connection with an MCP server
type InitializeResult ¶
type InitializeResult struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities ServerCapabilities `json:"capabilities"`
ServerInfo ServerInfo `json:"serverInfo"`
}
InitializeResult is the response to an initialize request
type ListToolsRequest ¶
type ListToolsRequest struct{}
ListToolsRequest requests the list of available tools
type ListToolsResult ¶
type ListToolsResult struct {
Tools []Tool `json:"tools"`
}
ListToolsResult contains the list of available tools
type LoggingCapability ¶
type LoggingCapability struct{}
LoggingCapability indicates if the server supports logging
type MCPTool ¶
type MCPTool struct {
// contains filtered or unexported fields
}
MCPTool wraps an MCP tool to implement Genie's Tool interface
func (*MCPTool) Declaration ¶
func (t *MCPTool) Declaration() *ai.FunctionDeclaration
Declaration converts MCP tool schema to Genie's function declaration
func (*MCPTool) FormatOutput ¶
FormatOutput formats the tool result for display
func (*MCPTool) Handler ¶
func (t *MCPTool) Handler() ai.HandlerFunc
Handler returns the execution handler for the MCP tool
type Notification ¶
type Notification struct {
Jsonrpc string `json:"jsonrpc"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
Notification represents a JSON-RPC 2.0 notification (no response expected)
func NewNotification ¶
func NewNotification(method string, params interface{}) *Notification
NewNotification creates a new JSON-RPC 2.0 notification
type PromptsCapability ¶
type PromptsCapability struct {
ListChanged bool `json:"listChanged,omitempty"`
}
PromptsCapability indicates if the server supports prompts
type Request ¶
type Request struct {
Jsonrpc string `json:"jsonrpc"`
ID interface{} `json:"id,omitempty"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
Request represents a JSON-RPC 2.0 request
func NewRequest ¶
NewRequest creates a new JSON-RPC 2.0 request
type ResourcesCapability ¶
type ResourcesCapability struct {
Subscribe bool `json:"subscribe,omitempty"`
ListChanged bool `json:"listChanged,omitempty"`
}
ResourcesCapability indicates if the server supports resources
type Response ¶
type Response struct {
Jsonrpc string `json:"jsonrpc"`
ID interface{} `json:"id,omitempty"`
Result interface{} `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
Response represents a JSON-RPC 2.0 response
func NewErrorResponse ¶
NewErrorResponse creates a new JSON-RPC 2.0 error response
func NewResponse ¶
func NewResponse(id interface{}, result interface{}) *Response
NewResponse creates a new JSON-RPC 2.0 response
type SSETransport ¶
type SSETransport struct {
// contains filtered or unexported fields
}
SSETransport implements MCP communication over Server-Sent Events
func NewSSETransport ¶
func NewSSETransport(url string, headers map[string]string) *SSETransport
NewSSETransport creates a new SSE transport
func (*SSETransport) Connect ¶
func (t *SSETransport) Connect(ctx context.Context) error
Connect establishes the SSE connection
func (*SSETransport) IsConnected ¶
func (t *SSETransport) IsConnected() bool
IsConnected returns true if the SSE transport is connected
type SamplingCapability ¶
type SamplingCapability struct{}
SamplingCapability indicates if the client supports sampling
type ServerCapabilities ¶
type ServerCapabilities struct {
Experimental map[string]interface{} `json:"experimental,omitempty"`
Logging *LoggingCapability `json:"logging,omitempty"`
Prompts *PromptsCapability `json:"prompts,omitempty"`
Resources *ResourcesCapability `json:"resources,omitempty"`
Tools *ToolsCapability `json:"tools,omitempty"`
}
ServerCapabilities describes what the server supports
type ServerConfig ¶
type ServerConfig struct {
// For stdio servers
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
// For SSE/HTTP servers
Type string `json:"type,omitempty"`
URL string `json:"url,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}
ServerConfig defines the configuration for an MCP server
func (ServerConfig) GetTransportType ¶
func (sc ServerConfig) GetTransportType() TransportType
GetTransportType returns the transport type for this server config
func (ServerConfig) Validate ¶
func (sc ServerConfig) Validate() error
Validate checks if the server configuration is valid
type ServerConnection ¶
type ServerConnection struct {
// contains filtered or unexported fields
}
ServerConnection represents a connection to an MCP server
type ServerInfo ¶
ServerInfo contains information about the server
type StdioTransport ¶
type StdioTransport struct {
// contains filtered or unexported fields
}
StdioTransport implements MCP communication over stdio
func NewStdioTransport ¶
func NewStdioTransport(command string, args []string, env []string) *StdioTransport
NewStdioTransport creates a new stdio transport
func (*StdioTransport) Close ¶
func (t *StdioTransport) Close() error
Close closes the stdio transport
func (*StdioTransport) Connect ¶
func (t *StdioTransport) Connect(ctx context.Context) error
Connect establishes the stdio connection
func (*StdioTransport) IsConnected ¶
func (t *StdioTransport) IsConnected() bool
IsConnected returns true if the stdio transport is connected
type TestMCPServer ¶
type TestMCPServer struct {
// contains filtered or unexported fields
}
TestMCPServer is a simple MCP server implementation for testing
func NewTestMCPServer ¶
func NewTestMCPServer() *TestMCPServer
NewTestMCPServer creates a new test MCP server
func (*TestMCPServer) Run ¶
func (s *TestMCPServer) Run()
Run starts the test MCP server using stdio
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema ToolSchema `json:"inputSchema"`
}
Tool represents an MCP tool definition
type ToolSchema ¶
type ToolSchema struct {
Type string `json:"type"`
Properties map[string]ToolSchemaProperty `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
AdditionalProperties interface{} `json:"additionalProperties,omitempty"`
}
ToolSchema represents the JSON schema for tool input
type ToolSchemaProperty ¶
type ToolSchemaProperty struct {
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Enum []string `json:"enum,omitempty"`
Default interface{} `json:"default,omitempty"`
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
Items *ToolSchemaProperty `json:"items,omitempty"` // For array types
Properties map[string]ToolSchemaProperty `json:"properties,omitempty"` // For object types
}
ToolSchemaProperty represents a property in a tool schema
type ToolsCapability ¶
type ToolsCapability struct {
ListChanged bool `json:"listChanged,omitempty"`
}
ToolsCapability indicates if the server supports tools
type Transport ¶
type Transport interface {
// Send sends a message to the server
Send(ctx context.Context, message interface{}) error
// Receive receives a message from the server
Receive(ctx context.Context) ([]byte, error)
// Close closes the transport connection
Close() error
// IsConnected returns true if the transport is connected
IsConnected() bool
}
Transport defines the interface for MCP communication transports
type TransportFactory ¶
type TransportFactory struct{}
TransportFactory creates transports based on server configuration
func NewTransportFactory ¶
func NewTransportFactory() *TransportFactory
NewTransportFactory creates a new transport factory
func (*TransportFactory) CreateTransport ¶
func (f *TransportFactory) CreateTransport(config ServerConfig) (Transport, error)
CreateTransport creates a transport based on the server configuration
type TransportType ¶
type TransportType string
TransportType represents the type of transport for an MCP server
const ( TransportStdio TransportType = "stdio" TransportSSE TransportType = "sse" TransportHTTP TransportType = "http" )