MCP: consume `func --json` output and forward structured errors via CallToolResult.StructuredContent
Open
@Ankitsinghsisodya is already working on this.
Since May 17, 2026.
- Dominant language
- Go
- Stars
- 365
- Forks
- 223
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 25
Description
Summary
Once func supports a --json flag (#3769), the MCP server should invoke func with --json everywhere and forward the structured payload to MCP clients via CallToolResult.StructuredContent — replacing all output parsing / error scraping currently done (or attempted) on the MCP side.
Depends on
- #3769 —
--jsonoutput mode on everyfuncsubcommand (prerequisite). This issue is implementable only after that lands.
Motivation
The MCP server currently treats func as a text-emitting black box: it captures stdout/stderr and either presents the blob to the agent verbatim or tries to classify it heuristically. Both shapes are dead ends:
- Verbatim text gives agents no machine-readable handle to dispatch on.
- Heuristic classification (see #3753) requires substring matching against output the producer can change at any time. Brittle, incomplete, and only deferred the problem.
Once func --json exists, the right MCP wrapper is roughly:
result, err := executor.Run("func", "build", "--json", ...)
// parse result.Stdout as the envelope from #3769
// on success: stick payload in StructuredContent
// on error: stick error object in StructuredContent, set IsError=true
Required changes
- Invoke
funcwith--jsonin every MCP tool handler (build,deploy,delete,create,list,describe,invoke, allconfig_*,healthcheck, etc.). Currently inconsistent — only some handlers attempt any structure at all. - Populate
CallToolResult.StructuredContentwith the parsed JSON, notTextContent. MCP already has a machine-readable channel; use it. - Surface the full error taxonomy to agents:
READONLY_ERROR,TIMEOUT_ERROR, and any other categoriesfuncemits — don't drop them on the floor. - Forward the
retryable/transientboolean from the structured error. This is the actual dispatch signal agents need ("try again" vs "give up"). - Keep
TextContentpopulated with a short human-readable summary for fallback / log display, but the canonical channel isStructuredContent. - Remove the in-MCP categorization heuristics entirely —
funcis the source of truth.
Related
- #3750 — original ask that motivated this. Should be closed-as-superseded once both this issue and #3769 are scoped.
- #3753 — first attempt, rejected because the categorization belonged in
funcrather than MCP.
Non-goals
- Defining the error taxonomy itself — that's #3769's job.
- Backwards compatibility with the current text-blob shape (the MCP surface is young; we'd rather get the shape right than freeze the current one).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.