Documentation
¶
Index ¶
- func NormalizeInputSchema(schema map[string]interface{}, toolName string) map[string]interface{}
- func SetClientGatewayVersion(version string)
- type CallToolParams
- type Connection
- func (c *Connection) Close() error
- func (c *Connection) GetHTTPHeaders() map[string]string
- func (c *Connection) GetHTTPURL() string
- func (c *Connection) IsHTTP() bool
- func (c *Connection) SendRequest(method string, params interface{}) (*Response, error)
- func (c *Connection) SendRequestWithServerID(ctx context.Context, method string, params interface{}, serverID string) (*Response, error)
- type ContentItem
- type ContextKey
- type HTTPTransportType
- type Request
- type Response
- type ResponseError
- type Tool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeInputSchema ¶
NormalizeInputSchema fixes common schema validation issues in tool definitions that can cause downstream validation errors.
Known issues fixed:
- Missing schema: When a backend returns no inputSchema (nil), we provide a default empty object schema that accepts any properties. This is required by the MCP SDK's Server.AddTool method.
- Object schemas without properties: When a schema declares "type": "object" but is missing the required "properties" field, we add an empty properties object to make it valid per JSON Schema standards.
func SetClientGatewayVersion ¶
func SetClientGatewayVersion(version string)
SetClientGatewayVersion sets the gateway version for MCP client implementation reporting
Types ¶
type CallToolParams ¶
type CallToolParams struct {
Name string `json:"name"`
Arguments map[string]interface{} `json:"arguments,omitempty"`
}
CallToolParams represents parameters for calling a tool
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection represents a connection to an MCP server using the official SDK
func NewConnection ¶
func NewConnection(ctx context.Context, command string, args []string, env map[string]string) (*Connection, error)
NewConnection creates a new MCP connection using the official SDK
func NewHTTPConnection ¶
func NewHTTPConnection(ctx context.Context, url string, headers map[string]string) (*Connection, error)
NewHTTPConnection creates a new HTTP-based MCP connection with transport fallback For HTTP servers that are already running, we connect and initialize a session
This function implements a fallback strategy for HTTP transports:
- If custom headers are provided, skip SDK transports (they don't support custom headers) and use plain JSON-RPC 2.0 over HTTP POST (for safeinputs compatibility)
- Otherwise, try standard transports: a. Streamable HTTP (2025-03-26 spec) using SDK's StreamableClientTransport b. SSE (2024-11-05 spec) using SDK's SSEClientTransport c. Plain JSON-RPC 2.0 over HTTP POST as final fallback
This ensures compatibility with all types of HTTP MCP servers.
func (*Connection) GetHTTPHeaders ¶
func (c *Connection) GetHTTPHeaders() map[string]string
GetHTTPHeaders returns the HTTP headers for this connection
func (*Connection) GetHTTPURL ¶
func (c *Connection) GetHTTPURL() string
GetHTTPURL returns the HTTP URL for this connection
func (*Connection) IsHTTP ¶
func (c *Connection) IsHTTP() bool
IsHTTP returns true if this is an HTTP connection
func (*Connection) SendRequest ¶
func (c *Connection) SendRequest(method string, params interface{}) (*Response, error)
SendRequest sends a JSON-RPC request and waits for the response The serverID parameter is used for logging to associate the request with a backend server
func (*Connection) SendRequestWithServerID ¶
func (c *Connection) SendRequestWithServerID(ctx context.Context, method string, params interface{}, serverID string) (*Response, error)
SendRequestWithServerID sends a JSON-RPC request with server ID for logging The ctx parameter is used to extract session ID for HTTP MCP servers
type ContentItem ¶
ContentItem represents a content item in tool responses
type ContextKey ¶
type ContextKey string
ContextKey for session ID
const SessionIDContextKey ContextKey = "awmg-session-id"
SessionIDContextKey is used to store MCP session ID in context This is the same key used in the server package to avoid circular dependencies
type HTTPTransportType ¶
type HTTPTransportType string
HTTPTransportType represents the type of HTTP transport being used
const ( // HTTPTransportStreamable uses the streamable HTTP transport (2025-03-26 spec) HTTPTransportStreamable HTTPTransportType = "streamable" // HTTPTransportSSE uses the SSE transport (2024-11-05 spec) HTTPTransportSSE HTTPTransportType = "sse" // HTTPTransportPlainJSON uses plain JSON-RPC 2.0 over HTTP POST (non-standard) HTTPTransportPlainJSON HTTPTransportType = "plain-json" )
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id,omitempty"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Request represents a JSON-RPC 2.0 request
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *ResponseError `json:"error,omitempty"`
}
Response represents a JSON-RPC 2.0 response
type ResponseError ¶
type ResponseError struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
ResponseError represents a JSON-RPC 2.0 error