Skip to content

mcp: populate Image and URL structured output fields#3681

Open
Ankitsinghsisodya wants to merge 1 commit intoknative:mainfrom
Ankitsinghsisodya:fix/mcp-structured-output-fields
Open

mcp: populate Image and URL structured output fields#3681
Ankitsinghsisodya wants to merge 1 commit intoknative:mainfrom
Ankitsinghsisodya:fix/mcp-structured-output-fields

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

What

The build and deploy MCP tool handlers declared structured output fields
(image, url) that were never populated — only the raw message string was
set. Agents inspecting the structured response to learn the deployed URL or
built image name always received empty strings and had to parse raw text instead.

Why

Structured output fields exist so MCP clients can consume typed values without
text scraping. Empty fields make the schema misleading and break any agent that
relies on them.

How

tools_build.go — after func build exits, reload the function from disk
and read f.Build.Image. The build CLI writes the final image reference (with
digest) to .func/built-image; fn.NewFunction picks it up via
getLastBuiltImage().

tools_deploy.go — two changes:

  • Added parseDeployedURL to extract the route URL from combined stdout. Handles
    both the local-deploy format (exposed at URL:\n <url>) and the remote
    pipeline format (Function Deployed at <url>).
  • After the subprocess exits, reload the function and read f.Deploy.Image from
    func.yaml (where the deploy step persists it).

Tests

  • TestTool_Build_StructuredOutput — verifies Image is read from
    .func/built-image after a successful build.
  • TestTool_Build_StructuredOutput_NoFuncYaml — verifies that a missing
    func.yaml does not cause the handler to fail; Image is empty but no
    error is returned.
  • TestParseDeployedURL — table-driven coverage of both output formats,
    surrounding noise, and the empty / no-URL cases.
  • TestTool_Deploy_StructuredOutput — end-to-end: mock executor returns
    local-deploy output; asserts URL is correctly extracted.

- Introduced TestTool_Build_StructuredOutput to verify that the Image field is correctly populated from the .func/built-image file after a successful build.
- Added TestTool_Build_StructuredOutput_NoFuncYaml to ensure that a missing func.yaml does not cause failures, resulting in an empty Image field.
- Implemented TestParseDeployedURL to validate URL extraction from various deploy output formats.
- Created TestTool_Deploy_StructuredOutput to confirm that the URL is correctly populated from parsed output after deployment.

These tests enhance coverage for the build and deploy functionalities, ensuring proper handling of structured outputs.
Copilot AI review requested due to automatic review settings May 8, 2026 16:00
@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos May 8, 2026 16:00
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 8, 2026

[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 gauron99 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

@knative-prow knative-prow Bot added size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels May 8, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 8, 2026

Hi @Ankitsinghsisodya. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@RayyanSeliya
Copy link
Copy Markdown
Contributor

/ok-to-test

@knative-prow knative-prow Bot added ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test 🤖 Needs an org member to approve testing labels May 8, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes MCP build and deploy tool handlers so their structured outputs (image, url) are actually populated (instead of requiring clients to scrape the raw message text).

Changes:

  • Populate BuildOutput.Image by reloading the function after func build and reading .func/built-image via fn.NewFunction(...).Build.Image.
  • Populate DeployOutput.URL by parsing combined command output, and populate DeployOutput.Image by reloading the function and reading f.Deploy.Image.
  • Add unit tests for URL parsing and end-to-end structured output assertions for both tools.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/mcp/tools_build.go Populate BuildOutput.Image from reloaded function state after build.
pkg/mcp/tools_build_test.go Add tests asserting structured image output (including missing func.yaml case).
pkg/mcp/tools_deploy.go Add URL parsing and populate structured url/image fields after deploy.
pkg/mcp/tools_deploy_test.go Add table tests for URL parsing and an end-to-end structured url output test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/mcp/tools_deploy.go
Comment on lines +55 to +57
scanner := bufio.NewScanner(bytes.NewReader(out))
urlNext := false
for scanner.Scan() {
@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.97%. Comparing base (cea1c1d) to head (eec414a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3681      +/-   ##
==========================================
+ Coverage   56.92%   56.97%   +0.04%     
==========================================
  Files         181      181              
  Lines       20933    20958      +25     
==========================================
+ Hits        11916    11940      +24     
  Misses       7809     7809              
- Partials     1208     1209       +1     
Flag Coverage Δ
e2e 36.10% <0.00%> (-0.05%) ⬇️
e2e go 32.70% <0.00%> (-0.06%) ⬇️
e2e node 28.44% <0.00%> (-0.05%) ⬇️
e2e python 33.07% <0.00%> (-0.05%) ⬇️
e2e quarkus 28.58% <0.00%> (-0.03%) ⬇️
e2e rust 27.99% <0.00%> (-0.02%) ⬇️
e2e springboot 26.47% <0.00%> (-0.06%) ⬇️
e2e typescript 28.55% <0.00%> (-0.06%) ⬇️
e2e-config-ci 17.85% <0.00%> (-0.03%) ⬇️
integration 17.42% <0.00%> (-0.02%) ⬇️
unit macos-14 45.06% <100.00%> (+0.07%) ⬆️
unit macos-latest 45.06% <100.00%> (+0.07%) ⬆️
unit ubuntu-24.04-arm 45.23% <100.00%> (+0.06%) ⬆️
unit ubuntu-latest 45.91% <100.00%> (+0.07%) ⬆️
unit windows-latest 45.04% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants