server

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 26 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server is an MCP server of a toolkit namespace's tools, which follows the namespace's tools as they change, and is connected to with a transport, such as one which is in memory, for a client in the same process.

Index

Constants

View Source
const MaxChunk = 8 * 1024 * 1024

MaxChunk is the most bytes of a resource's content which are read at once, as a chunk, as its JSON-RPC frame, in base64, is at most the SDK's DefaultMaxLineLength

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt added in v1.7.0

type Opt func(*opt) error

Opt is an option of a server

func WithKeepAlive

func WithKeepAlive(interval time.Duration) Opt

WithKeepAlive pings each client at the interval, and closes its session, when it doesn't reply

func WithLogger

func WithLogger(logger *slog.Logger) Opt

WithLogger is where the server logs, such as a tool which can't be served, and what its tools log, as they run, rather than nowhere

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

WithTracer traces the calls of the server's tools

func WithVersion added in v1.7.0

func WithVersion(version string) Opt

WithVersion is the version of the server, which its clients are told, as they connect, rather than schema.DefaultVersion

func WithWorkspace added in v1.7.0

func WithWorkspace(ws workspace.Workspace) Opt

WithWorkspace serves the workspace's resources, as well as the namespace's tools: resources/list lists its folders and resources, by the folder in the request's _meta, and resources/read reads them, when it's a workspace.Reader, and the server says it's a workspace, with the experimental capability schema.Capability

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an MCP server of a namespace's tools, whose name, title and instructions are the namespace's name, description and system prompt

func New

func New(ns toolkit.Namespace, opts ...Opt) (*Server, error)

New returns a server of the namespace's tools, as they are, with the options, such as its version, with WithVersion. Run follows its tools, as they change. Returns ErrBadParameter when there's no namespace.

func (*Server) Connect added in v1.7.0

func (s *Server) Connect(ctx context.Context, transport sdkmcp.Transport) (*sdkmcp.ServerSession, error)

Connect serves a session with the transport, such as stdio, until its client closes it, or it's closed

func (*Server) InMemoryTransport added in v1.7.0

func (s *Server) InMemoryTransport(ctx context.Context) (sdkmcp.Transport, error)

InMemoryTransport returns the client's end of a new transport in memory, whose server end is connected, so a client in the same process, such as one with client.WithTransport, is connected with it. Each is connected once, so it's called for each connection.

func (*Server) Run added in v1.7.0

func (s *Server) Run(ctx context.Context) error

Run follows the namespace's tools, as they change, so its clients are told, until the context is cancelled, when it returns nil, or the namespace's watch fails, when it returns its error. Its tools are also the namespace's as they're listed, or called, whether it runs or not.

Jump to

Keyboard shortcuts

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