Skip to content

feat(mcp): add Kmesh version tool - #1900

Open
AslinDhurai wants to merge 4 commits into
kmesh-net:mainfrom
AslinDhurai:feat/mcp-version-tool
Open

feat(mcp): add Kmesh version tool#1900
AslinDhurai wants to merge 4 commits into
kmesh-net:mainfrom
AslinDhurai:feat/mcp-version-tool

Conversation

@AslinDhurai

Copy link
Copy Markdown

What type of PR is this?

/kind feature

Summary

This PR adds an initial MCP server implementation for Kmesh with a version information tool.

Changes

  • Added MCP server using the official Model Context Protocol Go SDK
  • Added kmesh_version MCP tool
  • Exposed Kmesh build/version information through the MCP tool
  • Added unit tests for the version tool
  • Added required MCP SDK dependencies

Validation

  • go test ./mcp/...
  • go vet ./mcp/...
  • go test -race ./mcp/...
  • git diff --check

All checks pass.

Mentorship

I am interested in contributing to Kmesh as a mentee through the mentorship program. I would be happy to continue working on MCP-related improvements and take guidance from the maintainers on suitable follow-up tasks.

Copilot AI lite review requested due to automatic review settings August 8, 2026 11:35
@kmesh-bot
kmesh-bot requested review from hzxuzhonghu and nlgwcy August 8, 2026 11:35
@kmesh-bot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign yaozengzeng for approval. For more information see the Kubernetes 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

@kmesh-bot

Copy link
Copy Markdown
Collaborator

Welcome @AslinDhurai! It looks like this is your first PR to kmesh-net/kmesh 🎉

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

Adds an initial MCP (Model Context Protocol) server to the Kmesh repo, exposing build/version metadata via a new kmesh_version tool, along with supporting dependencies and a basic unit test.

Changes:

  • Introduced an MCP server binary (mcp/server.go) registering a kmesh_version tool.
  • Added a version tool implementation (mcp/tools/version.go) and unit test (mcp/tools/version_test.go) backed by pkg/version.
  • Updated Go module dependencies to include the official MCP Go SDK and related indirect deps.

Reviewed changes

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

Show a summary per file
File Description
mcp/tools/version.go Adds the MCP tool handler and output struct for version/build info.
mcp/tools/version_test.go Adds unit tests validating the tool output against version.Get().
mcp/server.go Adds a runnable MCP server exposing the tool over HTTP.
go.mod Adds MCP SDK dependency and updates golang.org/x/* versions.
go.sum Records new/updated module checksums.
Suppressed comments (1)

mcp/server.go:58

  • Starting the HTTP server via http.ListenAndServe(":8080", nil) leaves all server timeouts at their zero values. Prefer constructing an http.Server with explicit timeouts (similar to pkg/status/status_server.go) and calling ListenAndServe on it.
	log.Println("Kmesh MCP server listening on :8080")
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Fatalf("MCP server stopped: %v", err)
	}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread mcp/tools/version.go
Comment thread mcp/tools/version_test.go
Comment thread mcp/tools/version.go
Comment on lines +13 to +17
type VersionOutput struct {
Version string `json:"version"`
Commit string `json:"commit"`
TreeState string `json:"treeState"`
BuildDate string `json:"buildDate"`
Comment thread mcp/server.go
Copilot AI review requested due to automatic review settings August 8, 2026 11:53

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

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

Suppressed comments (1)

go.mod:154

  • github.com/modelcontextprotocol/go-sdk is directly imported by the new MCP code, but it appears in the large indirect require block (without // indirect) and there is also an extra small require block added above for a few indirect deps. This suggests go.mod is not in a go mod tidy state, which makes future dependency changes harder to review and can cause churn in later PRs.
	github.com/mitchellh/reflectwalk v1.0.2 // indirect
	github.com/moby/spdystream v0.5.0 // indirect
	github.com/moby/term v0.5.0 // indirect
	github.com/modelcontextprotocol/go-sdk v1.4.0
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect

Comment thread mcp/server.go
Copilot AI review requested due to automatic review settings August 8, 2026 11:59

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

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

Suppressed comments (2)

mcp/server.go:61

  • This uses the global DefaultServeMux via http.Handle and sets http.Server.Handler to nil. For a standalone server this makes handler registration global and can lead to accidental handler reuse if other packages register routes; prefer a dedicated ServeMux and pass it explicitly to the server.
	http.Handle("/mcp", transport)

	log.Println("Kmesh MCP server listening on :8080")
	srv := &http.Server{
		Addr:              ":8080",

go.mod:52

  • go.mod adds a standalone require (...) block containing only a few indirect dependencies. This makes future go mod tidy output noisier and increases the chance of merge conflicts; it’s usually better to let go mod tidy consolidate indirect requirements into the existing indirect require block(s).
require (
	github.com/google/jsonschema-go v0.4.2 // indirect
	github.com/segmentio/asm v1.1.3 // indirect
	github.com/segmentio/encoding v0.5.3 // indirect
	github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
)

Comment thread mcp/server.go
Comment on lines +46 to +52
transport := &mcp.StreamableServerTransport{
SessionID: "kmesh-mcp",
}

if _, err := server.Connect(context.Background(), transport, nil); err != nil {
log.Fatalf("failed to connect MCP server: %v", err)
}
Copilot AI review requested due to automatic review settings August 10, 2026 05:31

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

Copilot reviewed 4 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (4)

mcp/tools/version.go:33

  • VersionOutput duplicates pkg/version.Info but changes JSON field names (e.g., version vs gitVersion). Reusing version.Info (via a type alias) keeps the MCP response schema consistent with the existing version endpoint and avoids schema drift.
type VersionOutput struct {
	Version   string `json:"version"`
	Commit    string `json:"commit"`
	TreeState string `json:"treeState"`
	BuildDate string `json:"buildDate"`

mcp/tools/version.go:48

  • Once VersionOutput is a type alias of version.Info, the tool can return version.Get() directly instead of manually copying each field. This removes duplicate mapping code and keeps future additions to version.Info automatically reflected in the tool output.
	v := version.Get()

	return nil, VersionOutput{
		Version:   v.GitVersion,
		Commit:    v.GitCommit,

mcp/server.go:65

  • The HTTP server is started without ReadTimeout/WriteTimeout/IdleTimeout and uses the default global ServeMux (via http.Handle + Handler:nil). This makes the server more vulnerable to slow clients and can lead to handler registration conflicts if more endpoints are added. Prefer a dedicated ServeMux and set full server timeouts (similar to pkg/status/status_server.go).
	srv := &http.Server{
		Addr:              ":8080",
		Handler:           nil,
		ReadHeaderTimeout: 5 * time.Second,
	}

mcp/tools/version_test.go:57

  • If VersionOutput is changed to alias pkg/version.Info (recommended for schema consistency), this test must assert against Info field names (GitVersion/GitCommit/GitTreeState/...) or it will not compile.
	if output.Version != expected.GitVersion {
		t.Errorf("version = %q, want %q", output.Version, expected.GitVersion)
	}

	if output.Commit != expected.GitCommit {

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.50%. Comparing base (32fe3df) to head (f290643).
⚠️ Report is 3 commits behind head on main.
see 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 045678d...f290643. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

AslinDhurai and others added 4 commits August 10, 2026 11:36
Signed-off-by: AslinDhurai <aslindhurai1@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: AslinDhurai <aslindhurai1@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: AslinDhurai <aslindhurai1@gmail.com>
Signed-off-by: AslinDhurai <aslindhurai1@gmail.com>
@AslinDhurai
AslinDhurai force-pushed the feat/mcp-version-tool branch from 1453588 to f290643 Compare August 10, 2026 06:07
@AslinDhurai

AslinDhurai commented Aug 10, 2026

Copy link
Copy Markdown
Author

The goimports formatting issue in mcp/server.go has been fixed, and I verified the configured golangci-lint checks locally with no errors.

I also noticed an issue while running make e2e-ipv6: the E2E script appears to have a logging-related problem around kmesh_daemon.log/pod log capture. This seems unrelated to the changes in this PR, but it may be affecting the E2E build/check.

Could someone please rerun the failed CI job and confirm whether the E2E failure is related to the existing test infrastructure or the PR?

Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants