mcp

package
v1.1.87 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const BrowserAutomationInstallSpec = "playwright stdio npx -y @playwright/mcp"

Variables

This section is empty.

Functions

func BrowserAutomationPreset added in v1.1.7

func BrowserAutomationPreset() config.MCPServerConfig

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 AuthorizationServerMetadata added in v1.1.34

type AuthorizationServerMetadata struct {
	Issuer                            string   `json:"issuer"`
	AuthorizationEndpoint             string   `json:"authorization_endpoint"`
	TokenEndpoint                     string   `json:"token_endpoint"`
	RegistrationEndpoint              string   `json:"registration_endpoint,omitempty"`
	ScopesSupported                   []string `json:"scopes_supported,omitempty"`
	CodeChallengeMethodsSupported     []string `json:"code_challenge_methods_supported,omitempty"`
	GrantTypesSupported               []string `json:"grant_types_supported,omitempty"`
	ResponseTypesSupported            []string `json:"response_types_supported,omitempty"`
	TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported,omitempty"`
	RevocationEndpoint                string   `json:"revocation_endpoint,omitempty"`
}

AuthorizationServerMetadata represents RFC 8414 authorization server metadata.

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 ClientRegistration added in v1.1.34

type ClientRegistration struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret,omitempty"`
}

ClientRegistration represents RFC 7591 dynamic client registration response.

type DeviceFlowResponse added in v1.1.34

type DeviceFlowResponse struct {
	DeviceCode      string `json:"device_code"`
	UserCode        string `json:"user_code"`
	VerificationURI string `json:"verification_uri"`
	ExpiresIn       int    `json:"expires_in"`
	Interval        int    `json:"interval"`
}

DeviceFlowResponse holds the response from the device code endpoint.

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 OAuthHandler added in v1.1.34

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

OAuthHandler manages OAuth 2.1 authentication for a single MCP server.

func NewOAuthHandler added in v1.1.34

func NewOAuthHandler(serverName, serverURL string, store *auth.Store) *OAuthHandler

NewOAuthHandler creates a new OAuth handler for an MCP server.

func (*OAuthHandler) Close added in v1.1.34

func (h *OAuthHandler) Close()

Close cleans up the callback server.

func (*OAuthHandler) ExchangeCode added in v1.1.34

func (h *OAuthHandler) ExchangeCode(ctx context.Context, code string) (*TokenResponse, error)

ExchangeCode exchanges an authorization code for tokens.

func (*OAuthHandler) GetAccessToken added in v1.1.34

func (h *OAuthHandler) GetAccessToken(ctx context.Context) (string, error)

GetAccessToken returns a valid access token, refreshing if needed. Returns empty string if no token exists. If the token is expired but there is a refresh token, it attempts to refresh. If the token is expired and there is no refresh token, it still returns the access token optimistically — the server will return 401 if truly expired, which triggers the OAuth flow. This avoids premature re-authentication when the token has a few minutes left (the 5-minute IsExpired() buffer caused tokens to be discarded too early, requiring re-auth every time).

func (*OAuthHandler) GetScopes added in v1.1.34

func (h *OAuthHandler) GetScopes() []string

GetScopes returns the scopes supported by the protected resource.

func (*OAuthHandler) Handle401 added in v1.1.34

func (h *OAuthHandler) Handle401(resp *http.Response) (bool, error)

Handle401 processes a 401 response. Returns true if OAuth is needed.

func (*OAuthHandler) NeedsDiscovery added in v1.1.34

func (h *OAuthHandler) NeedsDiscovery() bool

NeedsDiscovery returns true if OAuth metadata hasn't been discovered yet.

func (*OAuthHandler) PollDeviceToken added in v1.1.34

func (h *OAuthHandler) PollDeviceToken(ctx context.Context) (*TokenResponse, error)

PollDeviceToken polls the token endpoint until the user authorizes the device code. Should be called after StartDeviceFlow and the user visits the verification URI.

func (*OAuthHandler) RegisterClient added in v1.1.34

func (h *OAuthHandler) RegisterClient(ctx context.Context) error

RegisterClient performs RFC 7591 dynamic client registration.

func (*OAuthHandler) SaveToken added in v1.1.34

func (h *OAuthHandler) SaveToken(tokenResp *TokenResponse) error

SaveToken persists the token response to the auth store.

func (*OAuthHandler) ServerName added in v1.1.34

func (h *OAuthHandler) ServerName() string

ServerName returns the name of the MCP server this handler is for.

func (*OAuthHandler) SetClientCredentials added in v1.1.34

func (h *OAuthHandler) SetClientCredentials(clientID, clientSecret string)

SetClientCredentials sets pre-configured client credentials for servers without DCR.

func (*OAuthHandler) StartAuthFlow added in v1.1.34

func (h *OAuthHandler) StartAuthFlow(ctx context.Context) (string, error)

StartAuthFlow initiates the authorization code + PKCE flow. Returns the authorize URL for the user's browser and starts a local callback listener.

func (*OAuthHandler) StartDeviceFlow added in v1.1.34

func (h *OAuthHandler) StartDeviceFlow(ctx context.Context, scopes []string) (*DeviceFlowResponse, error)

StartDeviceFlow initiates a device authorization flow (RFC 8628). Returns the device flow response containing user_code and verification URI.

func (*OAuthHandler) SupportsDCR added in v1.1.34

func (h *OAuthHandler) SupportsDCR() bool

SupportsDCR returns true if the authorization server supports dynamic client registration.

func (*OAuthHandler) SupportsDeviceFlow added in v1.1.34

func (h *OAuthHandler) SupportsDeviceFlow() bool

SupportsDeviceFlow returns true if we can attempt device flow for this server. Checks for a known device code endpoint or a device_authorization_endpoint in metadata.

func (*OAuthHandler) WaitForCallback added in v1.1.34

func (h *OAuthHandler) WaitForCallback(ctx context.Context) (string, error)

WaitForCallback waits for the OAuth callback on the local server.

type OAuthRequiredError added in v1.1.34

type OAuthRequiredError struct {
	Handler *OAuthHandler
}

OAuthRequiredError signals that OAuth authentication is needed.

func (*OAuthRequiredError) Error added in v1.1.34

func (e *OAuthRequiredError) Error() string

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 ProtectedResourceMetadata added in v1.1.34

type ProtectedResourceMetadata struct {
	Resource               string   `json:"resource"`
	AuthorizationServers   []string `json:"authorization_servers"`
	ScopesSupported        []string `json:"scopes_supported,omitempty"`
	BearerMethodsSupported []string `json:"bearer_methods_supported,omitempty"`
}

ProtectedResourceMetadata represents RFC 9728 protected resource metadata.

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 TokenResponse added in v1.1.34

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token,omitempty"`
	Scope        string `json:"scope,omitempty"`
	// Error fields (some providers return 200 with error body)
	Error            string `json:"error,omitempty"`
	ErrorDescription string `json:"error_description,omitempty"`
}

TokenResponse represents an OAuth 2.1 token endpoint response.

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