mcp

package
v0.0.99 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeInputSchema

func NormalizeInputSchema(schema map[string]interface{}, toolName string) map[string]interface{}

NormalizeInputSchema fixes common schema validation issues in tool definitions that can cause downstream validation errors.

Known issues fixed:

  1. 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.
  2. 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:

  1. 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)
  2. 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) Close

func (c *Connection) Close() error

Close closes the connection

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

type ContentItem struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

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

type Tool

type Tool struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description,omitempty"`
	InputSchema map[string]interface{} `json:"inputSchema"`
}

Tool represents an MCP tool definition

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL