mcp

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

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

Common JSON-RPC error codes

Variables

This section is empty.

Functions

func SanitizeError

func SanitizeError(err error) string

SanitizeError sanitizes error messages to prevent information disclosure

func SanitizeString

func SanitizeString(s string) string

SanitizeString sanitizes a string by removing/replacing dangerous characters

Types

type Annotation

type Annotation struct {
	Type     string `json:"type"`
	Text     string `json:"text,omitempty"`
	Audience string `json:"audience,omitempty"`
	Priority string `json:"priority,omitempty"`
}

Annotation represents an annotation

func CreateAnnotation

func CreateAnnotation(annoType AnnotationType, text string, audience Audience, priority Priority) Annotation

CreateAnnotation creates a new annotation

type AnnotationType

type AnnotationType string

AnnotationType represents different annotation types

const (
	AnnotationTypeInfo    AnnotationType = "info"
	AnnotationTypeWarning AnnotationType = "warning"
	AnnotationTypeError   AnnotationType = "error"
)

type Audience

type Audience string

Audience represents annotation audience

const (
	AudienceUser      Audience = "user"
	AudienceAssistant Audience = "assistant"
)

type ClientInfo

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

ClientInfo represents the client information

type ContentBlock

type ContentBlock struct {
	Type     ContentType `json:"type"`
	Text     string      `json:"text,omitempty"`
	Data     string      `json:"data,omitempty"`
	MimeType string      `json:"mimeType,omitempty"`
}

ContentBlock represents a content block

func AudioContent

func AudioContent(data, mimeType string) ContentBlock

AudioContent creates an audio content block

func ImageContent

func ImageContent(data, mimeType string) ContentBlock

ImageContent creates an image content block

func TextContent

func TextContent(text string) ContentBlock

TextContent creates a text content block

type ContentType

type ContentType string

ContentType represents different content types

const (
	ContentTypeText  ContentType = "text"
	ContentTypeImage ContentType = "image"
	ContentTypeAudio ContentType = "audio"
)

type EmbeddedResource

type EmbeddedResource struct {
	Type     string           `json:"type"`
	Resource ResourceContents `json:"resource"`
}

EmbeddedResource represents an embedded resource

type InitializationResult

type InitializationResult struct {
	ProtocolVersion string             `json:"protocolVersion"`
	Capabilities    ServerCapabilities `json:"capabilities"`
	ServerInfo      ServerInfo         `json:"serverInfo"`
}

InitializationResult represents the initialization result

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string                 `json:"jsonrpc"`
	Method  string                 `json:"method"`
	Params  map[string]interface{} `json:"params,omitempty"`
	ID      RequestID              `json:"id"`
}

JSONRPCRequest represents a JSON-RPC 2.0 request

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string      `json:"jsonrpc"`
	Result  interface{} `json:"result,omitempty"`
	Error   *RPCError   `json:"error,omitempty"`
	ID      RequestID   `json:"id"`
}

JSONRPCResponse represents a JSON-RPC 2.0 response

type Priority

type Priority string

Priority represents annotation priority

const (
	PriorityLow    Priority = "low"
	PriorityMedium Priority = "medium"
	PriorityHigh   Priority = "high"
)

type PromptsCapability

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

PromptsCapability represents prompts capability

type RPCError

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

RPCError represents a JSON-RPC 2.0 error

func (*RPCError) Error

func (e *RPCError) Error() string

Error implements the error interface

type RequestID

type RequestID struct {
	Value interface{}
}

RequestID can be either a string or a number

func (RequestID) MarshalJSON

func (r RequestID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (RequestID) String

func (r RequestID) String() string

String returns string representation of RequestID

func (*RequestID) UnmarshalJSON

func (r *RequestID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type ResourceContents

type ResourceContents struct {
	URI      string `json:"uri"`
	MimeType string `json:"mimeType,omitempty"`
	Text     string `json:"text,omitempty"`
	Blob     string `json:"blob,omitempty"`
}

ResourceContents represents resource contents

type ResourceLink struct {
	URI         string `json:"uri"`
	Description string `json:"description,omitempty"`
}

ResourceLink represents a resource link

type ResourcesCapability

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

ResourcesCapability represents resources capability

type Role

type Role string

Role represents different roles in MCP

const (
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleSystem    Role = "system"
)

type ServerCapabilities

type ServerCapabilities struct {
	Tools     *ToolsCapability     `json:"tools,omitempty"`
	Prompts   *PromptsCapability   `json:"prompts,omitempty"`
	Resources *ResourcesCapability `json:"resources,omitempty"`
}

ServerCapabilities represents server capabilities

type ServerInfo

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

ServerInfo represents the server information

type Tool

type Tool struct {
	Name         string      `json:"name"`
	Description  string      `json:"description"`
	InputSchema  interface{} `json:"inputSchema"`
	OutputSchema interface{} `json:"outputSchema,omitempty"`
}

Tool represents an MCP tool

type ToolCallResult

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

ToolCallResult represents the result of a tool call

type ToolsCapability

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

ToolsCapability represents tools capability

type ToolsListResult

type ToolsListResult struct {
	Tools []Tool `json:"tools"`
}

ToolsListResult represents the result of listing tools

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

ValidationError represents a validation error

func (ValidationError) Error

func (e ValidationError) Error() string

Error implements the error interface

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors represents multiple validation errors

func (*ValidationErrors) Add

func (e *ValidationErrors) Add(field, message string)

Add adds a validation error

func (ValidationErrors) Error

func (e ValidationErrors) Error() string

Error implements the error interface

func (ValidationErrors) HasErrors

func (e ValidationErrors) HasErrors() bool

HasErrors returns true if there are validation errors

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator provides validation functionality

func NewValidator

func NewValidator() *Validator

NewValidator creates a new validator with default settings

func (*Validator) ValidateRequest

func (v *Validator) ValidateRequest(req *JSONRPCRequest) error

ValidateRequest validates a JSON-RPC request

func (*Validator) ValidateTool

func (v *Validator) ValidateTool(tool *Tool) error

ValidateTool validates a tool definition

func (*Validator) ValidateToolCallParams

func (v *Validator) ValidateToolCallParams(params map[string]interface{}) error

ValidateToolCallParams validates tool call parameters

Jump to

Keyboard shortcuts

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