mcp

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 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 mcp serves tools to AI agents on this computer only, three ways: the Model Context Protocol's Streamable HTTP transport at Path (JSON only, no event stream and no sessions: initialize, ping, tools/list and tools/call), the same tools as a plain HTTP API under APIPath, and a skill telling an agent how to use that API at SkillPath. Every request needs the bearer token, and a Host or Origin that is not this computer is refused, against DNS rebinding.

Index

Constants

View Source
const (
	Path      = "/mcp"
	APIPath   = "/api/v1"
	SkillPath = "/skill"
)

Where each way in is served.

View Source
const MaxBody = 1 << 20

MaxBody is the largest request accepted.

Variables

View Source
var ErrBadPort = errors.New("mcp: port must be 1 to 65535")

ErrBadPort reports a port outside 1–65535.

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

Versions are the protocol versions spoken, newest first. A client asking for another gets the newest.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	Name, Version string
	// Instructions tell the agent how to use the tools.
	Instructions string
	// Token is the bearer token every request carries. Empty refuses all.
	Token string
	Tools []Tool
	// Skill is the skill's SKILL.md; nil serves none.
	Skill func() string
}

Handler is the endpoint.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Server

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

Server is the endpoint listening on 127.0.0.1.

func Listen

func Listen(port int, h http.Handler) (*Server, error)

Listen serves h on 127.0.0.1:port (0 picks one).

func (*Server) Base

func (s *Server) Base() string

Base is the server's address, without a path.

func (*Server) Close

func (s *Server) Close() error

Close stops listening and drops every connection, which cancels the tools running for them.

func (*Server) Port

func (s *Server) Port() int

Port is the port it listens on.

func (*Server) URL

func (s *Server) URL() string

URL is the MCP endpoint's address.

type Tool

type Tool struct {
	Name        string
	Description string
	// Schema is the JSON Schema of the arguments.
	Schema json.RawMessage
	Call   func(ctx context.Context, args json.RawMessage) (string, error)
}

Tool is one tool. Call's text is the result; an error is a failed result the agent reads, not a protocol error.

Jump to

Keyboard shortcuts

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