server

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package server provides a wrapper around the MCP SDK server that captures tool metadata at registration time, enabling runtime filtering by read-only status, whitelists, and blacklists.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTool

func AddTool[In, Out any](s *Server, t *mcp.Tool, h mcp.ToolHandlerFor[In, Out])

AddTool registers a typed tool on the server and records its metadata. This is a free generic function because Go does not allow generic methods on types — the same pattern the MCP SDK uses for mcp.AddTool.

func BoolPtr

func BoolPtr(v bool) *bool

BoolPtr returns a pointer to a bool value. Useful for MCP ToolAnnotations fields like DestructiveHint and OpenWorldHint which are *bool.

func RegisterAccountsListTool

func RegisterAccountsListTool(s *Server, mgr *auth.Manager)

RegisterAccountsListTool registers the list_accounts tool on the given server. This tool is shared across all servers (Gmail, Drive, Calendar).

func RegisterLocalFSTools

func RegisterLocalFSTools(s *Server)

RegisterLocalFSTools registers the list_local_files and read_local_file tools on the server. These are convenience tools that give the LLM visibility into the allowed local directories. This is a no-op if the server has no LocalFS configured.

Types

type Server

type Server struct {
	*mcp.Server
	// contains filtered or unexported fields
}

Server wraps an mcp.Server to capture tool metadata at registration time. Use AddTool to register tools; it records each tool's name and read-only status automatically. After all tools are registered, call ApplyFilter to remove tools that don't match the desired filter.

func NewServer

func NewServer(impl *mcp.Implementation, opts *mcp.ServerOptions) *Server

NewServer creates a new Server wrapper around an mcp.Server.

func (*Server) ApplyFilter

func (s *Server) ApplyFilter(filter ToolFilter) error

ApplyFilter removes tools from the server based on the filter configuration. Returns an error if the filter is invalid (e.g. enable and disable both set, or referencing unknown tool names).

func (*Server) LocalFS

func (s *Server) LocalFS() *localfs.FS

LocalFS returns the local filesystem access, or nil if not configured.

func (*Server) ReadDirsDescription

func (s *Server) ReadDirsDescription() string

ReadDirsDescription returns a description snippet listing all configured directories (both read-only and read-write), suitable for appending to a tool description. Returns an empty string if no local filesystem is configured.

func (*Server) SetLocalFS

func (s *Server) SetLocalFS(fs *localfs.FS)

SetLocalFS sets the local filesystem access for the server. Tools can use LocalFS() to read/write local files within allowed directories.

func (*Server) Tools

func (s *Server) Tools() []ToolInfo

Tools returns the metadata for all registered tools.

func (*Server) WriteDirsDescription

func (s *Server) WriteDirsDescription() string

WriteDirsDescription returns a description snippet listing the configured write-enabled directories, suitable for appending to a tool description. Returns an empty string if no local filesystem is configured or there are no write directories.

type ToolFilter

type ToolFilter struct {
	// ReadOnly limits the server to read-only tools.
	ReadOnly bool
	// Enable is a whitelist of tool names to expose. Mutually exclusive with Disable.
	Enable []string
	// Disable is a blacklist of tool names to hide. Mutually exclusive with Enable.
	Disable []string
}

ToolFilter configures which tools are exposed by an MCP server.

type ToolInfo

type ToolInfo struct {
	Name     string
	ReadOnly bool
}

ToolInfo describes a registered tool for filtering purposes.

Jump to

Keyboard shortcuts

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