mcp

package module
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotations

type Annotations struct {
	Audience     []string `json:"audience,omitempty"`
	Priority     *float64 `json:"priority,omitempty"`
	LastModified string   `json:"lastModified,omitempty"`
}

Annotations provide hints to clients about how to use or display content.

type AudioContent

type AudioContent struct {
	Type        string       `json:"type"` // "audio"
	Data        string       `json:"data"`
	MimeType    string       `json:"mimeType"`
	Annotations *Annotations `json:"annotations,omitempty"`
}

AudioContent represents base64-encoded audio content.

func NewAudioContent

func NewAudioContent(data string, mimeType string) AudioContent

NewAudioContent creates a new AudioContent with the type field set.

type CancelledParams

type CancelledParams struct {
	RequestID any    `json:"requestId"`
	Reason    string `json:"reason,omitempty"`
}

CancelledParams represents the parameters for a notifications/cancelled notification.

type Capabilities

type Capabilities struct {
	Tools       *ToolsCapability       `json:"tools,omitempty"`
	Resources   *ResourcesCapability   `json:"resources,omitempty"`
	Prompts     *PromptsCapability     `json:"prompts,omitempty"`
	Logging     *LoggingCapability     `json:"logging,omitempty"`
	Completions *CompletionsCapability `json:"completions,omitempty"`
}

type ClientInfo

type ClientInfo struct {
	Name        string `json:"name"`
	Title       string `json:"title,omitempty"`
	Version     string `json:"version"`
	Description string `json:"description,omitempty"`
	Icons       []Icon `json:"icons,omitempty"`
	WebsiteURL  string `json:"websiteUrl,omitempty"`
}

type CompleteArgument

type CompleteArgument struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type CompleteContext

type CompleteContext struct {
	Arguments map[string]string `json:"arguments,omitempty"`
}

type CompleteRequest

type CompleteRequest struct {
	Ref      CompletionRef    `json:"ref"`
	Argument CompleteArgument `json:"argument"`
	Context  *CompleteContext `json:"context,omitempty"`
}

type CompleteResult

type CompleteResult struct {
	Completion CompletionValues `json:"completion"`
}

type CompletionHandler

type CompletionHandler func(req CompleteRequest) (CompletionValues, error)

CompletionHandler represents a function that provides completion suggestions.

type CompletionHandlers

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

CompletionHandlers holds registered completion handlers.

func (*CompletionHandlers) Add

func (ch *CompletionHandlers) Add(refKey string, handler CompletionHandler)

func (*CompletionHandlers) GetHandler

func (ch *CompletionHandlers) GetHandler(refKey string) CompletionHandler

type CompletionRef

type CompletionRef struct {
	Type string `json:"type"` // "ref/prompt" or "ref/resource"
	Name string `json:"name,omitempty"`
	URI  string `json:"uri,omitempty"`
}

type CompletionValues

type CompletionValues struct {
	Values  []string `json:"values"`
	Total   int      `json:"total,omitempty"`
	HasMore bool     `json:"hasMore,omitempty"`
}

type CompletionsCapability

type CompletionsCapability struct{}

type EmbeddedResourceContent

type EmbeddedResourceContent struct {
	Type        string          `json:"type"` // "resource"
	Resource    ResourceContent `json:"resource"`
	Annotations *Annotations    `json:"annotations,omitempty"`
}

EmbeddedResourceContent represents an embedded resource in content.

func NewEmbeddedResourceContent

func NewEmbeddedResourceContent(resource ResourceContent) EmbeddedResourceContent

NewEmbeddedResourceContent creates a new EmbeddedResourceContent with the type field set.

type EmptyResult

type EmptyResult struct{}

EmptyResult represents an empty JSON-RPC result {}.

type GetPromptResult

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

type HealthCheckResponse

type HealthCheckResponse struct {
	Status  string `json:"status"`
	Server  string `json:"server"`
	Version string `json:"version"`
}

type Icon

type Icon struct {
	Src      string   `json:"src"`
	MimeType string   `json:"mimeType,omitempty"`
	Sizes    []string `json:"sizes,omitempty"`
}

Icon represents an icon for display in user interfaces.

type ImageContent

type ImageContent struct {
	Type        string       `json:"type"` // "image"
	Data        string       `json:"data"`
	MimeType    string       `json:"mimeType"`
	Annotations *Annotations `json:"annotations,omitempty"`
}

ImageContent represents base64-encoded image content.

func NewImageContent

func NewImageContent(data string, mimeType string) ImageContent

NewImageContent creates a new ImageContent with the type field set.

type InitializeParams

type InitializeParams struct {
	ProtocolVersion string         `json:"protocolVersion"`
	Capabilities    map[string]any `json:"capabilities"`
	ClientInfo      ClientInfo     `json:"clientInfo"`
}

type InitializeResult

type InitializeResult struct {
	ProtocolVersion string       `json:"protocolVersion"`
	Capabilities    Capabilities `json:"capabilities"`
	ServerInfo      ServerInfo   `json:"serverInfo"`
	Instructions    string       `json:"instructions,omitempty"`
}

type JSONRPCError

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

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      any             `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

type JSONRPCResponse

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

type LogMessageParams

type LogMessageParams struct {
	Level  string `json:"level"`
	Logger string `json:"logger,omitempty"`
	Data   any    `json:"data"`
}

type LoggingCapability

type LoggingCapability struct{}

type MCP

type MCP struct {
	Tools              Tools
	Resources          Resources
	ResourceTemplates  ResourceTemplates
	Prompts            Prompts
	CompletionHandlers CompletionHandlers

	ServerName    string
	ServerVersion string
	Instructions  string
}

func New

func New() *MCP

func (*MCP) AddCompletionHandler

func (s *MCP) AddCompletionHandler(refKey string, handler CompletionHandler)

AddCompletionHandler registers a completion handler for a reference key. Use "prompt:<name>" for prompt completions and "resource:<uri>" for resource completions.

func (*MCP) AddPrompt

func (s *MCP) AddPrompt(prompt Prompt, handler PromptHandler)

AddPrompt registers a prompt and its handler.

func (*MCP) AddResource

func (s *MCP) AddResource(resource Resource, handler ResourceHandler)

AddResource registers a resource and its handler.

func (*MCP) AddResourceTemplate

func (s *MCP) AddResourceTemplate(template ResourceTemplate)

AddResourceTemplate registers a resource template.

func (*MCP) AddTool

func (s *MCP) AddTool(tool Tool, handler ToolHandler)

AddTool registers a tool and its handler.

func (*MCP) ServeHTTP

func (s *MCP) ServeHTTP(w http.ResponseWriter, r *http.Request)

HTTP handler for MCP requests

type Prompt

type Prompt struct {
	Name        string      `json:"name"`
	Title       string      `json:"title,omitempty"`
	Description string      `json:"description,omitempty"`
	Icons       []Icon      `json:"icons,omitempty"`
	Arguments   []PromptArg `json:"arguments,omitempty"`
}

type PromptArg

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

type PromptContent

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

type PromptHandler

type PromptHandler func(args map[string]string) (GetPromptResult, error)

PromptHandler represents a function that generates prompt content.

type PromptMessage

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

type Prompts

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

func (*Prompts) Add

func (p *Prompts) Add(prompt Prompt, handler PromptHandler)

func (*Prompts) GetHandler

func (p *Prompts) GetHandler(name string) PromptHandler

func (*Prompts) List

func (p *Prompts) List() []Prompt

type PromptsCapability

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

type PromptsGetParams

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

PromptsGetParams represents the parameters for a prompts/get request.

type PromptsListResult

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

PromptsListResult is the result of a prompts/list request.

type Resource

type Resource struct {
	URI         string       `json:"uri"`
	Name        string       `json:"name"`
	Title       string       `json:"title,omitempty"`
	Description string       `json:"description,omitempty"`
	Icons       []Icon       `json:"icons,omitempty"`
	MimeType    string       `json:"mimeType,omitempty"`
	Size        *int64       `json:"size,omitempty"`
	Annotations *Annotations `json:"annotations,omitempty"`
}

type ResourceContent

type ResourceContent struct {
	URI         string       `json:"uri"`
	MimeType    string       `json:"mimeType,omitempty"`
	Text        string       `json:"text,omitempty"`
	Blob        string       `json:"blob,omitempty"`
	Annotations *Annotations `json:"annotations,omitempty"`
}

ResourceContent represents the contents of a resource (text or binary).

type ResourceHandler

type ResourceHandler func(uri string) (ResourceContent, error)

ResourceHandler represents a function that provides resource content.

type ResourceLinkContent

type ResourceLinkContent struct {
	Type        string       `json:"type"` // "resource_link"
	URI         string       `json:"uri"`
	Name        string       `json:"name,omitempty"`
	Description string       `json:"description,omitempty"`
	MimeType    string       `json:"mimeType,omitempty"`
	Annotations *Annotations `json:"annotations,omitempty"`
}

ResourceLinkContent represents a link to a resource.

func NewResourceLinkContent

func NewResourceLinkContent(uri string) ResourceLinkContent

NewResourceLinkContent creates a new ResourceLinkContent with the type field set.

type ResourceTemplate

type ResourceTemplate struct {
	URITemplate string       `json:"uriTemplate"`
	Name        string       `json:"name"`
	Title       string       `json:"title,omitempty"`
	Description string       `json:"description,omitempty"`
	Icons       []Icon       `json:"icons,omitempty"`
	MimeType    string       `json:"mimeType,omitempty"`
	Annotations *Annotations `json:"annotations,omitempty"`
}

type ResourceTemplates

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

func (*ResourceTemplates) Add

func (rt *ResourceTemplates) Add(template ResourceTemplate)

func (*ResourceTemplates) List

func (rt *ResourceTemplates) List() []ResourceTemplate

type ResourceTemplatesListResult

type ResourceTemplatesListResult struct {
	ResourceTemplates []ResourceTemplate `json:"resourceTemplates"`
	NextCursor        string             `json:"nextCursor,omitempty"`
}

ResourceTemplatesListResult is the result of a resources/templates/list request.

type ResourceUpdatedNotification

type ResourceUpdatedNotification struct {
	URI   string `json:"uri"`
	Title string `json:"title,omitempty"`
}

type Resources

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

func (*Resources) Add

func (r *Resources) Add(resource Resource, handler ResourceHandler)

func (*Resources) GetHandler

func (r *Resources) GetHandler(uri string) ResourceHandler

func (*Resources) List

func (r *Resources) List() []Resource

type ResourcesCapability

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

type ResourcesListResult

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

ResourcesListResult is the result of a resources/list request.

type ResourcesReadParams

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

ResourcesReadParams represents the parameters for a resources/read request.

type ResourcesReadResult

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

ResourcesReadResult is the result of a resources/read request.

type ServerInfo

type ServerInfo struct {
	Name        string `json:"name"`
	Title       string `json:"title,omitempty"`
	Version     string `json:"version"`
	Description string `json:"description,omitempty"`
	Icons       []Icon `json:"icons,omitempty"`
	WebsiteURL  string `json:"websiteUrl,omitempty"`
}

type SetLevelRequest

type SetLevelRequest struct {
	Level string `json:"level"`
}

type SubscribeRequest

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

type TaskStatusNotification

type TaskStatusNotification struct {
	TaskID        string `json:"taskId"`
	Status        string `json:"status"`
	StatusMessage string `json:"statusMessage,omitempty"`
	CreatedAt     string `json:"createdAt"`
	LastUpdatedAt string `json:"lastUpdatedAt,omitempty"`
	TTL           *int64 `json:"ttl,omitempty"`
	PollInterval  *int64 `json:"pollInterval,omitempty"`
}

TaskStatusNotification represents the parameters for a notifications/tasks/status notification.

type TextContent

type TextContent struct {
	Type        string       `json:"type"` // "text"
	Text        string       `json:"text"`
	Annotations *Annotations `json:"annotations,omitempty"`
}

TextContent represents plain text content.

func NewTextContent

func NewTextContent(text string) TextContent

NewTextContent creates a new TextContent with the type field set.

type Tool

type Tool struct {
	Name         string         `json:"name"`
	Title        string         `json:"title,omitempty"`
	Description  string         `json:"description"`
	Icons        []Icon         `json:"icons,omitempty"`
	InputSchema  map[string]any `json:"inputSchema"`
	OutputSchema map[string]any `json:"outputSchema,omitempty"`
	Annotations  *Annotations   `json:"annotations,omitempty"`
}

type ToolCallParams

type ToolCallParams struct {
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments"`
}

ToolCallParams represents the parameters for a tools/call request.

type ToolCallResult

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

ToolCallResult is the result of a tools/call request.

func NewToolCallErrorResult

func NewToolCallErrorResult(text string) ToolCallResult

NewToolCallErrorResult creates a ToolCallResult with isError set to true.

func NewToolCallResult

func NewToolCallResult(text string) ToolCallResult

NewToolCallResult creates a ToolCallResult with a single text content.

type ToolHandler

type ToolHandler func(args map[string]any) (ToolCallResult, error)

ToolHandler represents a function that handles tool calls.

type Tools

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

func (*Tools) Add

func (t *Tools) Add(tool Tool, handler ToolHandler)

func (*Tools) GetHandler

func (t *Tools) GetHandler(name string) ToolHandler

func (*Tools) List

func (t *Tools) List() []Tool

type ToolsCapability

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

type ToolsListResult

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

ToolsListResult is the result of a tools/list request.

type UnsubscribeRequest

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

Jump to

Keyboard shortcuts

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