Skip to content

Conversation

JAORMX
Copy link
Collaborator

@JAORMX JAORMX commented Aug 19, 2025

This commit introduces an optional integration between the ToolHive operator
and kagent, enabling kagent agents to discover and use MCP servers managed
by ToolHive.

  • Added new mcpserver_kagent.go with logic to manage kagent ToolServer resources

  • Implemented ensureKagentToolServer() to create/update kagent ToolServers

  • Implemented deleteKagentToolServer() for cleanup on MCPServer deletion

  • Added kagent ToolServer management to main reconciliation loop

  • Added kagent ToolServer cleanup to finalization logic

  • Added kagentIntegration.enabled flag to values.yaml (default: false)

  • Added KAGENT_INTEGRATION_ENABLED environment variable to operator deployment

  • Added conditional RBAC permissions for kagent.dev/toolservers resources

  • Automatically creates kagent ToolServer resources for each ToolHive MCPServer

  • ToolServers reference the ToolHive proxy service URL

  • Proper ownership chain ensures cleanup when MCPServers are deleted

  • Maps ToolHive transport types to kagent config types:

    • sse → sse
    • streamable-http → streamableHttp
    • stdio → sse (since ToolHive exposes all via HTTP)
  • Added comprehensive unit tests for kagent integration logic

  • Tests cover ToolServer creation, updates, and deletion

  • Tests validate proper URL generation and transport mapping

  • Added detailed kagent integration section to operator README

  • Included configuration examples and usage instructions

  • Documented requirements and how the integration works

Kagent is a framework for building AI agents in Kubernetes environments.
By creating kagent ToolServer references, we enable kagent agents to:

  • Discover available MCP servers managed by ToolHive
  • Use these MCP servers as tools in their workflows
  • Benefit from ToolHive's security and management features

This integration is optional and backward-compatible, requiring explicit
enablement via Helm values.

Fixes: Enables kagent to use ToolHive-managed MCP servers
Signed-off-by: Juan Antonio Osorio ozz@stacklok.com

This commit introduces an optional integration between the ToolHive operator
and kagent, enabling kagent agents to discover and use MCP servers managed
by ToolHive.

- Added new mcpserver_kagent.go with logic to manage kagent ToolServer resources
- Implemented ensureKagentToolServer() to create/update kagent ToolServers
- Implemented deleteKagentToolServer() for cleanup on MCPServer deletion
- Added kagent ToolServer management to main reconciliation loop
- Added kagent ToolServer cleanup to finalization logic

- Added kagentIntegration.enabled flag to values.yaml (default: false)
- Added KAGENT_INTEGRATION_ENABLED environment variable to operator deployment
- Added conditional RBAC permissions for kagent.dev/toolservers resources

- Automatically creates kagent ToolServer resources for each ToolHive MCPServer
- ToolServers reference the ToolHive proxy service URL
- Proper ownership chain ensures cleanup when MCPServers are deleted
- Maps ToolHive transport types to kagent config types:
  - sse → sse
  - streamable-http → streamableHttp
  - stdio → sse (since ToolHive exposes all via HTTP)

- Added comprehensive unit tests for kagent integration logic
- Tests cover ToolServer creation, updates, and deletion
- Tests validate proper URL generation and transport mapping

- Added detailed kagent integration section to operator README
- Included configuration examples and usage instructions
- Documented requirements and how the integration works

Kagent is a framework for building AI agents in Kubernetes environments.
By creating kagent ToolServer references, we enable kagent agents to:
- Discover available MCP servers managed by ToolHive
- Use these MCP servers as tools in their workflows
- Benefit from ToolHive's security and management features

This integration is optional and backward-compatible, requiring explicit
enablement via Helm values.

Fixes: Enables kagent to use ToolHive-managed MCP servers
Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
Copy link
Collaborator

@ChrisJBurns ChrisJBurns left a comment

Choose a reason for hiding this comment

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

A few comments, but is worth adding E2E tests for them too if possible?

name: github
namespace: toolhive-system
spec:
image: ghcr.io/github/github-mcp-server
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this work without the secret?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it won't. Let me update the example

JAORMX added 3 commits August 19, 2025 14:39
- Bump operator chart version from 0.2.5 to 0.2.6
- Regenerate helm docs to include kagentIntegration values

This fixes CI failures for chart version bump and helm-docs pre-commit hook.
This commit adds support for kagent v1alpha2 API which uses RemoteMCPServer
resources instead of the v1alpha1 ToolServer resources.

## Changes

### Controller Implementation
- Added detectKagentAPIVersion() to automatically detect available kagent API version
- Added getPreferredKagentAPIVersion() to check for user preference via env var
- Added createKagentRemoteMCPServerObject() for v1alpha2 RemoteMCPServer creation
- Updated ensureKagentToolServer() to support both v1alpha1 and v1alpha2
- Updated deleteKagentToolServer() to handle both resource types

### Helm Chart Configuration
- Added optional kagentIntegration.apiVersion to prefer v1alpha2 when available
- Added KAGENT_API_VERSION environment variable to operator deployment
- Added RBAC permissions for kagent.dev/remotemcpservers resources

### Key Features
- Automatic API version detection - uses the highest available version
- Backward compatible - defaults to v1alpha1 if v1alpha2 not available
- User can explicitly prefer v1alpha2 via Helm values
- Seamless migration path from v1alpha1 to v1alpha2

### Testing
- Added tests for API version detection logic
- Added tests for RemoteMCPServer object creation
- Updated existing tests to handle both API versions
- Fixed test parallelization issues with environment variables

## Why This Change?

Kagent v1alpha2 introduces the RemoteMCPServer resource which replaces
the v1alpha1 ToolServer resource. This change ensures ToolHive can work
with both versions of kagent, providing a smooth migration path for users.

The implementation maintains backward compatibility while being ready for
the newer kagent API version.
- Define constants for repeated string literals (goconst)
- Fix detectKagentAPIVersion function signature to return single value
- Update function calls to match new signature
- Add nolint comments for test parallelization with env vars

This resolves all golangci-lint issues and ensures CI passes.
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