e2emcp

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 24 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 e2emcp contains test-only MCP capture/replay boundary primitives. The ordinary daemon does not import it. No profile is registered by this package, and protocol-shape validation alone is not process or actuation proof.

Index

Constants

View Source
const MaxFrameBytes = 8 << 20
View Source
const MaxPendingRPCs = 128
View Source
const MaxRPCFrames = 4096
View Source
const SocketEnv = "PYRY_E2E_MCP_SOCKET"
View Source
const TokenEnv = "PYRY_E2E_MCP_TOKEN"

Variables

This section is empty.

Functions

func BindJSONString

func BindJSONString(raw []byte, path []string, want, replacement string) ([]byte, error)

BindJSONString replaces exactly one source-validated scalar in a disposable binding copy. Every byte outside that scalar remains literal, including whitespace, key order, unknown fields and escape spelling. It is only a codec: the profile must separately authorize the exact typed path and both values. Array steps use canonical zero-based decimal indices; object steps use keys.

func ProxyCommand

func ProxyCommand(socket, token string, args, env []string, stdio [3]*os.File) error

ProxyCommand is invoked only by a test-tag command-entry hook. It transfers the actual native-owned stdio capabilities without reading MCP stdin to EOF. It never writes environment, credentials, or the capability to disk/logs.

func WriteCapability

func WriteCapability(w io.Writer, c Capability) error

func WriteLine

func WriteLine(w io.Writer, raw []byte) error

WriteLine preserves the raw JSON exactly and requires a complete separator.

Types

type Capability

type Capability struct {
	Version             int
	Mode, Socket, Token string
}

Capability is startup-pipe data only. It must never be put in a job file, recording, process proof or diagnostic. Replay has no native proxy capability.

func ReadCapability

func ReadCapability(r io.Reader) (Capability, error)

type Coordinator

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

Coordinator orders successful complete native and MCP forwards under one mutex. A caller must perform the actual pipe write inside the supplied function; a pre-write observer cannot establish these causal barriers. Validation is supplied by the owner, including privacy and exact profile bindings. This primitive does not authorize processes or perform tool work.

func NewCoordinator

func NewCoordinator(validate func(Direction, []byte) error) (*Coordinator, error)

func NewReplayCoordinator

func NewReplayCoordinator(ctx context.Context, events []RPCEvent, validate func(Direction, []byte) error, match func(RPCEvent, []byte) error) (*Coordinator, error)

NewReplayCoordinator checks the complete immutable source trace, then gates actual current forwards against its causal counters. Matching a response is delegated to the profile's full literal or exact typed binding validator; this primitive never supplies an MCP response, approval verdict or file copy.

func (*Coordinator) Abort

func (c *Coordinator) Abort()

Abort prevents a failed runtime transfer or child from leaving sealable evidence.

func (*Coordinator) Checkpoint

func (c *Coordinator) Checkpoint() ([]RPCEvent, error)

Checkpoint freezes a pending-empty protocol prefix while the native owner is still alive. It proves no process termination. CloseRPC and Finish must later join actual EOF/Wait, and runtime must compare both complete event digests.

func (*Coordinator) CloseRPC

func (c *Coordinator) CloseRPC(connection string, inputEOF, outputEOF bool, waitErr error) error

CloseRPC requires both directions to have reached complete, non-partial EOF and the runtime's actual server Wait to have completed successfully. The boolean facts are supplied only by that owner; this is no process proof API.

func (*Coordinator) DiagnosticSnapshot

func (c *Coordinator) DiagnosticSnapshot() []RPCEvent

DiagnosticSnapshot returns only already successful complete forwards. It makes no completeness, EOF or acceptance claim and is usable after failure. The owner must separately label any retained carrier unpromotable and run its ordinary privacy checks before publication.

func (*Coordinator) Finish

func (c *Coordinator) Finish() ([]RPCEvent, error)

func (*Coordinator) ForwardRPC

func (c *Coordinator) ForwardRPC(connection string, direction Direction, wire []byte, forward func([]byte) error) error

ForwardRPC validates a trial ledger before writing. Failed/partial writes poison the coordinator, so they can never become a successful event or seal. wire excludes exactly one newline separator; forward must write it unchanged and append that separator, returning io.ErrShortWrite for any short write.

func (*Coordinator) NativeInput

func (c *Coordinator) NativeInput(user bool, forward func() error) error

NativeInput advances the all-input count after every full current forward, including controls. User frames separately advance the user ordinal. The caller validates its original frame.

func (*Coordinator) NativeOutput

func (c *Coordinator) NativeOutput(forward func() error) error

func (*Coordinator) Register

func (c *Coordinator) Register(connection string) error

Register is called only after the runtime has authenticated a current native child. A recorded connection name alone is never launch authority.

type Direction

type Direction string
const (
	ClientToServer Direction = "client-to-server"
	ServerToClient Direction = "server-to-client"
)

type Exchange

type Exchange struct {
	Ordinal  int
	Request  RPCFrame
	Response RPCFrame
}

type FrameKind

type FrameKind string
const (
	Request      FrameKind = "request"
	Notification FrameKind = "notification"
	Response     FrameKind = "response"
)

type LaunchBinding

type LaunchBinding struct {
	NativeOwnerPID                   int
	Binary, BinarySHA256             string
	Home, WorkDir, Socket, SessionID string
}

LaunchBinding is an in-memory current-source declaration supplied by the runtime owner. Never reconstruct it from recorded process IDs.

type ProxyServer

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

func NewProxyServer

func NewProxyServer(ctx context.Context, b LaunchBinding, c *Coordinator, validateStderr func([]byte) error) (*ProxyServer, error)

NewProxyServer has no production caller. It accepts only actual current native children of the supplied role owner. Real server work stays in a separately owned process; replay must not claim native parent/group semantics.

func (*ProxyServer) Capability

func (s *ProxyServer) Capability() (socket, token string)

func (*ProxyServer) FailureStage

func (s *ProxyServer) FailureStage() string

func (*ProxyServer) Join

func (s *ProxyServer) Join(budget time.Duration) ([]ServerProof, error)

Join stops new launches and joins actual authenticated servers. On deadline it cancels only exec.Cmd children owned by this server and closes its borrowed pipes/connections. It never signals a fixture ID or a native process group.

func (*ProxyServer) StderrSnapshot

func (s *ProxyServer) StderrSnapshot() (map[string]string, error)

type RPCEvent

type RPCEvent struct {
	Sequence          int
	Connection        string
	Direction         Direction
	Raw               string
	NativeInputCount  int
	UserOrdinal       int
	NativeStdoutCount int
}

RPCEvent stores the complete original line as a string: encoding/json's RawMessage marshaler would compact it. Decoding this string recovers every literal byte. Credentials/environment must never be placed in this ledger.

type RPCFrame

type RPCFrame struct {
	Kind                      FrameKind
	IDKey, Method             string
	ID, Params, Result, Error json.RawMessage
	Raw                       json.RawMessage
}

RPCFrame retains the entire original frame, including fields inside params, result and error that a typed consumer may not inspect. Raw is never rewritten. IDKey is for semantic correlation only; it is never emitted onto either pipe.

func ParseRPC

func ParseRPC(raw []byte) (RPCFrame, error)

ParseRPC checks a single newline-framed JSON-RPC envelope. It makes no tool authorization decision and neither removes nor rewrites unknown nested data.

type RPCSession

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

RPCSession is a sticky, append-only envelope ledger. Observe must be called only for successful complete forwards, in the real forwarding order. Its exchanges are shape/correlation evidence, never proof that a server executed or that a permission was granted. A runtime owner must separately bind actual process, source role/epoch, complete pipe EOF and exec.Cmd.Wait.

func NewRPCSession

func NewRPCSession() *RPCSession

func (*RPCSession) Finish

func (s *RPCSession) Finish() ([]Exchange, error)

func (*RPCSession) Observe

func (s *RPCSession) Observe(direction Direction, raw []byte) (RPCFrame, error)

type ReplayServers

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

ReplayServers owns real current MCP processes and replay-owned client pipes. It does not reproduce the native SDK's spawning, process groups or reaping. The caller must validate the complete primary/RPC causal join and declare the exact current source configuration before constructing these processes.

func StartReplayServers

func StartReplayServers(ctx context.Context, b LaunchBinding, c *Coordinator, declaredKinds []string, env []string, validateStderr func(string, []byte) error) (*ReplayServers, error)

StartReplayServers only launches the two closed command kinds, using the current binary and explicit current environment. No executable, arguments, environment or process IDs are taken from the recording. declaredKinds must equal the validated trace's connection set; this checks cardinality rather than treating a fixture connection name as launch authorization.

func (*ReplayServers) Abort

func (s *ReplayServers) Abort()

Abort interrupts and joins only this object's actual processes and pipes. Cancellation is never accepted as terminal EOF or a successful recording.

func (*ReplayServers) CompleteAndJoin

func (s *ReplayServers) CompleteAndJoin(budget time.Duration) ([]ServerProof, error)

CompleteAndJoin must be called only after successful primary termination. A previously verified live prefix is necessary, but does not itself prove primary termination. Closing these replay-owned stdin pipes then obtains genuine server EOF and actual Wait status; it cannot supply native SDK facts.

func (*ReplayServers) StderrSnapshot

func (s *ReplayServers) StderrSnapshot() (map[string]string, error)

type ServerLogs

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

ServerLogs is a bounded snapshot of bytes successfully forwarded from actual owned server stderr. It neither supplies log bytes nor declares stderr EOF. Prefix owners must pin a snapshot and require identical terminal bytes.

func (*ServerLogs) Snapshot

func (s *ServerLogs) Snapshot() (map[string]string, error)

type ServerProof

type ServerProof struct {
	Kind                                      string
	NativeOwnerPID, NativeProxyPID, ServerPID int
	InputFrames, OutputFrames                 int
	InputEOF, OutputEOF, StderrEOF            bool
	ExitCode                                  int
	Stderr                                    string
}

ServerProof is private runtime evidence, not fixture process authority. Native proxy status is deliberately absent: its actual parent is the SDK, whereas this owner can Wait only its own actual same-binary MCP server.

Jump to

Keyboard shortcuts

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