Shared ToolRegistry, DevConsole tools, analysis tools, and diagnostic prompts#24337
Shared ToolRegistry, DevConsole tools, analysis tools, and diagnostic prompts#24337gnodet wants to merge 7 commits into
Conversation
Add a shared ToolRegistry in camel-jbang-core that serves as the single source of truth for tool definitions and execution logic. This eliminates ~70% code duplication between the MCP server and Agent REPL, and ensures new tools automatically appear in both surfaces. - ToolDescriptor: builder-style descriptor bundling tool metadata + execution lambda - ToolContext: shared execution context wrapping RuntimeHelper + CamelCatalog - ToolRegistry: central registry with 40+ shared tools organized by category - Rewrite AskTools to delegate to ToolRegistry (995 -> 478 lines) - Add 5 new catalog tools (dataformats, languages, EIP doc) previously MCP-only - Add ToolRegistryTest with 10 tests covering registration, lookup, and execution - Add design/tui-mcp-agent-gaps.adoc with the full 4-phase plan Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add 6 new tools to ToolRegistry that expose DevConsole data previously only available in the TUI. This gives AI assistants (both MCP and Agent REPL) access to circuit breaker state, startup timing, datasource pools, SQL queries, OpenTelemetry spans, and Micrometer metrics. New tools: - get_circuit_breakers: merged resilience4j/fault-tolerance/core sections - get_startup_steps: startup recorder timing via action IPC - get_datasources: connection pool status (HikariCP/Agroal) - sql_query: execute SQL against application datasources - get_spans: OpenTelemetry trace spans via action IPC - get_metrics: Micrometer counters, gauges, timers, distributions Add readFullStatus() to ToolContext for multi-section status reads. Add 4 new tests covering DevConsole tool registration and validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add 3 new analysis tools to ToolRegistry that enable AI assistants to perform higher-level diagnostics on running Camel applications: - get_route_analysis: fetches route structure and dump with analysis hints for common anti-patterns (missing error handlers, no DLC, no timeouts, no circuit breakers, no idempotency, missing logging) - get_eip_stats: aggregates EIP/processor usage statistics across all routes with performance metrics (exchanges, failures, timing) - detect_config_drift: compares running route definitions with source files to identify runtime configuration drift These tools compose existing runtime actions (route-structure, route-dump, top-processors, source) and return structured data the LLM can analyze. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add two new MCP prompt definitions that guide LLMs through structured multi-step diagnostic and optimization workflows: - camel_diagnose_route: 7-step workflow that gathers runtime state, errors, health checks, route details, infrastructure metrics, and advanced diagnostics (circuit breakers, datasources, spans) to produce a structured root cause analysis with evidence, immediate actions, permanent fixes, and monitoring recommendations. - camel_optimize_route: 6-step workflow that establishes a performance baseline, analyzes resources, inspects route structure and EIP stats, checks infrastructure, and produces a prioritized optimization report with bottleneck identification, specific code changes, expected impact, risk assessment, and trade-off analysis. Both prompts leverage the new DevConsole and analysis tools added in previous commits (get_circuit_breakers, get_datasources, get_spans, get_metrics, get_route_analysis, get_eip_stats). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🧪 CI tested the following changed modules:
💡 Manual integration tests recommended:
All tested modules (7 modules)
|
davsclaus
left a comment
There was a problem hiding this comment.
Review: Shared ToolRegistry, DevConsole tools, analysis tools, and diagnostic prompts
This review evaluates the PR against project rules and conventions. It does not replace specialized AI review tools (CodeRabbit, Sourcery) or static analysis (SonarCloud).
Overall
Well-structured refactoring. The ToolRegistry pattern is clean, the registerStatusTool/registerRouteControlTool helpers eliminate boilerplate nicely, and backward compatibility is preserved (existing AskCliToolsTest tests pass, AskTools public API unchanged). The MCP prompts (camel_diagnose_route, camel_optimize_route) provide clear step-by-step workflows.
Findings
1. PR description overstates scope — MCP deduplication is not achieved yet (Medium)
The description claims this PR will "eliminate tool duplication between the MCP server and Agent REPL" and create a "single source of truth." However, the MCP server tools (RuntimeTools.java, CatalogTools.java, etc. in camel-jbang-mcp) are not refactored to use the new ToolRegistry — they retain their own Quarkus @Tool-annotated implementations backed by RuntimeService. Currently, ToolRegistry is consumed by AskTools only. This isn't a code defect, but the PR description should accurately reflect what was done vs. what's planned as follow-up.
2. Missing JIRA reference in commits (Low)
Per project conventions, commit format should be CAMEL-XXXX: Brief description. All 5 commits lack a JIRA reference.
3. sql_query tool should be marked destructive (Medium) — see inline comment
4. ToolContext.catalog() lazy init is not thread-safe (Low) — see inline comment
Questions
- Is refactoring the MCP server (
RuntimeTools,CatalogTools, etc.) to consumeToolRegistryplanned as a follow-up? - The 5th commit says "Remove planning document now that implementation is complete" but no file removal appears in the diff. Was this a file added and removed within this branch?
- The DevConsole tools (
get_startup_steps,get_datasources,get_spans,get_metrics) call actions/status sections that may not exist in all Camel applications. Has the behavior been verified for absent sections — does the IPC protocol return a clean "not available" response vs. an error? - The PR body has unchecked manual test items ("Manual verification with a running Camel application" and "MCP server smoke test"). These should ideally be verified before merge.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
| } | ||
| return catalog; | ||
| } | ||
|
|
There was a problem hiding this comment.
This lazy initialization is not thread-safe. If ToolContext instances can be shared across threads (e.g., concurrent MCP server requests), two threads could create separate DefaultCamelCatalog instances. If single-threaded use is the intent, a brief comment would clarify that assumption. Otherwise, synchronized or a holder pattern would be safer.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
- Mark sql_query tool as destructive(true) since arbitrary SQL can include DDL/DML (DROP TABLE, DELETE, UPDATE) - Make ToolContext.catalog() thread-safe with volatile + double-checked locking for safe use from concurrent MCP server requests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
RuntimeTools was maintaining its own independent implementations of all runtime tools, defeating the purpose of the shared ToolRegistry. Now every @tool method (except MCP-specific process discovery and receive) delegates to ToolRegistry via a helper that resolves nameOrPid, creates a ToolContext, and translates exceptions. Also aligns ToolRegistry with MCP behavior: - get_memory now combines memory+gc+threads sections - get_route_topology now accepts metric/external parameters - trace_control now throws on unknown actions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
davsclaus
left a comment
There was a problem hiding this comment.
Updated Review — PR #24337
Following up on my earlier review. The two new commits address all prior findings.
Prior findings — all addressed
sql_querydestructive flag — Now.readOnly(false).destructive(true). ✅ToolContext.catalog()thread safety — Proper double-checked locking withvolatilefields. ✅- MCP deduplication —
RuntimeToolsnow delegates toToolRegistryviadelegateToRegistry(), with onlycamel_runtime_processesandcamel_runtime_receiveremaining as MCP-specific. The "single source of truth" claim is now accurate. ✅
New changes look good
get_memoryenriched in ToolRegistry to combine memory/gc/threads sections — matches prior MCP behavior.get_route_topologynow has configurablemetric/externalparams instead of hardcoded values.trace_controlthrows on unknown action instead of silently passing through.toJsonObjecthelper handles the String→JsonObject conversion cleanly with a reasonable fallback.camel_runtime_receiveproperly documented as MCP-only.
Remaining (low severity, already flagged)
- Commit messages lack JIRA references per project conventions (
CAMEL-XXXX: ...format).
No blocking issues. The PR delivers on its stated goals — nice work consolidating the tool definitions.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Summary
Claude Code on behalf of Guillaume Nodet
Introduce a shared ToolRegistry to eliminate tool duplication between the MCP server and Agent REPL, surface DevConsole data as AI-accessible tools, add higher-level analysis capabilities, and create guided diagnostic/optimization prompts. The MCP server's RuntimeTools now delegates to ToolRegistry, making it the single source of truth.
Changes by commit
Commit 1: Introduce shared ToolRegistry (
camel-jbang-core)ToolDescriptor,ToolContext,ToolExecutorAskTools(Agent REPL) refactored to delegate to ToolRegistry for shared toolsAskTools(depend onCamelJBangMain)catalog_dataformats,catalog_dataformat_doc,catalog_languages,catalog_language_doc,catalog_eip_docCommit 2: Surface DevConsole data as AI tools (
camel-jbang-core)get_circuit_breakers) — aggregates Resilience4j + Fault Tolerance sectionsget_startup_steps)get_datasources)sql_query) — marked as destructive since arbitrary SQL can include DDL/DMLget_spans)get_metrics)Commit 3: Add analysis and diagnostic tools (
camel-jbang-core)get_route_analysis— route structure analysis with anti-pattern hintsget_eip_stats— EIP usage statistics across routesdetect_config_drift— compare running routes vs source filesCommit 4: Add MCP prompts for diagnosis and optimization (
camel-jbang-mcp)camel_diagnose_route— guided 7-step workflow for root cause analysiscamel_optimize_route— guided 6-step workflow for performance optimizationCommit 5: Address review feedback
sql_querymarked as destructive (arbitrary SQL can include DDL/DML)ToolContext.catalog()made thread-safe with volatile + double-checked lockingdesign/tui-mcp-agent-gaps.adoc)Commit 6: Refactor RuntimeTools to delegate to ToolRegistry
@Toolmethods inRuntimeToolsnow delegate toToolRegistryvia a helper that resolvesnameOrPid, createsToolContext, and translates exceptionscamel_runtime_processes,camel_runtime_receive) keep their own implementationsget_memorycombines memory+gc+threads sections,get_route_topologyaccepts metric/external params,trace_controlthrows on unknown actionsArchitecture
Test plan
ToolRegistryTest— 16 tests covering registration, execution, edge casesdelegateToRegistry()correctly bridgesToolExecutionException→ToolCallException🤖 Generated with Claude Code