Documentation
¶
Index ¶
- func SessionFromContext(ctx context.Context) llm.ConnectorSession
- type Resource
- type Server
- func (s *Server) AddConnector(ctx context.Context, conn llm.Connector) error
- func (s *Server) AddPrompts(prompts ...llm.Prompt)
- 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SessionFromContext ¶
func SessionFromContext(ctx context.Context) llm.ConnectorSession
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.
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) AddConnector ¶
AddConnector registers all tools, prompts, and resources currently exposed by an llm.Connector on this MCP server.
AddConnector does not call conn.Run. Callers are responsible for managing the connector lifecycle when working with connectors that require an active background session.
func (*Server) AddPrompts ¶
AddPrompts registers one or more llm.Prompt values as MCP prompts.
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 WithTracer ¶
WithTracer sets the OpenTelemetry tracer for distributed tracing. If not set, tracing is disabled.
func WithWebsiteURL ¶
WithWebsiteURL sets the website URL advertised in the server's Implementation descriptor.