Skip to content

Shared ToolRegistry, DevConsole tools, analysis tools, and diagnostic prompts#24337

Draft
gnodet wants to merge 7 commits into
apache:mainfrom
gnodet:the-new-camel-tui-is-an-entry-point-for-in-depth-k
Draft

Shared ToolRegistry, DevConsole tools, analysis tools, and diagnostic prompts#24337
gnodet wants to merge 7 commits into
apache:mainfrom
gnodet:the-new-camel-tui-is-an-entry-point-for-in-depth-k

Conversation

@gnodet

@gnodet gnodet commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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)

  • Central registry of 49+ shared tool descriptors with ToolDescriptor, ToolContext, ToolExecutor
  • AskTools (Agent REPL) refactored to delegate to ToolRegistry for shared tools
  • CLI-only and file-system tools remain in AskTools (depend on CamelJBangMain)
  • New catalog tools added to registry: catalog_dataformats, catalog_dataformat_doc, catalog_languages, catalog_language_doc, catalog_eip_doc
  • 16 unit tests covering tool registration, execution, and edge cases

Commit 2: Surface DevConsole data as AI tools (camel-jbang-core)

  • Circuit breaker status (get_circuit_breakers) — aggregates Resilience4j + Fault Tolerance sections
  • Startup recorder steps (get_startup_steps)
  • Datasource pool status (get_datasources)
  • SQL query execution (sql_query) — marked as destructive since arbitrary SQL can include DDL/DML
  • OpenTelemetry spans (get_spans)
  • Micrometer metrics (get_metrics)

Commit 3: Add analysis and diagnostic tools (camel-jbang-core)

  • get_route_analysis — route structure analysis with anti-pattern hints
  • get_eip_stats — EIP usage statistics across routes
  • detect_config_drift — compare running routes vs source files

Commit 4: Add MCP prompts for diagnosis and optimization (camel-jbang-mcp)

  • camel_diagnose_route — guided 7-step workflow for root cause analysis
  • camel_optimize_route — guided 6-step workflow for performance optimization

Commit 5: Address review feedback

  • sql_query marked as destructive (arbitrary SQL can include DDL/DML)
  • ToolContext.catalog() made thread-safe with volatile + double-checked locking
  • Removed planning document (design/tui-mcp-agent-gaps.adoc)

Commit 6: Refactor RuntimeTools to delegate to ToolRegistry

  • All @Tool methods in RuntimeTools now delegate to ToolRegistry via a helper that resolves nameOrPid, creates ToolContext, and translates exceptions
  • Only MCP-specific tools (camel_runtime_processes, camel_runtime_receive) keep their own implementations
  • ToolRegistry aligned with MCP behavior: get_memory combines memory+gc+threads sections, get_route_topology accepts metric/external params, trace_control throws on unknown actions
  • This makes ToolRegistry the actual single source of truth — changes to tool logic only need to happen in one place

Architecture

ToolRegistry (camel-jbang-core)
  └── 49+ shared tool descriptors (ToolDescriptor + ToolExecutor)
       ├── AskTools (Agent REPL) — delegates to ToolRegistry for shared tools
       └── RuntimeTools (MCP server) — delegates to ToolRegistry for runtime tools
  
CatalogTools (camel-jbang-mcp) — stays separate (versioned catalog, typed records)
ExampleTools (camel-jbang-mcp) — stays separate (typed records, Docker info)

Test plan

  • ToolRegistryTest — 16 tests covering registration, execution, edge cases
  • MCP module — 280 tests passing
  • Both modules compile and pass formatting checks
  • Verified delegateToRegistry() correctly bridges ToolExecutionExceptionToolCallException

🤖 Generated with Claude Code

gnodet and others added 4 commits June 30, 2026 09:26
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>
@gnodet gnodet requested review from davsclaus June 30, 2026 09:45
@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot removed the docs label Jun 30, 2026
@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • dsl/camel-jbang/camel-jbang-core
  • dsl/camel-jbang/camel-jbang-mcp

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • dsl/camel-jbang/camel-jbang-core: 1 test(s) disabled on GitHub Actions
  • dsl/camel-jbang/camel-jbang-mcp: 1 test(s) disabled on GitHub Actions

💡 Manual integration tests recommended:

You modified dsl/camel-jbang/camel-jbang-core. The related integration tests in dsl/camel-jbang/camel-jbang-it are excluded from CI. Consider running them manually:

mvn verify -f dsl/camel-jbang/camel-jbang-it -Djbang-it-test
All tested modules (7 modules)
  • Camel :: JBang :: Core
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Launcher :: Container

⚙️ View full build and test results

@davsclaus davsclaus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Is refactoring the MCP server (RuntimeTools, CatalogTools, etc.) to consume ToolRegistry planned as a follow-up?
  2. 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?
  3. 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?
  4. 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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@gnodet gnodet requested a review from davsclaus June 30, 2026 12:45

@davsclaus davsclaus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated Review — PR #24337

Following up on my earlier review. The two new commits address all prior findings.

Prior findings — all addressed

  1. sql_query destructive flag — Now .readOnly(false).destructive(true). ✅
  2. ToolContext.catalog() thread safety — Proper double-checked locking with volatile fields. ✅
  3. MCP deduplicationRuntimeTools now delegates to ToolRegistry via delegateToRegistry(), with only camel_runtime_processes and camel_runtime_receive remaining as MCP-specific. The "single source of truth" claim is now accurate. ✅

New changes look good

  • get_memory enriched in ToolRegistry to combine memory/gc/threads sections — matches prior MCP behavior.
  • get_route_topology now has configurable metric/external params instead of hardcoded values.
  • trace_control throws on unknown action instead of silently passing through.
  • toJsonObject helper handles the String→JsonObject conversion cleanly with a reasonable fallback.
  • camel_runtime_receive properly 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.

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

Labels

2 participants