mcpserver

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package mcpserver implements `backyard mcp`: a Model Context Protocol server (stdio) that lets coding agents read the Backyard docs, scaffold sites, deploy them and look at — or reuse code from — other sites, using the credentials of the current CLI profile (SPEC §14).

Tool failures are reported as MCP tool errors (IsError results with a readable message), never as crashes: handlers recover from panics.

Index

Constants

View Source
const (
	// MaxReadBytes caps backyard_read_site_file.
	MaxReadBytes = 256 << 10
)

Variables

View Source
var DocTopics = []string{"skill", "api", "recipes", "deploy"}

DocTopics are the topics of backyard_docs.

Functions

func BinaryExt added in v0.2.0

func BinaryExt(p string) bool

BinaryExt reports whether p has the extension of a binary format.

func DefaultDocs

func DefaultDocs(topic string) (string, error)

DefaultDocs returns the embedded skill documentation for topic.

func LooksBinary added in v0.2.0

func LooksBinary(b []byte) bool

LooksBinary reports whether b is not readable text: invalid UTF-8, any NUL byte, or more than 1% control characters other than tab, newlines, form feed and escape.

func New

func New(o Options) *mcp.Server

New returns an MCP server exposing the Backyard tools.

func Run

func Run(ctx context.Context, o Options) error

Run serves the tools over o.Transport (default stdin/stdout) until ctx is cancelled or the client disconnects.

func ValidSite added in v0.2.0

func ValidSite(site string) error

ValidSite checks a site name a tool was given (the DNS-label rule; the reserved list is the server's to apply).

Types

type DeployInput

type DeployInput struct {
	Dir     string `` /* 225-byte string literal not displayed */
	Site    string `json:"site,omitempty" jsonschema:"site name (default: .backyard.json site, else the directory name)"`
	Message string `json:"message,omitempty" jsonschema:"optional deploy message"`
	DryRun  bool   `json:"dry_run,omitempty" jsonschema:"only report what would change"`
	// Overwrite allows replacing a site last deployed by another user.
	Overwrite bool `json:"overwrite,omitempty" jsonschema:"replace the site even if someone else deployed it last (only after the user agreed)"`
}

DeployInput is the input of backyard_deploy.

type DeployOutput

type DeployOutput struct {
	Site string `json:"site"`
	// Dir is the local folder that was published.
	Dir       string `json:"dir"`
	URL       string `json:"url"`
	DryRun    bool   `json:"dry_run"`
	Uploaded  int    `json:"uploaded"`
	Unchanged int    `json:"unchanged"`
	Deleted   int    `json:"deleted"`
	Bytes     int64  `json:"bytes"`
	Files     int    `json:"files"`
	Summary   string `json:"summary"`
}

DeployOutput is the result of backyard_deploy.

type DocsInput

type DocsInput struct {
	Topic string `json:"topic,omitempty" jsonschema:"documentation topic: skill (default), api, recipes or deploy"`
}

DocsInput is the input of backyard_docs.

type InitInput

type InitInput struct {
	Dir    string   `` /* 137-byte string literal not displayed */
	Site   string   `json:"site" jsonschema:"site name: lowercase letters, digits and '-' (becomes the URL)"`
	Agents []string `` /* 126-byte string literal not displayed */
}

InitInput is the input of backyard_init.

type InitOutput

type InitOutput struct {
	Dir       string   `json:"dir"`
	Site      string   `json:"site"`
	Created   []string `json:"created"`
	Skipped   []string `json:"skipped"`
	NextSteps string   `json:"next_steps"`
}

InitOutput is the result of backyard_init.

type ListSitesInput

type ListSitesInput struct {
	Query string `json:"query,omitempty" jsonschema:"optional case-insensitive filter on name, title and description"`
}

ListSitesInput is the input of backyard_list_sites.

type ListSitesOutput

type ListSitesOutput struct {
	Sites     []SiteSummary `json:"sites"`
	Total     int           `json:"total"`
	Truncated bool          `json:"truncated"`
}

ListSitesOutput is the result of backyard_list_sites.

type OpenURLInput

type OpenURLInput struct {
	Site string `json:"site,omitempty" jsonschema:"site name; omit for the hub (site directory)"`
}

OpenURLInput is the input of backyard_open_url.

type Options

type Options struct {
	// ConfigPath is the CLI config file (default clientconfig.DefaultPath()).
	ConfigPath string
	// Overrides select profile/server/gateway/token like the CLI's flags.
	Overrides clientconfig.Overrides
	// HTTP replaces the HTTP client for gateway and IdP calls (optional).
	HTTP *http.Client
	// Render renders backyard_init templates (default templates.Render).
	Render scaffold.Renderer
	// Docs returns the markdown for a topic (default: the embedded skill).
	Docs func(topic string) (string, error)
	// Getwd resolves relative directories (default os.Getwd).
	Getwd func() (string, error)
	// Now is the clock (default time.Now).
	Now func() time.Time
	// Logger receives server logs; it must not write to stdout (default:
	// discard).
	Logger *slog.Logger
	// Transport is what Run serves on (default: the process's stdin and
	// stdout, mcp.StdioTransport).
	Transport mcp.Transport
}

Options configure the server.

type ReadFileInput

type ReadFileInput struct {
	Site string `json:"site" jsonschema:"site name"`
	Path string `json:"path" jsonschema:"file path inside the site, e.g. index.html or js/app.js"`
}

ReadFileInput is the input of backyard_read_site_file.

type SiteFileEntry

type SiteFileEntry struct {
	Path string `json:"path"`
	Size int64  `json:"size"`
}

SiteFileEntry is one deployed file.

type SiteFilesOutput

type SiteFilesOutput struct {
	Site      string          `json:"site"`
	URL       string          `json:"url,omitempty"`
	Files     []SiteFileEntry `json:"files"`
	Total     int             `json:"total"`
	Truncated bool            `json:"truncated"`
}

SiteFilesOutput is the result of backyard_site_files.

type SiteInput

type SiteInput struct {
	Site string `json:"site" jsonschema:"site name"`
}

SiteInput names a site.

type SiteSummary

type SiteSummary struct {
	Name        string `json:"name"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	URL         string `json:"url"`
	UpdatedAt   string `json:"updated_at,omitempty"`
	UpdatedBy   string `json:"updated_by,omitempty"`
	FileCount   int    `json:"file_count"`
}

SiteSummary describes a site in listings.

type URLOutput

type URLOutput struct {
	URL string `json:"url"`
}

URLOutput is the result of backyard_open_url.

type WhoamiOutput

type WhoamiOutput struct {
	User      string `json:"user"`
	Email     string `json:"email,omitempty"`
	Name      string `json:"name,omitempty"`
	Admin     bool   `json:"admin"`
	Anonymous bool   `json:"anonymous"`
	Server    string `json:"server"`
	Gateway   string `json:"gateway"`
	Profile   string `json:"profile"`
	Login     string `json:"login,omitempty"`
}

WhoamiOutput is the result of backyard_whoami.

Jump to

Keyboard shortcuts

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