Skip to content

mcp: use build-time version instead of hardcoded "0.1.0" - #3832

Open
Ankitsinghsisodya wants to merge 2 commits into
knative:mainfrom
Ankitsinghsisodya:fix/mcp-hardcoded-version
Open

Ankitsinghsisodya wants to merge 2 commits into
knative:mainfrom
Ankitsinghsisodya:fix/mcp-hardcoded-version

Conversation

@Ankitsinghsisodya

@Ankitsinghsisodya Ankitsinghsisodya commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Note: Re-submission of #3662, accidentally closed when the head repository was deleted.

Summary

  • The MCP server advertised a static version = "0.1.0" constant to every MCP client regardless of the actual binary version, causing stale version metadata in clients that display server info.
  • Replace the constant with version.Vers from pkg/version, which is already injected at build time via ldflags (-X knative.dev/func/pkg/version.Vers=$(VERS)).
  • Fall back to "0.0.0+source" when the variable is empty (source builds that bypass the Makefile), consistent with how cmd/root.go handles the same case.

Changes

  • pkg/mcp/mcp.go: remove const version = "0.1.0", import knative.dev/func/pkg/version, and use version.Vers (with fallback) when constructing the mcp.Implementation passed to mcp.NewServer.

Test plan

  • go test ./pkg/mcp/... passes
  • func version and func mcp start report the same version string
  • MCP client (e.g. Claude Code) shows the correct version after func mcp start

Copilot AI review requested due to automatic review settings May 21, 2026 11:23
@knative-prow
knative-prow Bot requested review from dsimansk and jrangelramos May 21, 2026 11:23
@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 21, 2026
@knative-prow

knative-prow Bot commented May 21, 2026

Copy link
Copy Markdown

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.

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Introduces a centralized version parsing API and updates MCP/CLI version reporting to use a normalized semver string for machine consumers while preserving the original injected value for human-readable output.

Changes:

  • Added pkg/version.Get() with DefaultVers fallback and semver parsing, plus unit tests.
  • Updated MCP server implementation and healthcheck tool to report version.Get().String() instead of a hardcoded constant.
  • Updated CLI version wiring to use version.Get().Original() and deduplicated the default version constant.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/version/version.go Adds semver-backed version parsing with a shared fallback constant.
pkg/version/version_test.go Adds tests for empty, injected, and invalid version behavior.
pkg/mcp/mcp.go Replaces hardcoded MCP server version with parsed version string.
pkg/mcp/tools_healthcheck.go Reports normalized version string in healthcheck output.
pkg/app/app.go Uses the original injected version string for CLI output.
cmd/root.go Delegates default version constant to version.DefaultVers.
go.mod Adds a direct dependency on github.com/Masterminds/semver/v3.

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

Comment thread pkg/mcp/tools_healthcheck.go Resolved
Comment thread pkg/mcp/mcp.go Resolved
Comment thread go.mod Resolved
Comment thread pkg/version/version.go Resolved
@codecov

codecov Bot commented May 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.33%. Comparing base (584c11e) to head (f7c7f8d).
⚠️ Report is 114 commits behind head on main.

Files with missing lines Patch % Lines
pkg/version/version.go 85.71% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3832      +/-   ##
==========================================
- Coverage   57.03%   53.33%   -3.70%     
==========================================
  Files         182      201      +19     
  Lines       21376    23456    +2080     
==========================================
+ Hits        12191    12511     +320     
- Misses       7953     9699    +1746     
- Partials     1232     1246      +14     
Flag Coverage Δ
e2e 33.71% <44.44%> (-2.10%) ⬇️
e2e go ?
e2e node 25.97% <43.75%> (-1.29%) ⬇️
e2e python ?
e2e quarkus ?
e2e rust ?
e2e springboot ?
e2e typescript 26.06% <43.75%> (-1.30%) ⬇️
e2e-config-ci 26.77% <43.75%> (-1.40%) ⬇️
integration 15.76% <18.75%> (-1.41%) ⬇️
unit macos-14 42.27% <81.25%> (-2.83%) ⬇️
unit macos-latest 42.27% <81.25%> (-2.83%) ⬇️
unit ubuntu-24.04-arm 42.57% <83.33%> (-2.77%) ⬇️
unit ubuntu-latest 43.13% <81.25%> (-2.91%) ⬇️
unit windows-latest 42.33% <81.25%> (-2.81%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

@lkingland lkingland 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 22, 2026
@lkingland lkingland self-assigned this Jun 2, 2026
@lkingland lkingland moved this to New in Functions Traige Jun 2, 2026
@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Aug 20, 2026
@lkingland

lkingland commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Let's keep the version package a simple "string-stamp" library. Move the default from the CLI in there like you did. Set Vers to that default. Then it's up to the user if they want it as a Semver or not.

Finally, we'd need a patch the Makefile to ensure it doesn't overwrite the default with an empty value (-X pkg.Var= with an empty value clears the Go initializer).

Here's the whole version package:

package version

const Default = "v0.0.0+source"

var (
	Vers = Default // overwritten by ldflags when make actually has a describe
	Kver string
	Hash string
)

No Get(), no Masterminds. Semver stays an exercise for the caller (func version already parses if it needs to).

And here's a proper conditional for the Makefile:

LDFLAGS :=
ifneq ($(VERS),)
LDFLAGS += -X knative.dev/func/pkg/version.Vers=$(VERS)
endif
ifneq ($(KVER),)
LDFLAGS += -X knative.dev/func/pkg/version.Kver=$(KVER)
endif
ifneq ($(HASH),)
LDFLAGS += -X knative.dev/func/pkg/version.Hash=$(HASH)
endif

MCP server can load it in on start:

s := &Server{
	prefix:  "func",
	version: version.Vers,
	// ...
}

Healthcheck can just use the member directly:

output = HealthcheckOutput{
	Status:  "ok",
	Message: "The MCP server is running!",
	Version: s.version,
}

CLI can use the strings directly, no .Get().Original() confusion:

// pkg/app/app.go
Version: cmd.Version{
	Vers: version.Vers,
	Kver: version.Kver,
	Hash: version.Hash,
}
// cmd/root.go
const DefaultVersion = version.Default

Furthermore, the check in cmd.version.go can be removed because of the Makefile hardening:

if v.Vers == "" { v.Vers = DefaultVersion }

Lastly, we can keep the leading v for now because a semver is a simple strings.TrimPrefix away, and this way we're coherent with Git/Go/Knative/Kubernetes.

@lkingland lkingland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's keep the version package a simple "string-stamp" library. Move the default from the CLI in there like you did. Set Vers to that default. Then it's up to the user if they want it as a Semver or not.

Finally, we'd need a patch the Makefile to ensure it doesn't overwrite the default with an empty value (-X pkg.Var= with an empty value clears the Go initializer).

Here's the whole version package:

package version

const Default = "v0.0.0+source"

var (
	Vers = Default // overwritten by ldflags when make actually has a describe
	Kver string
	Hash string
)

No Get(), no Masterminds. Semver stays an exercise for the caller (func version already parses if it needs to).

And here's a proper conditional for the Makefile:

LDFLAGS :=
ifneq ($(VERS),)
LDFLAGS += -X knative.dev/func/pkg/version.Vers=$(VERS)
endif
ifneq ($(KVER),)
LDFLAGS += -X knative.dev/func/pkg/version.Kver=$(KVER)
endif
ifneq ($(HASH),)
LDFLAGS += -X knative.dev/func/pkg/version.Hash=$(HASH)
endif

(be sure to keep the existing LDFLAGS += -X ... SocatImage / TarImage / FuncUtilImage lines after it)

MCP server can load it in on new:

s := &Server{
	prefix:  "func",
	version: version.Vers,
	// ...
}

i := mcp.NewServer(&mcp.Implementation{
    Name:    name,
    Title:   title,
    Version: s.version, // same stamp
}, ...)

Healthcheck can just use the member directly:

output = HealthcheckOutput{
	Status:  "ok",
	Message: "The MCP server is running!",
	Version: s.version,
}

CLI can use the strings directly, no .Get().Original() confusion:

// pkg/app/app.go
Version: cmd.Version{
	Vers: version.Vers,
	Kver: version.Kver,
	Hash: version.Hash,
}
// cmd/root.go
const DefaultVersion = version.Default

Furthermore, the check in cmd/version.go can be removed because of the Makefile hardening:

if v.Vers == "" { v.Vers = DefaultVersion }

Lastly, we can keep the leading v for now because a semver is a simple strings.TrimPrefix away in most cases, and this way we're coherent with Git/Go/Knative/Kubernetes.

@Ankitsinghsisodya
Ankitsinghsisodya force-pushed the fix/mcp-hardcoded-version branch from f7c7f8d to 91c910d Compare August 20, 2026 04:24
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Aug 20, 2026
@knative-prow knative-prow Bot added size/M 🤖 PR changes 30-99 lines, ignoring generated files. and removed size/L 🤖 PR changes 100-499 lines, ignoring generated files. labels Aug 20, 2026
@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Aug 24, 2026
@Ankitsinghsisodya
Ankitsinghsisodya force-pushed the fix/mcp-hardcoded-version branch from 91c910d to 0d86f23 Compare August 31, 2026 14:34
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Aug 31, 2026
@Ankitsinghsisodya

Copy link
Copy Markdown
Contributor Author

@lkingland Can you re run the tests?

@Ankitsinghsisodya

Copy link
Copy Markdown
Contributor Author

@lkingland Can you re run the tests?

@lkingland

@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Nov 7, 2026
Ankitsinghsisodya and others added 2 commits November 24, 2026 14:22
The MCP server advertised a static version = "0.1.0" regardless of the
actual binary version. Stamp the Server with pkg/version.Vers (already
set via ldflags, defaulting to "v0.0.0+source" for source builds) and
use it for both the MCP Implementation version and the healthcheck
tool's reported version.

Per review feedback, keep pkg/version a plain string-stamp package with
no semver parsing (no Get(), no Masterminds dependency), and harden the
Makefile's LDFLAGS so an empty VERS/KVER/HASH doesn't clear the
package-level defaults via -X.
A hardcoded "0.1.0" still looks like a version, so the old
healthcheck test stayed green. Compare the reported version
with the build stamp.
@lkingland
lkingland force-pushed the fix/mcp-hardcoded-version branch from dc3403d to 1ab6509 Compare November 24, 2026 05:25
@lkingland

Copy link
Copy Markdown
Member

Thanks for your patience on this one, @Ankitsinghsisodya. We rebased it onto current main, kept go.mod as main has it, and added a test that pins the healthcheck to the build version. Your change is otherwise as you wrote it.

/lgtm
/approve

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label Nov 24, 2026
@knative-prow

knative-prow Bot commented Nov 24, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Ankitsinghsisodya, lkingland

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

The pull request process is described 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 the approved 🤖 PR has been approved by an approver from all required OWNERS files. label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. lgtm 🤖 PR is ready to be merged. ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

4 participants