Skip to content

Fix Missing Kubernetes API Routes for MCP#351

Merged
cjimti merged 3 commits intomasterfrom
enhancements/mcp
Dec 31, 2025
Merged

Fix Missing Kubernetes API Routes for MCP#351
cjimti merged 3 commits intomasterfrom
enhancements/mcp

Conversation

@cjimti
Copy link
Copy Markdown
Member

@cjimti cjimti commented Dec 31, 2025

Fixed 5 missing HTTP API routes that MCP tools were calling but didn't exist, plus fixed response format issues and improved get_connection_info behavior.

Problem

MCP tools had HTTP clients calling endpoints that were never registered on the API server, resulting in 404 errors. The HTTP client code existed, the backend implementations existed in adapters.go, but the routes were never connected.

Changes

1. Added 5 Missing Route Handlers (pkg/fwdapi/handlers/kubernetes.go)

Handler Route Purpose
GetPodLogs GET /v1/kubernetes/pods/:namespace/:podName/logs Get logs from a pod
ListPods GET /v1/kubernetes/pods/:namespace List pods in a namespace
GetPod GET /v1/kubernetes/pods/:namespace/:podName Get pod details
GetEvents GET /v1/kubernetes/events/:namespace Get Kubernetes events
GetEndpoints GET /v1/kubernetes/endpoints/:namespace/:serviceName Get service endpoints

2. Registered Routes (pkg/fwdapi/server.go)

Added 5 route registrations after existing kubernetes routes:

v1.GET("/kubernetes/pods/:namespace", k8sHandler.ListPods)
v1.GET("/kubernetes/pods/:namespace/:podName", k8sHandler.GetPod)
v1.GET("/kubernetes/pods/:namespace/:podName/logs", k8sHandler.GetPodLogs)
v1.GET("/kubernetes/events/:namespace", k8sHandler.GetEvents)
v1.GET("/kubernetes/endpoints/:namespace/:serviceName", k8sHandler.GetEndpoints)

3. Fixed Response Format Issues (pkg/fwdapi/handlers/kubernetes.go)

  • ListPods: Changed from Data: map[string]interface{}{"pods": pods} to Data: pods
  • GetEvents: Changed from Data: map[string]interface{}{"events": events} to Data: events

The HTTP clients expected arrays directly in Data, not wrapped in objects.

4. Fixed get_connection_info Without Namespace (pkg/fwdmcp/tools.go)

When namespace is not provided, the handler now:

  1. Uses FindServices to search for the service by name
  2. Filters to exact name matches
  3. If exactly one match, returns that service's connection info
  4. If multiple matches, returns an error with the list of namespaces to help disambiguate

Previously it would construct an incomplete key (just service name) which always returned 404.

Files Modified

  • pkg/fwdapi/handlers/kubernetes.go - Added 5 handler methods, added strconv import
  • pkg/fwdapi/server.go - Added 5 route registrations
  • pkg/fwdmcp/tools.go - Fixed handleGetConnectionInfo to search when namespace not provided

Testing

  • All existing tests pass
  • Build succeeds
  • MCP tools now have working backend routes

MCP Tools Now Working

  • get_pod_logs - Get container logs from pods
  • list_pods - List pods in a namespace
  • get_pod - Get detailed pod information
  • get_events - Get Kubernetes events
  • get_endpoints - Get service endpoints
  • get_connection_info - Now works with just service name (searches for it)

- Implemented new handlers in `pkg/fwdapi/handlers/kubernetes.go` to support endpoints for pod logs, pod listing, pod details, events, and service endpoints.
- Included parameter validation and error responses for missing or invalid inputs.
…atches

- Added logic to search for services when `Namespace` is not provided.
- Implemented filtering for exact matches and error-handling for ambiguous namespace cases.
- Simplified key construction logic for connection info retrieval.
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 31, 2025

Codecov Report

❌ Patch coverage is 3.71901% with 233 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.64%. Comparing base (60238c7) to head (4c59040).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/fwdapi/handlers/kubernetes.go 0.00% 213 Missing ⚠️
pkg/fwdmcp/tools.go 16.66% 18 Missing and 2 partials ⚠️

❌ Your patch status has failed because the patch coverage (3.71%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #351      +/-   ##
==========================================
- Coverage   61.85%   60.64%   -1.22%     
==========================================
  Files          69       69              
  Lines       11583    11817     +234     
==========================================
+ Hits         7165     7166       +1     
- Misses       4124     4355     +231     
- Partials      294      296       +2     
Files with missing lines Coverage Δ
pkg/fwdapi/server.go 96.29% <100.00%> (+0.24%) ⬆️
pkg/fwdmcp/tools.go 75.86% <16.66%> (-1.67%) ⬇️
pkg/fwdapi/handlers/kubernetes.go 37.81% <0.00%> (-55.94%) ⬇️

... and 1 file with indirect coverage changes

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

@cjimti cjimti merged commit 516bdc3 into master Dec 31, 2025
11 of 12 checks passed
@cjimti cjimti deleted the enhancements/mcp branch December 31, 2025 00:50
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.

1 participant