ramu11 opened a new pull request, #30671:
URL: https://github.com/apache/camel/pull/30671

   ## Motivation
   
   Introduce a transport-independent runtime access abstraction in Camel JBang 
so that Camel MCP tools can interact with both local and remote Camel 
integrations.
   
   The implementation preserves the existing local file-based IPC behavior 
while enabling remote Camel runtimes to connect to the Camel JBang MCP server 
through the existing Camel CLI Connector WebSocket protocol.
   
   The objective is to keep runtime tool logic independent of the underlying 
transport and platform, without introducing duplicate protocols or 
platform-specific runtime tool implementations.
   
   ## Changes
   
   ### 1. Runtime access abstraction
   
   Introduce a framework-independent runtime access SPI in `camel-jbang-core`.
   
   - Add `RuntimeAccess` to define the common contract for runtime discovery, 
status and snapshot access, action execution, message sending, SQL queries and 
application lifecycle operations.
   - Introduce `RuntimeTarget` as an opaque runtime reference, separating 
stable runtime identity from the operating-system PID.
   - Implement `LocalRuntimeAccess` using the existing file-based IPC mechanism.
   - Refactor `ToolContext` and `ToolRegistry` to use the runtime access 
abstraction.
   - Preserve existing local behavior, including the default `ToolContext` 
constructor and PID-based compatibility APIs.
   
   ### 2. Remote runtime connectivity
   
   Implement remote runtime connectivity in `camel-jbang-mcp`.
   
   - Add an authenticated WebSocket endpoint at `/connect`.
   - Reuse the existing `camel-cli-connector` WebSocket protocol and versioned 
message frames.
   - Introduce `RemoteRuntimeAccess` to provide runtime operations through 
remote connections.
   - Add `RemoteRuntimeRegistry` to manage remote runtime discovery, 
registration, duplicate identities and reconnections.
   - Use a stable `executionId` to identify an integration independently of its 
PID.
   - Retain runtime snapshots and metadata across network reconnections.
   
   ### 3. Remote runtime lifecycle and protocol handling
   
   Add remote connection management and lifecycle handling.
   
   - Authenticate incoming connections using a bearer token.
   - Validate the runtime execution identity during connection establishment.
   - Handle hello messages, status and other snapshots, heartbeats and action 
request/response correlation.
   - Support remote action execution and cancellation.
   - Handle connection loss, reconnection and stale connection cleanup.
   - Apply configurable connection limits, runtime retention, heartbeat 
timeouts, frame limits and bounded snapshot/message buffers.
   
   ### 4. MCP runtime tool integration
   
   Integrate remote runtimes into the existing MCP runtime tool architecture.
   
   - Update `RuntimeService` to discover and operate on local and remote 
runtimes.
   - Update `RuntimeTools` and `AiTraceTools` to work with opaque runtime 
targets.
   - Support remote status, error and history snapshots, trace and receive 
data, application shutdown, message sending and SQL query execution.
   - Preserve existing local runtime discovery and execution behavior.
   
   MCP tools use the same runtime access contract regardless of whether the 
integration runs locally or remotely.
   
   ### 5. Camel CLI Connector integration
   
   Enhance the existing `WebSocketCliConnectorTransport` to support a WebSocket 
client supplied through the Camel registry, with the JDK WebSocket client as 
the default fallback.
   
   This allows platform-specific WebSocket client and TLS configuration to be 
supplied by existing Spring Boot and Camel Quarkus adapters while retaining one 
shared connector transport and protocol implementation.
   
   No duplicate Spring Boot or Quarkus remote runtime protocol is introduced.
   
   ### 6. Configuration and documentation
   
   - Document remote Camel runtime connectivity in the Camel JBang MCP user 
manual.
   - Document WebSocket connector configuration and lifecycle behavior.
   - Add configuration guidance for Camel Main, Spring Boot and Quarkus.
   - Document authentication, TLS, security considerations, deployment, 
troubleshooting and operational limits.
   - Keep remote connectivity disabled by default so existing local MCP and 
STDIO behavior remains unchanged.
   
   ## Testing
   
   The implementation includes:
   
   - Runtime access and local runtime access unit tests.
   - Remote runtime configuration and protocol tests.
   - Remote connection and registry lifecycle tests.
   - Remote runtime snapshot retention and buffer tests.
   - WebSocket transport and CLI Connector SPI lifecycle tests.
   - `RemoteRuntimeEndpointIT`, which exercises the packaged MCP server against 
the real `WebSocketCliConnectorTransport` using Testcontainers.
   
   The remote endpoint integration test verifies:
   - Rejection of invalid bearer tokens.
   - Rejection of connections without an execution ID.
   - Successful WebSocket connection and hello exchange.
   - Status snapshot exchange.
   - Connection stability and heartbeat handling.
   - Clean disconnection and runtime lifecycle handling.
   
   **Verification results:**
   - Maven build: SUCCESS.
   - Camel CLI Connector: SUCCESS.
   - RemoteRuntimeEndpointIT: 1 test, 0 failures, 0 errors, 0 skipped.
   
   Note: The Spring Boot and Quarkus adapter-specific end-to-end smoke tests 
are separate from the in-repository integration test.
   
   ## Backward Compatibility
   
   - Existing local file-based runtime access remains the default.
   - Existing local MCP and STDIO workflows are preserved.
   - Existing Camel CLI Connector protocol is reused.
   - Existing PID-based APIs and local runtime behavior are retained through 
compatibility methods.
   - Remote connectivity is opt-in and disabled by default.
   
   Relates to: CAMEL-26686


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to