mcpscripted

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package mcpscripted provides an MCP server whose tool results a scenario scripts, so a policy that reads tool results can be tested on every shape a server may send. The SDK-backed server in services/mcp answers only well-formed results; this one also answers JSON-RPC errors, non-2xx statuses, bodies that are not JSON-RPC, and server-sent events with progress notifications before the result.

It is reached at http://testbench:3021/<partition>/mcp and records every request, so a scenario can assert whether a call reached the server: GET /<partition>/test/requests returns {"count": n, "requests": [{"method", "tool", "arguments"}, ...]}, oldest first.

Every tool name is accepted. A tools/call's arguments script the reply:

  • text: the text of the result (default "ok"). It can carry jev:<key>=<value> markers, so the Jev answers follow the result a policy screens.
  • repeat: how many times text is repeated, for a large result (default 1). The repeated text may be at most MaxResultBytes.
  • shape: what the server sends (default "text"): text a result with one text block structured a result with the text in structuredContent and no content blocks resource a result with the text in an embedded resource image a result with one image block and no text rpc-error HTTP 200 with a JSON-RPC error whose message is the text http-error HTTP 500 with the text as a plain-text body not-jsonrpc HTTP 200 with the text as a plain-text body events server-sent events: a text result, after two progress notifications when the request carries params._meta.progressToken

Index

Constants

View Source
const (
	ShapeText       = "text"
	ShapeStructured = "structured"
	ShapeResource   = "resource"
	ShapeImage      = "image"
	ShapeRPCError   = "rpc-error"
	ShapeHTTPError  = "http-error"
	ShapeNotJSONRPC = "not-jsonrpc"
	ShapeEvents     = "events"
)

Shapes a tools/call's "shape" argument selects.

View Source
const MaxResultBytes = 1 << 20

MaxResultBytes bounds the text a call's arguments can ask for, after repeat, so one request cannot exhaust the shared testbench process.

View Source
const Path = "/mcp"

Path is the MCP endpoint path, after the partition.

View Source
const Port = 3021

Port is the container port used by the testbench.

View Source
const SessionID = "mcp-scripted-session"

SessionID is the Mcp-Session-Id the server returns from initialize.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	Method    string          `json:"method"`
	Tool      string          `json:"tool,omitempty"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
}

Request is one recorded request to the MCP endpoint.

type Service

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

Service implements testbench.Service and testbench.Partitioned.

func New

func New() *Service

New returns a new scripted MCP service.

func (*Service) Handler

func (s *Service) Handler() http.Handler

Handler serves the partitioned routes.

func (*Service) Name

func (s *Service) Name() string

Name returns the service registration name.

func (*Service) PartitionKey

func (s *Service) PartitionKey() string

PartitionKey returns the partitioning strategy used by this stateful service.

func (*Service) Port

func (s *Service) Port() int

Port returns the service's listening port.

func (*Service) Stateful

func (s *Service) Stateful() bool

Stateful reports that the service retains the requests it receives.

Jump to

Keyboard shortcuts

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