Documentation
¶
Index ¶
- type Resource
- type Server
- func (s *Server) AddPrompts(metas ...schema.AgentMeta)
- func (s *Server) AddResources(resources ...Resource) error
- func (s *Server) AddTools(tools ...llm.Tool) error
- func (s *Server) Handler() http.Handler
- func (s *Server) RemovePrompts(names ...string)
- func (s *Server) RemoveResources(uris ...string)
- func (s *Server) RemoveTools(names ...string)
- type ServerOpt
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
sdkmcp.Implementation
// contains filtered or unexported fields
}
Server wraps the official MCP SDK server and exposes methods to run it on various transports (stdio, HTTP streamable, SSE).
func (*Server) AddPrompts ¶
AddPrompts registers one or more agents as MCP prompts. Each prompt's arguments are derived from the AgentMeta's Input JSON Schema, and the handler renders the agent's template with the arguments supplied by the client.
func (*Server) AddResources ¶
AddResources registers one or more Resource values on the server. Each resource is reachable by its URI. Returns an error for the first resource whose URI is invalid; resources registered before the error are still active. AddResources panics if the URI is not absolute (has an empty scheme) — this mirrors the SDK's own behaviour. If a URI was already registered (replace), notifications/resources/updated is sent so subscribed clients are notified of the content change.
func (*Server) AddTools ¶
AddTools registers one or more tool.Tool values on the server, converting each to the SDK types automatically. Returns an error if any schema cannot be marshalled; tools registered before the error are still active.
func (*Server) Handler ¶
Handler returns an http.Handler that speaks the 2025-03-26 Streamable HTTP MCP transport. Mount this on an HTTP server at a path of your choice.
Every request is served by the same underlying Server instance.
func (*Server) RemovePrompts ¶
RemovePrompts removes the named prompts from the server. Unknown names are silently ignored.
func (*Server) RemoveResources ¶
RemoveResources removes the resources with the given URIs from the server. Unknown URIs are silently ignored.
func (*Server) RemoveTools ¶
RemoveTools removes the named tools from the server. Unknown names are silently ignored.
type ServerOpt ¶
type ServerOpt func(*opts) error
ServerOpt is a functional option for configuring a Server.
func WithInstructions ¶
WithInstructions sets the instructions string sent to clients during initialization. Clients may forward this to an LLM as a system prompt hint.
func WithKeepAlive ¶
WithKeepAlive sets the interval at which the server sends ping requests to connected clients. If a client fails to respond, its session is closed. A zero duration (the default) disables keepalive.
func WithLogger ¶
WithLogger sets the slog.Logger used for server activity logging. If not set, no logging is performed.
func WithTitle ¶
WithTitle sets a human-readable display title for the server, shown in UIs that support the MCP title field.
func WithWebsiteURL ¶
WithWebsiteURL sets the website URL advertised in the server's Implementation descriptor.
type Session ¶
type Session interface {
// ID returns the unique identifier for this client session.
ID() string
// ClientInfo returns the name and version of the connected client, as
// reported during the MCP handshake. May return nil if unavailable.
ClientInfo() *sdkmcp.Implementation
// Capabilities returns the capabilities advertised by the client during
// the MCP handshake. May return nil if unavailable.
Capabilities() *sdkmcp.ClientCapabilities
// Meta returns the _meta map sent by the client in this tool call.
// Returns nil when no _meta was provided.
Meta() map[string]any
// Logger returns a slog.Logger whose output is forwarded to the client
// as MCP notifications/message events.
Logger() *slog.Logger
// Progress sends a progress notification to the client.
// progress is the amount completed so far; total is the total expected
// (0 means unknown); message is an optional human-readable status string.
Progress(progress, total float64, message string) error
}
Session is available inside every tool call via SessionFromContext. It provides logging and progress reporting back to the connected MCP client, as well as read-only metadata about the client.
func SessionFromContext ¶
SessionFromContext returns the Session injected into ctx for the current tool call. If no session is present (e.g. in unit tests that invoke Run directly), a no-op session backed by slog.Default() is returned.