mcp

package
v1.0.22 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeStartupServers

func MergeStartupServers(workingDir string, explicit []config.MCPServerConfig) ([]config.MCPServerConfig, []string)

func ParseInstallArgs

func ParseInstallArgs(args []string) (config.MCPServerConfig, error)

func ParseMessage

func ParseMessage(data []byte) (interface{}, error)

ParseMessage parses a JSON-RPC message from raw bytes. It can be a Request, Response, or Notification.

func PersistUserClaudeServers

func PersistUserClaudeServers(cfg *config.Config) ([]string, bool, error)

Types

type Adapter

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

Adapter wraps MCP tools into ggcode's Tool interface.

func NewAdapter

func NewAdapter(serverName string, caller toolCaller, tools []ToolDefinition) *Adapter

NewAdapter creates an MCP adapter from server config and tool definitions.

func (*Adapter) RegisterTools

func (a *Adapter) RegisterTools(registry *tool.Registry) error

RegisterTools registers all MCP tools into the registry with "mcp__" prefix.

func (*Adapter) ServerName

func (a *Adapter) ServerName() string

ServerName returns the MCP server name.

func (*Adapter) ToolCount

func (a *Adapter) ToolCount() int

ToolCount returns the number of tools from this server.

func (*Adapter) ToolNames

func (a *Adapter) ToolNames() []string

ToolNames returns the full ggcode tool names for all MCP tools.

type CallToolParams

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

type CallToolResult

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

type Client

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

Client connects to an MCP server via stdio transport.

func NewClient

func NewClient(name, command string, args []string) *Client

NewClient creates a new MCP client for the given server config.

func NewClientFromConfig

func NewClientFromConfig(cfg config.MCPServerConfig) *Client

func (*Client) Abort

func (c *Client) Abort()

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args map[string]interface{}) (*CallToolResult, error)

CallTool invokes a tool on the MCP server.

func (*Client) Close

func (c *Client) Close() error

Close terminates the server process.

func (*Client) GetPrompt

func (c *Client) GetPrompt(ctx context.Context, name string, args map[string]interface{}) (*GetPromptResult, error)

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context) (*InitializeResult, error)

Initialize sends the initialize request and returns server capabilities.

func (*Client) ListPrompts

func (c *Client) ListPrompts(ctx context.Context) ([]PromptDefinition, error)

func (*Client) ListResources

func (c *Client) ListResources(ctx context.Context) ([]ResourceDefinition, error)

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]ToolDefinition, error)

ListTools returns the tools provided by the MCP server.

func (*Client) Name

func (c *Client) Name() string

Name returns the MCP server name.

func (*Client) ReadResource

func (c *Client) ReadResource(ctx context.Context, uri string) (*ReadResourceResult, error)

func (*Client) Start

func (c *Client) Start(ctx context.Context) error

Start launches the MCP server process.

type ClientCaps

type ClientCaps struct {
	Roots struct {
		ListChanged bool `json:"listChanged,omitempty"`
	} `json:"roots,omitempty"`
}

type Error

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

Error is a JSON-RPC error object.

func (*Error) Error

func (e *Error) Error() string

type GetPromptParams

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

type GetPromptResult

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

type ID

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

ID can be a string or number.

func NewIntID

func NewIntID(n int64) ID

func NewStringID

func NewStringID(s string) ID

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

type Implementation

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

type InitializeParams

type InitializeParams struct {
	ProtocolVersion string         `json:"protocolVersion"`
	Capabilities    ClientCaps     `json:"capabilities"`
	ClientInfo      Implementation `json:"clientInfo"`
}

type InitializeResult

type InitializeResult struct {
	ProtocolVersion string         `json:"protocolVersion"`
	Capabilities    ServerCaps     `json:"capabilities"`
	ServerInfo      Implementation `json:"serverInfo"`
}

type ListPromptsResult

type ListPromptsResult struct {
	Prompts []PromptDefinition `json:"prompts"`
}

type ListResourcesResult

type ListResourcesResult struct {
	Resources []ResourceDefinition `json:"resources"`
}

type ListToolsParams

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

type ListToolsResult

type ListToolsResult struct {
	Tools []ToolDefinition `json:"tools"`
}

type Notification

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

Notification is a JSON-RPC notification (no ID).

type PromptArgument

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

type PromptDefinition

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

type PromptMessage

type PromptMessage struct {
	Role    string          `json:"role,omitempty"`
	Content json.RawMessage `json:"content"`
}

type ReadResourceParams

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

type ReadResourceResult

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

type Request

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

Request is a JSON-RPC request.

type ResourceContent

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

type ResourceDefinition

type ResourceDefinition struct {
	URI         string `json:"uri"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	MIMEType    string `json:"mimeType,omitempty"`
}

type Response

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

Response is a JSON-RPC response.

func (*Response) IsError

func (r *Response) IsError() bool

IsResponseError returns true if the response contains an error.

type ServerCaps

type ServerCaps struct {
	Tools *struct {
		ListChanged bool `json:"listChanged,omitempty"`
	} `json:"tools,omitempty"`
}

type ToolContent

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

type ToolDefinition

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

Jump to

Keyboard shortcuts

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