sessionmcp

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

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.

func Run

func Run(ctx context.Context, store Store, opts ...ServerOption) error

Run serves the session state MCP server over stdio.

func RunHTTP

func RunHTTP(ctx context.Context, store Store, addr string, opts ...ServerOption) error

RunHTTP serves the session state MCP server over HTTP.

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.

func (*MemoryStore) Clear

func (s *MemoryStore) Clear(_ context.Context) error

func (*MemoryStore) Delete

func (s *MemoryStore) Delete(_ context.Context, key string) error

func (*MemoryStore) Get

func (s *MemoryStore) Get(_ context.Context, key string) (string, bool, error)

func (*MemoryStore) GetJSON

func (s *MemoryStore) GetJSON(_ context.Context, key string) (interface{}, bool, error)

GetJSON retrieves a value by key and unmarshals it as JSON.

func (*MemoryStore) List

func (s *MemoryStore) List(_ context.Context, prefix string) ([]string, error)

func (*MemoryStore) MergeJSON

func (s *MemoryStore) MergeJSON(_ context.Context, key string, fields map[string]interface{}) (map[string]interface{}, error)

MergeJSON merges fields into an existing JSON object at key. If the key doesn't exist, it creates a new object with the provided fields.

func (*MemoryStore) Set

func (s *MemoryStore) Set(_ context.Context, key, value string) error

func (*MemoryStore) SetJSON

func (s *MemoryStore) SetJSON(_ context.Context, key string, value interface{}) error

SetJSON stores a value by key as JSON.

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.

Jump to

Keyboard shortcuts

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