Model Context Protocol
LangChain4j supports the Model Context Protocol (MCP) to communicate with
MCP compliant servers that can provide and execute tools. General
information about the protocol can be found at the
MCP website. More detailed information can
also be found in the LangChain4j
documentation, this documentation focuses on features that Quarkus provides
on top of the upstream module. For an example project that uses MCP, see
mcp-tools
project in the quarkus-langchain4j
repository.
There is also a Quarkus extension for developing MCP servers. See GitHub repo and documentation. |
Declaratively generating a tool provider backed by MCP
Quarkus offers a way to generate a tool provider backed by one or more MCP servers declaratively from the configuration model. When using this, all AI services that don’t explicitly declare to use a different tool provider will then be wired up to it, without having to write any MCP-specific code in the AI service. Example:
quarkus.langchain4j.mcp.github.transport-type=stdio
quarkus.langchain4j.mcp.github.command=npm,exec,@modelcontextprotocol/server-github
quarkus.langchain4j.mcp.github.environment.GITHUB_PERSONAL_ACCESS_TOKEN=<YOUR_TOKEN>
With this configuration, Quarkus will generate a tool provider that talks to the server-github
MCP server. The server will be started automatically as a subprocess using the provided command
(npm exec @modelcontextprotocol/server-github
). The environment.*
properties define
environment variables that will be passed to the subprocess. With this configuration, any
AI Service that does not declare a specific tool provider will be wired to this one.
Configuration reference
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
---|---|---|
Type |
Default |
|
Transport type Environment variable: |
|
required |
The URL of the SSE endpoint. This only applies to MCP clients using the HTTP transport. Environment variable: |
string |
|
The command to execute to spawn the MCP server process. This only applies to MCP clients using the STDIO transport. Environment variable: |
list of string |
|
Environment variables for the spawned MCP server process. This only applies to MCP clients using the STDIO transport. Environment variable: |
Map<String,String> |
|
Whether to log requests Environment variable: |
boolean |
|
Whether to log responses Environment variable: |
boolean |
|
Timeout for tool executions performed by the MCP client Environment variable: |
|
|
Whether the MCP extension should automatically generate a ToolProvider that is wired up to all the configured MCP clients. The default is true if at least one MCP client is configured, false otherwise. Environment variable: |
boolean |
|
About the Duration format
To write duration values, use the standard You can also use a simplified format, starting with a number:
In other cases, the simplified format is translated to the
|