Documentation
¶
Index ¶
- func NewServer(store Store, opts ...ServerOption) (*mcp.Server, error)
- func RegisterTools(server *mcp.Server, store Store, opts ...ServerOption)
- func ResetSharedStore()
- func Run(ctx context.Context, store Store, opts ...ServerOption) error
- func RunHTTP(ctx context.Context, store Store, addr string, opts ...ServerOption) error
- type HTTPServerResult
- type MemoryStore
- func (s *MemoryStore) Clear(_ context.Context) error
- func (s *MemoryStore) Delete(_ context.Context, key string) error
- func (s *MemoryStore) Get(_ context.Context, key string) (string, bool, error)
- func (s *MemoryStore) GetJSON(_ context.Context, key string) (interface{}, bool, error)
- func (s *MemoryStore) List(_ context.Context, prefix string) ([]string, error)
- func (s *MemoryStore) MergeJSON(_ context.Context, key string, fields map[string]interface{}) (map[string]interface{}, error)
- func (s *MemoryStore) Set(_ context.Context, key, value string) error
- func (s *MemoryStore) SetJSON(_ context.Context, key string, value interface{}) error
- type ServerOption
- type Store
- type ToolError
- type ToolOutcome
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewServer ¶
func NewServer(store Store, opts ...ServerOption) (*mcp.Server, error)
NewServer builds the session state MCP server.
func RegisterTools ¶
func RegisterTools(server *mcp.Server, store Store, opts ...ServerOption)
RegisterTools adds session-state MCP tools to an existing server.
func ResetSharedStore ¶
func ResetSharedStore()
ResetSharedStore resets the global shared store for testing purposes. This allows tests to start with a clean state.
Types ¶
type HTTPServerResult ¶
type HTTPServerResult struct {
// Addr is the actual listen address (e.g., "127.0.0.1:54321").
Addr string
// Close shuts down the server.
Close func() error
}
HTTPServerResult contains the address and cleanup function for an embedded HTTP server.
func StartHTTPServer ¶
func StartHTTPServer(ctx context.Context, store Store, addr string, opts ...ServerOption) (*HTTPServerResult, error)
StartHTTPServer starts an HTTP server on the given address and returns immediately. Use ":0" to let the OS assign a random port.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-memory session state store backed by ADK session.State. This is the default driver for inter-process state sharing.
All MemoryStore instances share a single global ADK session, so state set by one process is visible to all other processes connected to the same server.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore creates a new in-memory store using the shared ADK session. Multiple calls return stores backed by the same underlying state.
type ServerOption ¶
type ServerOption func(*serverConfig)
ServerOption customizes server construction.
func WithToolPrefix ¶
func WithToolPrefix(prefix string) ServerOption
WithToolPrefix configures MCP tool names (for example: "state" -> "state.get").
type Store ¶
type Store interface {
// Get retrieves a value by key. Returns empty string and false if not found.
Get(ctx context.Context, key string) (value string, ok bool, err error)
// Set stores a value by key.
Set(ctx context.Context, key, value string) error
// Delete removes a key. No-op if key doesn't exist.
Delete(ctx context.Context, key string) error
// List returns all keys, optionally filtered by prefix.
List(ctx context.Context, prefix string) ([]string, error)
// Clear removes all keys.
Clear(ctx context.Context) error
// GetJSON retrieves a value by key as parsed JSON.
GetJSON(ctx context.Context, key string) (value interface{}, ok bool, err error)
// SetJSON stores a value by key as JSON.
SetJSON(ctx context.Context, key string, value interface{}) error
// MergeJSON merges fields into an existing JSON object at key.
MergeJSON(ctx context.Context, key string, fields map[string]interface{}) (merged map[string]interface{}, err error)
}
Store is the interface for session state storage drivers. It wraps ADK's session.State with additional methods for MCP tools.
type ToolError ¶
type ToolError struct {
Operation string `json:"operation" jsonschema:"tool name that produced the error"`
Code string `json:"code" jsonschema:"stable machine-readable error code"`
Message string `json:"message" jsonschema:"human-readable error message"`
}
ToolError represents an error from a tool operation.
type ToolOutcome ¶
type ToolOutcome struct {
OK bool `json:"ok" jsonschema:"true when the tool completed successfully"`
Error *ToolError `json:"error,omitempty" jsonschema:"error details when ok is false"`
}
ToolOutcome represents the result of a tool operation.