Skip to content

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

Open
Ankitsinghsisodya wants to merge 3 commits intoknative:mainfrom
Ankitsinghsisodya:fix/mcp-hardcoded-version
Open

mcp: use build-time version instead of hardcoded "0.1.0"#3662
Ankitsinghsisodya wants to merge 3 commits intoknative:mainfrom
Ankitsinghsisodya:fix/mcp-hardcoded-version

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

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
  • make test passes for mcp package
  • 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 6, 2026 08:24
@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos May 6, 2026 08:24
@knative-prow knative-prow Bot added size/S 🤖 PR changes 10-29 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels May 6, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 6, 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.

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

This PR updates the MCP server’s advertised implementation version to reflect the actual build-time pkg/version.Vers value (instead of a hardcoded "0.1.0"), improving accuracy of version metadata shown by MCP clients.

Changes:

  • Remove the hardcoded MCP server version constant.
  • Import knative.dev/func/pkg/version and use version.Vers when constructing the MCP Implementation.
  • Add a source-build fallback version string when version.Vers is empty.

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

Comment thread pkg/mcp/mcp.go Outdated
Comment on lines +77 to +80
vers := version.Vers
if vers == "" {
vers = "0.0.0+source"
}
Comment thread pkg/mcp/mcp.go Outdated
Comment on lines +77 to +86
vers := version.Vers
if vers == "" {
vers = "0.0.0+source"
}

i := mcp.NewServer(
&mcp.Implementation{
Name: name,
Title: title,
Version: version},
Version: vers},
@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 6, 2026
@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor Author

cc @gauron99

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.89%. Comparing base (b819db5) to head (60d6e34).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3662      +/-   ##
==========================================
+ Coverage   54.42%   56.89%   +2.46%     
==========================================
  Files         181      182       +1     
  Lines       20926    20936      +10     
==========================================
+ Hits        11389    11911     +522     
+ Misses       8423     7814     -609     
- Partials     1114     1211      +97     
Flag Coverage Δ
e2e 36.15% <66.66%> (-0.01%) ⬇️
e2e go 32.75% <70.00%> (+<0.01%) ⬆️
e2e node 28.48% <70.00%> (+0.01%) ⬆️
e2e python 33.12% <70.00%> (+<0.01%) ⬆️
e2e quarkus 28.59% <70.00%> (-0.01%) ⬇️
e2e rust 28.03% <70.00%> (+0.01%) ⬆️
e2e springboot 26.53% <70.00%> (+0.01%) ⬆️
e2e typescript 28.61% <70.00%> (+0.03%) ⬆️
e2e-config-ci 17.90% <70.00%> (+0.01%) ⬆️
integration 17.42% <0.00%> (?)
unit macos-14 44.98% <90.00%> (+0.02%) ⬆️
unit macos-latest 44.98% <90.00%> (+0.02%) ⬆️
unit ubuntu-24.04-arm 45.15% <91.66%> (+0.02%) ⬆️
unit ubuntu-latest 45.82% <90.00%> (+0.02%) ⬆️
unit windows-latest 44.96% <90.00%> (+0.02%) ⬆️

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.

@gauron99
Copy link
Copy Markdown
Contributor

gauron99 commented May 7, 2026

I wonder if mcp version should be different to func cli version. Underneath we just run 'func' as a command so technically its possible to run /func1 mcp start and that invokes func as a different binary, resulting in 2 different versions being used for starting the mcp and running the commands.

I like more that the mcp has its own versioning to be fair but we can have it be the same for the sake of identifying what func is used to run the mcp server. or we can display both the mcp version and func version?
maybe its an over-optimized approach for a problem we yet dont have 😄
@lkingland wdyt?

Comment thread pkg/mcp/mcp.go Outdated
Comment on lines +77 to +80
vers := version.Vers
if vers == "" {
vers = "0.0.0+source"
}
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.

This splits the logic of the default version into two places.

Let's consolidate into a single Get() *semver.Version.

Then it's all in one place, AND we can decide on the leading v depending on the situation: human-readable output prefers leading v, whereas machine-readable (like the MCP server) perfer a proper semver format which does not.

Quick sketch:

  // pkg/version/version.go
  package version

  import "github.com/Masterminds/semver/v3"

  var Vers, Kver, Hash string

  const DefaultVers = "v0.0.0+source"

  // Get returns the parsed semver, with a fallback when no
  // build-time version was injected.
  func Get() *semver.Version {
      s := Vers
      if s == "" {
          s = DefaultVers
      }
      v, err := semver.NewVersion(s)  // permissive: accepts leading 'v'
      if err != nil {
          v, _ = semver.NewVersion(DefaultVers)
      }
      return v
  }

  Callers:
  // cmd/version.go (human form):
  fmt.Printf("v%s\n", version.Get().String())  // String() returns "0.0.0+source"; we add the v
  // or use .Original() to round-trip whatever was injected, including the v.

  // pkg/mcp/mcp.go (machine form):
  Version: version.Get().String(),  // "0.0.0+source", clean semver

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done sir!!

@lkingland
Copy link
Copy Markdown
Member

I wonder if mcp version should be different to func cli version. Underneath we just run 'func' as a command so technically its possible to run /func1 mcp start and that invokes func as a different binary, resulting in 2 different versions being used for starting the mcp and running the commands.

I like more that the mcp has its own versioning to be fair but we can have it be the same for the sake of identifying what func is used to run the mcp server. or we can display both the mcp version and func version? maybe its an over-optimized approach for a problem we yet dont have 😄 @lkingland wdyt?

That's a good point about perhaps the MCP server having a different version than func, but for simplicity let's just keep them the same for now so we don't forget to bump versions!

- Refactor MCP server implementation to retrieve version from the new version package.
- Default to "0.0.0+source" if version is not specified.
- Clean up version constants for clarity.
- Updated DefaultVersion in root.go to delegate to version.DefaultVers for consistency.
- Modified app.go to retrieve the version using version.Get().Original() for accurate versioning.
- Adjusted mcp.go to use version.Get().String() for server versioning, ensuring fallback to DefaultVers if necessary.
- Added unit tests in version_test.go to verify behavior of version retrieval and fallback logic.
@Ankitsinghsisodya Ankitsinghsisodya force-pushed the fix/mcp-hardcoded-version branch from e9d77f9 to 1510117 Compare May 8, 2026 08:16
@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 ask for approval from lkingland. 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. and removed size/S 🤖 PR changes 10-29 lines, ignoring generated files. labels May 8, 2026
…endency

- Added Masterminds/semver/v3 v3.4.0 to the require section for version handling.
- Removed the indirect reference to Masterminds/semver/v3 v3.4.0 for clarity.
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.

5 participants