Skip to content

[subtask] [Subtask 3/4] Implement MCP JSON-RPC API server in operator #537

@github-actions

Description

@github-actions

Parent Issue: #20

Objective

Expose a standardized MCP JSON-RPC API endpoint in the Kubernetes operator that dynamically routes tool calls to loaded WebAssembly components.

Context

With the operator framework in place (Subtask 2), this subtask adds the MCP protocol layer. The operator must:

  1. Expose an HTTP endpoint serving the MCP JSON-RPC protocol
  2. Dynamically route tool calls based on loaded components
  3. Handle tool discovery (list available tools from all components)
  4. Execute tool calls with proper permission enforcement

This reuses the existing MCP server infrastructure from crates/mcp-server/ but adapts it for the Kubernetes operator context.

Implementation Details

1. MCP Server Integration

Reuse existing MCP server implementation:

  • Leverage crates/mcp-server/src/lib.rs - existing MCP server logic
  • Adapt transport layer for HTTP endpoint (reuse existing HTTP transports)
  • Share tool registry with operator controller

2. HTTP Endpoint Setup

Add HTTP server to operator:

  • Use existing axum dependency (already used in main Wassette server)
  • Expose endpoint: (redacted)):9001/mcp
  • Support both SSE and streamable-http transports (reuse from main server)

3. Dynamic Tool Routing

Implement tool registry that:

  • Aggregates tools from all loaded components (from CRD reconciliation)
  • Maps tool names to component IDs
  • Routes tool calls to appropriate component via LifecycleManager

Key mapping:

  • MCP tools/list → Return all tools from all loaded components
  • MCP tools/call → Route to correct component based on tool name

4. Tool Discovery Flow

MCP Client → tools/list → Operator aggregates tools from all WassetteComponent CRDs
                        → Returns combined tool schemas

5. Tool Execution Flow

MCP Client → tools/call {name: "get_time", args: {}}
           → Operator looks up component for "get_time" tool
           → Calls LifecycleManager.execute_component_call(component_id, "get_time", args)
           → Returns result to client

6. Files to Create/Modify

  • New: crates/wassette-operator/src/mcp_server.rs - MCP server setup for operator
  • Modify: crates/wassette-operator/src/main.rs - Add HTTP server alongside controller
  • New: crates/wassette-operator/src/tool_registry.rs - Dynamic tool aggregation
  • Modify: crates/wassette-operator/src/controller.rs - Register tools when components load

7. Kubernetes Service Configuration

Create Kubernetes Service manifest:

apiVersion: v1
kind: Service
metadata:
  name: wassette-mcp
spec:
  selector:
    app: wassette-operator
  ports:
    - port: 9001
      targetPort: 9001
      protocol: TCP
  type: ClusterIP  # or LoadBalancer for external access

Acceptance Criteria

  • MCP JSON-RPC endpoint is exposed on HTTP port 9001
  • tools/list returns all tools from all loaded components
  • tools/call correctly routes to appropriate component
  • Tool calls execute with proper permission enforcement
  • Multiple components can be loaded simultaneously with distinct tools
  • Error responses follow MCP error format
  • Integration test calling tools via MCP protocol

Testing Strategy

Unit Tests

  • Mock tool registry with multiple components
  • Test tool name collision detection
  • Verify routing logic for tool calls

Integration Tests

Use MCP Inspector to test:

# Start operator in test cluster
kubectl apply -f test-components.yaml

# Wait for components to load
kubectl wait --for=condition=Ready wassettecomponent/time-server

# Test with MCP Inspector
npx `@modelcontextprotocol/inspector` --cli (redacted) --method tools/list

# Call a tool
npx `@modelcontextprotocol/inspector` --cli (redacted) \
  --method tools/call --tool-name get_time

Test Scenarios

  1. Load single component, list tools, call tool
  2. Load multiple components, verify all tools appear
  3. Delete component, verify tools are removed from registry
  4. Test error handling when component fails to load
  5. Test permission enforcement during tool execution

Dependencies

  • Requires: Subtask 2 (operator core framework) must be completed
  • Blocks: None (Subtask 4 can proceed in parallel)

References

  • Existing MCP server: crates/mcp-server/src/lib.rs
  • MCP protocol tools: crates/mcp-server/src/tools.rs
  • Wassette HTTP server: src/server.rs
  • MCP specification: (redacted)
    Related to Kubernetes Operator for mcp-wasmtime #20

AI generated by Plan for #20

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions