Skip to content

Commit 70db06a

Browse files
committed
feat(operator): add kagent v1alpha2 RemoteMCPServer support
This commit adds support for kagent v1alpha2 API which uses RemoteMCPServer resources instead of the v1alpha1 ToolServer resources. - 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 - 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 - 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 - 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 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.
1 parent 769594a commit 70db06a

File tree

6 files changed

+471
-65
lines changed

6 files changed

+471
-65
lines changed

cmd/thv-operator/README.md

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,13 @@ kubectl describe mcpserver <name>
215215

216216
### Kagent Integration
217217

218-
The ToolHive operator supports optional integration with [kagent](https://kagent.dev), allowing kagent agents to discover and use MCP servers managed by ToolHive. When enabled, the operator automatically creates kagent ToolServer resources that reference the ToolHive-managed MCP servers.
218+
The ToolHive operator supports optional integration with [kagent](https://kagent.dev), allowing kagent agents to discover and use MCP servers managed by ToolHive. When enabled, the operator automatically creates kagent resources that reference the ToolHive-managed MCP servers.
219+
220+
The integration supports both:
221+
- **kagent v1alpha1**: Creates `ToolServer` resources
222+
- **kagent v1alpha2**: Creates `RemoteMCPServer` resources (when available)
223+
224+
The operator automatically detects which kagent API version is available in your cluster and creates the appropriate resources.
219225

220226
#### Enabling Kagent Integration
221227

@@ -234,25 +240,43 @@ kagentIntegration:
234240
enabled: true
235241
```
236242
243+
#### Configuration Options
244+
245+
You can control the kagent API version preference via environment variable:
246+
247+
```yaml
248+
# In your values file
249+
kagentIntegration:
250+
enabled: true
251+
apiVersion: v1alpha2 # Optional: prefer v1alpha2 when available (defaults to v1alpha1)
252+
```
253+
254+
This sets the `KAGENT_API_VERSION` environment variable in the operator deployment.
255+
237256
#### How It Works
238257

239258
When kagent integration is enabled:
240259

241-
1. For each ToolHive MCPServer resource created, the operator automatically creates a corresponding kagent ToolServer resource
242-
2. The ToolServer resource references the ToolHive-managed MCP server service URL
243-
3. The ToolServer is owned by the MCPServer, ensuring it's deleted when the MCPServer is removed
244-
4. Kagent agents can then discover and use these ToolServers to access the MCP servers
260+
1. The operator detects which kagent API version is available in your cluster
261+
2. For each ToolHive MCPServer resource created, the operator automatically creates:
262+
- A kagent `ToolServer` resource (v1alpha1), OR
263+
- A kagent `RemoteMCPServer` resource (v1alpha2)
264+
3. The kagent resource references the ToolHive-managed MCP server service URL
265+
4. The resource is owned by the MCPServer, ensuring it's deleted when the MCPServer is removed
266+
5. Kagent agents can then discover and use these resources to access the MCP servers
245267

246-
The kagent ToolServer resources are created with:
268+
The kagent resources are created with:
247269
- Name: `toolhive-<mcpserver-name>`
248270
- Namespace: Same as the MCPServer
249-
- Transport configuration: Mapped from ToolHive transport types (sse → sse, streamable-http → streamableHttp, stdio → sse)
271+
- Transport configuration:
272+
- v1alpha1: Mapped to config types (sse → sse, streamable-http → streamableHttp, stdio → sse)
273+
- v1alpha2: Mapped to protocols (sse → SSE, streamable-http → STREAMABLE_HTTP, stdio → SSE)
250274
- Service URL: Points to the ToolHive proxy service
251275

252276
#### Requirements
253277

254-
- Kagent must be installed in your cluster
255-
- The operator needs permissions to manage kagent ToolServer resources (automatically configured when integration is enabled)
278+
- Kagent must be installed in your cluster (either v1alpha1 or v1alpha2)
279+
- The operator needs permissions to manage kagent resources (automatically configured when integration is enabled)
256280

257281
#### Example
258282

@@ -270,8 +294,9 @@ spec:
270294
port: 8080
271295
```
272296

273-
With kagent integration enabled, the operator automatically creates:
297+
With kagent integration enabled, the operator automatically creates one of the following:
274298

299+
**For kagent v1alpha1:**
275300
```yaml
276301
apiVersion: kagent.dev/v1alpha1
277302
kind: ToolServer
@@ -289,7 +314,23 @@ spec:
289314
url: http://mcp-github-proxy.toolhive-system.svc.cluster.local:8080
290315
```
291316

292-
Kagent agents can then reference this ToolServer to use the GitHub MCP server in their workflows.
317+
**For kagent v1alpha2:**
318+
```yaml
319+
apiVersion: kagent.dev/v1alpha2
320+
kind: RemoteMCPServer
321+
metadata:
322+
name: toolhive-github
323+
namespace: toolhive-system
324+
labels:
325+
toolhive.stacklok.dev/managed-by: toolhive-operator
326+
toolhive.stacklok.dev/mcpserver: github
327+
spec:
328+
description: "ToolHive MCP Server: github"
329+
url: http://mcp-github-proxy.toolhive-system.svc.cluster.local:8080
330+
protocol: SSE
331+
```
332+
333+
Kagent agents can then reference these resources to use the GitHub MCP server in their workflows.
293334

294335
### Permission Profiles
295336

0 commit comments

Comments
 (0)