Skip to content

MCP Kubernetes Discovery Enhancements#350

Merged
cjimti merged 14 commits intomasterfrom
housekeeping/improvements
Dec 30, 2025
Merged

MCP Kubernetes Discovery Enhancements#350
cjimti merged 14 commits intomasterfrom
housekeeping/improvements

Conversation

@cjimti
Copy link
Copy Markdown
Member

@cjimti cjimti commented Dec 30, 2025

Expands MCP server capabilities with comprehensive Kubernetes read operations for debugging and discovery.

Description

This PR addresses a significant gap in the MCP server: the inability to inspect Kubernetes resources beyond forwarded services. Previously, users could not list pods, check pod status, view events, or debug startup failures through the MCP interface.

New MCP Tools (5 tools)

Tool Description Key Parameters
get_pod_logs Get container logs from a pod namespace, pod_name, tail_lines, previous, timestamps
list_pods List pods with status/ready/restarts namespace, label_selector, service_name
get_pod Detailed pod info (containers, conditions, resources) namespace, pod_name
get_events K8s events for debugging startup failures namespace, resource_kind, resource_name, limit
get_endpoints Service endpoints showing backing pods namespace, service_name

Complete MCP Tool Inventory (29 tools)

Forwarding Management (7):

  • add_namespace, remove_namespace, add_service, remove_service
  • reconnect_service, reconnect_all_errors, sync_service

Service Discovery (7):

  • list_services, get_service, find_services
  • list_k8s_namespaces, list_k8s_services, list_contexts
  • get_connection_info, list_hostnames

Pod Operations (5) - NEW:

  • list_pods, get_pod, get_pod_logs, get_events, get_endpoints

Monitoring & Diagnostics (10):

  • get_health, get_quick_status, get_metrics, get_http_traffic
  • get_analysis, diagnose_errors, get_logs, get_history

Use Case Examples

Now Claude Desktop (or any MCP client) can:

  1. Debug a failing service:

    • "What pods are backing auth-service?" → list_pods with service_name filter
    • "Is the pod healthy?" → get_pod for detailed status
    • "Why won't it start?" → get_events for scheduling/pulling/startup events
  2. Investigate pod issues:

    • "Show me the logs" → get_pod_logs
    • "What was the last error?" → get_pod_logs with previous=true
    • "Check container status" → get_pod with container details
  3. Verify service routing:

    • "Which pods are ready?" → get_endpoints shows ready vs not-ready addresses

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Test improvement (new or updated tests)
  • Documentation update
  • Stability/performance improvement
  • New feature (non-breaking change that adds functionality)

Testing

  • Ran go test ./... locally
  • Ran go test -race ./... locally
  • Ran golangci-lint run ./... with 0 issues
  • Tested manually with a Kubernetes cluster

Checklist

  • My code follows the project's style guidelines
  • I have read CONTRIBUTING.md
  • This PR is focused and does not include unrelated changes
  • All mocks updated for new interface methods
  • HTTP client implementations added for standalone mode

Files Changed

pkg/fwdapi/types/interfaces.go      (mod)  - Added 4 new interface methods
pkg/fwdapi/types/types.go           (mod)  - Added pod, event, endpoint types (~140 lines)
pkg/fwdapi/adapters.go              (mod)  - Implemented all 4 methods (~400 lines)
pkg/fwdmcp/tools.go                 (mod)  - 5 input types + 5 registrations + 5 handlers
pkg/fwdmcp/httpclient.go            (mod)  - HTTP client implementations
pkg/fwdmcp/tools_test.go            (mod)  - Updated mocks, added tests
pkg/fwdapi/manager_test.go          (mod)  - Updated mocks
pkg/fwdapi/handlers/handlers_test.go (mod) - Updated mocks

New Types Added

  • ListPodsOptions, K8sPod, K8sPodDetail
  • K8sContainerInfo, K8sContainerPort, K8sResourceRequire, K8sPodCondition
  • GetEventsOptions, K8sEvent
  • K8sEndpoints, K8sEndpointSubset, K8sEndpointAddress, K8sEndpointPort

- Implements a function to fetch pod logs with configurable options, including tail line limits, timestamps, and stream size constraints.
- Adds helper `splitLogLines` function to process log content into lines.
- Implements a function to fetch pod logs with configurable options, such as container, timestamps, tail lines, and more.
- Introduces `GetPodLogs`, enabling retrieval of pod logs with configurable options.
- Adds `PodLogsOptions` and `PodLogsResponse` types for log retrieval parameters and responses.
- Adds `GetPodLogsInput` type for customizable log retrieval parameters.
- Registers `get_pod_logs` as an MCP tool for debugging Kubernetes services.
- Implements `handleGetPodLogs` to fetch logs via Kubernetes discovery.
- Introduce `GetPodLogs` mock methods in test files for Kubernetes discovery.
- Add unit tests for `handleGetPodLogs` to verify functionality with various scenarios.
- Introduces `ListPods`, `GetPod`, and `GetEndpoints` for Kubernetes resource discovery.
- Implements `GetEvents` to fetch Kubernetes events with customizable options.
- Adds helper functions for pod conversion and formatting.
- Implements `ListPods`, `GetPod`, `GetEvents`, and `GetEndpoints` methods for pod, event, and endpoint discovery.
- Registers `list_pods`, `get_pod`, `get_events`, and `get_endpoints` MCP tools to provide detailed resource and event diagnostics for Kubernetes namespaces.
- Adds supporting types like `ListPodsOptions`, `GetEventsOptions`, `K8sPod`, and `K8sEndpoints` for better resource representation and filtering.
- Adds `ListPods`, `GetPod`, `GetEvents`, and `GetEndpoints` mocks to support KubernetesDiscovery testing.
- Updates test files to include mock resource discovery for enhanced coverage.
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 30, 2025

Codecov Report

❌ Patch coverage is 24.42040% with 489 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.85%. Comparing base (5622aeb) to head (430a987).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/fwdapi/adapters.go 12.03% 346 Missing and 5 partials ⚠️
pkg/fwdmcp/httpclient.go 0.00% 100 Missing ⚠️
pkg/fwdmcp/tools.go 74.32% 28 Missing and 10 partials ⚠️

❌ Your patch status has failed because the patch coverage (24.42%) 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     #350      +/-   ##
==========================================
- Coverage   63.79%   61.85%   -1.95%     
==========================================
  Files          69       69              
  Lines       10936    11583     +647     
==========================================
+ Hits         6977     7165     +188     
- Misses       3681     4124     +443     
- Partials      278      294      +16     
Files with missing lines Coverage Δ
pkg/fwdmcp/tools.go 77.52% <74.32%> (+2.45%) ⬆️
pkg/fwdmcp/httpclient.go 58.18% <0.00%> (-7.90%) ⬇️
pkg/fwdapi/adapters.go 35.31% <12.03%> (-16.56%) ⬇️

... 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 and others added 4 commits December 30, 2025 14:43
- Add tests for handleListPods, handleGetPod, handleGetEvents, handleGetEndpoints
- Add tests for handleListContexts, handleGetAnalysis, handleGetQuickStatus, handleGetHistory
- Add tests for splitLogLines and formatDuration helper functions
- Add tests for KubernetesDiscoveryAdapter pod/event/endpoint methods with nil manager

This improves patch coverage from 59.8% to 65.2% for fwdmcp package.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Update .fossa.yml to use the correct v3 format:
- Use 'targets: only:' instead of 'analyze: types:'
- Specify 'type: go' to analyze only Go modules
- This should exclude Python/pip documentation dependencies

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@cjimti cjimti self-assigned this Dec 30, 2025
@cjimti cjimti merged commit fc0c161 into master Dec 30, 2025
10 of 12 checks passed
@cjimti cjimti deleted the housekeeping/improvements branch December 30, 2025 23:26
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