mcp

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package mcp implements an in-process Model Context Protocol server.

The MCP server allows users to register custom tools that the agent can invoke during execution. Tools are registered via the SDK and exposed through the protocol controller's MCP message handler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorResult

func ErrorResult(message string) *mcp.CallToolResult

ErrorResult creates a CallToolResult indicating an error.

func ImageResult

func ImageResult(data []byte, mimeType string) *mcp.CallToolResult

ImageResult creates a CallToolResult with image content.

func NewTool

func NewTool(name, description string, inputSchema *jsonschema.Schema) *mcp.Tool

NewTool creates an mcp.Tool with the given parameters.

func ParseArguments

func ParseArguments(req *mcp.CallToolRequest) (map[string]any, error)

ParseArguments unmarshals CallToolRequest arguments into a map.

func SimpleSchema

func SimpleSchema(props map[string]string) *jsonschema.Schema

SimpleSchema creates a jsonschema.Schema from a simple type map.

func TextResult

func TextResult(text string) *mcp.CallToolResult

TextResult creates a CallToolResult with text content.

Types

type AuthStatus added in v0.0.2

type AuthStatus string

AuthStatus describes the authentication state of an MCP server.

const (
	// AuthStatusUnsupported means the server does not use authentication.
	AuthStatusUnsupported AuthStatus = "unsupported"
	// AuthStatusNotLoggedIn means the server requires login before use.
	AuthStatusNotLoggedIn AuthStatus = "notLoggedIn"
	// AuthStatusBearerToken means the server is authenticated with a bearer token.
	AuthStatusBearerToken AuthStatus = "bearerToken"
	// AuthStatusOAuth means the server is authenticated with OAuth.
	AuthStatusOAuth AuthStatus = "oAuth"
)

type HTTPServerConfig

type HTTPServerConfig struct {
	Type    ServerType        `json:"type"`
	URL     string            `json:"url"`
	Headers map[string]string `json:"headers,omitempty"`
}

HTTPServerConfig configures an HTTP-based MCP server.

func (*HTTPServerConfig) GetType

func (m *HTTPServerConfig) GetType() ServerType

GetType implements ServerConfig.

type Resource added in v0.0.2

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"`
	Title       *string        `json:"title,omitempty"`
	Annotations map[string]any `json:"annotations,omitempty"`
	Icons       []any          `json:"icons,omitempty"`
	Meta        any            `json:"_meta,omitempty"` //nolint:tagliatelle // MCP protocol uses _meta.
}

Resource describes a concrete resource available from an MCP server.

type ResourceTemplate added in v0.0.2

type ResourceTemplate struct {
	URITemplate string         `json:"uriTemplate"`
	Name        string         `json:"name"`
	Description *string        `json:"description,omitempty"`
	MIMEType    *string        `json:"mimeType,omitempty"`
	Title       *string        `json:"title,omitempty"`
	Annotations map[string]any `json:"annotations,omitempty"`
}

ResourceTemplate describes a parameterized resource exposed by an MCP server.

type SDKServer

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

SDKServer wraps the official MCP SDK server for programmatic access.

func NewSDKServer

func NewSDKServer(name, version string) *SDKServer

NewSDKServer creates a new MCP SDK server wrapper.

func (*SDKServer) AddTool

func (s *SDKServer) AddTool(tool *mcp.Tool, handler mcp.ToolHandler)

AddTool registers a tool with the server.

func (*SDKServer) CallTool

func (s *SDKServer) CallTool(
	ctx context.Context,
	name string,
	input map[string]any,
) (map[string]any, error)

CallTool executes a tool by name with the given input.

func (*SDKServer) Capabilities

func (s *SDKServer) Capabilities() map[string]any

Capabilities returns server capabilities for MCP initialize response.

func (*SDKServer) ListTools

func (s *SDKServer) ListTools() []map[string]any

ListTools returns metadata for all registered tools.

func (*SDKServer) Name

func (s *SDKServer) Name() string

Name returns the server name.

func (*SDKServer) ServerInfo

func (s *SDKServer) ServerInfo() map[string]any

ServerInfo returns server information for MCP initialize response.

func (*SDKServer) Version

func (s *SDKServer) Version() string

Version returns the server version.

type SSEServerConfig

type SSEServerConfig struct {
	Type    ServerType        `json:"type"`
	URL     string            `json:"url"`
	Headers map[string]string `json:"headers,omitempty"`
}

SSEServerConfig configures a Server-Sent Events MCP server.

func (*SSEServerConfig) GetType

func (m *SSEServerConfig) GetType() ServerType

GetType implements ServerConfig.

type SdkServerConfig

type SdkServerConfig struct {
	Type     ServerType `json:"type"`
	Name     string     `json:"name"`
	Instance any        `json:"-"`
}

SdkServerConfig configures an SDK-provided MCP server.

func (*SdkServerConfig) GetType

func (m *SdkServerConfig) GetType() ServerType

GetType implements ServerConfig.

type ServerConfig

type ServerConfig interface {
	GetType() ServerType
}

ServerConfig is the interface for MCP server configurations.

type ServerInstance

type ServerInstance interface {
	// Name returns the server name.
	Name() string
	// Version returns the server version.
	Version() string
	// ListTools returns metadata for all registered tools.
	ListTools() []map[string]any
	// CallTool executes a tool by name with the given input.
	CallTool(ctx context.Context, name string, input map[string]any) (map[string]any, error)
}

ServerInstance is the interface that SDK MCP servers must implement.

type ServerStatus

type ServerStatus struct {
	Name              string             `json:"name"`
	Status            string             `json:"status"`
	AuthStatus        AuthStatus         `json:"authStatus,omitempty"`
	Tools             map[string]Tool    `json:"tools,omitempty"`
	Resources         []Resource         `json:"resources,omitempty"`
	ResourceTemplates []ResourceTemplate `json:"resourceTemplates,omitempty"`
}

ServerStatus represents the connection status of a single MCP server.

type ServerType

type ServerType string

ServerType represents the type of MCP server.

const (
	// ServerTypeStdio uses stdio for communication.
	ServerTypeStdio ServerType = "stdio"
	// ServerTypeSSE uses Server-Sent Events.
	ServerTypeSSE ServerType = "sse"
	// ServerTypeHTTP uses HTTP for communication.
	ServerTypeHTTP ServerType = "http"
	// ServerTypeSDK uses the SDK interface.
	ServerTypeSDK ServerType = "sdk"
)

type Status

type Status struct {
	MCPServers []ServerStatus `json:"mcpServers"`
}

Status represents the connection status of all configured MCP servers.

type StdioServerConfig

type StdioServerConfig struct {
	Type    *ServerType       `json:"type,omitempty"`
	Command string            `json:"command"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
}

StdioServerConfig configures a stdio-based MCP server.

func (*StdioServerConfig) GetType

func (m *StdioServerConfig) GetType() ServerType

GetType implements ServerConfig.

type Tool added in v0.0.2

type Tool struct {
	Name         string         `json:"name"`
	Description  *string        `json:"description,omitempty"`
	Title        *string        `json:"title,omitempty"`
	InputSchema  any            `json:"inputSchema"`
	OutputSchema any            `json:"outputSchema,omitempty"`
	Annotations  map[string]any `json:"annotations,omitempty"`
	Icons        []any          `json:"icons,omitempty"`
	Meta         any            `json:"_meta,omitempty"` //nolint:tagliatelle // MCP protocol uses _meta.
}

Tool describes an MCP tool exposed by a server.

Jump to

Keyboard shortcuts

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