Skip to content

Support Auto-Generation of MCP Gateway CRs from ToolHive MCP Server #39

Closed

Description

@cwiklik

Summary

Extend the kagenti webhook that mutates ToolHive MCP Server Custom Resources to automatically generate the corresponding MCP Gateway CRs (HTTPRoute and MCPServer). This will streamline the developer workflow by automating the registration of ToolHive MCP Servers with the MCP Gateway and hiding implementation details.

Background

Currently, when deploying a ToolHive MCP Server, developers must manually create two additional Custom Resources to register the server with the MCP Gateway:

  1. HTTPRoute (Gateway API) - Defines the routing rules for the MCP server
  2. MCPServer (MCP Gateway CR) - Links the server to the gateway via the HTTPRoute

Important Note: There are two different MCPServer CRs in play:

  • ToolHive MCPServer (toolhive.kagenti.com/v1alpha1) - The application MCP server
  • MCP Gateway MCPServer (mcp.kagenti.com/v1alpha1) - The gateway registration CR

This manual process is error-prone and exposes unnecessary implementation details to developers.

Proposed Solution

Enhance the existing kagenti mutating webhook to automatically generate the MCP Gateway CRs when a ToolHive MCP Server CR is created or updated.

Generated Resources

For each ToolHive MCP Server, the webhook should generate:

1. HTTPRoute CR

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: <tool-name-route>
  namespace: <tool-namespace>
  labels:
    mcp-server: "true"

spec:
  parentRefs:
  - name: mcp-gateway
    namespace: gateway-system
  hostnames:
  - "<tool-name>.mcp.local"
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /
    backendRefs:
    - name: <tool-name>
      port: <tool-port>

2. MCP Gateway MCPServer CR

apiVersion: mcp.kagenti.com/v1alpha1
kind: MCPServer
metadata:
  name: <tool-name>-gateway
  namespace: <tool-namespace>

spec:
  toolPrefix: 
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: <tool-name-route>
    namespace: <tool-namespace>

Implementation Details

Webhook Behavior

  1. On ToolHive MCPServer Creation:

    • Generate HTTPRoute with appropriate hostname and routing rules
    • Generate MCP Gateway MCPServer with reference to the HTTPRoute
    • Apply ownership labels for garbage collection and management
  2. On ToolHive MCPServer Update:

    • Update generated CRs if relevant fields change (service name, port, tool prefix)
    • Maintain idempotency
  3. On ToolHive MCPServer Deletion:

    • Ensure generated CRs are cleaned up via owner references or labels

Configuration Options

The webhook should extract the following from the ToolHive MCPServer:

  • Service name and port (for HTTPRoute backendRef)
  • Tool prefix (for MCP Gateway MCPServer spec)
  • Namespace
  • Any custom annotations or labels to propagate

Activity

  1. self-assigned this
    on Dec 2, 2025
  2. added
    enhancement
    on Dec 2, 2025
  3. added theissue type on Dec 2, 2025
  4. esnible commented on Dec 2, 2025

    @esnible
    Member

    Is there documentation or PowerPoint proposals of how we expect the completed system to work? I want to share it with the MCP Gateway developers.

    Does the Kagenti UI or Kagenti Operator require the MCP Gateway and/or its CRs? Or is the MCP Gateway merely a part of the Kagenti environment?

    cc @david-martin

  5. rubambiza commented on Feb 2, 2026

    @rubambiza
    Contributor

    No longer valid as ToolHive is no longer being used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions