mcp

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParseError     = -32700
	InvalidRequest = -32600
	MethodNotFound = -32601
	InvalidParams  = -32602
	InternalError  = -32603
)

Error codes

View Source
const (
	ProtocolVersion = "2024-11-05"
	ServerName      = "go-mcp-atlassian"
	ServerVersion   = "0.1.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CallToolParams

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

CallToolParams represents the parameters for the tools/call method

type CallToolResult

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

CallToolResult represents the result of the tools/call method

func NewErrorResult

func NewErrorResult(err error) *CallToolResult

NewErrorResult creates an error tool result

func NewJSONResult

func NewJSONResult(data interface{}) (*CallToolResult, error)

NewJSONResult creates a tool result with JSON-formatted text

func NewSuccessResult

func NewSuccessResult(text string) *CallToolResult

NewSuccessResult creates a successful tool result with text content

type ClientCapabilities

type ClientCapabilities struct {
	Tools     *ToolCapabilities     `json:"tools,omitempty"`
	Resources *ResourceCapabilities `json:"resources,omitempty"`
	Prompts   *PromptCapabilities   `json:"prompts,omitempty"`
}

ClientCapabilities represents the capabilities of the client

type ClientInfo

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

ClientInfo represents information about the client

type Content

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

Content represents content in the result

func NewTextContent

func NewTextContent(text string) Content

NewTextContent creates a new text content item

type Error

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

Error represents a JSON-RPC 2.0 error

type InitializeParams

type InitializeParams struct {
	ProtocolVersion string                 `json:"protocolVersion"`
	Capabilities    ClientCapabilities     `json:"capabilities"`
	ClientInfo      ClientInfo             `json:"clientInfo"`
	Meta            map[string]interface{} `json:"meta,omitempty"`
}

InitializeParams represents the parameters for the initialize method

type InitializeResult

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

InitializeResult represents the result of the initialize method

type InputSchema

type InputSchema struct {
	Type       string                 `json:"type"`
	Properties map[string]Property    `json:"properties"`
	Required   []string               `json:"required,omitempty"`
	Additional map[string]interface{} `json:"-"` // For additional schema properties
}

InputSchema represents the JSON schema for tool input

func NewInputSchema

func NewInputSchema(properties map[string]Property, required ...string) InputSchema

NewInputSchema creates a new input schema

type ListToolsParams

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

ListToolsParams represents the parameters for the tools/list method

type ListToolsResult

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

ListToolsResult represents the result of the tools/list method

type Message

type Message struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id,omitempty"`
	Method  string          `json:"method,omitempty"`
	Params  json.RawMessage `json:"params,omitempty"`
	Result  interface{}     `json:"result,omitempty"`
	Error   *Error          `json:"error,omitempty"`
}

Message represents any JSON-RPC message (request, response, or notification)

func (*Message) IsNotification

func (m *Message) IsNotification() bool

IsNotification returns true if the message is a notification

func (*Message) IsRequest

func (m *Message) IsRequest() bool

IsRequest returns true if the message is a request

func (*Message) IsResponse

func (m *Message) IsResponse() bool

IsResponse returns true if the message is a response

func (*Message) ToNotification

func (m *Message) ToNotification() *Notification

ToNotification converts the message to a Notification

func (*Message) ToRequest

func (m *Message) ToRequest() *Request

ToRequest converts the message to a Request

func (*Message) ToResponse

func (m *Message) ToResponse() *Response

ToResponse converts the message to a Response

type Notification

type Notification struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Notification represents a JSON-RPC 2.0 notification

func NewNotification

func NewNotification(method string, params interface{}) (*Notification, error)

NewNotification creates a new notification

type PromptCapabilities

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

PromptCapabilities represents prompt-related capabilities

type PromptsCapability

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

PromptsCapability represents prompt capabilities

type Property

type Property struct {
	Type        string      `json:"type"`
	Description string      `json:"description,omitempty"`
	Default     interface{} `json:"default,omitempty"`
	Enum        []string    `json:"enum,omitempty"`
	Items       *Property   `json:"items,omitempty"`
}

Property represents a property in the input schema

func NewArrayProperty

func NewArrayProperty(description string, items Property) Property

NewArrayProperty creates a new array property

func NewBooleanProperty

func NewBooleanProperty(description string) Property

NewBooleanProperty creates a new boolean property

func NewEnumProperty

func NewEnumProperty(description string, values ...string) Property

NewEnumProperty creates a new enum property

func NewIntegerProperty

func NewIntegerProperty(description string) Property

NewIntegerProperty creates a new integer property

func NewProperty

func NewProperty(propType, description string) Property

NewProperty creates a new property definition

func NewStringProperty

func NewStringProperty(description string) Property

NewStringProperty creates a new string property

func (Property) WithDefault

func (p Property) WithDefault(value interface{}) Property

WithDefault adds a default value to a property

type Request

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

Request represents a JSON-RPC 2.0 request

type ResourceCapabilities

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

ResourceCapabilities represents resource-related capabilities

type ResourcesCapability

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

ResourcesCapability represents resource capabilities

type Response

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

Response represents a JSON-RPC 2.0 response

func NewErrorResponse

func NewErrorResponse(id interface{}, code int, message string, data interface{}) *Response

NewErrorResponse creates a new error response

func NewResponse

func NewResponse(id interface{}, result interface{}) *Response

NewResponse creates a new successful response

type Server

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

Server represents the MCP server

func NewServer

func NewServer(cfg *ServerConfig) *Server

NewServer creates a new MCP server

func (*Server) HandleMessage

func (s *Server) HandleMessage(ctx context.Context, data []byte) ([]byte, error)

HandleMessage handles an incoming JSON-RPC message

func (*Server) RegisterTool

func (s *Server) RegisterTool(def *ToolDefinition) error

RegisterTool registers a new tool

type ServerCapabilities

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

ServerCapabilities represents the capabilities of the server

type ServerConfig

type ServerConfig struct {
	Logger       *zerolog.Logger
	ReadOnlyMode bool
	EnabledTools []string
}

ServerConfig holds the configuration for the MCP server

type ServerInfo

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

ServerInfo represents information about the server

type StdioTransport

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

StdioTransport implements the stdio transport for MCP

func NewStdioTransport

func NewStdioTransport(server *Server, logger *zerolog.Logger) *StdioTransport

NewStdioTransport creates a new stdio transport

func (*StdioTransport) Start

func (t *StdioTransport) Start(ctx context.Context) error

Start starts the stdio transport loop

type Tool

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

Tool represents a tool definition

type ToolCapabilities

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

ToolCapabilities represents tool-related capabilities

type ToolDefinition

type ToolDefinition struct {
	Tool
	Handler ToolHandler
	Tags    []string // For filtering (e.g., "jira", "confluence", "read", "write")
}

ToolDefinition represents a complete tool definition

func NewTool

func NewTool(name, description string, schema InputSchema, handler ToolHandler, tags ...string) *ToolDefinition

NewTool creates a new tool definition

type ToolHandler

type ToolHandler func(ctx context.Context, arguments map[string]interface{}) (*CallToolResult, error)

ToolHandler is a function that handles a tool call

type ToolRegistry

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

ToolRegistry manages tool registration and execution

func NewToolRegistry

func NewToolRegistry() *ToolRegistry

NewToolRegistry creates a new tool registry

func (*ToolRegistry) CallTool

func (r *ToolRegistry) CallTool(ctx context.Context, name string, arguments map[string]interface{}) (*CallToolResult, error)

CallTool executes a tool by name with the given arguments

func (*ToolRegistry) GetTool

func (r *ToolRegistry) GetTool(name string) (*ToolDefinition, bool)

GetTool returns a tool definition by name

func (*ToolRegistry) ListTools

func (r *ToolRegistry) ListTools() []Tool

ListTools returns all registered tools

func (*ToolRegistry) ListToolsFiltered

func (r *ToolRegistry) ListToolsFiltered(enabledTools []string, readOnlyMode bool) []Tool

ListToolsFiltered returns tools filtered by tags and enabled list

func (*ToolRegistry) RegisterTool

func (r *ToolRegistry) RegisterTool(def *ToolDefinition) error

RegisterTool registers a new tool with its handler

type ToolsCapability

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

ToolsCapability represents tool capabilities

Jump to

Keyboard shortcuts

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