Documentation
¶
Overview ¶
Package mcp provides MCP (Model Context Protocol) server functionality. This file implements the AgentTracker, which manages spawned agent processes with resource limits, timeout enforcement, and output capture.
Package mcp implements an MCP (Model Context Protocol) server that exposes grut's git and file operations as tools for AI agent integration.
Index ¶
- func IsSensitivePath(path string) error
- type AgentInfo
- type AgentStatus
- type AgentTracker
- func (t *AgentTracker) Kill(pid int) error
- func (t *AgentTracker) KillAll()
- func (t *AgentTracker) List() []AgentInfo
- func (t *AgentTracker) Output(pid int) (stdout, stderr []string)
- func (t *AgentTracker) RunningCount() int
- func (t *AgentTracker) Spawn(ctx context.Context, command string, args []string) (int, error)
- type AuditLogger
- type PathJail
- type RateLimiter
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSensitivePath ¶
IsSensitivePath reports whether the given path (relative to the repo root) points to a file that should never be read or written through MCP or chat file operations. This blocks access to credential stores, secret keys, and internal git metadata while still allowing benign dot-files such as .gitignore and .gitattributes.
Types ¶
type AgentInfo ¶
type AgentInfo struct {
StartedAt time.Time
EndedAt time.Time
Command string
Args []string
PID int
Status AgentStatus
ExitCode int
Duration time.Duration
}
AgentInfo holds metadata about a tracked agent process.
type AgentStatus ¶
type AgentStatus int
AgentStatus represents the lifecycle state of a tracked agent.
const ( // AgentRunning indicates the agent process is still executing. AgentRunning AgentStatus = iota // AgentExited indicates the agent process exited successfully (code 0). AgentExited // AgentFailed indicates the agent process exited with a non-zero code. AgentFailed )
func (AgentStatus) String ¶
func (s AgentStatus) String() string
String returns a human-readable label for the agent status.
type AgentTracker ¶
type AgentTracker struct {
// contains filtered or unexported fields
}
AgentTracker manages spawned agent processes with concurrent access safety, resource limits (max concurrent), timeout enforcement, and output capture.
func NewAgentTracker ¶
func NewAgentTracker(maxProcesses, timeoutSeconds int) *AgentTracker
NewAgentTracker creates a new AgentTracker with the given limits. maxProcesses <= 0 defaults to 5; timeoutSeconds <= 0 defaults to 1800.
func (*AgentTracker) Kill ¶
func (t *AgentTracker) Kill(pid int) error
Kill terminates a specific agent by PID.
func (*AgentTracker) KillAll ¶
func (t *AgentTracker) KillAll()
KillAll terminates all running agents. Called on application shutdown.
func (*AgentTracker) List ¶
func (t *AgentTracker) List() []AgentInfo
List returns info for all tracked agents, in no particular order.
func (*AgentTracker) Output ¶
func (t *AgentTracker) Output(pid int) (stdout, stderr []string)
Output returns captured stdout and stderr lines for the given PID. For running agents, only previously-parsed output is returned because the underlying bytes.Buffer is concurrently written to by the exec package and reading it here without additional synchronisation would be a data race.
func (*AgentTracker) RunningCount ¶
func (t *AgentTracker) RunningCount() int
RunningCount returns the number of currently running agents.
type AuditLogger ¶
type AuditLogger struct {
// contains filtered or unexported fields
}
AuditLogger records MCP tool invocations to a structured log file.
func NewAuditLogger ¶
func NewAuditLogger(cfg config.MCPSecurityConfig) (*AuditLogger, error)
NewAuditLogger creates an audit logger based on the MCP security config. If audit logging is disabled, the returned logger is a no-op.
func (*AuditLogger) Close ¶
func (al *AuditLogger) Close() error
Close releases the underlying log file, if any.
type PathJail ¶
type PathJail struct {
// contains filtered or unexported fields
}
PathJail restricts file operations to within the git repository root. It resolves symlinks and rejects traversal attempts before any I/O occurs.
func NewPathJail ¶
NewPathJail creates a PathJail anchored at root. The root path is resolved to an absolute path and symlinks are evaluated to establish the canonical boundary.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements per-category token bucket rate limiting. Categories are "read" and "write" with independently configurable rates expressed as calls per minute.
func NewRateLimiter ¶
func NewRateLimiter(readPerMin, writePerMin int) *RateLimiter
NewRateLimiter creates a rate limiter with separate read and write rates (calls per minute).
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(category string) bool
Allow checks whether a call in the given category is permitted. Returns true if the call is allowed (and consumes a token), false if the rate limit has been exceeded.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps an MCP protocol server with grut git and file tools, rate limiting, path jailing, and audit logging.
func NewServer ¶
NewServer creates a fully configured MCP server with all git and file tools registered. The server is ready to serve over stdin/stdout.