Skip to content

feat(mcp): return structured JSON from the 'list' tool - #4001

Open
Ankitsinghsisodya wants to merge 7 commits into
knative:mainfrom
Ankitsinghsisodya:feat/mcp-list-structured-output
Open

feat(mcp): return structured JSON from the 'list' tool#4001
Ankitsinghsisodya wants to merge 7 commits into
knative:mainfrom
Ankitsinghsisodya:feat/mcp-list-structured-output

Conversation

@Ankitsinghsisodya

Copy link
Copy Markdown
Contributor

Changes

  • 🎁 Update the list MCP tool to return structured JSON (items: name, namespace, runtime, url, ready, deployer; plus warnings) instead of an opaque message string, following the same "semantic" pattern introduced by the describe tool in feat(mcp): add 'describe' tool and update documentation #3995
  • 🎁 Force --output json internally regardless of caller input, using ExecuteSplit so stderr content can never corrupt the parsed JSON (same rationale as describe)
  • 🎁 Handle the CLI's "no functions found" text (printed on stdout even under --output json) as a valid empty result instead of a parse error
  • 🎁 Add tests covering args, empty results, malformed output, stderr warnings, and CLI errors
  • 🎁 Update pkg/mcp/instructions.md to document the new items/warnings output shape

This follows up on review feedback from #3995 (#3995 (comment)), which identified list as the highest-priority command to move from the "passthrough" (Message: string) pattern to the "semantic" (structured, parsed) pattern, since it already supports --output json.

/kind enhancement

Fixes #

Release Note
release-note Changed the `list` MCP tool to return structured JSON (an `items` array with each Function's name, namespace, runtime, url, readiness, and deployer, plus a `warnings` field) instead of raw CLI text output. ​

Docs
docs ​

- Introduced the 'describe' tool with support for both path and name parameters.
- Updated instructions to clarify the requirements for 'delete' and 'describe' tools.
- Added help resources for the 'describe' tool in the MCP server.

This enhances the functionality of the MCP by providing a way to describe functions in the cluster.
- Added a new test to verify that the describe handler correctly parses JSON output even when preceded by non-JSON warnings in stderr.
- Introduced a new function, parseDescribeOutput, to extract and parse the JSON object from combined stdout+stderr output, ensuring robustness against leading noise.

This improves the reliability of the describe tool in real-world scenarios where warnings may be emitted before the JSON payload.
- Added ExecuteSplit method to the executor interface, allowing separate capture of stdout and stderr.
- Updated the describe handler to utilize ExecuteSplit, ensuring JSON parsing is unaffected by stderr warnings.
- Modified tests to validate the new execution method and its behavior with leading stderr content.

This enhancement increases the robustness of the describe tool by preventing stderr noise from interfering with JSON output parsing.
…on rules

- Updated the describe tool to include middleware version information in the output.
- Added validation to ensure 'namespace' is only valid when describing by 'name', rejecting cases where both 'path' and 'namespace' are provided.
- Enhanced documentation to clarify usage and requirements for the describe command.
- Added tests to verify the new middleware handling and validation logic.

These changes improve the functionality and robustness of the describe tool, ensuring accurate representation of function instances in the cluster.
- Updated the list tool to return structured JSON output, including an `items` array with details of deployed Functions and a `warnings` field for non-fatal issues.
- Modified the list handler to utilize separate stdout and stderr capturing, improving error reporting and JSON parsing reliability.
- Added tests to ensure correct handling of various output scenarios, including no functions found, empty stdout, and malformed JSON.

These changes enhance the usability and robustness of the list tool, providing clearer output and better error management.
Copilot AI lite review requested due to automatic review settings August 10, 2026 19:17
@knative-prow knative-prow Bot added the kind/enhancement Feature additions or improvements to existing label Aug 10, 2026
@knative-prow

knative-prow Bot commented Aug 10, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ankitsinghsisodya
Once this PR has been reviewed and has the lgtm label, please assign lkingland for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@knative-prow knative-prow Bot added the size/XL 🤖 PR changes 500-999 lines, ignoring generated files. label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement Feature additions or improvements to existing size/XL 🤖 PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants