mcp

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidServer   = errors.New("mcp: invalid server")
	ErrInvalidResource = errors.New("mcp: invalid resource")
	ErrUnknownServer   = errors.New("mcp: unknown server")
	ErrProcessExit     = errors.New("mcp: process exited")
	ErrRPC             = errors.New("mcp: json-rpc error")
)

Functions

func IsUnsupported

func IsUnsupported(err error) bool

Types

type CallToolResult

type CallToolResult struct {
	Content []Content       `json:"content"`
	IsError bool            `json:"isError,omitempty"`
	Raw     json.RawMessage `json:"-"`
}

type Clock

type Clock func() time.Time

type Content

type Content struct {
	Type     string          `json:"type"`
	Text     string          `json:"text,omitempty"`
	Data     string          `json:"data,omitempty"`
	MimeType string          `json:"mimeType,omitempty"`
	Raw      json.RawMessage `json:"-"`
}

type ListResourceTemplatesRequest

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

type ListResourceTemplatesResult

type ListResourceTemplatesResult struct {
	ResourceTemplates []ResourceTemplateDescriptor `json:"resourceTemplates"`
	NextCursor        string                       `json:"nextCursor,omitempty"`
	Raw               json.RawMessage              `json:"-"`
}

type ListResourcesRequest

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

type ListResourcesResult

type ListResourcesResult struct {
	Resources  []ResourceDescriptor `json:"resources"`
	NextCursor string               `json:"nextCursor,omitempty"`
	Raw        json.RawMessage      `json:"-"`
}

type Manager

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

func NewManager

func NewManager(clock Clock) *Manager

func (*Manager) CallTool

func (m *Manager) CallTool(ctx context.Context, server string, tool string, args json.RawMessage) (CallToolResult, error)

func (*Manager) EnsureStarted

func (m *Manager) EnsureStarted(ctx context.Context, name string) (ServerStatus, error)

func (*Manager) List

func (m *Manager) List() []ServerStatus

func (*Manager) ListResourceTemplates

func (m *Manager) ListResourceTemplates(ctx context.Context, server string, req ListResourceTemplatesRequest) (ListResourceTemplatesResult, error)

func (*Manager) ListResources

func (m *Manager) ListResources(ctx context.Context, server string, req ListResourcesRequest) (ListResourcesResult, error)

func (*Manager) ListTools

func (m *Manager) ListTools(ctx context.Context, name string) ([]Tool, error)

func (*Manager) ReadResource

func (m *Manager) ReadResource(ctx context.Context, server string, req ReadResourceRequest) (ReadResourceResult, error)

func (*Manager) Register

func (m *Manager) Register(cfg ServerConfig) error

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context, name string) error

func (*Manager) StopIdle

func (m *Manager) StopIdle(ctx context.Context) error

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*RPCError) Error

func (e *RPCError) Error() string

func (*RPCError) Is

func (e *RPCError) Is(target error) bool

type ReadResourceRequest

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

type ReadResourceResult

type ReadResourceResult struct {
	Contents []ResourceContent `json:"contents"`
	Raw      json.RawMessage   `json:"-"`
}

type ResourceClient

type ResourceClient interface {
	ListResources(ctx context.Context, server string, req ListResourcesRequest) (ListResourcesResult, error)
	ReadResource(ctx context.Context, server string, req ReadResourceRequest) (ReadResourceResult, error)
	ListResourceTemplates(ctx context.Context, server string, req ListResourceTemplatesRequest) (ListResourceTemplatesResult, error)
}

ResourceClient is the stable seam callers use for MCP resource discovery and reads.

type ResourceContent

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

type ResourceDescriptor

type ResourceDescriptor struct {
	URI         string          `json:"uri"`
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	MimeType    string          `json:"mimeType,omitempty"`
	Annotations json.RawMessage `json:"annotations,omitempty"`
}

type ResourceTemplateDescriptor

type ResourceTemplateDescriptor struct {
	URITemplate string          `json:"uriTemplate"`
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	MimeType    string          `json:"mimeType,omitempty"`
	Annotations json.RawMessage `json:"annotations,omitempty"`
}

type ServerConfig

type ServerConfig struct {
	Name    string
	Command string
	Args    []string
	Env     []string
	IdleTTL time.Duration
}

type ServerStatus

type ServerStatus struct {
	Name    string
	Running bool
	PID     int
}

type Tool

type Tool struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	InputSchema json.RawMessage `json:"inputSchema,omitempty"`
	Annotations ToolAnnotations `json:"annotations,omitempty"`
}

type ToolAnnotations added in v0.0.2

type ToolAnnotations struct {
	ReadOnlyHint *bool `json:"readOnlyHint,omitempty"`
}

ToolAnnotations are the server's self-reported behavioral hints. They are UNTRUSTED — a server declaring a destructive tool read-only would otherwise talk its way past a read-only approval tier — so consumers may only act on them in the restrictive direction: honor readOnlyHint:true as a downgrade to read, and treat everything else (absent, false, or unparseable) as the stricter class.

func (ToolAnnotations) IsReadOnly added in v0.0.2

func (a ToolAnnotations) IsReadOnly() bool

IsReadOnly reports an explicit readOnlyHint:true. Absent or false is not read-only.

Jump to

Keyboard shortcuts

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