server

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

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 Resource

type Resource = llm.Resource

Resource is an alias for llm.Resource.

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 New

func New(name, version string, optFns ...ServerOpt) (*Server, error)

New creates a new MCP server with the given implementation name and version.

func (*Server) AddConnector

func (s *Server) AddConnector(ctx context.Context, conn llm.Connector) error

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

func (s *Server) AddPrompts(prompts ...llm.Prompt)

AddPrompts registers one or more llm.Prompt values as MCP prompts.

func (*Server) AddResources

func (s *Server) AddResources(resources ...Resource) error

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

func (s *Server) AddTools(tools ...llm.Tool) error

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

func (s *Server) Handler() http.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

func (s *Server) RemovePrompts(names ...string)

RemovePrompts removes the named prompts from the server. Unknown names are silently ignored.

func (*Server) RemoveResources

func (s *Server) RemoveResources(uris ...string)

RemoveResources removes the resources with the given URIs from the server. Unknown URIs are silently ignored.

func (*Server) RemoveTools

func (s *Server) RemoveTools(names ...string)

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

func WithInstructions(instructions string) ServerOpt

WithInstructions sets the instructions string sent to clients during initialization. Clients may forward this to an LLM as a system prompt hint.

func WithKeepAlive

func WithKeepAlive(d time.Duration) ServerOpt

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

func WithLogger(logger *slog.Logger) ServerOpt

WithLogger sets the slog.Logger used for server activity logging. If not set, no logging is performed.

func WithTitle

func WithTitle(title string) ServerOpt

WithTitle sets a human-readable display title for the server, shown in UIs that support the MCP title field.

func WithTracer

func WithTracer(t trace.Tracer) ServerOpt

WithTracer sets the OpenTelemetry tracer for distributed tracing. If not set, tracing is disabled.

func WithWebsiteURL

func WithWebsiteURL(url string) ServerOpt

WithWebsiteURL sets the website URL advertised in the server's Implementation descriptor.

Jump to

Keyboard shortcuts

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