mcp

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package mcp is a small Model Context Protocol server over stdio: tools and resources, as JSON-RPC 2.0 messages, one per line. It implements what tern mcp needs, without a dependency for users' modules.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("invalid arguments")

ErrInvalid wraps argument errors.

View Source
var Versions = []string{"2025-06-18", "2025-03-26", "2024-11-05"}

Versions are the protocol versions the server speaks, newest first.

Functions

func Args

func Args[T any](raw json.RawMessage) (T, error)

Args decodes a tool's arguments into T.

Types

type Resource

type Resource struct {
	URI         string
	Name        string
	Description string
	MimeType    string
	Read        func() (string, error)
}

Resource is a document a client can read.

type Server

type Server struct {
	Name, Version string
	// Instructions tell the client's model how to use the server.
	Instructions string
	Tools        []Tool
	Resources    []Resource
}

Server serves tools and resources.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, r io.Reader, w io.Writer) error

Serve reads requests from r and writes responses to w until r ends or ctx is canceled.

type Tool

type Tool struct {
	Name        string
	Title       string
	Description string
	// Schema is the JSON schema of the arguments, an object.
	Schema map[string]any
	// ReadOnly marks tools that change nothing, for clients that ask
	// before running others.
	ReadOnly bool
	Handler  func(ctx context.Context, args json.RawMessage) (string, error)
}

Tool is a function a client can call.

Jump to

Keyboard shortcuts

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