mcpserver

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 9 Imported by: 3 modules, 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 mcpserver serves an app's generated MCP tools over the Go MCP SDK (github.com/modelcontextprotocol/go-sdk).

1 tool is 1 RPC that the app exposes to agents: its name, its JSON Schemas, the effect that becomes its hints, and the call itself. The server puts the caller in the call's context, so that the generated permission check runs inside it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Annotations

func Annotations(effect Effect) *mcp.ToolAnnotations

Annotations returns the hints of 1 effect:

read:    readOnlyHint true, destructiveHint false, openWorldHint false
write:   readOnlyHint false, destructiveHint false, openWorldHint false
outward: readOnlyHint false, destructiveHint true, openWorldHint true

An effect the package does not know gets an outward tool's hints, so that a later effect never arrives as a harmless 1.

func NewServer

func NewServer(impl *mcp.Implementation, caller authz.Caller, tools ...[]Tool) *mcp.Server

NewServer returns an MCP server with 1 tool for each tool of tools, and the caller of every call.

The tools are registered with the SDK's raw handler: the server validates no argument and no result, and each call passes its arguments to the tool as they arrive.

func ServeStdio

func ServeStdio(ctx context.Context, server *mcp.Server, in io.ReadCloser, out io.WriteCloser) error

ServeStdio runs server on 1 standard input and 1 standard output, as an app's stdio MCP server.

The transport is newline-delimited JSON over those 2 streams, and it needs no token: the process belongs to the local user, so build the server with authz.LocalCaller, and its tools act as that user. ServeStdio returns when the stream ends or the context is cancelled.

Types

type Effect

type Effect string

Effect is what 1 tool call does, and it decides the tool's hints.

const (
	// EffectRead reads data and changes nothing.
	EffectRead Effect = "read"
	// EffectWrite changes data reversibly.
	EffectWrite Effect = "write"
	// EffectOutward is irreversible, or leaves the system.
	EffectOutward Effect = "outward"
)

The 3 effects, as docs/specs/options.md names them.

type Tool

type Tool struct {
	// Name is the tool's name: the RPC name in snake_case.
	Name string
	// Description tells an agent when to call the tool.
	Description string
	// Effect is what the call does; it decides the tool's hints.
	Effect Effect
	// InputSchema is the JSON Schema of the call's arguments.
	InputSchema json.RawMessage
	// OutputSchema is the JSON Schema of the call's result, or nil.
	OutputSchema json.RawMessage
	// Call runs the call with the caller in its context, and returns the
	// response. It decodes args, which are 1 JSON object in the proto3 JSON
	// form of the RPC's request, and reports an error for empty or malformed
	// arguments.
	Call func(ctx context.Context, args json.RawMessage) (proto.Message, error)
}

Tool is 1 MCP tool of an app: 1 RPC that the app exposes to agents.

Jump to

Keyboard shortcuts

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