summarize

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package summarize provides pluggable tool result summarization hooks.

Use summarize.Passthrough for proxy tools before domain summarizers exist. Use summarize.Meta to pass context from present hooks to summarizers. Limit is the common cross-app field; SinceSeq, RunID, and Extra are optional.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToolListItems

func ToolListItems[T any](items []T, total int, meta Meta, spec ToolListSummary[T]) (summary string, next []string)

ToolListItems builds envelope summary and next hints from a counted tool list payload.

Types

type Meta

type Meta struct {
	Limit    int            // List cap applied during present.
	SinceSeq int            // Optional paging cursor.
	RunID    string         // Optional entity id context.
	Extra    map[string]any // App-specific present→summarize context.
}

Meta carries presentation metadata from prepare/present hooks to summarizers.

Named fields are optional convenience slots for common patterns. Extra is an open bag for app-specific context. Summarizers should ignore fields they do not use.

func (Meta) Get

func (m Meta) Get(key string) any

Get returns a value from Extra.

func (Meta) Int

func (m Meta) Int(key string) int

Int returns an int value from Extra.

func (*Meta) Put

func (m *Meta) Put(key string, value any)

Put stores a value in Extra, allocating the map when needed.

func (Meta) String

func (m Meta) String(key string) string

String returns a string value from Extra.

type Registry

type Registry struct {
	Summarize SummaryFunc
	Subjects  SubjectsFunc
}

Registry holds pluggable summarization hooks for a tool server.

func Default

func Default() *Registry

Default returns a registry that uses the tool name as summary.

func Passthrough

func Passthrough() *Registry

Passthrough returns a registry that uses the tool name as summary and omits subjects. Use with summarize.NewResponder for proxy tools before domain summarizers are ready.

func RegistryFromSummaries

func RegistryFromSummaries(summaries ToolSummaries) *Registry

RegistryFromSummaries builds a Registry backed by per-tool summarizers.

type Responder

type Responder struct {
	Registry *Registry
	Adapter  adapter.Options
}

Responder builds MCP tool results from envelopes using a registry.

func NewResponder

func NewResponder(reg *Registry) *Responder

NewResponder returns a responder with the given registry or Default when nil.

func (*Responder) Error

func (r *Responder) Error(err error) (*sdkmcp.CallToolResult, any, error)

Error builds an error CallToolResult.

func (*Responder) OK

func (r *Responder) OK(tool string, data any, meta Meta) (*sdkmcp.CallToolResult, any, error)

OK builds a success CallToolResult for tool name and payload data.

type SubjectsFunc

type SubjectsFunc func(tool string, data any, meta Meta) []envelope.Subject

SubjectsFunc returns entity references extracted from a tool result.

type SummaryFunc

type SummaryFunc func(tool string, data any, meta Meta) (summary string, next []string)

SummaryFunc returns a short summary and continuation hints for a tool result.

type ToolListSummary

type ToolListSummary[T any] struct {
	CountLabel string
	Next       []string
	PageHint   string
	SampleSize int
	NextFor    func(T) []string
}

ToolListSummary configures summary and next-hint generation for a list tool result.

type ToolSummaries

type ToolSummaries map[string]ToolSummary

ToolSummaries maps MCP tool names to result summarizers.

func (ToolSummaries) Subjects

func (b ToolSummaries) Subjects(tool string, data any, meta Meta) []envelope.Subject

Subjects dispatches to a registered tool summarizer.

func (ToolSummaries) Summarize

func (b ToolSummaries) Summarize(tool string, data any, meta Meta) (summary string, next []string)

Summarize dispatches to a registered tool summarizer or returns the tool name.

type ToolSummary

type ToolSummary struct {
	Summarize func(data any, meta Meta) (summary string, next []string, ok bool)
	Subjects  func(data any, meta Meta) ([]envelope.Subject, bool)
}

ToolSummary summarizes one MCP tool result and extracts envelope subjects.

Jump to

Keyboard shortcuts

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