Documentation
¶
Index ¶
- Constants
- func ConvertToCallToolResult(data interface{}) (*sdk.CallToolResult, error)
- func ExpandEnvArgs(args []string) []string
- func LogConnectionError(errCtx ConnectionErrorContext, err error)
- func NormalizeInputSchema(schema map[string]interface{}, toolName string) map[string]interface{}
- func ParseToolArguments(req *sdk.CallToolRequest) (map[string]interface{}, error)
- type AgentTagsSnapshot
- 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 ConnectionErrorContext
- type ContentItem
- type ContextKey
- type HTTPTransportType
- type Request
- type Response
- type ResponseError
- type Tool
Constants ¶
const MCPProtocolVersion = "2025-11-25"
MCPProtocolVersion is the MCP protocol version used in initialization requests.
Variables ¶
This section is empty.
Functions ¶
func ConvertToCallToolResult ¶ added in v0.1.16
func ConvertToCallToolResult(data interface{}) (*sdk.CallToolResult, error)
ConvertToCallToolResult converts backend result data to SDK CallToolResult format. The backend returns a JSON object with a "content" field containing an array of content items.
func ExpandEnvArgs ¶ added in v0.1.16
ExpandEnvArgs expands Docker -e flags that reference environment variables. Converts "-e VAR_NAME" to "-e VAR_NAME=value" by reading from the process environment.
func LogConnectionError ¶ added in v0.2.7
func LogConnectionError(errCtx ConnectionErrorContext, err error)
LogConnectionError logs detailed diagnostics for a connection failure, including command context, captured stderr, and actionable hints based on the error type and execution environment. All callers (launcher and mcp connection) use this single function so that hint analysis and output format remain consistent.
func NormalizeInputSchema ¶
NormalizeInputSchema ensures tool input schemas are valid for the MCP SDK The MCP SDK requires that object type schemas have a "properties" field, even if it's empty. This function normalizes schemas to meet that requirement.
Returns a normalized copy of the schema, never modifies the original.
func ParseToolArguments ¶ added in v0.1.16
func ParseToolArguments(req *sdk.CallToolRequest) (map[string]interface{}, error)
ParseToolArguments extracts and unmarshals tool arguments from a CallToolRequest. Returns the parsed arguments as a map, or an error if parsing fails.
Types ¶
type AgentTagsSnapshot ¶ added in v0.1.10
AgentTagsSnapshot contains agent secrecy/integrity tag snapshots for log enrichment.
func GetAgentTagsSnapshotFromContext ¶ added in v0.1.14
func GetAgentTagsSnapshotFromContext(ctx context.Context) (*AgentTagsSnapshot, bool)
GetAgentTagsSnapshotFromContext extracts the agent DIFC tag snapshot from the request context. Used by guards (e.g., write-sink) that need the agent's current labels to mirror onto resources.
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, serverID, 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, serverID, 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:
- Try standard transports in order: 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
Custom headers (e.g. Authorization) are injected into every outgoing request via a custom http.RoundTripper, so the SDK transports are used even when authentication headers are configured.
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 ConnectionErrorContext ¶ added in v0.2.7
type ConnectionErrorContext struct {
ServerID string
SessionID string
Command string
Args []string
Env map[string]string
RunningInContainer bool
IsDirectCommand bool
StartupTimeout time.Duration
StderrOutput string
}
ConnectionErrorContext holds all context needed to produce a detailed connection failure diagnostic. Fields left at their zero values are omitted from the output.
type ContentItem ¶
ContentItem represents a content item in tool responses
type ContextKey ¶
type ContextKey string
ContextKey for session ID
const AgentTagsSnapshotContextKey ContextKey = "awmg-agent-tags-snapshot"
AgentTagsSnapshotContextKey stores a per-request snapshot of agent DIFC tags for enriched logging.
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