mcp

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleBuffer

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

ConsoleBuffer is a thread-safe ring buffer for console log entries.

func NewConsoleBuffer

func NewConsoleBuffer(maxSize int) *ConsoleBuffer

NewConsoleBuffer creates a new console buffer with the given maximum size.

func (*ConsoleBuffer) Add

func (b *ConsoleBuffer) Add(entry ConsoleEntry)

Add appends an entry to the buffer. If the buffer is full, the oldest entry is dropped.

func (*ConsoleBuffer) Clear

func (b *ConsoleBuffer) Clear()

Clear removes all entries from the buffer.

func (*ConsoleBuffer) Get

func (b *ConsoleBuffer) Get(n int, level string) []ConsoleEntry

Get returns the last n entries, optionally filtered by level. If level is "all" or empty, all entries are returned. If n is 0 or negative, all matching entries are returned.

type ConsoleEntry

type ConsoleEntry struct {
	Timestamp string `json:"timestamp"`
	Level     string `json:"level"`
	Message   string `json:"message"`
}

ConsoleEntry represents a single console log entry from the webview.

type DevProcessManager

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

DevProcessManager manages the lightshell dev child process and communicates with it over a Unix domain socket.

func NewDevProcessManager

func NewDevProcessManager(projectDir string) *DevProcessManager

NewDevProcessManager creates a new dev process manager for the given project directory.

func (*DevProcessManager) Cleanup

func (d *DevProcessManager) Cleanup()

Cleanup is called on MCP server shutdown. It stops the dev process and cleans up all resources.

func (*DevProcessManager) IsRunning

func (d *DevProcessManager) IsRunning() bool

IsRunning returns whether the dev process is currently running.

func (*DevProcessManager) SendCommand

func (d *DevProcessManager) SendCommand(cmd MCPCommand) (*MCPResponse, error)

SendCommand sends a command to the dev process over the Unix socket and returns the response. Commands are serialized (one at a time).

func (*DevProcessManager) SocketPath

func (d *DevProcessManager) SocketPath() string

SocketPath returns the path of the Unix domain socket used for communication.

func (*DevProcessManager) Start

func (d *DevProcessManager) Start() error

Start launches the lightshell dev process with MCP socket support. It waits for the socket to become available and connects to it.

func (*DevProcessManager) Stop

func (d *DevProcessManager) Stop() error

Stop gracefully stops the dev process.

type MCPCommand

type MCPCommand struct {
	ID       int    `json:"id"`
	Cmd      string `json:"cmd"`
	Delay    int    `json:"delay,omitempty"`    // for screenshot (ms to wait before capture)
	Lines    int    `json:"lines,omitempty"`    // for console (number of entries)
	Level    string `json:"level,omitempty"`    // for console (filter level)
	Clear    bool   `json:"clear,omitempty"`    // for console (clear after read)
	Selector string `json:"selector,omitempty"` // for dom (CSS selector)
	Depth    int    `json:"depth,omitempty"`    // for dom (traversal depth)
	Code     string `json:"code,omitempty"`     // for eval (JS code)
}

MCPCommand is the JSON command sent from the MCP server to the dev process over the Unix socket.

type MCPResponse

type MCPResponse struct {
	ID      int             `json:"id"`
	Error   string          `json:"error,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Image   string          `json:"image,omitempty"`
	Width   int             `json:"width,omitempty"`
	Height  int             `json:"height,omitempty"`
	Status  string          `json:"status,omitempty"`
	HTML    string          `json:"html,omitempty"`
	Entries []ConsoleEntry  `json:"entries,omitempty"`
}

MCPResponse is the JSON response from the dev process back to the MCP server.

type Resource

type Resource struct {
	URI         string                 `json:"uri"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	MimeType    string                 `json:"mimeType"`
	Handler     func() (string, error) `json:"-"`
}

Resource defines an MCP resource with its URI and handler function.

type Server

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

Server is the MCP JSON-RPC 2.0 server that communicates over stdio.

func NewServer

func NewServer(projectDir string, apiDocs string) *Server

NewServer creates a new MCP server for the given project directory. apiDocs is the full LightShell API reference text to expose as a resource.

func (*Server) Run

func (s *Server) Run() error

Run starts the MCP server main loop, reading JSON-RPC requests from stdin and writing responses to stdout.

type Tool

type Tool struct {
	Name        string                                   `json:"name"`
	Description string                                   `json:"description"`
	InputSchema map[string]any                           `json:"inputSchema"`
	Handler     func(params map[string]any) (any, error) `json:"-"`
}

Tool defines an MCP tool with its schema and handler function.

Jump to

Keyboard shortcuts

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