Documentation
¶
Index ¶
- Constants
- func BrowserAutomationPreset() config.MCPServerConfig
- func MergeStartupServers(workingDir string, explicit []config.MCPServerConfig) ([]config.MCPServerConfig, []string)
- func ParseInstallArgs(args []string) (config.MCPServerConfig, error)
- func ParseMessage(data []byte) (interface{}, error)
- func PersistUserClaudeServers(cfg *config.Config) ([]string, bool, error)
- type Adapter
- type AuthorizationServerMetadata
- type CallToolParams
- type CallToolResult
- type Client
- func (c *Client) Abort()
- func (c *Client) CallTool(ctx context.Context, name string, args map[string]interface{}) (*CallToolResult, error)
- func (c *Client) Close() error
- func (c *Client) GetPrompt(ctx context.Context, name string, args map[string]interface{}) (*GetPromptResult, error)
- func (c *Client) Initialize(ctx context.Context) (*InitializeResult, error)
- func (c *Client) ListPrompts(ctx context.Context) ([]PromptDefinition, error)
- func (c *Client) ListResources(ctx context.Context) ([]ResourceDefinition, error)
- func (c *Client) ListTools(ctx context.Context) ([]ToolDefinition, error)
- func (c *Client) Name() string
- func (c *Client) ReadResource(ctx context.Context, uri string) (*ReadResourceResult, error)
- func (c *Client) Start(ctx context.Context) error
- type ClientCaps
- type ClientRegistration
- type DeviceFlowResponse
- type Error
- type GetPromptParams
- type GetPromptResult
- type ID
- type Implementation
- type InitializeParams
- type InitializeResult
- type ListPromptsResult
- type ListResourcesResult
- type ListToolsParams
- type ListToolsResult
- type Notification
- type OAuthHandler
- func (h *OAuthHandler) Close()
- func (h *OAuthHandler) ExchangeCode(ctx context.Context, code string) (*TokenResponse, error)
- func (h *OAuthHandler) GetAccessToken(ctx context.Context) (string, error)
- func (h *OAuthHandler) GetScopes() []string
- func (h *OAuthHandler) Handle401(resp *http.Response) (bool, error)
- func (h *OAuthHandler) NeedsDiscovery() bool
- func (h *OAuthHandler) PollDeviceToken(ctx context.Context) (*TokenResponse, error)
- func (h *OAuthHandler) RegisterClient(ctx context.Context) error
- func (h *OAuthHandler) SaveToken(tokenResp *TokenResponse) error
- func (h *OAuthHandler) ServerName() string
- func (h *OAuthHandler) SetClientCredentials(clientID, clientSecret string)
- func (h *OAuthHandler) StartAuthFlow(ctx context.Context) (string, error)
- func (h *OAuthHandler) StartDeviceFlow(ctx context.Context, scopes []string) (*DeviceFlowResponse, error)
- func (h *OAuthHandler) SupportsDCR() bool
- func (h *OAuthHandler) SupportsDeviceFlow() bool
- func (h *OAuthHandler) WaitForCallback(ctx context.Context) (string, error)
- type OAuthRequiredError
- type PromptArgument
- type PromptDefinition
- type PromptMessage
- type ProtectedResourceMetadata
- type ReadResourceParams
- type ReadResourceResult
- type Request
- type ResourceContent
- type ResourceDefinition
- type Response
- type ServerCaps
- type TokenResponse
- type ToolContent
- type ToolDefinition
Constants ¶
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 ¶
ParseMessage parses a JSON-RPC message from raw bytes. It can be a Request, Response, or Notification.
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 ¶
RegisterTools registers all MCP tools into the registry with "mcp__" prefix.
func (*Adapter) ServerName ¶
ServerName returns the MCP server name.
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 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 NewClientFromConfig ¶
func NewClientFromConfig(cfg config.MCPServerConfig) *Client
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) 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) ReadResource ¶
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.
type GetPromptParams ¶
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 NewStringID ¶
func (ID) MarshalJSON ¶
func (*ID) UnmarshalJSON ¶
type Implementation ¶
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 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 ResourceDefinition ¶
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.
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 ToolDefinition ¶
type ToolDefinition struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"inputSchema"`
}