AI Resource
Since Camel 4.23
Only consumer is supported
The AI Resource component exposes Camel routes as read-only resources that an AI client can fetch by uri. Where AI Tool models an action the model decides to invoke, a resource models content the client reads: a configuration file, a report on S3, a document on an FTP server.
Today the only adapter reading this registry is camel-mcp-server, which publishes the selected resources over MCP resources/list and resources/read.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ai-resource</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> URI format
ai-resource:resourceName?resourceUri=uri[&options]
Where resourceName is the human-readable label shown in resource listings, and resourceUri is the address clients use to read the resource. The uri must be unique within the CamelContext.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The AI Resource component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
The component configuration. | AiResourceConfiguration | ||
Human-readable description of what this resource contains. Passed verbatim to the client. When omitted, defaults to the resource name. | String | ||
MIME type of the content the route produces. Types denoting text, such as any text subtype, application/json, and any subtype ending in json, xml or yaml, are read as a string. Every other type is read as raw bytes and delivered to clients as a binary blob. | text/plain | String | |
Required The resource uri clients use to read this resource, for example camel:///config/app.json or s3://reports/latest.pdf. It must be unique within the CamelContext and is what an MCP client sends in a resources/read request. | String | ||
Comma-separated list of tags used to group resources. Adapters filter the registry by these tags to select which resources to expose. When omitted, the resource goes into a default pool which camel-mcp-server never exposes. | String | ||
Optional display title for resource listings. Advisory hint for clients only. | String | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The AI Resource endpoint is configured using URI syntax:
ai-resource:resourceName
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Human-readable description of what this resource contains. Passed verbatim to the client. When omitted, defaults to the resource name. | String | ||
MIME type of the content the route produces. Types denoting text, such as any text subtype, application/json, and any subtype ending in json, xml or yaml, are read as a string. Every other type is read as raw bytes and delivered to clients as a binary blob. | text/plain | String | |
Required The resource uri clients use to read this resource, for example camel:///config/app.json or s3://reports/latest.pdf. It must be unique within the CamelContext and is what an MCP client sends in a resources/read request. | String | ||
Comma-separated list of tags used to group resources. Adapters filter the registry by these tags to select which resources to expose. When omitted, the resource goes into a default pool which camel-mcp-server never exposes. | String | ||
Optional display title for resource listings. Advisory hint for clients only. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern |
Usage
A resource read carries no arguments: the route is invoked with an empty exchange and its message body is the content returned to the client. Retrieval therefore uses whatever Camel already offers for reading on demand: a producer with a read operation (aws2-s3 with operation=getObject), or pollEnrich for the polling components (file, ftp, sftp), whose producers write rather than read.
Always give pollEnrich an explicit timeout - it is a parameter of the EIP, not an endpoint option. It defaults to -1, which waits until a message is available and parks the route thread for good when the file is not there. The client is still answered - the read returns a timeout error after camel.server.mcp-resource-timeout - but the route stays blocked. Note also that noop=true implies idempotent=true, so idempotent=false is what keeps the same file readable on every request.
Textual resource
-
Java
-
XML
-
YAML
from("ai-resource:app_config"
+ "?resourceUri=camel:///config/app.json"
+ "&tags=crm"
+ "&description=Current application configuration"
+ "&mimeType=application/json")
.pollEnrich("file:config?fileName=app.json&noop=true&idempotent=false", 5000); <route>
<from uri="ai-resource:app_config?resourceUri=camel:///config/app.json&tags=crm&description=Current application configuration&mimeType=application/json"/>
<pollEnrich uri="file:config?fileName=app.json&noop=true&idempotent=false" timeout="5000"/>
</route> - route:
from:
uri: ai-resource:app_config
parameters:
resourceUri: "camel:///config/app.json"
tags: crm
description: "Current application configuration"
mimeType: application/json
steps:
- poll-enrich:
uri: "file:config?fileName=app.json&noop=true&idempotent=false"
timeout: 5000 Binary resource
The mimeType decides how the route body is read. Types denoting text, such as any text subtype, application/json, and any subtype ending in json, xml or yaml, are converted to a string. Every other type is read as byte[] and delivered to the client as a binary blob.
from("ai-resource:latest_report"
+ "?resourceUri=s3://reports/latest.pdf"
+ "&tags=crm"
+ "&description=Latest sales report"
+ "&mimeType=application/pdf")
.to("aws2-s3://reports?fileName=latest.pdf&operation=getObject"); Tags and exposure
Tags group resources so that an adapter can select which ones to expose. A resource without tags goes into a default pool that camel-mcp-server never exposes: crossing the boundary to a remote client is an explicit per-route opt-in. See the MCP server documentation for how the tag patterns are configured.