knative / knative/func

MCP: Implement Structured Error Categories for Agent Decision-making

Open
#3,750 2 comments 0 reactions 1 assignee Claimed by @sneharathod7 View on GitHub
Dominant language
Go
Stars
365
Forks
223
Avg merge
2d 3h
Merged PRs (30d)
25

Description

### Problem

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

```go id="m7x8wq"
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

```go id="hm1wfw"
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:

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

instead of parsing raw CLI output.

---

## Possible Implementation Area

```text id="8p0ey2"
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.