Help us shape the future of Go! Take the 2026 Go Developer Survey

types

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeRequest      = "request"
	TypeResponse     = "response"
	TypeNotification = "notification"
)

Message types

View Source
const (
	ErrorCodeParseError     = -32700
	ErrorCodeInvalidRequest = -32600
	ErrorCodeMethodNotFound = -32601
	ErrorCodeInvalidParams  = -32602
	ErrorCodeInternalError  = -32603
)

Standard error codes

View Source
const (
	EventTypeConnected    = "connected"
	EventTypeDisconnected = "disconnected"
	EventTypeError        = "error"
	EventTypeMessage      = "message"
)
View Source
const (
	ProtocolVersion = "2025-06-18"
)

Protocol version

Variables

This section is empty.

Functions

This section is empty.

Types

type CallToolRequest

type CallToolRequest struct {
	Name      string      `json:"name"`
	Arguments interface{} `json:"arguments,omitempty"`
}

type CallToolResponse

type CallToolResponse struct {
	Content []ToolContent `json:"content"`
	IsError bool          `json:"isError,omitempty"`
}

type CallToolsBatchRequest

type CallToolsBatchRequest struct {
	Tools []ToolCall `json:"tools"`
}

type CallToolsBatchResponse deprecated

type CallToolsBatchResponse = CallToolsResponse

Deprecated: Use CallToolsResponse instead

type CallToolsResponse

type CallToolsResponse struct {
	Results []CallToolResponse `json:"results"`
}

type CancelRequest

type CancelRequest struct {
	RequestID interface{} `json:"requestId"`
}

Cancellation types

type ClientCapabilities

type ClientCapabilities struct {
	Sampling     *SamplingCapability    `json:"sampling,omitempty"`
	Roots        *RootsCapability       `json:"roots,omitempty"`
	Elicitation  *ElicitationCapability `json:"elicitation,omitempty"`
	Experimental map[string]interface{} `json:"experimental,omitempty"`
}

Capabilities

type ClientDSL

type ClientDSL struct {
	ID        string        `json:"id,omitempty"`      // The ID of the MCP Client (required)
	Name      string        `json:"name"`              // The name of the MCP Client (required)
	Version   string        `json:"version,omitempty"` // The version of the MCP Client
	Type      string        `json:"type,omitempty"`    // The type of the MCP Client (e.g., "standard", "agent", "system")
	Transport TransportType `json:"transport"`         // One of the TransportType (required)

	types.MetaInfo

	Dependencies map[string]string `json:"dependencies,omitempty"` // Dependencies on other MCP Clients (name -> version constraint)

	// Client capabilities configuration
	EnableSampling    bool `json:"enable_sampling,omitempty"`    // Enable sampling capability
	EnableRoots       bool `json:"enable_roots,omitempty"`       // Enable roots capability
	RootsListChanged  bool `json:"roots_list_changed,omitempty"` // Whether to be notified of root changes
	EnableElicitation bool `json:"enable_elicitation,omitempty"` // Enable elicitation capability

	// For HTTP, SSE transport
	URL                string `json:"url,omitempty"`                 // For HTTP、SSE transport (optional)
	Endpoint           string `json:"endpoint,omitempty"`            // API endpoint path (e.g., "/api/mcp")
	AuthorizationToken string `json:"authorization_token,omitempty"` // For HTTP、SSE transport

	// For stdio transport
	Command   string            `json:"command,omitempty"`   // for stdio transport
	Arguments []string          `json:"arguments,omitempty"` // for stdio transport
	Env       map[string]string `json:"env,omitempty"`       // for stdio transport

	Timeout string `json:"timeout,omitempty"` // for HTTP、SSE transport (1s, 1m, 1h, 1d)

	// For process transport - mapping data (tools, prompts, resources)
	Tools     map[string]string `json:"tools,omitempty"`     // tool_name -> process_name mapping
	Resources map[string]string `json:"resources,omitempty"` // resource_name -> process_name mapping
	Prompts   map[string]string `json:"prompts,omitempty"`   // prompt_name -> process_name mapping
}

ClientDSL the MCP Client DSL

func (*ClientDSL) GetAuthorizationToken

func (client *ClientDSL) GetAuthorizationToken() string

GetAuthorizationToken get the authorization token

func (*ClientDSL) GetClientCapabilities

func (client *ClientDSL) GetClientCapabilities() ClientCapabilities

GetClientCapabilities get the default client capabilities

func (*ClientDSL) GetEnvs

func (client *ClientDSL) GetEnvs() []string

GetEnvs get the environment variables

func (*ClientDSL) GetImplementation

func (client *ClientDSL) GetImplementation() Implementation

GetImplementation get the implementation info

func (*ClientDSL) GetTimeout

func (client *ClientDSL) GetTimeout() time.Duration

GetTimeout get the timeout

func (*ClientDSL) GetVersion

func (client *ClientDSL) GetVersion() string

GetVersion get the version, default to "1.0.0" if not set

type ClientInfo

type ClientInfo struct {
	ID           string            `json:"id,omitempty"`           // Client ID
	Name         string            `json:"name"`                   // Client name
	Version      string            `json:"version,omitempty"`      // Client version
	Type         string            `json:"type,omitempty"`         // Client type (standard, agent, system)
	Transport    TransportType     `json:"transport,omitempty"`    // Transport type
	Label        string            `json:"label,omitempty"`        // Display label
	Description  string            `json:"description,omitempty"`  // Description
	Tags         []string          `json:"tags,omitempty"`         // Tags for search and filtering
	Dependencies map[string]string `json:"dependencies,omitempty"` // Dependencies (name -> version constraint)
}

Client and Server info

type Config

type Config struct {
	ServerCommand []string               `json:"serverCommand,omitempty"`
	ServerEnv     map[string]string      `json:"serverEnv,omitempty"`
	InitOptions   map[string]interface{} `json:"initOptions,omitempty"`
	Timeout       time.Duration          `json:"timeout,omitempty"`
}

Configuration

type ConnectionOptions

type ConnectionOptions struct {
	// Headers for HTTP/SSE transports (e.g., Mcp-Session-Id, Custom-Auth, etc.)
	Headers map[string]string `json:"headers,omitempty"`
	// Timeout for connection establishment
	Timeout time.Duration `json:"timeout,omitempty"`
	// Retry configuration
	MaxRetries int           `json:"max_retries,omitempty"`
	RetryDelay time.Duration `json:"retry_delay,omitempty"`
}

ConnectionOptions provides options for establishing connection

type ConnectionState

type ConnectionState string

Connection state

const (
	StateDisconnected ConnectionState = "disconnected"
	StateConnecting   ConnectionState = "connecting"
	StateConnected    ConnectionState = "connected"
	StateInitialized  ConnectionState = "initialized"
	StateError        ConnectionState = "error"
)

type ElicitationCapability

type ElicitationCapability struct{}

type EmbeddedResource

type EmbeddedResource struct {
	URI      string `json:"uri"`
	MimeType string `json:"mimeType"`
	Text     string `json:"text,omitempty"`
	Blob     string `json:"blob,omitempty"` // base64-encoded binary data
}

EmbeddedResource represents an embedded resource in prompt content

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

Error represents a JSON-RPC error

type ErrorHandler

type ErrorHandler func(ctx context.Context, err error) error

type Event

type Event struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

Event types

type GetPromptRequest

type GetPromptRequest struct {
	Name      string                 `json:"name"`
	Arguments map[string]interface{} `json:"arguments,omitempty"`
}

type GetPromptResponse

type GetPromptResponse struct {
	Description string          `json:"description,omitempty"`
	Messages    []PromptMessage `json:"messages"`
}

type Implementation

type Implementation struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Implementation describes the name and version of an MCP implementation

type InitializeRequest

type InitializeRequest struct {
	ProtocolVersion string                 `json:"protocolVersion"`
	Capabilities    ClientCapabilities     `json:"capabilities"`
	ClientInfo      ClientInfo             `json:"clientInfo"`
	Meta            map[string]interface{} `json:"meta,omitempty"`
}

Initialize request and response

type InitializeResponse

type InitializeResponse struct {
	ProtocolVersion string                 `json:"protocolVersion"`
	Capabilities    ServerCapabilities     `json:"capabilities"`
	ServerInfo      ServerInfo             `json:"serverInfo"`
	Meta            map[string]interface{} `json:"meta,omitempty"`
}

type ListPromptsRequest

type ListPromptsRequest struct {
	Cursor string `json:"cursor,omitempty"`
}

type ListPromptsResponse

type ListPromptsResponse struct {
	Prompts    []Prompt `json:"prompts"`
	NextCursor string   `json:"nextCursor,omitempty"`
}

type ListResourcesRequest

type ListResourcesRequest struct {
	Cursor string `json:"cursor,omitempty"`
}

type ListResourcesResponse

type ListResourcesResponse struct {
	Resources  []Resource `json:"resources"`
	NextCursor string     `json:"nextCursor,omitempty"`
}

type ListSamplesResponse

type ListSamplesResponse struct {
	Samples []SampleData `json:"samples"`
	Total   int          `json:"total"`
}

type ListToolsRequest

type ListToolsRequest struct {
	Cursor string `json:"cursor,omitempty"`
}

type ListToolsResponse

type ListToolsResponse struct {
	Tools      []Tool `json:"tools"`
	NextCursor string `json:"nextCursor,omitempty"`
}

type LogLevel

type LogLevel string

Logging types

const (
	LogLevelDebug     LogLevel = "debug"
	LogLevelInfo      LogLevel = "info"
	LogLevelNotice    LogLevel = "notice"
	LogLevelWarning   LogLevel = "warning"
	LogLevelError     LogLevel = "error"
	LogLevelCritical  LogLevel = "critical"
	LogLevelAlert     LogLevel = "alert"
	LogLevelEmergency LogLevel = "emergency"
)

type LogMessage

type LogMessage struct {
	Level  LogLevel               `json:"level"`
	Data   interface{}            `json:"data"`
	Logger string                 `json:"logger,omitempty"`
	Meta   map[string]interface{} `json:"meta,omitempty"`
}

type LoggingCapability

type LoggingCapability struct{}

type MappingData

type MappingData struct {
	Tools     map[string]*ToolSchema     `json:"tools"`     // tool_name -> ToolSchema
	Resources map[string]*ResourceSchema `json:"resources"` // resource_name -> ResourceSchema
	Prompts   map[string]*PromptSchema   `json:"prompts"`   // prompt_name -> PromptSchema
}

MappingData contains all loaded schemas for a process-based MCP client

type Message

type Message struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      interface{} `json:"id,omitempty"`
	Method  string      `json:"method,omitempty"`
	Params  interface{} `json:"params,omitempty"`
	Result  interface{} `json:"result,omitempty"`
	Error   *Error      `json:"error,omitempty"`
}

Message JSON-RPC 2.0 message structure

type NotificationHandler

type NotificationHandler func(ctx context.Context, notification Message) error

type Progress

type Progress struct {
	Token uint64 `json:"token"`
	Total uint64 `json:"total,omitempty"`
}

Progress types

type ProgressNotification

type ProgressNotification struct {
	Token    uint64 `json:"token"`
	Progress uint64 `json:"progress"`
	Total    uint64 `json:"total,omitempty"`
}

type Prompt

type Prompt struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description,omitempty"`
	Arguments   []PromptArgument       `json:"arguments,omitempty"`
	Meta        map[string]interface{} `json:"meta,omitempty"`
}

Prompt types

type PromptArgument

type PromptArgument struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

type PromptContent

type PromptContent struct {
	Type PromptContentType `json:"type"`

	// Text content
	Text string `json:"text,omitempty"`

	// Image content
	Data     string `json:"data,omitempty"`     // base64-encoded data for image/audio
	MimeType string `json:"mimeType,omitempty"` // MIME type for image/audio

	// Resource content
	Resource *EmbeddedResource `json:"resource,omitempty"`
}

type PromptContentType

type PromptContentType string

PromptContentType represents the type of prompt content

const (
	PromptContentTypeText     PromptContentType = "text"
	PromptContentTypeImage    PromptContentType = "image"
	PromptContentTypeAudio    PromptContentType = "audio"
	PromptContentTypeResource PromptContentType = "resource"
)

type PromptMessage

type PromptMessage struct {
	Role    PromptRole    `json:"role"`
	Content PromptContent `json:"content"`
}

type PromptRole

type PromptRole string

PromptRole represents the role of a prompt message

const (
	PromptRoleUser      PromptRole = "user"
	PromptRoleAssistant PromptRole = "assistant"
)

type PromptSchema

type PromptSchema struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description,omitempty"`
	Template    string                 `json:"template"` // Prompt template content
	Arguments   []PromptArgument       `json:"arguments,omitempty"`
	Meta        map[string]interface{} `json:"meta,omitempty"`
}

PromptSchema represents a prompt template definition

type PromptsCapability

type PromptsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

type ReadResourceRequest

type ReadResourceRequest struct {
	URI string `json:"uri"`
}

type ReadResourceResponse

type ReadResourceResponse struct {
	Contents []ResourceContent `json:"contents"`
}

type RequestHandler

type RequestHandler func(ctx context.Context, request Message) (interface{}, error)

Handler function types

type Resource

type Resource struct {
	URI         string                 `json:"uri"`
	Name        string                 `json:"name"`
	Description string                 `json:"description,omitempty"`
	MimeType    string                 `json:"mimeType,omitempty"`
	Meta        map[string]interface{} `json:"meta,omitempty"`
}

Resource types

type ResourceContent

type ResourceContent struct {
	URI      string `json:"uri"`
	MimeType string `json:"mimeType"`
	Text     string `json:"text,omitempty"`
	Blob     []byte `json:"blob,omitempty"`
}

type ResourceParameter

type ResourceParameter struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

ResourceParameter defines a parameter for a resource URI

type ResourceSchema

type ResourceSchema struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description,omitempty"`
	Process     string                 `json:"process"` // Yao process name
	URI         string                 `json:"uri"`     // URI template (e.g., "customer://{id}")
	MimeType    string                 `json:"mimeType,omitempty"`
	Parameters  []ResourceParameter    `json:"parameters,omitempty"` // URI parameters
	Meta        map[string]interface{} `json:"meta,omitempty"`
	ProcessArgs []string               `json:"x-process-args,omitempty"` // Mapping from URI/parameters to Process positional args
}

ResourceSchema represents a resource definition

type ResourceUpdatedNotification

type ResourceUpdatedNotification struct {
	URI string `json:"uri"`
}

type ResourcesCapability

type ResourcesCapability struct {
	Subscribe   bool `json:"subscribe,omitempty"`
	ListChanged bool `json:"listChanged,omitempty"`
}

type RootsCapability

type RootsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

type SampleData

type SampleData struct {
	Index    int    `json:"index"`               // Auto-generated index (set by loader)
	Name     string `json:"name,omitempty"`      // Optional sample name
	ItemName string `json:"item_name,omitempty"` // Tool/Resource name (set by loader)

	// Multi-purpose fields (semantics depend on item type)
	Input  map[string]interface{} `json:"input,omitempty"`  // For tools: input args; For resources: parsed from URI
	Output interface{}            `json:"output,omitempty"` // For tools: expected output; Not used for resources
	URI    string                 `json:"uri,omitempty"`    // For resources: full URI with params
	Data   interface{}            `json:"data,omitempty"`   // For resources: response data

	Metadata  map[string]interface{} `json:"metadata,omitempty"`  // Optional metadata (e.g., description)
	Timestamp string                 `json:"timestamp,omitempty"` // Optional timestamp
}

Sample types - for training/example data from .jsonl files

type SampleItemType

type SampleItemType string

SampleItemType represents the type of item for samples

const (
	SampleTool     SampleItemType = "tool"
	SampleResource SampleItemType = "resource"
)

Sample item types

type SamplingCapability

type SamplingCapability struct{}

type SamplingContent

type SamplingContent struct {
	Type     string `json:"type"`
	Text     string `json:"text,omitempty"`
	ImageURL string `json:"imageUrl,omitempty"`
}

type SamplingMessage

type SamplingMessage struct {
	Role    string          `json:"role"`
	Content SamplingContent `json:"content"`
}

type SamplingRequest

type SamplingRequest struct {
	Model          string                 `json:"model"`
	Messages       []SamplingMessage      `json:"messages"`
	SystemPrompt   string                 `json:"systemPrompt,omitempty"`
	IncludeContext string                 `json:"includeContext,omitempty"`
	Temperature    float64                `json:"temperature,omitempty"`
	MaxTokens      int                    `json:"maxTokens,omitempty"`
	StopSequences  []string               `json:"stopSequences,omitempty"`
	Meta           map[string]interface{} `json:"meta,omitempty"`
}

Sampling types (LLM text generation - MCP protocol standard)

type SamplingResponse

type SamplingResponse struct {
	Model      string          `json:"model"`
	Role       string          `json:"role"`
	Content    SamplingContent `json:"content"`
	StopReason string          `json:"stopReason,omitempty"`
}

type ServerCapabilities

type ServerCapabilities struct {
	Resources    *ResourcesCapability   `json:"resources,omitempty"`
	Tools        *ToolsCapability       `json:"tools,omitempty"`
	Prompts      *PromptsCapability     `json:"prompts,omitempty"`
	Logging      *LoggingCapability     `json:"logging,omitempty"`
	Experimental map[string]interface{} `json:"experimental,omitempty"`
}

type ServerInfo

type ServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type SetLogLevelRequest

type SetLogLevelRequest struct {
	Level LogLevel `json:"level"`
}

type Tool

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

Tool types

type ToolCall

type ToolCall struct {
	Name      string      `json:"name"`
	Arguments interface{} `json:"arguments,omitempty"`
}

Batch tool call types

type ToolContent

type ToolContent struct {
	Type ToolContentType `json:"type"`

	// Text content
	Text string `json:"text,omitempty"`

	// Image content (base64 encoded)
	Data     string `json:"data,omitempty"`     // base64-encoded image data
	MimeType string `json:"mimeType,omitempty"` // MIME type for image

	// Resource content
	Resource *EmbeddedResource `json:"resource,omitempty"`
}

type ToolContentType

type ToolContentType string

ToolContentType represents the type of tool content

const (
	ToolContentTypeText     ToolContentType = "text"
	ToolContentTypeImage    ToolContentType = "image"
	ToolContentTypeResource ToolContentType = "resource"
)

type ToolSchema

type ToolSchema struct {
	Name         string          `json:"name"`
	Description  string          `json:"description,omitempty"`
	Process      string          `json:"process"`                  // Yao process name
	InputSchema  json.RawMessage `json:"inputSchema"`              // JSON Schema for input
	OutputSchema json.RawMessage `json:"outputSchema,omitempty"`   // Optional JSON Schema for output
	ProcessArgs  []string        `json:"x-process-args,omitempty"` // Mapping from MCP arguments to Process positional args
}

ToolSchema represents a tool's input/output schema

type ToolsCapability

type ToolsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

type Transport

type Transport interface {
	Start(ctx context.Context) error
	Stop() error
	Send(message Message) error
	Receive() (<-chan Message, error)
	Close() error
}

Transport interface

type TransportType

type TransportType string

TransportType the transport type

const (
	// TransportHTTP the HTTP transport
	TransportHTTP TransportType = "http"
	// TransportSSE the SSE transport
	TransportSSE TransportType = "sse"
	// TransportStdio the Stdio transport
	TransportStdio TransportType = "stdio"
	// TransportProcess the Yao transport ( For Yao internal processes)
	TransportProcess TransportType = "process"
)

Jump to

Keyboard shortcuts

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