mcpsh

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 20 Imported by: 0 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

mcp-sh

A Go library for giving agents a sandboxed bash shell over a running program, served through MCP. Agents get three tools—run, list_commands and help—and combine app commands with pipes, loops and builtins such as jq and grep.

Each integration is a small binary with embedded configuration. It connects to a bridge inside the program, wraps an existing MCP server, or both. The shell blocks OS process execution and restricts file access; app commands retain the program's permissions. See Sandbox and limitations.

For ready-made integrations, see Godot, GIMP and Krita.

Install

Requires Go 1.26.4 or newer. Add the library to a new integration module:

macOS / Linux (sh)

mkdir my-shell
cd my-shell
go mod init example.com/my-shell
go get github.com/brohd11/mcp-sh

Windows (PowerShell)

mkdir my-shell
cd my-shell
go mod init example.com/my-shell
go get github.com/brohd11/mcp-sh

Quickstart

This example connects to a Godot editor bridge on port 9510. Enable the bridge using Godot's setup instructions, or use your own native host's address. The CLI requires a host or upstream server in its config.

Create config.json:

{
  "host": { "address": "127.0.0.1:9510" }
}

Create main.go:

package main

import (
	"embed"

	"github.com/brohd11/mcp-sh"
)

//go:embed config.json
var appFS embed.FS

func main() {
	mcpsh.Main(mcpsh.Config{
		Name: "my_shell",
		App:  "my-shell",
		FS:   appFS,
	})
}

Run this in either shell:

go run . run 'echo hello | tr a-z A-Z'

It prints HELLO. With the bridge running, go run . commands lists the host's commands too. See Native hosts for the bridge protocol or Upstream MCP servers to wrap an existing server. Building an app covers embedding scripts and the shared CLI.

Build and prepare MCP registration:

go build -o my_shell .
./my_shell setup

On Windows, use go build -o my_shell.exe . and .\my_shell.exe setup. Run the appropriate registration command printed by setup for your MCP client; setup creates user config but does not register the server itself. Launching the binary without arguments serves MCP over stdio.

Documentation

Documentation

Overview

Package mcpsh is the CLI and MCP server behind an app's shell binary: a sandboxed bash shell over a running program, built from the app's layered config (see package profile). Each app is its own module and binary that embeds its config.json and commands/ and calls Main:

//go:embed config.json commands
var appFS embed.FS

func main() {
	mcpsh.Main(mcpsh.Config{Name: "mcp-sh-blender", App: "blender", FS: appFS})
}

`<binary> setup` prints the commands that register it with Claude Code or Codex, and what the app needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(cfg Config)

Main runs the CLI and exits.

Types

type Builtin

type Builtin = engine.Command

Builtin is a Go-side command an app binary adds to its shell.

type Config

type Config struct {
	Name    string // binary and MCP server name, e.g. "mcp-sh-blender"
	App     string // config folder name, e.g. "blender" for ~/.mcp-sh/blender/ (default: Name)
	Version string
	// UpdateRepo ("owner/repo") enables `update` via GitHub releases.
	UpdateRepo string
	// FS is the built-in config layer: config.json and an optional commands/ folder,
	// usually an embed.FS. Nil means the app is configured by user files only.
	FS fs.FS
	// Builtins are extra Go-side commands; they win over every other command source.
	Builtins []Builtin
	// Subcommands are extra CLI verbs, listed in --help after the core ones.
	Subcommands []Subcommand
	// Options overrides where config files are looked up (tests).
	Options profile.Options
	// Registrations are extra MCP server entries `setup` and --help print, such as the same
	// binary pointed at another port.
	Registrations []Registration
}

type Invocation

type Invocation = engine.Invocation

Invocation is one call of a Builtin.

type Registration added in v0.1.2

type Registration struct {
	Suffix string            // appended to the server name: "_game" -> mcp_sh_godot_game
	Env    map[string]string // environment for that entry
	Label  string            // shown as a trailing comment, e.g. "running game"
}

Registration is an extra MCP server entry for the same binary.

type Subcommand

type Subcommand struct {
	Name    string // first argument that selects it, e.g. "addon"
	Usage   string // help usage after the binary name, e.g. "addon install|status|remove [DIR]"
	Summary string // help description
	// Run gets the arguments after Name and returns the exit code.
	Run func(args []string, stdout, stderr io.Writer) int
}

Subcommand is an app-specific CLI verb, such as mcp-sh-godot's `addon`. Core verbs win over a Subcommand of the same name.

Directories

Path Synopsis
Package builtins provides in-process utilities so scripts can filter host output without ever starting an OS process: cat, grep, head, tail, wc, sort, uniq, cut, tr, seq, sed (s/// only), jq, and help.
Package builtins provides in-process utilities so scripts can filter host output without ever starting an OS process: cat, grep, head, tail, wc, sort, uniq, cut, tr, seq, sed (s/// only), jq, and help.
Package engine defines the seam between mcp-sh and the interpreter that runs scripts.
Package engine defines the seam between mcp-sh and the interpreter that runs scripts.
shengine
Package shengine is the default engine: a POSIX/bash interpreter (mvdan.cc/sh) with every side effect routed through handlers we control.
Package shengine is the default engine: a POSIX/bash interpreter (mvdan.cc/sh) with every side effect routed through handlers we control.
Package host is the server side of the host protocol: the link between mcp-sh and the program that implements commands (Godot, Blender, ...).
Package host is the server side of the host protocol: the link between mcp-sh and the program that implements commands (Godot, Blender, ...).
mcphost
Package mcphost makes an existing MCP server a source of shell commands.
Package mcphost makes an existing MCP server a source of shell commands.
scripts
Package scripts turns script files into shell commands.
Package scripts turns script files into shell commands.
Package hosttest is an in-process host speaking the host protocol, for tests of mcp-sh itself and of host binaries' Go-side builtins.
Package hosttest is an in-process host speaking the host protocol, for tests of mcp-sh itself and of host binaries' Go-side builtins.
Package mcpserver exposes a shell.Shell as MCP tools: run, list_commands and help.
Package mcpserver exposes a shell.Shell as MCP tools: run, list_commands and help.
Package profile describes one app's shell: an optional native host, upstream MCP servers, script commands and limits.
Package profile describes one app's shell: an optional native host, upstream MCP servers, script commands and limits.
Package shell ties command sources (native host, upstream MCP servers, scripts), the builtins and an engine together into one runnable shell.
Package shell ties command sources (native host, upstream MCP servers, scripts), the builtins and an engine together into one runnable shell.

Jump to

Keyboard shortcuts

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