Skip to content

refactor(mcp): call pkg/functions directly for list tool#3778

Open
xenonnn4w wants to merge 1 commit into
knative:mainfrom
xenonnn4w:mcpaddon
Open

refactor(mcp): call pkg/functions directly for list tool#3778
xenonnn4w wants to merge 1 commit into
knative:mainfrom
xenonnn4w:mcpaddon

Conversation

@xenonnn4w
Copy link
Copy Markdown
Contributor

@xenonnn4w xenonnn4w commented May 17, 2026

Describe what this PR does

Migrates the MCP list tool from shelling out to func list (and parsing stdout) to a direct call into pkg/functions.Client.List.

This is the first slice of the broader pkg/mcp -> pkg/functions migration tracked in #3771.

Changes

  • pkg/mcp/tools_list.go

    • Updates the handler to call client.List(ctx, namespace) directly.
    • ListOutput.Functions now carries typed []fn.ListItem into CallToolResult.StructuredContent.
    • Keeps Message as a short readable fallback summary.
    • Removes Output and Verbose from ListInput since they were CLI-rendering flags that no longer apply once the canonical result is structured.
  • pkg/mcp/mcp.go

    • Adds WithClientProvider(func() *fn.Client) so the MCP server can lazily resolve a *fn.Client per tool invocation.
  • cmd/mcp.go

    • Captures the client by closure and passes it to the MCP server through the new provider.
    • Avoids the chicken-and-egg issue with fn.WithMCPServer, where the MCP server is constructed before the client.
  • Tests

    • Rewrites tests to inject a mock fn.Lister via fn.WithListers.
    • Verifies structured output population.
    • Verifies the lister path is invoked directly instead of using subprocess execution.

Other MCP tools continue using the executor interface for now and will migrate incrementally as part of the phased plan in #3771.

Why

This change removes subprocess execution and stdout parsing from the MCP list tool path in favor of typed structured data returned directly from pkg/functions.

The migration:

  • Improves reliability by avoiding fragile output parsing.
  • Aligns MCP tooling with the canonical pkg/functions API surface.
  • Establishes the migration pattern for remaining MCP tools.

Related Issues

Describe how to verify it

go test ./pkg/mcp/...
go test ./pkg/functions/...
go build ./...

Verify that:

  • MCP list tool returns structured function items in CallToolResult.StructuredContent.
  • Mock fn.Lister implementations are invoked directly.
  • No subprocess execution path is used for the list tool.

Special notes for reviews

  • This is an internal refactor with no intended user-visible behavior change.
  • MCP surface remains experimental as noted in cmd/mcp.go.
  • Output and Verbose inputs were removed because they only controlled CLI rendering behavior and are no longer relevant with structured output.
  • Remaining MCP tools still use the existing executor interface and will migrate incrementally.

Checklist

  • I have written necessary docs and comments
  • I have added necessary unit tests and integration tests where applicable
  • All checks passed in make test where applicable

@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 17, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: xenonnn4w
Once this PR has been reviewed and has the lgtm label, please assign jrangelramos 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 requested review from dsimansk and jrangelramos May 17, 2026 17:57
@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 17, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 17, 2026

Hi @xenonnn4w. 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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 17, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.06%. Comparing base (584c11e) to head (0a9d887).

Files with missing lines Patch % Lines
pkg/mcp/tools_list.go 78.78% 5 Missing and 2 partials ⚠️
cmd/mcp.go 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3778      +/-   ##
==========================================
+ Coverage   57.03%   57.06%   +0.03%     
==========================================
  Files         182      182              
  Lines       21376    21408      +32     
==========================================
+ Hits        12191    12216      +25     
- Misses       7953     7957       +4     
- Partials     1232     1235       +3     
Flag Coverage Δ
e2e 35.75% <0.00%> (-0.06%) ⬇️
e2e go 31.36% <0.00%> (-0.05%) ⬇️
e2e node 27.21% <0.00%> (-0.05%) ⬇️
e2e python 31.73% <0.00%> (-0.05%) ⬇️
e2e quarkus 27.33% <0.00%> (-0.05%) ⬇️
e2e rust 26.74% <0.00%> (-0.03%) ⬇️
e2e springboot 25.27% <0.00%> (-0.04%) ⬇️
e2e typescript 27.31% <0.00%> (-0.05%) ⬇️
e2e-config-ci 28.11% <0.00%> (-0.05%) ⬇️
integration 17.18% <0.00%> (+<0.01%) ⬆️
unit macos-14 45.14% <83.78%> (+0.04%) ⬆️
unit macos-latest 45.14% <83.78%> (+0.04%) ⬆️
unit ubuntu-24.04-arm 45.38% <83.33%> (+0.04%) ⬆️
unit ubuntu-latest 46.08% <83.78%> (+0.04%) ⬆️
unit windows-latest 45.18% <83.78%> (+0.04%) ⬆️

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.

@xenonnn4w
Copy link
Copy Markdown
Contributor Author

@lkingland can you give a review. thanks!

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

Labels

needs-ok-to-test 🤖 Needs an org member to approve testing size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant