Federico Mariani created CAMEL-23396:
----------------------------------------
Summary: camel-openai: Extract MCP server management and
deduplicate producer utilities
Key: CAMEL-23396
URL: https://issues.apache.org/jira/browse/CAMEL-23396
Project: Camel
Issue Type: Improvement
Components: camel-openai
Reporter: Federico Mariani
_OpenAIEndpoint_ currently handles too many concerns: OpenAI client creation,
SSL configuration, MCP server lifecycle (init, reconnect, close), MCP transport
factory, and tool registry management. At _~540_ lines, the class mixes
endpoint wiring with infrastructure management, making it hard to test and
extend.
Additionally, utility methods are duplicated across producers:
- `extractTextContent(List<McpSchema.Content>)` is identical in
`OpenAIProducer` (line 529) and `OpenAIToolExecutionProducer` (line 177).
- `resolveParameter(Message, String, T, Class<T>)` appears in both
`OpenAIProducer` (line 755) and `OpenAIAudioTranscriptionProducer` (line 155)
with slightly different signatures.
1. *Extract `McpServerManager`* — move MCP server initialization
(`initializeMcpServers()`), transport creation (`createMcpTransport()`),
reconnection (`reconnectMcpServer()`), tool call delegation (`callTool()`), and
shutdown logic from `OpenAIEndpoint` into a dedicated `McpServerManager` class.
The endpoint would hold a reference and delegate. This also makes it reusable
if other camel-ai components need MCP support in the future (see
[CAMEL-23382|https://issues.apache.org/jira/browse/CAMEL-23382]).
2. *Deduplicate `extractTextContent()`* — move to `McpToolConverter` (which
already handles MCP-to-OpenAI conversion) or a new `McpUtils` class.
3. *Deduplicate `resolveParameter()`* — unify the two signatures and place in a
shared utility or a common base class for the producers.
These are pure refactoring changes with no behavioral impact. The MCP
extraction is the most impactful since it reduces `OpenAIEndpoint` by ~250
lines.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)