mcpserve

package module
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 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.

README

mcpserve

Project Badges

Standalone, decoupled Model Context Protocol (MCP) server for the TinyWasm ecosystem.

Core Features

  • Decoupled Architecture: Domain handlers remain agnostic of MCP types while using shared metadata.
  • Interface-based Discovery: Strict typing via ToolProvider interface.
  • IDE Integration: automated configuration for VS Code & Antigravity (Profiles supported).

Setup

h.mcp = mcpserve.NewHandler(config, toolProviders, tui, exit)
h.mcp.ConfigureIDEs() // Auto-configures IDEs
go h.mcp.Serve()      // Starts HTTP server

Documentation

Documentation

Index

Constants

View Source
const HandlerTypeLoggable = 4

LogEntry is the structured SSE payload. JSON keys and types must match devtui.tabContentDTO exactly for client-side routing. Type uses uint8 to match devtui.MessageType (tinywasm/fmt): 0=Normal,1=Info,2=Error,3=Warning. HandlerType uses int to match devtui.handlerType iota: 0=display,1=edit,2=execution,3=interactive,4=loggable. HandlerTypeLoggable is the handler_type value for plain log messages. Defined locally to avoid a circular import with devtui. MUST equal devtui.HandlerTypeLoggable (= 4). If devtui's HandlerType iota changes, update both constants in lockstep.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryData

type BinaryData struct {
	MimeType string
	Data     []byte
}

BinaryData represents binary response from tools (imported from handlers)

type Config

type Config struct {
	Port          string
	ServerName    string // MCP server name
	ServerVersion string // MCP server version
	AppName       string // Application name (used to generate MCP server ID)
	AppVersion    string // Binary version for /version endpoint (used to detect stale daemons)
}

Config contains the configuration for Handler

type Handler

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

Handler handles the Model Context Protocol server and configuration

func NewHandler

func NewHandler(config Config, toolHandlers []ToolProvider, tui TuiInterface, exitChan chan bool) *Handler

NewHandler creates a new MCP handler with minimal dependencies

func (*Handler) ConfigureIDEs

func (h *Handler) ConfigureIDEs()

ConfigureIDEs automatically configures supported IDEs with this MCP server

func (*Handler) Name added in v0.0.5

func (h *Handler) Name() string

Name returns the handler name for Loggable interface

func (*Handler) OnUIAction added in v0.0.22

func (h *Handler) OnUIAction(actionFunc func(key, value string))

OnUIAction sets the callback for generic UI actions triggered from TUI or IDE

func (*Handler) PublishLog added in v0.0.22

func (h *Handler) PublishLog(msg string)

PublishLog publishes a log message to the BUILD section as a generic MCP log.

func (*Handler) PublishTabLog added in v0.0.23

func (h *Handler) PublishTabLog(tabTitle, handlerName, handlerColor, msg string)

PublishTabLog publishes a structured log entry to the SSE stream with full routing metadata. tabTitle must match one of the section titles registered in the client TUI (e.g. "BUILD", "DEPLOY").

func (*Handler) RegisterStateProvider added in v0.0.28

func (h *Handler) RegisterStateProvider(fn func() []byte)

RegisterStateProvider registers a function that returns current handler state as JSON bytes. Called on GET /state; mcpserve does not interpret the bytes.

func (*Handler) Serve

func (h *Handler) Serve()

Serve starts the Model Context Protocol server for LLM integration via HTTP

func (*Handler) SetLog added in v0.0.5

func (h *Handler) SetLog(f func(message ...any))

SetLog implements Loggable interface

func (*Handler) Stop added in v0.0.8

func (h *Handler) Stop() error

Stop gracefully shuts down the MCP HTTP server

func (*Handler) URL added in v0.0.20

func (h *Handler) URL() string

URL returns the address where the MCP server is serving. This allows *Handler to satisfy the agent.MCPServer interface via duck typing.

type IDEInfo

type IDEInfo struct {
	ID             string
	Name           string
	GetConfigDir   func() (string, error)
	ConfigFileName string

	// IDE-specific JSON format configuration
	ServersKey   string         // "servers" for VS Code, "mcpServers" for Antigravity
	URLKey       string         // "url" for VS Code, "serverUrl" for Antigravity
	ExtraFields  map[string]any // Additional fields like "type", "autoStart"
	HasInputs    bool           // VS Code has "inputs" array, Antigravity doesn't
	SkipProfiles bool           // true = single config file, no profile scanning
}

IDEInfo represents a supported IDE and its MCP configuration format

type LogEntry added in v0.0.23

type LogEntry struct {
	Id           string `json:"id"`
	Timestamp    string `json:"timestamp"`
	Content      string `json:"content"`
	Type         uint8  `json:"type"` // matches devtui.MessageType (uint8): 1 = Info
	TabTitle     string `json:"tab_title"`
	HandlerName  string `json:"handler_name"`
	HandlerColor string `json:"handler_color"`
	HandlerType  int    `json:"handler_type"` // matches devtui.handlerType iota: 4 = loggable
}

type Loggable added in v0.0.5

type Loggable interface {
	Name() string
	SetLog(logger func(message ...any))
}

Loggable defines the interface for handlers that support logging

type Parameter added in v0.0.30

type Parameter struct {
	Name        string
	Description string
	Required    bool
	Type        string // "string", "number", "boolean"
	EnumValues  []string
	Default     any
}

Parameter describes a tool parameter

type Tool added in v0.0.30

type Tool struct {
	Name        string
	Description string
	Parameters  []Parameter
	Execute     ToolExecutor // Handler provides execution function
}

Tool provides MCP tool configuration metadata This is the standard interface that all handlers should implement

type ToolExecutor

type ToolExecutor func(args map[string]any)

ToolExecutor defines how a tool should be executed Handlers implement this to provide execution logic without exposing internals args: map of parameter name to value from MCP request

type ToolProvider added in v0.0.16

type ToolProvider interface {
	GetMCPTools() []Tool
}

ToolProvider defines the interface for handlers that support MCP tools

type TuiInterface

type TuiInterface interface {
	RefreshUI()
}

TuiInterface defines what the MCP handler needs from the TUI

Jump to

Keyboard shortcuts

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