Skip to content

Maat LibreChat — LLM and MCP Integration

LibreChat provides a conversational AI interface for working with Maat and other services connected through MCP servers. It combines Large Language Models with tools exposed by Maat, EventListener and other systems, allowing users to query live infrastructure data using natural language.

LibreChat acts as an integration layer between the user, available LLM models and MCP tools. Depending on the selected configuration, users can work directly in a normal chat or use a preconfigured Agent with its model, instructions and tools already assigned.

Maat and LibreChat integration architecture

Architecture overview

The integration consists of several layers working together:

Component Role
LibreChat Provides the chat interface, conversation handling, Agents and tool orchestration.
Keycloak Authenticates users and provides roles used to control access to LibreChat functionality.
LLM Gateway / LiteLLM Provides a common API endpoint for the LLM models available in LibreChat.
LLM models Interpret user requests, generate responses and decide when MCP tools should be called.
MCP servers Expose functions that the model can invoke, for example Maat, EventListener or operations provided by other integrated systems.
Maat / EventListener / monitoring systems Provide the live data returned through MCP tools.

The important distinction is that LibreChat itself does not provide Maat inventory data. When current Maat or EventListener information is required, the selected model has to call an appropriate MCP tool.

Think of LibreChat as the orchestration layer

The user talks to LibreChat, the LLM decides what should happen, MCP exposes the available operations, and the target systems remain the source of truth.

Authentication and access

By default, LibreChat can authenticate users with accounts created and stored directly in the LibreChat instance. In the Maat environment, however, the preferred approach is to use Keycloak as the identity provider.

Using Keycloak is especially useful when Maat itself is protected by authentication and authorization mechanisms. In that case, the same identity provider can be used across the environment, making user authentication and role-based access more consistent between LibreChat, Maat and the services exposed through MCP.

Keycloak - roles

After authentication, the roles assigned to the user can determine which parts of LibreChat are available, such as normal conversations, Agents, MCP functionality or administrative options.

Typical roles used in the Maat environment include:

Role Purpose
user Standard access to chat and the functionality made available to normal users.
admin Administrative access, including configuration and management functions.

Note

The exact permissions assigned to each role are part of the LibreChat and Keycloak configuration. The role name alone should not be treated as a full description of permissions.

LibreChat can also be configured with additional custom roles. However, for a new LibreChat instance it is recommended to start with the standard user and admin roles. Synchronizing additional roles from Keycloak before they are properly defined and available in LibreChat can lead to incorrect role assignment.

Choosing an LLM model

The selected model is responsible for understanding the user request and, when necessary, deciding which MCP tool should be called.

For normal text conversations almost any configured chat model may be usable. For Maat integration, however, the important requirement is tool / function calling support.

MCP requires a tool-capable model

Connecting an MCP server is not enough. If the selected model cannot call tools, it cannot query Maat, EventListener or another MCP-backed service.

Before using Maat tools in a normal conversation:

  1. Open the model selector.
  2. Select one of the models configured for the Maat environment.
  3. Make sure the selected model supports tool calling.
  4. Enable the MCP servers required for the task.

Select model and MCP servers

The available model list can contain locally hosted models, models exposed through LiteLLM, or other endpoints configured by the administrator.

Connecting MCP servers

MCP servers expose external functions to the model as tools. In the Maat environment, different servers can provide access to different systems.

Typical integrations include:

MCP server Purpose
Maat MCP Queries and operations related to the current Maat inventory.
EventListener MCP Access to events and historical changes recorded by EventListener.
Other MCP servers Additional systems integrated with LibreChat when required.

When working in a normal chat, make sure the MCP servers needed for the request are available and enabled for the conversation.

No MCP tool means no live Maat query

If the required MCP server is unavailable, disabled or not accessible to the selected model, the assistant may answer without querying the live system. For questions about current infrastructure state, verify that the expected tool was actually called.

Two ways to work with Maat

LibreChat provides two useful interaction patterns for the Maat environment: direct chat and a preconfigured Agent.

Direct chat and Maat Agent comparison

Direct chat

Direct chat is the flexible option. The user chooses the model and enables the MCP servers needed for the current task.

A typical workflow is:

  1. Select a model that supports tool calling.
  2. Enable the required MCP server or servers.
  3. Ask a question in natural language.
  4. Let the model decide whether one or more tools are needed.
  5. Review the answer and, when necessary, inspect the tool calls.

Direct chat is useful for testing new models, comparing their tool-calling behaviour and experimenting with different MCP integrations.

Maat Agent

A Maat Agent provides a more controlled and repeatable experience. The Agent can have its model, instructions and MCP tools selected in advance, so the user does not need to configure every conversation manually.

A typical Maat Agent can define:

  • the LLM model used for the conversation,
  • system instructions describing how the assistant should behave,
  • the Maat MCP tools available to the Agent,
  • EventListener MCP tools,
  • other approved MCP integrations.

Create Agent

Use an Agent for a standardized Maat assistant

An Agent is especially useful when many users should work with the same model, the same instructions and the same approved MCP tool set. An administrator can prepare such Agents in advance and easily share them with users, providing a consistent setup without requiring each user to configure the model and tools manually.

How a request is processed

When a user asks a question that requires live Maat data, several components work together before the final answer is returned.

How a Maat request is processed in LibreChat

For example, consider the question:

"What services use resource router-1?"

A simplified processing flow is:

  1. LibreChat receives the prompt and conversation context.
  2. The LLM interprets the request and checks which tools are available.
  3. The model decides that the answer requires information from Maat.
  4. It creates an MCP tool call with the required parameters.
  5. The MCP server queries the target API.
  6. The tool result is returned to the model as structured data.
  7. The model uses that data to prepare the final natural-language answer.

The same conversation can involve multiple tools. For example, a request can first query the current state from Maat and then use EventListener to retrieve historical changes for the same object.

Seeing MCP tools in action

When a model calls a tool, LibreChat exposes the tool execution inside the conversation. Depending on the LibreChat version and interface configuration, the tool block can show information such as:

  • the tool name,
  • the arguments / parameters generated by the model,
  • the result returned by the MCP server.

Tool parameters

This is useful both for normal verification and troubleshooting.

For example, if the answer contains an unexpected resource, expand the tool call and verify whether the model generated the expected filter or object identifier.

Inspect the tool call when an answer looks suspicious

A model can choose the correct tool but still generate incorrect parameters. The tool block helps distinguish an LLM interpretation problem from an MCP server or API problem.

Combining Maat and EventListener

Maat and EventListener complement each other:

  • Maat represents the current state of inventory objects and services.
  • EventListener provides information about changes and historical events.

This makes it possible to ask questions that require both systems, for example:

"Show the current state of resource router-1 and its recent change history."

The model can first call a Maat MCP tool to retrieve the current object and then use an EventListener MCP tool to find events related to the same object.

Another example:

"Was this resource modified recently, and what does its current configuration look like?"

A tool-capable model can combine multiple MCP calls and use their results in one final response.

Quick checklist before you ask

Before trusting an answer about live Maat data, verify:

  • Authentication: you are logged in to LibreChat successfully.
  • Model: the selected model supports tool / function calling.
  • MCP: the required MCP server is available to the conversation or Agent.
  • Agent: if using an Agent, the expected tools are assigned to it.
  • Tool execution: for live-data questions, confirm that the expected MCP tool was actually called.
  • Parameters: if the answer looks wrong, inspect the tool arguments.

Troubleshooting

Symptom What it usually means What to check
The assistant answers without using a tool The model did not decide to call MCP, cannot call tools, or the tool is not available Check model capabilities, MCP availability and Agent configuration.
The selected model works for chat but not for Maat queries The model may not support tool calling correctly Select a model known to support function/tool calling.
MCP server is unavailable LibreChat cannot establish or restore the MCP connection Check the MCP server process, URL, authentication and LibreChat configuration.
Tool is visible in LibreChat but not available to the Agent The tool has not been assigned to that Agent Edit the Agent and verify its MCP tool configuration.
The answer contains incorrect data The model may have called the correct tool with incorrect parameters Expand the tool block and inspect the arguments and returned result.
Maat data is returned but EventListener history is missing Only the Maat tool may have been called Verify that EventListener MCP is available and ask explicitly for change history.
A user cannot access an Agent Agent sharing or role permissions may be incomplete Check Agent sharing and the user's LibreChat / Keycloak permissions.

Tips for good results

  • Ask in plain language. Users do not need to know MCP tool names or REST API parameters.
  • Be explicit when live data matters. If necessary, ask the assistant to use the available Maat tools instead of relying on general knowledge.
  • Use object names or identifiers when available. This reduces ambiguity and helps the model build more precise tool calls.

Deployment and configuration

This section focuses on the practical configuration required to run LibreChat as part of the Maat environment and connect it to Keycloak, the selected LLM backend, and the Maat MCP and EventListener MCP servers.

The recommended configuration order is:

  1. configure the LibreChat client, roles and groups in Keycloak,
  2. configure LibreChat runtime and OpenID settings in .env,
  3. apply local Docker settings in docker-compose.override.yml,
  4. configure the LLM endpoint and MCP servers in librechat.yaml,
  5. start LibreChat and verify the complete authentication and MCP flow.

For the LibreChat deployment itself, three files are especially important:

File Purpose
.env / Maat environment overlay Runtime settings, secrets, LLM API keys and OpenID / Keycloak configuration.
librechat.yaml LibreChat-specific configuration, including custom LLM endpoints and the Maat / EventListener MCP servers.
docker-compose.override.yml Local Docker Compose customizations layered on top of the upstream LibreChat stack, for example mounting librechat.yaml, disabling unused services and adjusting networking.

Keeping local changes in these files makes it easier to update the upstream LibreChat deployment without modifying the base docker-compose.yml.

Example configuration repository

A repository containing the files and helper scripts required to integrate MaatAI with LibreChat is available here:

Maat LibreChat integration repository

The helper script can be used to:

  1. download the LibreChat repository,
  2. copy the LibreChat configuration files prepared specifically for integration with the Maat environment,
  3. display a set of recommended next steps that should be completed after the script finishes.

The copied files should still be reviewed and adjusted before starting the deployment, especially URLs, credentials, Keycloak settings and LLM endpoints.

What is required

Before configuring LibreChat for Maat, make sure the following components are available:

  • a working Docker / Docker Compose environment,
  • a LibreChat deployment,
  • an LLM provider or LLM gateway reachable from LibreChat,
  • access to the Keycloak realm used by Maat,
  • a reachable Maat MCP Server,
  • a reachable EventListener MCP Server,
  • connectivity from the MCP servers to the corresponding Maat and EventListener APIs.

Keycloak configuration — client, roles and groups

Before configuring LibreChat itself, create a dedicated OpenID Connect client for it in Keycloak. In the Maat environment the client can be named:

maat-librechat

Using a dedicated client makes it possible to authenticate LibreChat users with Keycloak, synchronize their LibreChat role from the access token, and forward the authenticated user's token to the MCP servers.

Create the LibreChat client

Create a new client in the same Keycloak realm that is used by the Maat environment.

Recommended client settings are:

Setting Value
Client type / protocol OpenID Connect
Client ID maat-librechat
Client authentication Enabled
Standard flow Enabled
Direct access grants Not required for the LibreChat browser login flow
Valid redirect URI https://<librechat-host>/oauth/openid/callback
Web origins https://<librechat-host>

Keycloak client configuration Keycloak client configuration2

For local testing, replace the public LibreChat URL with the address actually used by the browser, for example:

http://localhost:3080/oauth/openid/callback

After creating the client, copy its client secret. It will later be used as OPENID_CLIENT_SECRET in the LibreChat .env file.

The redirect URI must match LibreChat

The redirect URI configured in Keycloak must correspond to the LibreChat address and to OPENID_CALLBACK_URL. If these values do not match, Keycloak will reject the login callback.

Create client roles

Roles used by LibreChat should be created as client roles of maat-librechat, because the LibreChat role synchronization configuration reads them from:

resource_access.maat-librechat.roles

For the Maat deployment, configure the roles used by your LibreChat instance, for example:

Keycloak client role LibreChat purpose
ADMIN Administrative LibreChat access.
USER Standard LibreChat access.

Roles in client

The role names are case-sensitive and must match the values configured later in the LibreChat environment variables.

Additional client roles can be created and synchronized if required. For a new LibreChat instance, however, it is recommended to use only the standard ADMIN and USER roles during the initial integration. Custom roles should be introduced only after the corresponding role has been created and properly configured in LibreChat; otherwise, synchronization from Keycloak may not work as expected.

Create groups and map roles to them

Instead of assigning client roles directly to every user, it is recommended to create Keycloak groups and assign the LibreChat client roles to those groups.

A simple structure can be:

LibreChat
├── Admins
└── Users

Map the maat-librechat client roles to the groups as follows:

Group Client role
LibreChat / Admins ADMIN
LibreChat / Users USER

Groups in Keycloak

In Keycloak, open the group and add the appropriate role under its Role mapping configuration. Make sure that the selected role comes from the maat-librechat client rather than from realm roles.

Use groups instead of per-user role mappings

With group-based role assignment, access can be managed simply by adding or removing users from a group. The LibreChat role inherited by the user then changes without modifying the user's individual role mappings.

Assign users to groups

Add each LibreChat user to the appropriate Keycloak group.

For example:

  • normal users → LibreChat / Users,
  • LibreChat administrators → LibreChat / Admins.

Assign users to groups in Keycloak

A user should normally receive the role that represents the intended LibreChat permission level. If multiple LibreChat roles are present in the token, the role-priority configuration in .env determines which synchronized role is used.

Verify the roles in the access token

After the user signs in, the Keycloak access token should contain the maat-librechat client roles under resource_access, for example:

{
  "resource_access": {
    "maat-librechat": {
      "roles": [
        "USER"
      ]
    }
  }
}

This structure is important because the LibreChat configuration later uses:

OPENID_ADMIN_ROLE_PARAMETER_PATH=resource_access.maat-librechat.roles
OPENID_ROLE_SYNC_CLAIM=resource_access.maat-librechat.roles

If the maat-librechat entry or its roles array is missing from the access token, check the user's group membership, client-role mapping and the Keycloak client scopes / role mappers before continuing with the LibreChat configuration.

Environment configuration — .env

The .env file contains runtime settings and secrets used by LibreChat. In the Maat deployment, Maat-specific values can be maintained as an environment overlay based on a template such as .env.maat.template, while real secrets are kept outside version control.

The most important groups of settings are shown below.

LibreChat address and proxy settings

DOMAIN_CLIENT=http://localhost:3080
DOMAIN_SERVER=http://localhost:3080
TRUST_PROXY=1

HTTP and secure cookies

When DOMAIN_SERVER points to a non-localhost address while LibreChat is accessed over plain HTTP, secure-cookie behavior can prevent the login flow from working correctly. Use HTTPS for non-local deployments.

Keycloak as the login method

The Maat deployment disables local e-mail login and registration and uses OpenID Connect instead:

ALLOW_EMAIL_LOGIN=false
ALLOW_REGISTRATION=false
ALLOW_SOCIAL_LOGIN=true

The Keycloak / OpenID configuration can then be defined as:

OPENID_CLIENT_ID=maat-librechat
OPENID_CLIENT_SECRET=<client-secret>
OPENID_ISSUER=https://<keycloak-host>:8443/realms/MaatRealm
OPENID_SESSION_SECRET=<session-secret>
OPENID_SCOPE="openid profile email"
OPENID_CALLBACK_URL=/oauth/openid/callback
OPENID_BUTTON_LABEL="Login via Keycloak"
OPENID_USE_END_SESSION_ENDPOINT=true

The client secret and session secret should not be committed to the repository. A random secret can for example be generated with:

openssl rand -hex 32

Retaining the Keycloak token for MCP

The following option is especially important for the Maat integration:

OPENID_REUSE_TOKENS=true

LibreChat must retain the user's OpenID access token so that it can later be forwarded to the MCP server through the Authorization header. Without this setting, the token placeholder used in librechat.yaml can resolve to an empty value.

The authentication flow is therefore:

Token flow

Keycloak role mapping

LibreChat roles can also be synchronized from the Keycloak access token. In the Maat deployment, the roles are read from the maat-librechat client:

OPENID_ADMIN_ROLE=ADMIN
OPENID_ADMIN_ROLE_PARAMETER_PATH=resource_access.maat-librechat.roles
OPENID_ADMIN_ROLE_TOKEN_KIND=access

OPENID_ROLE_SYNC_ENABLED=true
OPENID_ROLE_SYNC_SOURCE=access
OPENID_ROLE_SYNC_CLAIM=resource_access.maat-librechat.roles
OPENID_ROLE_SYNC_ROLE_PRIORITY=USER
OPENID_ROLE_SYNC_FALLBACK_ROLE=USER

LLM API keys

API keys referenced by custom endpoints in librechat.yaml should be stored in the environment file rather than directly in the YAML configuration.

For example:

OPENWEBUI_API_KEY=<api-key>

Only the variables required by the configured endpoints need to be populated.

LibreChat application secrets

LibreChat application secrets

LibreChat requires several cryptographic secrets used to protect credentials, user sessions and the Admin Panel.

Variable Purpose
CREDS_KEY Encryption key used to protect supported credentials stored by LibreChat.
CREDS_IV Initialization vector used together with CREDS_KEY when encrypting stored credentials.
JWT_SECRET Secret used for LibreChat access / session tokens.
JWT_REFRESH_SECRET Separate secret used for refresh tokens.
ADMIN_PANEL_SESSION_SECRET Secret used to protect sessions in the LibreChat Admin Panel.

Generate unique random values before starting the production deployment.

For example, using OpenSSL:

openssl rand -hex 32   # CREDS_KEY
openssl rand -hex 16   # CREDS_IV
openssl rand -hex 32   # JWT_SECRET
openssl rand -hex 32   # JWT_REFRESH_SECRET
openssl rand -hex 32   # ADMIN_PANEL_SESSION_SECRET

docker-compose.override.yml — local deployment customizations

The override file is used to keep deployment-specific changes separate from the upstream LibreChat docker-compose.yml.

A Maat deployment can for example use:

# Local customizations layered on top of docker-compose.yml.
# Docker Compose merges this automatically; keeps the base file upgrade-safe.
services:
  api:
    environment:
      - NODE_TLS_REJECT_UNAUTHORIZED=0
    volumes:
      - type: bind
        source: ./librechat.yaml
        target: /app/librechat.yaml
    depends_on: !override
      - mongodb

  rag_api:
    profiles: ['rag']

  vectordb:
    profiles: ['rag']

networks:
  default:
    ipam:
      config:
        - subnet: 172.28.0.0/24

This override performs several useful tasks.

Mounting librechat.yaml

volumes:
  - type: bind
    source: ./librechat.yaml
    target: /app/librechat.yaml

This makes the local librechat.yaml available to the LibreChat API container. Configuration changes can therefore be maintained outside the container image.

Self-signed certificates

environment:
  - NODE_TLS_REJECT_UNAUTHORIZED=0

This can be required when an internal LLM backend uses a self-signed TLS certificate.

Warning

NODE_TLS_REJECT_UNAUTHORIZED=0 disables TLS certificate verification for Node.js connections in the container. Use it only when it is required by the environment. For a production deployment, installing the trusted internal CA certificate is preferable.

Disabling unused RAG services

If file upload / embedding functionality is not used, rag_api and vectordb can be moved behind a non-default Compose profile:

rag_api:
  profiles: ['rag']

vectordb:
  profiles: ['rag']

This prevents the RAG services from starting during a normal:

docker compose up -d

They can still be started explicitly with:

docker compose --profile rag up -d

The API dependency list is also overridden so that the disabled rag_api service is not retained through Docker Compose dependency merging:

depends_on: !override
  - mongodb

Docker network

The default Docker subnet should not overlap with networks used to reach Maat or other infrastructure systems.

For example:

networks:
  default:
    ipam:
      config:
        - subnet: 172.28.0.0/24

In the Maat environment this avoids using Docker's 172.19.0.0/16 range when the same address space is already used by the host, LAN or WSL interfaces.

librechat.yaml — LibreChat integration configuration

The librechat.yaml file contains the configuration that connects LibreChat to the selected LLM backend and to the Maat MCP services.

For the Maat integration, the two most important parts are:

  1. the LLM endpoint,
  2. the Maat MCP and EventListener MCP servers.

LLM endpoint

LibreChat can connect directly to an LLM provider or to an LLM gateway such as LiteLLM.

A simplified configuration can look like:

endpoints:
  custom:
    - name: 'OpenWebUI'
      apiKey: '${OPENWEBUI_API_KEY}'
      baseURL: 'http://<openwebui-host>:4000/api/v1'
      models:
        default: ['GLM-5.1', 'GLM-5.2', 'Qwen3.5-397B-A17B']
        fetch: true
      modelDisplayLabel: 'Open WebUI (Maat)'

The API key is referenced from .env, which keeps the secret outside librechat.yaml.

Note

Endpoint names, URLs, model IDs and credentials depend on the deployment. The selected model should support tool / function calling if it is expected to use Maat MCP tools.

MCP server configuration

The Maat environment uses two primary MCP servers:

MCP server Purpose
Maat MCP Access to the current Maat inventory, resources and services.
EventListener MCP Access to events and historical changes related to Maat objects.

Both servers can be configured in librechat.yaml using the streamable-http transport.

A practical configuration can look like:

mcpServers:
  maat-mcp:
    type: streamable-http
    url: http://<maat-mcp-host>:<port>/mcp
    headers:
      Authorization: "Bearer {{LIBRECHAT_OPENID_TOKEN}}"
    serverInstructions: |
      Use this MCP server for queries about the current state of Maat.
      Use its tools when the user asks about Maat resources, services,
      relationships or other current inventory information.

  eventlistener-mcp:
    type: streamable-http
    url: http://<eventlistener-mcp-host>:<port>/mcp
    headers:
      Authorization: "Bearer {{LIBRECHAT_OPENID_TOKEN}}"
    serverInstructions: |
      Use this MCP server for queries about historical changes and events
      related to Maat objects. Use it when the user asks what changed,
      when an object was modified or for the history of a resource or service.

Passing the Keycloak token to MCP

The Authorization header forwards the token associated with the user who authenticated to LibreChat through Keycloak:

headers:
  Authorization: "Bearer {{LIBRECHAT_OPENID_TOKEN}}"

Together with:

OPENID_REUSE_TOKENS=true

this allows LibreChat to pass the authenticated user's token to the MCP server instead of using one shared static token for every request.

Do not hard-code a user access token

The token passed to MCP should come from the authenticated LibreChat session. A static user token should not be stored directly in librechat.yaml or .env.

serverInstructions

serverInstructions provides high-level guidance describing how the model should use a particular MCP server.

For Maat, the instruction should make it clear that the server represents the current state of the inventory. For EventListener, it should indicate that the server is intended for events and historical changes.

This helps the model choose between the two servers when both are available in the same conversation or Agent.

The instructions should remain short and describe the responsibility of the server rather than individual tool parameters. Detailed tool behavior should still be described by the tools exposed by the MCP server itself.

Agents

After authentication, model access and MCP connectivity are working, an administrator can create a prepared Maat Agent in LibreChat.

The Agent can package together:

  • the recommended LLM model,
  • predefined system instructions,
  • the Maat MCP tools,
  • the EventListener MCP tools.

The configured Agent can then be shared with users, providing a common Maat assistant without requiring every user to select the model and MCP tools manually.

Applying and verifying the configuration

After changing .env, docker-compose.override.yml or librechat.yaml, recreate the LibreChat services:

docker compose up -d --force-recreate

Then verify the integration in the following order:

  1. Open LibreChat and authenticate through Keycloak.
  2. Confirm that the configured LLM model is available.
  3. Confirm that Maat MCP and EventListener MCP are available.
  4. Start a conversation or open the prepared Maat Agent.
  5. Ask a question that requires current Maat data, for example:

"Show me information about resource router-1."

  1. Verify that LibreChat performs an Maat MCP tool call.
  2. Ask for historical information about the same object and verify that EventListener MCP is used.
  3. If authorization is enabled behind MCP, verify that the request contains the Keycloak bearer token of the currently logged-in user.

If the model is available but no MCP calls are made, first check the model's tool-calling capability, MCP connectivity and the MCP configuration in librechat.yaml.