Skip to content

MCP: Implement Structured Error Categories for Agent Decision-making #3750

@sneharathod7

Description

@sneharathod7

Problem

Currently, MCP handlers return most CLI failures as raw strings:

fmt.Errorf("%w\n%s", err, string(out))

This works for humans, but it is difficult for agents to reliably reason about failures. Parsing CLI output is fragile and dependent on message formatting.

For example, an agent should be able to distinguish between:

  • build failures
  • registry authentication issues
  • Kubernetes connectivity problems
  • read-only mode violations

without relying on string matching.


Proposed Solution

Introduce structured error categories in MCP responses.

Proposed Model

type McpErrorResponse struct {
    Category string `json:"category"`
    Code     int    `json:"code"`
    Message  string `json:"message"`
}

Suggested Categories

  • VALIDATION_ERROR
  • BUILD_ERROR
  • REGISTRY_ERROR
  • CLUSTER_ERROR
  • READONLY_ERROR
  • TIMEOUT_ERROR

Why This Helps

Structured errors would allow agents to make better decisions programmatically.

Example:

if error.category == "REGISTRY_ERROR":
    suggest("Run 'func config registry'")

instead of parsing raw CLI output.


Possible Implementation Area

pkg/mcp/mcp.go
pkg/mcp/*

The handlers can map known failure cases into stable categories while still preserving existing human-readable messages.


Strategic Alignment

This aligns well with the "agent-native toolchain" direction and would improve:

  • autonomous workflows
  • guided remediation
  • IDE integrations
  • conversational debugging

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions