mcp

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "2024-11-05"

Version is the Model Context Protocol version

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotations

type Annotations struct {
	// Describes who the intended customer of this object or data is
	Audience []Role `json:"audience,omitempty"`
	// Describes how important this data is for operating the server (0-1)
	Priority *float64 `json:"priority,omitempty"`
}

Annotations represents optional annotations for objects

type CompleteRequest

type CompleteRequest struct {
	Ref      interface{} `json:"ref"`
	Argument struct {
		Name  string `json:"name"`
		Value string `json:"value"`
	} `json:"argument"`
}

CompleteRequest represents a request for completion options

type CompleteResponse

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

CompleteResponse represents the response for completion/complete

type Content

type Content struct {
	Type        string       `json:"type"`
	Text        string       `json:"text,omitempty"`
	Data        string       `json:"data,omitempty"`
	MimeType    string       `json:"mimeType,omitempty"`
	Annotations *Annotations `json:"annotations,omitempty"`
}

Content represents the base content type

func NewImageContent

func NewImageContent(data string, mimeType string, audience []Role, priority *float64) Content

NewImageContent creates a new ImageContent with the given data and optional annotations

func NewTextContent

func NewTextContent(text string, audience []Role, priority *float64) Content

NewTextContent creates a new TextContent with the given text and optional annotations

type CreateMessageRequest

type CreateMessageRequest struct {
	Messages         []SamplingMessage      `json:"messages"`
	ModelPreferences *ModelPreferences      `json:"modelPreferences,omitempty"`
	SystemPrompt     string                 `json:"systemPrompt,omitempty"`
	IncludeContext   string                 `json:"includeContext,omitempty"`
	Temperature      float64                `json:"temperature,omitempty"`
	MaxTokens        int                    `json:"maxTokens"`
	StopSequences    []string               `json:"stopSequences,omitempty"`
	Metadata         map[string]interface{} `json:"metadata,omitempty"`
}

CreateMessageRequest represents a request to create a message via sampling

type CreateMessageResponse

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

CreateMessageResponse represents the response for sampling/createMessage

type GetPromptRequest

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

GetPromptRequest represents a request to get a specific prompt

type GetPromptResponse

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

GetPromptResponse represents the response for prompts/get

type InitializeRequest

type InitializeRequest struct{}

InitializeRequest represents a request to initialize the server

type InitializeResponse

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

InitializeResponse represents the server's response to an initialize request

type InitializedNotification

type InitializedNotification struct{}

InitializedNotification represents a notification that initialization is complete

type InputSchema

type InputSchema struct {
	Type       string                 `json:"type"`
	Properties map[string]interface{} `json:"properties,omitempty"`
	Required   []string               `json:"required,omitempty"`
}

InputSchema represents the JSON Schema for tool parameters

type ListPromptsRequest

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

ListPromptsRequest represents a request to list available prompts

type ListPromptsResponse

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

ListPromptsResponse represents the response for prompts/list

type ListResourceTemplatesRequest

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

ListResourceTemplatesRequest represents a request to list resource templates

type ListResourceTemplatesResponse

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

ListResourceTemplatesResponse represents the response for resources/templates/list

type ListResourcesRequest

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

ListResourcesRequest represents a request to list available resources

type ListResourcesResponse

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

ListResourcesResponse represents the response for resources/list

type ListRootsRequest

type ListRootsRequest struct{}

ListRootsRequest represents a request to list root directories

type ListRootsResponse

type ListRootsResponse struct {
	Roots []Root `json:"roots"`
}

ListRootsResponse represents the response for roots/list

type LogNotification

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

LogNotification represents a log message from the server

type ModelHint

type ModelHint struct {
	Name string `json:"name,omitempty"`
}

ModelHint represents hints for model selection

type ModelPreferences

type ModelPreferences struct {
	Hints                []ModelHint `json:"hints,omitempty"`
	CostPriority         float64     `json:"costPriority,omitempty"`
	SpeedPriority        float64     `json:"speedPriority,omitempty"`
	IntelligencePriority float64     `json:"intelligencePriority,omitempty"`
}

ModelPreferences represents preferences for model selection

type PingRequest

type PingRequest struct{}

PingRequest represents a ping request

type PingResponse

type PingResponse struct{}

PingResponse represents the response for ping/ping

type ProgressNotification

type ProgressNotification struct {
	ProgressToken string  `json:"progressToken"`
	Progress      float64 `json:"progress"`
	Total         float64 `json:"total,omitempty"`
}

ProgressNotification represents a progress update for a long-running request

type Prompt

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

Prompt represents a prompt or prompt template

type PromptArgument

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

PromptArgument represents an argument for a prompt

type PromptListChangedNotification

type PromptListChangedNotification struct{}

PromptListChangedNotification represents a notification that the prompt list has changed

type PromptMessage

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

PromptMessage represents a message in a prompt

type ReadResourceRequest

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

ReadResourceRequest represents a request to read a resource

type ReadResourceResponse

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

ReadResourceResponse represents the response for resources/read

type Resource

type Resource struct {
	URI         string                 `json:"uri"`
	Name        string                 `json:"name"`
	Description string                 `json:"description,omitempty"`
	MimeType    string                 `json:"mimeType,omitempty"`
	Size        int64                  `json:"size,omitempty"`
	Annotations map[string]interface{} `json:"annotations,omitempty"`
}

Resource represents a known resource that the server can read

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 the contents of a specific resource

type ResourceListChangedNotification

type ResourceListChangedNotification struct{}

ResourceListChangedNotification represents a notification that the resource list has changed

type ResourceTemplate

type ResourceTemplate struct {
	URITemplate string                 `json:"uriTemplate"`
	Name        string                 `json:"name"`
	Description string                 `json:"description,omitempty"`
	MimeType    string                 `json:"mimeType,omitempty"`
	Annotations map[string]interface{} `json:"annotations,omitempty"`
}

ResourceTemplate represents a template for resources

type ResourceUpdatedNotification

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

ResourceUpdatedNotification represents a notification that a resource has been updated

type Role

type Role string

Role represents the sender or recipient of messages and data in a conversation

const (
	// RoleUser represents the user
	RoleUser Role = "user"

	// RoleAssistant represents the assistant
	RoleAssistant Role = "assistant"
)

type Root

type Root struct {
	URI  string `json:"uri"`
	Name string `json:"name,omitempty"`
}

Root represents a root directory or file

type RootsListChangedNotification

type RootsListChangedNotification struct{}

RootsListChangedNotification represents a notification that the roots list has changed

type SamplingMessage

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

SamplingMessage represents a message for LLM sampling

type Server

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

Server represents an MCP server that processes JSON-RPC requests

func NewServer

func NewServer(opts ...ServerOption) (*Server, error)

NewServer creates a new MCP server instance

func (*Server) HandleRequest

func (s *Server) HandleRequest(request jsonrpc.Request) *jsonrpc.Response

HandleRequest processes a single JSON-RPC request and returns a response

type ServerCapabilities

type ServerCapabilities struct {
	Experimental map[string]interface{} `json:"experimental,omitempty"`
	Logging      *struct{}              `json:"logging,omitempty"`
	Prompts      *struct {
		ListChanged bool `json:"listChanged"`
	} `json:"prompts,omitempty"`
	Resources *struct {
		Subscribe   bool `json:"subscribe"`
		ListChanged bool `json:"listChanged"`
	} `json:"resources,omitempty"`
	Tools *struct {
		ListChanged bool `json:"listChanged"`
	} `json:"tools,omitempty"`
}

ServerCapabilities represents the server's supported capabilities

type ServerInfo

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

ServerInfo represents information about an MCP implementation

type ServerOption

type ServerOption func(*Server) error

ServerOption configures a Server

func WithAuth

func WithAuth(auth string) ServerOption

WithAuth sets the authentication header for the server

func WithClient

func WithClient(client *http.Client) ServerOption

WithClient sets the HTTP client

func WithLogger

func WithLogger(logger *slog.Logger) ServerOption

WithLogger sets the logger for the server

func WithServerInfo

func WithServerInfo(name, version string) ServerOption

WithServerInfo sets server info

func WithSpecData

func WithSpecData(data []byte) ServerOption

WithSpecData sets the OpenAPI spec from a byte slice

type SetLevelRequest

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

SetLevelRequest represents a request to set logging level

type SubscribeRequest

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

SubscribeRequest represents a request to subscribe to resource updates

type Tool

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

Tool represents a single tool in the tools/list response

type ToolCallRequest

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

ToolCallRequest represents a request to call a specific tool

type ToolCallResponse

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

ToolCallResponse represents the response from a tool call

type ToolsChangedNotification

type ToolsChangedNotification struct{}

ToolsChangedNotification represents a notification that the tools list has changed

type ToolsListRequest

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

ToolsListRequest represents a request to list available tools

type ToolsListResponse

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

ToolsListResponse represents the response for the tools/list method

type Transport

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

Transport handles the communication between stdin/stdout and the MCP server

func NewStdioTransport

func NewStdioTransport(in io.Reader, out io.Writer, logger io.Writer) *Transport

NewStdioTransport creates a new stdio transport

func (*Transport) Run

func (t *Transport) Run(ctx context.Context, handler func(jsonrpc.Request) *jsonrpc.Response) error

Run starts the transport loop, reading from stdin and writing to stdout

type UnsubscribeRequest

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

UnsubscribeRequest represents a request to unsubscribe from resource updates

Jump to

Keyboard shortcuts

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