feat(mcp): integrate tools with functions.Client API instead of CLI shell-out#3889
feat(mcp): integrate tools with functions.Client API instead of CLI shell-out#3889vishwas-droid wants to merge 4 commits into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: vishwas-droid The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @vishwas-droid. 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 Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
6185eb4 to
797955f
Compare
…hell-out Replace MCP tool handlers that exec'd the func binary with a native service layer backed by functions.Client. This enables structured JSON outputs, correct path handling, and readonly enforcement at the API level. Adds describe, invoke, run, and logs MCP tools. Help resources continue to use CLI subprocess for --help text.
797955f to
96ba29e
Compare
There was a problem hiding this comment.
Pull request overview
This PR migrates the MCP server implementation from shelling out to the func CLI toward a native Service layer backed by functions.Client, enabling structured JSON outputs for tool responses and avoiding subprocess cwd/path fragility.
Changes:
- Introduces a
Serviceabstraction that executes MCP tool operations viafunctions.Client(build/deploy/list/delete/create + new describe/invoke/run/logs tools). - Refactors MCP server startup (
cmd/mcp start) to inject a client factory into the MCP server, decoupling MCP fromfn.WithMCPServer(...). - Updates MCP resources (e.g., languages, function state) to use the native service layer where possible, while keeping help/templates via CLI executor.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/mcp/types.go | Adds ClientConfig and ClientFactory types for constructing functions.Client instances. |
| pkg/mcp/tools_test.go | Adds initTestFunction helper to create an initialized function for tests. |
| pkg/mcp/tools_run.go | Adds new run MCP tool and handler wired to the service layer. |
| pkg/mcp/tools_logs.go | Adds new logs MCP tool and handler wired to the service layer. |
| pkg/mcp/tools_list.go | Switches list tool from CLI executor output to service-backed structured output. |
| pkg/mcp/tools_list_test.go | Updates list tool tests to use the service-backed implementation. |
| pkg/mcp/tools_invoke.go | Adds new invoke MCP tool and handler wired to the service layer. |
| pkg/mcp/tools_describe.go | Adds new describe MCP tool and handler wired to the service layer. |
| pkg/mcp/tools_deploy.go | Switches deploy tool to service-backed deploy and structured output. |
| pkg/mcp/tools_deploy_test.go | Updates deploy tool tests (keeps readonly rejection coverage). |
| pkg/mcp/tools_delete.go | Switches delete tool to service-backed delete while retaining input validation + readonly behavior. |
| pkg/mcp/tools_delete_test.go | Updates delete tool tests (keeps readonly rejection coverage). |
| pkg/mcp/tools_create.go | Switches create tool to service-backed create and structured output. |
| pkg/mcp/tools_create_test.go | Updates create tool test to create into a temp dir via service-backed handler. |
| pkg/mcp/tools_config_volumes.go | Switches config volumes tools to service-backed operations. |
| pkg/mcp/tools_config_volumes_test.go | Updates config volumes tests to use real service-backed behavior. |
| pkg/mcp/tools_config_labels.go | Switches config labels tools to service-backed operations. |
| pkg/mcp/tools_config_labels_test.go | Updates config labels tests to use real service-backed behavior. |
| pkg/mcp/tools_config_envs.go | Switches config envs tools to service-backed operations (validation still present). |
| pkg/mcp/tools_config_envs_test.go | Updates config envs tests to use real service-backed behavior. |
| pkg/mcp/tools_build.go | Switches build tool to service-backed build and structured output. |
| pkg/mcp/tools_build_test.go | Updates build test to avoid requiring CLI executor; checks for missing factory error. |
| pkg/mcp/service.go | Adds the core service implementation for MCP tool operations using functions.Client. |
| pkg/mcp/service_test.go | Adds service-level tests for config operations + list/create basics. |
| pkg/mcp/resources_test.go | Adjusts resource tests for languages/templates now that languages is service-backed. |
| pkg/mcp/resources_language.go | Switches languages resource from CLI executor to service Runtimes(). |
| pkg/mcp/resources_function.go | Switches function-state resource to service FunctionState(). |
| pkg/mcp/mcp.go | Adds WithClientFactory, registers new tools/resources, and retains executor only for help. |
| pkg/mcp/mcp_test.go | Injects a test client factory into server construction. |
| pkg/mcp/client_options.go | Adds shared helpers to build functions.Client options for builders/deployers/credentials. |
| cmd/mcp.go | Refactors mcp start to create an MCP server with a client factory (no longer uses fn.WithMCPServer). |
| cmd/mcp_test.go | Updates MCP start tests to validate server startup via in-memory transports. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi, did you run anything manually? test this works as expected? worked through some scenarios yourself with the different func commands? any screenshots showing anything important? highlights? |
Default push to true when unset during deploy, select deployer from func.yaml, and apply deployDecorator on deploy/pipeline clients. Co-authored-by: Cursor <cursoragent@cursor.com>
13a3f36 to
c25ae60
Compare
|
@gauron99 Yes, I tested this on my machine. I went through the main MCP tools — create, config, list, healthcheck, run, and invoke — and they all return proper structured JSON now instead of shelling out to the CLI. Readonly mode correctly blocks deploy/delete too. Unit tests pass as well. Also fixed a few things I noticed while testing — push default, deployer from func.yaml, and deployDecorator. Couldn't test build/deploy on a real cluster since I don't have Docker/k8s set up locally. would be good if someone with a cluster setup can give that a quick pass.
|
|
Some check are failing. |
Drop resultToString and CLI arg-building test helpers that became dead code when MCP tools switched to the functions.Client service layer. Fixes golangci-lint unused violations blocking CI precheck.
c25ae60 to
f795888
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3889 +/- ##
==========================================
- Coverage 53.72% 52.19% -1.53%
==========================================
Files 200 206 +6
Lines 23674 24469 +795
==========================================
+ Hits 12719 12772 +53
- Misses 9730 10400 +670
- Partials 1225 1297 +72
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|





Summary
funcbinary with a nativeServicelayer backed byfunctions.Clientcmd/mcp startto construct clients via the existingClientFactory, decoupling MCP startup fromWithMCPServeron the same client instancedescribe,invoke,run, andlogsBuildOutput.Image,DeployOutput.URL,ListOutput.Functions) instead of parsing CLI stdoutHelp resources (
func://help/*) and templates listing continue to use CLI subprocess for--helptext.The MCP server had an explicit comment that shell-out should be replaced with direct
functions.Clientintegration. The subprocess approach caused cwd/path issues (documented inpkg/mcp/instructions.md) and produced unstructured stdout that agents could not reliably parse.Test plan
CGO_ENABLED=0 go test ./pkg/mcp/...CGO_ENABLED=0 go test ./cmd/ -run MCPfunc mcp startwith Cursor/Claude MCP clientbuild,deploy,list,describe,invoketools return structured JSONdeployanddelete