How fzxbl/terminal-mcp works
terminal-mcp is an MCP server that gives agents persistent interactive PTY sessions and lets people observe or take over those same sessions in a browser. The main flow is MCP client → registered tools → session operations → PTY process and captured output, with oversized output explored on demand. The README also documents shell-switch rearming, audit/replay, and multi-node routing. Relationships use the README and indexed or excerpted source references; unsampled internals are represented only where documented.
Main entry points: session.go Session operations · server.go MCP HTTP server · tools.go Terminal tools · proc.go PTY process
Components 22
Client interfaces
- MCP HTTP server
mcpserver/server.go - Terminal tools
mcpserver/tools.go - Web terminal
internal/terminal/page.go - Terminal endpoints
internal/terminal/terminal.go
Session runtime
- Session operations
internal/session/session.go - Session API
internal/session/api.go - Session registry
internal/session/store.go - Session access
internal/session/access.go - Shell rearming
internal/session/rearm.go - PTY process
internal/pty/proc.go
Output and replay
- Raw transcript
internal/pty/transcript.go - Output log
internal/oplog/oplog.go - Output cleaning
internal/clean/clean.go - ANSI and sentinel
internal/interp/interp.go - Output exploration
internal/textexplore/textexplore.go - Output references
internal/outputref/outputref.go
Operations and routing
- Session routing
mcpserver/routing.go - List fan-out
mcpserver/fanout.go - Configuration
internal/config/config.go - Tool audit
internal/audit/audit.go
Other components
- MCP client
- Human operator
Connections 21
- MCP client → MCP HTTP server: calls tools
README.md - MCP HTTP server → Terminal tools: registers
mcpserver/server.go - Terminal tools → Session operations: invokes operations
mcpserver/tools.go - Terminal tools → Tool audit: records calls
mcpserver/tools.go - Human operator → Web terminal: opens terminal
README.md - Web terminal → Terminal endpoints: drives session
README.md - Terminal endpoints → Session operations: accesses session
internal/terminal/terminal.go - MCP HTTP server → Session routing: routes requests
mcpserver/server.go - Session routing → MCP HTTP server: proxies requests
mcpserver/routing.go - Terminal tools → List fan-out: aggregates listing
mcpserver/tools.go - Session operations → Session registry: adds sessions
internal/session/session.go - Session operations → PTY process: starts and controls
internal/session/session.go - Session operations → Shell rearming: rearms shells
README.md - PTY process → Output log: appends output
internal/pty/proc.go - Session operations → Output exploration: explores output
internal/session/session.go - Output exploration → Output cleaning: cleans lines
internal/textexplore/textexplore.go - Output cleaning → ANSI and sentinel: strips sequences
internal/clean/clean.go - Session operations → Output references: returns large results
internal/session/session.go - Session operations → Raw transcript: saves raw stream
README.md - Session registry → PTY process: closes processes
internal/session/store.go - MCP HTTP server → Configuration: uses settings
mcpserver/server.go