mcpserver

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 14 Imported by: ? 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 mcpserver exposes TUICast terminal automation as MCP tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMCPServer

func NewMCPServer(service *Service, version string) (*mcp.Server, error)

NewMCPServer creates a protocol server backed by service.

Types

type CloseInfo

type CloseInfo struct {
	Closed bool `json:"closed"`
}

CloseInfo reports whether a live object was closed. Closing an already absent object is successful and returns false.

type ConnectionInfo

type ConnectionInfo struct {
	ConnectionID uint64 `json:"connectionId"`
	Profile      string `json:"profile"`
}

ConnectionInfo identifies an opened TUICast connection.

type CursorInfo

type CursorInfo struct {
	Column  int  `json:"column"`
	Row     int  `json:"row"`
	Visible bool `json:"visible"`
}

CursorInfo is the zero-based cursor location and visibility state.

type EventInfo added in v0.2.0

type EventInfo struct {
	Sequence uint64 `json:"sequence"`
	Type     string `json:"type"`
	Data     string `json:"data,omitempty"`
}

EventInfo is one terminal event. Type is "bell", "enquiry", or "unsupported"; Data is the answerback for an enquiry and the ignored sequence for an unsupported event.

type EventsInfo added in v0.2.0

type EventsInfo struct {
	SessionID uint64      `json:"sessionId"`
	Events    []EventInfo `json:"events"`
	Missed    uint64      `json:"missed,omitempty"`
}

EventsInfo lists a session's terminal events after a sequence number. Missed counts events in that range that are no longer retained.

type FailureDumpInfo added in v0.2.0

type FailureDumpInfo struct {
	SessionID          uint64                `json:"sessionId"`
	Expected           string                `json:"expected"`
	Cause              string                `json:"cause"`
	LastScreenRevision uint64                `json:"lastScreenRevision"`
	Terminal           string                `json:"terminal,omitempty"`
	Width              int                   `json:"width,omitempty"`
	Height             int                   `json:"height,omitempty"`
	DroppedBytes       uint64                `json:"droppedBytes,omitempty"`
	Records            []FlightRecordInfo    `json:"records,omitempty"`
	Unsupported        []UnsupportedSequence `json:"unsupported,omitempty"`
	Dump               string                `json:"dump,omitempty"`
}

FailureDumpInfo is the flight-recorder dump of a session's most recent failed wait. The readable format lists the recorded host output with Go escapes, such as \x1b for ESC; the jsonl format returns Dump, the same JSON-lines trace the driver SDKs receive, for saving or replay.

type FlightRecordInfo added in v0.2.0

type FlightRecordInfo struct {
	Type               string  `json:"type"`
	OffsetMilliseconds float64 `json:"offsetMilliseconds"`
	Text               string  `json:"text,omitempty"`
	Revision           uint64  `json:"revision,omitempty"`
	Width              int     `json:"width,omitempty"`
	Height             int     `json:"height,omitempty"`
}

FlightRecordInfo is one recorded read of host output or one resize. Revision is the screen revision after the output was applied.

type Profile

type Profile struct {
	Name        string
	Description string
	Protocol    string
	Terminal    tuicast.TerminalProfile
	Width       int
	Height      int
	Connector   tuicast.Connector
}

Profile is one operator-approved terminal endpoint available to MCP clients. Connector may contain resolved credentials; those values are never exposed by the service or its MCP tools.

type ProfileInfo

type ProfileInfo struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Protocol    string `json:"protocol"`
	Terminal    string `json:"terminal"`
	Width       int    `json:"width"`
	Height      int    `json:"height"`
}

ProfileInfo is the non-sensitive profile metadata returned to MCP clients.

type ScreenInfo

type ScreenInfo struct {
	SessionID    uint64     `json:"sessionId"`
	Text         string     `json:"text"`
	Width        int        `json:"width"`
	Height       int        `json:"height"`
	Cursor       CursorInfo `json:"cursor"`
	Revision     uint64     `json:"revision"`
	Title        string     `json:"title,omitempty"`
	SessionState string     `json:"sessionState"`
	SessionError string     `json:"sessionError,omitempty"`
}

ScreenInfo is a detached text representation of a terminal screen. Title is the window title set by the host, if any. SessionState is "active" or "ended"; SessionError is set only when a transport or terminal failure ended the session.

type Service

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

Service owns terminal connections and sessions used by one MCP server.

func New

func New(logger *slog.Logger, profiles []Profile, terminal TerminalFactory) (*Service, error)

New creates an MCP terminal automation service.

func (*Service) Close

func (s *Service) Close() error

Close closes all service-owned sessions and connections. It is idempotent.

func (*Service) CloseConnection

func (s *Service) CloseConnection(connectionID uint64) (CloseInfo, error)

CloseConnection closes a connection and its sessions. Repeated cleanup succeeds with Closed false.

func (*Service) CloseSession

func (s *Service) CloseSession(sessionID uint64) (CloseInfo, error)

CloseSession closes a session. Repeated cleanup succeeds with Closed false.

func (*Service) Connect

func (s *Service) Connect(ctx context.Context, profileName string) (ConnectionInfo, error)

Connect opens an operator-approved named profile.

func (*Service) Events added in v0.2.0

func (s *Service) Events(sessionID, afterSequence uint64) (EventsInfo, error)

Events returns a session's retained terminal events with sequence numbers greater than afterSequence. Events remain readable after the session ends, until it is closed.

func (*Service) FailureDump added in v0.2.0

func (s *Service) FailureDump(sessionID uint64, format string) (FailureDumpInfo, error)

FailureDump returns the flight-recorder dump of the session's most recent failed wait. Format "readable" (the default) lists the recorded output; format "jsonl" returns the JSON-lines trace in Dump.

func (*Service) OpenSession

func (s *Service) OpenSession(ctx context.Context, connectionID uint64) (SessionInfo, error)

OpenSession opens a terminal using the selected profile's fixed terminal and dimensions.

func (*Service) Press

func (s *Service) Press(sessionID uint64, key tuicast.Key, modifiers ...tuicast.KeyModifier) error

Press sends one key with optional modifiers to a terminal session.

func (*Service) Profiles

func (s *Service) Profiles() []ProfileInfo

Profiles returns sorted, non-sensitive metadata for approved endpoints.

func (*Service) Screen

func (s *Service) Screen(sessionID uint64) (ScreenInfo, error)

Screen returns the current detached screen for a session.

func (*Service) StartRecording added in v0.1.0

func (s *Service) StartRecording(sessionID uint64) (workbench.Recording, error)

StartRecording begins recording successful input and wait operations on a session. A session may have only one active recording.

func (*Service) StopRecording added in v0.1.0

func (s *Service) StopRecording(sessionID uint64) (workbench.Recording, error)

StopRecording ends a session's recording and returns its trace.

func (*Service) Type

func (s *Service) Type(sessionID uint64, text, parameter string) error

Type sends literal text to a terminal session. When the session is recording, a non-empty parameter is recorded in place of text.

func (*Service) Wait added in v0.1.0

func (s *Service) Wait(ctx context.Context, sessionID uint64, matcher tuicast.MatcherSpec, timeout, stable time.Duration) (ScreenInfo, error)

Wait waits until matcher succeeds on a session screen. A positive stable period also requires that no host output arrives for that period.

func (*Service) WaitForEnd added in v0.2.0

func (s *Service) WaitForEnd(ctx context.Context, sessionID uint64, timeout time.Duration) (ScreenInfo, error)

WaitForEnd waits until the host ends a session, such as after a sign-out, and returns its final screen. A timeout error includes the last screen.

func (*Service) WaitForIdle added in v0.1.0

func (s *Service) WaitForIdle(ctx context.Context, sessionID uint64, quiet, timeout time.Duration) (ScreenInfo, error)

WaitForIdle waits until no host output arrives for quiet.

func (*Service) WaitForText

func (s *Service) WaitForText(ctx context.Context, sessionID uint64, text string, timeout time.Duration) (ScreenInfo, error)

WaitForText waits until exact text appears on a session screen.

type SessionInfo

type SessionInfo struct {
	SessionID    uint64 `json:"sessionId"`
	ConnectionID uint64 `json:"connectionId"`
	Terminal     string `json:"terminal"`
	Width        int    `json:"width"`
	Height       int    `json:"height"`
}

SessionInfo identifies an opened TUICast terminal session.

type TerminalFactory

type TerminalFactory func(tuicast.TerminalProfile, int, int) (tuicast.Terminal, error)

TerminalFactory creates the terminal configured for a connection profile.

type UnsupportedSequence added in v0.2.0

type UnsupportedSequence struct {
	Sequence string `json:"sequence"`
	Count    uint64 `json:"count"`
}

UnsupportedSequence counts one sequence the terminal ignored.

Jump to

Keyboard shortcuts

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