Documentation
¶
Index ¶
Constants ¶
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.
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.
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 ¶
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 ¶
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.).