Skip to content

Conversation

@dimetron
Copy link
Collaborator

Migrated to Official Go MCP SDK

Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
@dimetron dimetron self-assigned this Sep 27, 2025
@dimetron dimetron requested a review from EItanya as a code owner September 27, 2025 00:04
@dimetron dimetron marked this pull request as draft September 27, 2025 00:04
# Conflicts:
#	go.mod
#	go.sum
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
@dimetron dimetron requested review from Copilot and removed request for EItanya September 27, 2025 03:16
Copy link

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 migrates the KAgent Tools project from an unofficial MCP SDK (github.com/mark3labs/mcp-go) to the official Model Context Protocol Go SDK (github.com/modelcontextprotocol/go-sdk). The migration includes updates across all tool categories, test files, and server implementation to use the new SDK patterns and APIs.

  • Updates all MCP-related imports from mark3labs/mcp-go to the official github.com/modelcontextprotocol/go-sdk/mcp
  • Refactors tool registration and handler implementations to match the new SDK's API structure
  • Updates test files to work with the new SDK's types and patterns

Reviewed Changes

Copilot reviewed 39 out of 42 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/integration/*.go New comprehensive integration tests for the MCP SDK migration
test/e2e/helpers_test.go Updated to placeholder MCP client functionality pending new SDK client
test/e2e/cli_test.go Minor cleanup to handle response body closing
pkg/utils/*.go Updated to use new SDK types and patterns for tool registration
pkg/prometheus/*.go Migrated tool handlers and registration to new SDK format
pkg/k8s/*.go Extensive refactoring to use new SDK API structure

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
- fix k8s get events format - default wide

Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
@dimetron dimetron requested a review from Copilot October 3, 2025 19:40
Copy link

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

Copilot reviewed 43 out of 46 changed files in this pull request and generated 6 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +17 to +22
request := &mcp.CallToolRequest{
Params: &mcp.CallToolParamsRaw{
Name: "datetime_get_current_time",
Arguments: json.RawMessage(`{}`),
},
}
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The Name field is being set in CallToolParamsRaw but based on the new SDK structure, this field may not be needed or correctly placed. Verify that the tool name is properly configured in the MCP request structure.

Copilot uses AI. Check for mistakes.
var args map[string]interface{}
if err := json.Unmarshal(request.Params.Arguments, &args); err != nil {
return &mcp.CallToolResult{
Content: []mcp.Content{&mcp.TextContent{Text: "failed to parse arguments"}},
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The error message 'failed to parse arguments' doesn't provide enough context about what went wrong. Consider including the original error details to help with debugging.

Suggested change
Content: []mcp.Content{&mcp.TextContent{Text: "failed to parse arguments"}},
Content: []mcp.Content{&mcp.TextContent{Text: fmt.Sprintf("failed to parse arguments: %v", err)}},

Copilot uses AI. Check for mistakes.
}, nil
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

[nitpick] Using anonymous function in defer when a simple method call would suffice adds unnecessary complexity. Consider using defer resp.Body.Close() directly.

Suggested change
defer func() { _ = resp.Body.Close() }()
defer resp.Body.Close()

Copilot uses AI. Check for mistakes.
if _, err := tmpFile.WriteString(manifest); err != nil {
tmpFile.Close()
return mcp.NewToolResultError(fmt.Sprintf("Failed to write to temp file: %v", err)), nil
_ = tmpFile.Close()
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

Error handling is being silently ignored. If this fails, it could indicate a serious problem with file system operations. Consider logging the error or handling it appropriately.

Suggested change
_ = tmpFile.Close()
if closeErr := tmpFile.Close(); closeErr != nil {
logger.Get().Error("Failed to close temp file after write error", "error", closeErr, "file", tmpFile.Name())
}

Copilot uses AI. Check for mistakes.
Comment on lines +63 to +70
func createCallToolRequest(args map[string]interface{}) *mcp.CallToolRequest {
argsJSON, _ := json.Marshal(args)
return &mcp.CallToolRequest{
Params: &mcp.CallToolParamsRaw{
Arguments: argsJSON,
},
}
}
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The json.Marshal error is being silently ignored with _. In test code, this could lead to subtle bugs if marshaling fails. Consider handling the error or using require.NoError in the test context.

Copilot uses AI. Check for mistakes.
return mcp.NewToolResultError("resource_type, resource_name, and annotation_key parameters are required"), nil
}
// RegisterTools registers all k8s tools with the MCP server
func RegisterTools(server *mcp.Server, llm llms.Model, kubeconfig string) error {
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The function signature accepts an llm parameter but it's not used in most of the registered tools. Consider if this parameter is still needed or if it should be optional for tools that don't require LLM functionality.

Copilot uses AI. Check for mistakes.
- allow filter tools in helm
- fix k8s get events format - default wide

Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
- fix k8s get events format - default wide
- added helm template
- added argocd cli

Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
@dimetron
Copy link
Collaborator Author

latest argo-rollouts cli has several CVE's

@dimetron dimetron requested a review from Copilot October 29, 2025 11:44
Copy link

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

Copilot reviewed 57 out of 61 changed files in this pull request and generated 2 comments.


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

t.Log("✅ HTTP Error Handling test PASSED (implementation complete)")
}

// createHTTPTransport creates an HTTP transport for testing
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The function createHTTPTransport is declared in the comment on line 333 but its implementation is not shown in the diff. This appears to be an incomplete code snippet. Ensure the function implementation is included or the comment should be removed if the function is defined elsewhere.

Copilot uses AI. Check for mistakes.
}

func TestHelmInstall(t *testing.T) {
releaseName := "test-release"
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

Changed Helm chart reference from bitnami/nginx to chainguard/nginx. Ensure that the chainguard/nginx chart is consistently available and accessible in test environments. If this change is intentional for security or reliability reasons, consider documenting the rationale.

Suggested change
releaseName := "test-release"
releaseName := "test-release"
// Using 'chainguard/nginx' chart instead of 'bitnami/nginx' for improved security and reliability.
// Ensure the 'chainguard' Helm repository is added and accessible in test environments.

Copilot uses AI. Check for mistakes.
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Resolves TODO in cmd/main.go line 253 by implementing ToolRegistry
support for all tool providers (k8s, helm, istio, argo, cilium, prometheus).

Changes:
- Added ToolRegistry interface to all tool providers
- Created RegisterToolsWithRegistry functions alongside existing RegisterTools
- Updated main.go to pass ToolRegistry to all providers in HTTP mode
- HTTP transport now discovers and executes tools from all providers
- Backward compatibility maintained for stdio mode (registry is optional)

HTTP Transport Verification:
- Server starts successfully with all tool providers
- Tool discovery endpoint lists all registered tools (29 tools from k8s+helm+istio tested)
- Tool execution works correctly via HTTP POST
- All tools properly registered with both MCP server and ToolRegistry

Closes #TODO-253
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Copy link

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

Copilot reviewed 65 out of 73 changed files in this pull request and generated 1 comment.


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

t.Log("✅ HTTP Error Handling test PASSED (implementation complete)")
}

// createHTTPTransport creates an HTTP transport for testing
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The comment indicates a function definition should follow, but the actual function implementation is missing from the diff. This appears to be an incomplete code block that would cause compilation errors.

Suggested change
// createHTTPTransport creates an HTTP transport for testing
// createHTTPTransport creates an HTTP transport for testing
func createHTTPTransport(serverURL string) mcp.Transport {
return mcp.NewHTTPTransport(serverURL, nil)
}

Copilot uses AI. Check for mistakes.
- http transport fixes

Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
✅ TOOLS_ISTIO_VERSION=1.28.0 == 1.28.0
✅ TOOLS_HELM_VERSION=3.19.1 == v3.19.1

Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
@dimetron dimetron requested a review from Copilot November 12, 2025 03:46
Copy link

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

Copilot reviewed 59 out of 77 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

pkg/utils/common.go:1

  • [nitpick] Empty line 200 appears unnecessary between the condition check and the comment. Remove for cleaner code formatting.
// Package utils provides common utility functions and tools.

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

Version: "1.0.0",
}, nil)

// Create HTTP transport for the MCP server
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

The StreamableClientTransport struct initialization lacks context. Consider adding a comment explaining that this transport connects to the MCP server running in the Kubernetes cluster via NodePort 30885.

Suggested change
// Create HTTP transport for the MCP server
// Create HTTP transport for the MCP server
// This transport connects to the MCP server running in the Kubernetes cluster via NodePort 30885.

Copilot uses AI. Check for mistakes.
if _, err := tmpFile.WriteString(manifest); err != nil {
tmpFile.Close()
return mcp.NewToolResultError(fmt.Sprintf("Failed to write to temp file: %v", err)), nil
_ = tmpFile.Close()
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

[nitpick] Error from tmpFile.Close() is silently discarded. Since this is in an error path where file writing failed, this is acceptable. However, consider logging this error for better debugging.

Suggested change
_ = tmpFile.Close()
if closeErr := tmpFile.Close(); closeErr != nil {
logger.Get().Error("Failed to close temporary file after write error", "error", closeErr, "file", tmpFile.Name())
}

Copilot uses AI. Check for mistakes.
Signed-off-by: Dmytro Rashko <dmitriy.rashko@amdocs.com>
@dimetron dimetron closed this Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants