helpers

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package helpers builds the servers, tools and readers that this module's own tests drive.

Everything here is exported because the tests import it from another package, which is the cost of a test tree that only sees the public API. None of it is part of what this module publishes: it is scaffolding for the suite under tests/, it carries no compatibility promise, and the layout guard fails if a package that ships ever reaches it.

Index

Constants

View Source
const (
	CodeParse          = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInternal       = -32603
)

The error codes the protocol declares, repeated here because the package keeps them unexported and a test that imported them would be asserting that a constant equals itself.

Variables

This section is empty.

Functions

func Blog

func Blog(tool mcp.Tool) *mcp.Server

Blog is a server carrying the one tool it is given, so a test can keep hold of the tool and assert about what it was called with.

func Everything

func Everything() *mcp.Server

Everything carries one of each kind, so a message can reach every branch.

func IsNonEmptyString

func IsNonEmptyString(raw json.RawMessage) bool

IsNonEmptyString reports whether a raw member is a string with something in it, which is what the protocol requires of a method name.

func ObjectMembers

func ObjectMembers(body []byte) (map[string]json.RawMessage, bool)

ObjectMembers reads a message as a JSON object, and reports whether it was one. It is how a test tells a member that is absent from one that is null, which is the difference between a notification and a request.

func Post

func Post(body string) *httptest.ResponseRecorder

Post sends one message to the web transport, through the router that mounts it, and returns what came back.

func SameJSON

func SameJSON(a, b []byte) bool

SameJSON reports whether two encodings carry the same value.

Types

type AnswerShape

type AnswerShape struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id"`
	Result  json.RawMessage `json:"result"`
	Error   *struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
	} `json:"error"`
}

AnswerShape is the response the protocol carries, read back loosely: every member is raw, so a test can tell "absent" from "null".

type Posts

type Posts struct {
	// Asked records who the tool was told to act as, which is the thing worth
	// asserting about -- everything else in this package is transport.
	Asked security.Subject
	// Refuse makes the service answer the way an authorization failure does.
	Refuse bool
}

Posts is a tool shaped the way a real one is: it asks a service, and the service is handed the Subject the request carried.

func (*Posts) Description

func (p *Posts) Description() string

func (*Posts) Handle

func (p *Posts) Handle(_ context.Context, r mcp.Request) (mcp.Response, error)

Handle records the subject it was called as, and then answers or refuses.

func (*Posts) Name

func (p *Posts) Name() string

Name and Description are what a client lists the tool as.

func (*Posts) Schema

func (p *Posts) Schema() mcp.Schema

Schema declares one closed string and one number, so a call can be wrong in both of the ways a schema catches.

type Readme

type Readme struct{}

Readme is a resource, so a message can reach the branches that list and read one.

func (Readme) Description

func (Readme) Description() string

func (Readme) MimeType

func (Readme) MimeType() string

func (Readme) Name

func (Readme) Name() string

func (Readme) Read

func (Readme) URI

func (Readme) URI() string

URI, Name, Description, MimeType and Read make it a resource.

type Summarise

type Summarise struct{}

Summarise is a prompt, so a message can reach the branches that list and render one.

func (Summarise) Arguments

func (Summarise) Arguments() []mcp.Argument

Arguments declares the one input the prompt needs before it is useful.

func (Summarise) Description

func (Summarise) Description() string

func (Summarise) Name

func (Summarise) Name() string

Name and Description are what a client lists the prompt as.

func (Summarise) Render

func (Summarise) Render(_ context.Context, r mcp.Request) ([]mcp.Message, error)

Render builds the single turn.

type Undescribed

type Undescribed struct{}

Undescribed is the mistake a server is required to refuse at boot: a tool with nothing for the model to read before deciding whether to call it.

func (Undescribed) Description

func (Undescribed) Description() string

func (Undescribed) Handle

func (Undescribed) Name

func (Undescribed) Name() string

Name, Description, Schema and Handle make it a tool, and the empty description is the whole point of it.

func (Undescribed) Schema

func (Undescribed) Schema() mcp.Schema

Jump to

Keyboard shortcuts

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