Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateSigningKey() ([]byte, error)
- func NewToolError(code int, message string, data interface{}) error
- func NewToolErrorInternal(message string) error
- func NewToolErrorInvalidParams(message string) error
- type AuthProvider
- type BearerTokenAuth
- type Client
- type JWTSessionManager
- func (m *JWTSessionManager) CleanupExpiredSessions(ctx context.Context, maxIdleTime time.Duration) error
- func (m *JWTSessionManager) CreateSession(ctx context.Context, protocolVersion string) (string, error)
- func (m *JWTSessionManager) DeleteSession(ctx context.Context, sessionID string) error
- func (m *JWTSessionManager) GetProtocolVersion(ctx context.Context, sessionID string) (string, error)
- func (m *JWTSessionManager) ValidateSession(ctx context.Context, sessionID string) (bool, error)
- type MCPError
- type MCPRequest
- type MCPResponse
- type MCPTool
- type OAuth2Auth
- type Option
- type Parameter
- func Boolean(name, description string, options ...Option) Parameter
- func Number(name, description string, options ...Option) Parameter
- func NumberArray(name, description string, options ...Option) Parameter
- func Object(name, description string, propertiesAndOptions ...interface{}) Parameter
- func ObjectArray(name, description string, propertiesAndOptions ...interface{}) Parameter
- func Output(parameters ...Parameter) Parameter
- func String(name, description string, options ...Option) Parameter
- func StringArray(name, description string, options ...Option) Parameter
- type ResourceContent
- type ResourceResponse
- type Server
- func (s *Server) CallTool(ctx context.Context, name string, args map[string]interface{}) (*ToolResponse, error)
- func (s *Server) CleanupExpiredSessions(maxIdleTime time.Duration) error
- func (s *Server) EnableSessionManagement() error
- func (s *Server) EnableSessionManagementWithKey(signingKey []byte, ttl time.Duration)
- func (s *Server) HandleRequest(w http.ResponseWriter, r *http.Request)
- func (s *Server) ListTools() []MCPTool
- func (s *Server) RefreshTools() error
- func (s *Server) RegisterRemoteServer(url, namespace string, auth AuthProvider) error
- func (s *Server) RegisterRemoteServerHidden(url, namespace string, auth AuthProvider) error
- func (s *Server) RegisterTool(tool *ToolBuilder, handler ToolHandler)
- func (s *Server) SetInstructions(instructions string)
- func (s *Server) SetSessionManager(manager SessionManager)
- type SessionManager
- type ToolBuilder
- type ToolCallParams
- type ToolContent
- type ToolError
- type ToolHandler
- type ToolRequest
- func (r *ToolRequest) Args() map[string]interface{}
- func (r *ToolRequest) Bool(name string) (bool, error)
- func (r *ToolRequest) BoolOr(name string, defaultValue bool) bool
- func (r *ToolRequest) Float(name string) (float64, error)
- func (r *ToolRequest) FloatOr(name string, defaultValue float64) float64
- func (r *ToolRequest) FloatSlice(name string) ([]float64, error)
- func (r *ToolRequest) FloatSliceOr(name string, defaultValue []float64) []float64
- func (r *ToolRequest) GetObjectBoolProperty(objectName, propertyName string) (bool, error)
- func (r *ToolRequest) GetObjectIntProperty(objectName, propertyName string) (int, error)
- func (r *ToolRequest) GetObjectProperty(objectName, propertyName string) (interface{}, error)
- func (r *ToolRequest) GetObjectStringProperty(objectName, propertyName string) (string, error)
- func (r *ToolRequest) Int(name string) (int, error)
- func (r *ToolRequest) IntOr(name string, defaultValue int) int
- func (r *ToolRequest) IntSlice(name string) ([]int, error)
- func (r *ToolRequest) IntSliceOr(name string, defaultValue []int) []int
- func (r *ToolRequest) Object(name string) (map[string]interface{}, error)
- func (r *ToolRequest) ObjectOr(name string, defaultValue map[string]interface{}) map[string]interface{}
- func (r *ToolRequest) ObjectSlice(name string) ([]map[string]interface{}, error)
- func (r *ToolRequest) ObjectSliceOr(name string, defaultValue []map[string]interface{}) []map[string]interface{}
- func (r *ToolRequest) String(name string) (string, error)
- func (r *ToolRequest) StringOr(name, defaultValue string) string
- func (r *ToolRequest) StringSlice(name string) ([]string, error)
- func (r *ToolRequest) StringSliceOr(name string, defaultValue []string) []string
- type ToolResponse
- func NewToolResponseAudio(data []byte, mimeType string) *ToolResponse
- func NewToolResponseImage(data []byte, mimeType string) *ToolResponse
- func NewToolResponseJSON(data interface{}) *ToolResponse
- func NewToolResponseMulti(responses ...*ToolResponse) *ToolResponse
- func NewToolResponseResource(uri, text, mimeType string) *ToolResponse
- func NewToolResponseResourceLink(uri, text string) *ToolResponse
- func NewToolResponseStructured(data interface{}) *ToolResponse
- func NewToolResponseText(text string) *ToolResponse
- type ToolResult
Constants ¶
const ( MCPProtocolVersionLatest = "2025-11-25" MCPProtocolVersionMin = "2024-11-05" )
const ( ErrorCodeParseError = -32700 ErrorCodeInvalidRequest = -32600 ErrorCodeMethodNotFound = -32601 ErrorCodeInvalidParams = -32602 ErrorCodeInternalError = -32603 ErrorCodeImplementationErrorStart = -32000 ErrorCodeImplementationErrorEnd = -32099 )
MCP error codes
Variables ¶
var ( ErrUnknownTool = errors.New("unknown tool") ErrUnknownParameter = errors.New("parameter not found") )
Functions ¶
func GenerateSigningKey ¶ added in v0.6.6
GenerateSigningKey creates a cryptographically secure random signing key
func NewToolError ¶
NewToolError creates a custom MCP error with specific code
func NewToolErrorInternal ¶
NewToolErrorInternal creates an error for internal server errors
func NewToolErrorInvalidParams ¶
NewToolErrorInvalidParams creates an error for invalid parameters
Types ¶
type AuthProvider ¶
AuthProvider interface for different authentication methods
type BearerTokenAuth ¶
type BearerTokenAuth struct {
// contains filtered or unexported fields
}
BearerTokenAuth implements simple bearer token authentication
func NewBearerTokenAuth ¶
func NewBearerTokenAuth(token string) *BearerTokenAuth
NewBearerTokenAuth creates a new bearer token auth provider
func (*BearerTokenAuth) GetAuthHeader ¶
func (b *BearerTokenAuth) GetAuthHeader() (string, error)
func (*BearerTokenAuth) Refresh ¶
func (b *BearerTokenAuth) Refresh() error
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an MCP client for connecting to remote servers
func NewClient ¶
func NewClient(baseURL string, auth AuthProvider) *Client
NewClient creates a new MCP client
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, name string, args map[string]interface{}) (*ToolResponse, error)
CallTool executes a tool on the remote server
func (*Client) Initialize ¶
Initialize performs the MCP handshake with the remote server
type JWTSessionManager ¶ added in v0.6.6
type JWTSessionManager struct {
// contains filtered or unexported fields
}
JWTSessionManager provides stateless session management using JWT tokens This is the RECOMMENDED approach for production clusters as it: - Requires no external storage (Redis, Database) - Scales horizontally without coordination - Works across all server instances - Has zero infrastructure dependencies
Trade-off: Sessions cannot be revoked before expiry (acceptable for most use cases)
func NewJWTSessionManager ¶ added in v0.6.6
func NewJWTSessionManager(signingKey []byte, ttl time.Duration) *JWTSessionManager
NewJWTSessionManager creates a new JWT-based session manager signingKey should be a cryptographically secure random key (at least 32 bytes recommended) ttl is the session lifetime (e.g., 30 * time.Minute)
func (*JWTSessionManager) CleanupExpiredSessions ¶ added in v0.6.6
func (m *JWTSessionManager) CleanupExpiredSessions(ctx context.Context, maxIdleTime time.Duration) error
CleanupExpiredSessions is a no-op for JWT sessions (tokens expire automatically)
func (*JWTSessionManager) CreateSession ¶ added in v0.6.6
func (m *JWTSessionManager) CreateSession(ctx context.Context, protocolVersion string) (string, error)
CreateSession generates a new JWT session token
func (*JWTSessionManager) DeleteSession ¶ added in v0.6.6
func (m *JWTSessionManager) DeleteSession(ctx context.Context, sessionID string) error
DeleteSession is a no-op for JWT sessions (cannot revoke before expiry)
func (*JWTSessionManager) GetProtocolVersion ¶ added in v0.6.6
func (m *JWTSessionManager) GetProtocolVersion(ctx context.Context, sessionID string) (string, error)
GetProtocolVersion extracts the protocol version from a JWT session token
func (*JWTSessionManager) ValidateSession ¶ added in v0.6.6
ValidateSession validates a JWT session token
type MCPRequest ¶
type MCPRequest struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
MCP Protocol types
type MCPResponse ¶
type OAuth2Auth ¶
type OAuth2Auth struct {
// contains filtered or unexported fields
}
OAuth2Auth implements OAuth2 authentication with token refresh
func NewOAuth2Auth ¶
func NewOAuth2Auth(clientID, clientSecret, tokenURL string, scopes []string) *OAuth2Auth
NewOAuth2Auth creates a new OAuth2 auth provider
func (*OAuth2Auth) GetAuthHeader ¶
func (o *OAuth2Auth) GetAuthHeader() (string, error)
func (*OAuth2Auth) Refresh ¶
func (o *OAuth2Auth) Refresh() error
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option interface for parameter options
type Parameter ¶
type Parameter interface {
// contains filtered or unexported methods
}
Parameter interface for all parameter types
func NumberArray ¶
NumberArray creates a number array parameter
func ObjectArray ¶
ObjectArray creates an array of objects parameter
func StringArray ¶
StringArray creates a string array parameter
type ResourceContent ¶
type ResourceResponse ¶
type ResourceResponse struct {
Contents []ResourceContent `json:"contents"`
}
func NewResourceResponseBlob ¶
func NewResourceResponseBlob(uri string, data []byte, mimeType string) *ResourceResponse
func NewResourceResponseText ¶
func NewResourceResponseText(uri, text, mimeType string) *ResourceResponse
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an MCP server instance
func (*Server) CallTool ¶
func (s *Server) CallTool(ctx context.Context, name string, args map[string]interface{}) (*ToolResponse, error)
CallTool executes a tool directly with namespace support (direct API) It checks local tools first, then remote tools, then deferred/dynamic tools from the registry
func (*Server) CleanupExpiredSessions ¶ added in v0.6.6
CleanupExpiredSessions removes sessions that haven't been used in the specified duration Only works if a session manager is configured
func (*Server) EnableSessionManagement ¶ added in v0.6.6
EnableSessionManagement enables JWT-based session management (stateless, production-ready) This is the recommended approach for all deployments as it: - Requires no external dependencies (Redis, Database) - Scales horizontally without coordination - Works across all server instances - Validates sessions in ~12 microseconds
Only use SetSessionManager() if you need session revocation (Redis, Database)
func (*Server) EnableSessionManagementWithKey ¶ added in v0.6.6
EnableSessionManagementWithKey enables JWT session management with a specific signing key Use this to maintain sessions across server restarts (persist the key securely)
func (*Server) HandleRequest ¶
func (s *Server) HandleRequest(w http.ResponseWriter, r *http.Request)
HandleRequest handles MCP protocol requests
func (*Server) ListTools ¶
ListTools returns all registered tools including remote ones (direct API)
func (*Server) RefreshTools ¶
RefreshTools manually refreshes the tool cache and lookup from all remote servers
func (*Server) RegisterRemoteServer ¶
func (s *Server) RegisterRemoteServer(url, namespace string, auth AuthProvider) error
RegisterRemoteServer registers a remote MCP server
func (*Server) RegisterRemoteServerHidden ¶ added in v0.6.5
func (s *Server) RegisterRemoteServerHidden(url, namespace string, auth AuthProvider) error
RegisterRemoteServerHidden registers a remote MCP server with hidden tools
func (*Server) RegisterTool ¶
func (s *Server) RegisterTool(tool *ToolBuilder, handler ToolHandler)
RegisterTool registers a new tool with the server
func (*Server) SetInstructions ¶
func (*Server) SetSessionManager ¶ added in v0.6.6
func (s *Server) SetSessionManager(manager SessionManager)
SetSessionManager sets a custom session manager for the server For most deployments, use the default EnableSessionManagement() (JWT-based) Only use this if you need custom session storage (e.g., Redis for revocation)
type SessionManager ¶ added in v0.6.6
type SessionManager interface {
// CreateSession creates a new session and returns its ID
CreateSession(ctx context.Context, protocolVersion string) (sessionID string, err error)
// ValidateSession checks if a session exists and is valid
// Returns true if valid, updates lastUsed timestamp if applicable
ValidateSession(ctx context.Context, sessionID string) (valid bool, err error)
// GetProtocolVersion returns the negotiated protocol version for a session
GetProtocolVersion(ctx context.Context, sessionID string) (version string, err error)
// DeleteSession removes a session
DeleteSession(ctx context.Context, sessionID string) error
// CleanupExpiredSessions removes sessions older than maxIdleTime
CleanupExpiredSessions(ctx context.Context, maxIdleTime time.Duration) error
}
SessionManager defines the interface for session storage and validation Implement this interface to create custom session stores (Redis, Database, etc.)
type ToolBuilder ¶
type ToolBuilder struct {
// contains filtered or unexported fields
}
ToolBuilder provides fluent API for building tools
func NewTool ¶
func NewTool(name, description string, parameters ...Parameter) *ToolBuilder
NewTool creates a new tool with the declarative API
func (*ToolBuilder) BuildOutputSchema ¶
func (t *ToolBuilder) BuildOutputSchema() map[string]interface{}
BuildOutputSchema is a public method for building the output schema
func (*ToolBuilder) BuildSchema ¶
func (t *ToolBuilder) BuildSchema() map[string]interface{}
BuildSchema is a public method for building the input schema
func (*ToolBuilder) Description ¶ added in v0.6.0
func (t *ToolBuilder) Description() string
Description returns the tool's description
func (*ToolBuilder) Name ¶ added in v0.6.0
func (t *ToolBuilder) Name() string
Name returns the tool's name
type ToolCallParams ¶
type ToolContent ¶
type ToolContent struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Data string `json:"data,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Resource *ResourceContent `json:"resource,omitempty"`
}
type ToolHandler ¶
type ToolHandler func(ctx context.Context, req *ToolRequest) (*ToolResponse, error)
ToolHandler represents a function that handles tool calls
type ToolRequest ¶
type ToolRequest struct {
// contains filtered or unexported fields
}
ToolRequest provides typed access to tool arguments
func NewToolRequest ¶ added in v0.6.0
func NewToolRequest(args map[string]interface{}) *ToolRequest
NewToolRequest creates a new ToolRequest with the given arguments
func (*ToolRequest) Args ¶ added in v0.6.3
func (r *ToolRequest) Args() map[string]interface{}
Args returns all arguments as a map
func (*ToolRequest) FloatOr ¶
func (r *ToolRequest) FloatOr(name string, defaultValue float64) float64
func (*ToolRequest) FloatSlice ¶
func (r *ToolRequest) FloatSlice(name string) ([]float64, error)
func (*ToolRequest) FloatSliceOr ¶
func (r *ToolRequest) FloatSliceOr(name string, defaultValue []float64) []float64
func (*ToolRequest) GetObjectBoolProperty ¶
func (r *ToolRequest) GetObjectBoolProperty(objectName, propertyName string) (bool, error)
GetObjectBoolProperty extracts a bool property from an object parameter
func (*ToolRequest) GetObjectIntProperty ¶
func (r *ToolRequest) GetObjectIntProperty(objectName, propertyName string) (int, error)
GetObjectIntProperty extracts an int property from an object parameter
func (*ToolRequest) GetObjectProperty ¶
func (r *ToolRequest) GetObjectProperty(objectName, propertyName string) (interface{}, error)
GetObjectProperty extracts a property from an object parameter
func (*ToolRequest) GetObjectStringProperty ¶
func (r *ToolRequest) GetObjectStringProperty(objectName, propertyName string) (string, error)
GetObjectStringProperty extracts a string property from an object parameter
func (*ToolRequest) IntSliceOr ¶
func (r *ToolRequest) IntSliceOr(name string, defaultValue []int) []int
func (*ToolRequest) Object ¶
func (r *ToolRequest) Object(name string) (map[string]interface{}, error)
Object returns a parameter as a map[string]interface{} (generic object)
func (*ToolRequest) ObjectOr ¶
func (r *ToolRequest) ObjectOr(name string, defaultValue map[string]interface{}) map[string]interface{}
ObjectOr returns a parameter as an object or the default value
func (*ToolRequest) ObjectSlice ¶
func (r *ToolRequest) ObjectSlice(name string) ([]map[string]interface{}, error)
ObjectSlice returns a parameter as a slice of objects
func (*ToolRequest) ObjectSliceOr ¶
func (r *ToolRequest) ObjectSliceOr(name string, defaultValue []map[string]interface{}) []map[string]interface{}
ObjectSliceOr returns a parameter as a slice of objects or the default value
func (*ToolRequest) StringOr ¶
func (r *ToolRequest) StringOr(name, defaultValue string) string
func (*ToolRequest) StringSlice ¶
func (r *ToolRequest) StringSlice(name string) ([]string, error)
func (*ToolRequest) StringSliceOr ¶
func (r *ToolRequest) StringSliceOr(name string, defaultValue []string) []string
type ToolResponse ¶
type ToolResponse struct {
Content []ToolContent `json:"content"`
StructuredContent interface{} `json:"structuredContent,omitempty"`
}
ToolResponse represents the response from a tool
func NewToolResponseAudio ¶
func NewToolResponseAudio(data []byte, mimeType string) *ToolResponse
func NewToolResponseImage ¶
func NewToolResponseImage(data []byte, mimeType string) *ToolResponse
func NewToolResponseJSON ¶
func NewToolResponseJSON(data interface{}) *ToolResponse
func NewToolResponseMulti ¶
func NewToolResponseMulti(responses ...*ToolResponse) *ToolResponse
func NewToolResponseResource ¶
func NewToolResponseResource(uri, text, mimeType string) *ToolResponse
func NewToolResponseResourceLink ¶
func NewToolResponseResourceLink(uri, text string) *ToolResponse
func NewToolResponseStructured ¶
func NewToolResponseStructured(data interface{}) *ToolResponse
func NewToolResponseText ¶
func NewToolResponseText(text string) *ToolResponse
type ToolResult ¶
type ToolResult struct {
Content []ToolContent `json:"content,omitempty"`
StructuredContent interface{} `json:"structuredContent,omitempty"`
IsError bool `json:"isError,omitempty"`
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package discovery provides tool discovery functionality for MCP servers.
|
Package discovery provides tool discovery functionality for MCP servers. |
|
examples
|
|
|
client
command
|
|
|
multitenant-server
command
|
|
|
object-example
command
|
|
|
server
command
|
|
|
session-server
command
|
|
|
tool-discovery
command
|
|
|
unified-server
command
|
|
|
example
command
|