builtins

package
v0.11.9 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: EUPL-1.2 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const MaxGrepLines = 10_000

MaxGrepLines caps the number of matching lines accumulated in "content" mode. This prevents grepHandler from building an unbounded in-memory slice when a regex matches most lines of a large file tree (e.g., grepping for "." across the entire workspace). The "files_with_matches" and "count" modes are not bounded here because they accumulate file paths or a single integer rather than full line content.

View Source
const MaxReadBytes = 5 * 1024 * 1024 // 5 MiB

MaxReadBytes caps how many bytes a single Read or Edit handler will load from disk in one call. The agent can still page through a large file via the `offset`/`limit` arguments on Read. The cap protects the subprocess against prompt-injection that asks the agent to read /dev/zero or another arbitrarily-large source, which would otherwise OOM the mcp-serve process.

View Source
const MaxWriteBytes = 5 * 1024 * 1024 // 5 MiB

MaxWriteBytes caps the maximum content size for a single Write call. Matching MaxReadBytes (5 MiB) so an agent cannot trivially allocate unbounded memory by writing a file larger than what it could read back.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Provider)

Option configures a Provider at construction time.

func WithExecutor

func WithExecutor(exec ports.CommandExecutor) Option

WithExecutor injects a CommandExecutor used by the Bash handler.

func WithRootDir

func WithRootDir(dir string) Option

WithRootDir restricts all file-touching handlers (Read, Write, Edit, Glob, Grep, Bash cwd) to paths under dir. When dir is empty, no restriction is applied — callers that opt out must justify the broader access. Production callers (mcp-serve) always set this from the proxy config, which defaults to the workspace working directory. Tests may leave it empty when intentionally reading paths outside the working directory (e.g. t.TempDir()).

The check is a lexical prefix match on the absolute, cleaned path. It does not follow symlinks, which leaves a residual TOCTOU window; callers requiring stronger guarantees should run mcp-serve in a chrooted or sandboxed environment.

type Provider

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

Provider implements ports.ToolProvider for the built-in file-operation tools.

Tool naming convention: built-in tools intentionally use PascalCase (Read, Write, Edit, Bash, Glob, Grep) to align with the names emitted by Anthropic-class agents (Claude Code, OpenCode) in their tool_use events. This is the only deliberate exception to the plugin convention `<plugin>_<op>` (snake_case) documented in ADR 017; plugin-sourced tools continue to follow snake_case. The PascalCase alignment makes the proxy a drop-in for the agent's native tools.

func NewProvider

func NewProvider(opts ...Option) *Provider

NewProvider returns a Provider with Read, Write, Edit, Bash, Glob, and Grep registered.

func (*Provider) CallTool

func (p *Provider) CallTool(ctx context.Context, name string, args map[string]any) (*ports.ToolResult, error)

CallTool dispatches to the named tool after validating args against its JSON Schema.

Returns a Go error for unknown tool names and schema-validation failures. Returns IsError:true inside ToolResult for execution-level failures (file not found, etc.).

func (*Provider) Close

func (p *Provider) Close(_ context.Context) error

Close is a no-op; the built-in provider holds no external resources.

func (*Provider) ListTools

func (p *Provider) ListTools(_ context.Context) ([]ports.ToolDefinition, error)

ListTools returns the definitions of all registered built-in tools. Results are sorted by name to ensure deterministic ordering across calls; map iteration over p.tools is random.

Jump to

Keyboard shortcuts

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