Searching Fess from AI Agents with MCP

Introduction

When you want an AI agent such as Claude Code to look things up in your internal documents, letting the agent call Fess search directly means it can use the indexed documents as its evidence. The mechanism for this is MCP (Model Context Protocol). In Fess, installing the fess-webapp-mcp plugin adds an MCP server endpoint at /mcp.

This article explains how to install the plugin on Fess 15.9, require authentication, connect from an AI agent, and verify that everything works.

When you have finished the steps in this article, you will have the following:

  • You can confirm with curl that /mcp is working

  • Calls without an access token are rejected

  • The range of documents the agent can search is determined by the token’s permissions

  • Claude Code can call the Fess search tool

Note

The direction of the calls is the opposite of the AI search mode in Answers from Internal documents with AI Search (RAG). In AI search mode, Fess calls an LLM (Ollama, OpenAI, etc.) to generate answers. Ollama is a runtime for that LLM, not an MCP client. With MCP, an external AI agent calls Fess as a search tool, and the answer is generated by the LLM on the agent’s side.

What /mcp Provides

/mcp accepts only POST and returns one JSON response per request (it keeps no sessions). Searches go through the same processing as the search page, so role-based filtering of search results applies as is.

The 15.9.0 plugin exposes the following. All of them are read-only; none of them modifies Fess data.

Name Description Availability
search (tool) Full-text search. Each result includes a doc_id Always available
suggest (tool) Suggestion candidates for a partially typed term Always available
get_document (tool) Retrieves the body of one document by doc_id Always available
get_index_stats (tool) Index name, document count, and JVM memory usage Not available by default (see below)
fess://document/{doc_id} (resource) Performs the same retrieval as get_document, as a resource Always available
fess://index/stats (resource) Same content as get_index_stats Same as get_index_stats
basic_search / advanced_search (prompt) Prompt templates for searching. advanced_search also accepts sort and num Always available

If you omit num in search, only 3 results are returned (the default of mcp.default.page.size). Both the excerpts from search and the body from get_document are truncated to at most 10000 characters, and get_document sets truncated to true (mcp.content.max.length).

Installing the Plugin

Match the plugin version to the Fess minor version. For Fess 15.9, use fess-webapp-mcp 15.9.x. Install it with one of the following methods, and restart Fess afterwards.

  • Admin console: under [System] > [Plugin], click [Install], select fess-webapp-mcp on the [Remote] tab, and install it

  • Command line: bin/fess-setup install plugin fess-webapp-mcp:15.9.0

  • Docker: add FESS_PLUGINS to the environment of fess01 in compose.yaml. The Docker image does not include this plugin

environment:
  - "FESS_PLUGINS=fess-webapp-mcp:15.9.0"

In the Docker version, if the name or version is wrong, that plugin is skipped and the container starts anyway. After adding it, check the startup log to confirm that the plugin was downloaded.

Warning

When upgrading Fess, replace this plugin with the new version before starting Fess. If an old version of the plugin jar (e.g. the one for 15.8) remains in WEB-INF/plugin, Fess 15.9 fails to initialize at startup, and not only /mcp but every page and API returns 404. On the command line, you can replace it with bin/fess-setup upgrade plugins.

After the restart, if the following WARN appears in the log file fess.log, the endpoint is enabled.

[MCP] mcp.auth.mode=none - every /mcp caller is treated as anonymous. Set mcp.auth.mode=fess_token, ...

This message indicates that the endpoint is running without authentication, as described in the next section.

Verifying Without Authentication First

Warning

Right after installation, /mcp runs without authentication (mcp.auth.mode=none). Anyone who can reach /mcp can search with the same privileges as a user who is not logged in (a guest), and can even retrieve document bodies with get_document. Every document from crawl configurations whose permissions are left at the default {role}guest is exposed. Limit testing in this state to your local environment, and require authentication as described in the next section. If “Login Required” is enabled under [System] > [General], /mcp in this state rejects every call with HTTP 403. In that case, go on to the next section.

Assuming Fess is running at http://localhost:8080, call server/discover.

$ curl -sS -X POST http://localhost:8080/mcp \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json, text/event-stream' \
    -H 'MCP-Protocol-Version: 2026-07-28' \
    -H 'Mcp-Method: server/discover' \
    -d '{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}'

The call succeeded if result.supportedVersions in the response contains 2026-07-28 and result.capabilities contains tools and so on.

Next, call the search tool. Set q to a word that appears in your crawled documents.

$ curl -sS -X POST http://localhost:8080/mcp \
    -H 'Content-Type: application/json' \
    -H 'MCP-Protocol-Version: 2026-07-28' \
    -H 'Mcp-Method: tools/call' \
    -H 'Mcp-Name: search' \
    -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"search","arguments":{"q":"Fess","num":5},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}'

The search results are in result.structuredContent.hits, and the hit count is in total. The header values must match the request body. MCP-Protocol-Version must equal the version in params._meta, Mcp-Method must equal method, and Mcp-Name must equal the tool name. If they differ, the result is HTTP 400 (error code -32020).

Requiring Authentication

Switch to fess_token mode, which authenticates with Fess access tokens. There is also an oauth mode, which authenticates with JWTs issued by an external authorization server. For its configuration, see “OAuth 2.1 reference” in the README.

Creating an Access Token

  1. In the admin console, open [System] > [Access Token] and click [Create New]

  2. In “Name”, enter a name that shows its purpose, such as mcp-agent

  3. In “Permissions”, enter the roles of the documents the agent may see, one per line. If documents for guests are enough, enter {role}guest (how to choose is explained in “Token Permissions and Search Results”)

  4. Specify “Expires” if needed, and click [Create]

  5. In the list, click the name of the token you created; the value is shown in “Token” on the details page

Setting mcp.auth.mode

All mcp.* settings are read from the Fess system properties (system.properties). Writing them in fess_config.properties or as -Dfess.config.* has no effect, and no error or log message is produced.

For the ZIP version, add the following line to app/WEB-INF/conf/system.properties; for the RPM/DEB versions, add it to /etc/fess/system.properties.

mcp.auth.mode=fess_token

The value is reloaded at runtime, so it takes effect within a few seconds; no restart is needed.

The fess01 container of the Docker version has no volume, so settings written to files inside the container are lost when the container is recreated. Specify the setting in FESS_JAVA_OPTS in compose.yaml with the -Dfess.system. prefix (not fess.config.).

environment:
  - "FESS_PLUGINS=fess-webapp-mcp:15.9.0"
  - "FESS_JAVA_OPTS=-Dfess.system.mcp.auth.mode=fess_token"

FESS_PLUGINS and FESS_JAVA_OPTS take effect when the container is recreated. After editing compose.yaml, run the following command.

$ docker compose -f compose.yaml -f compose-opensearch3.yaml up -d

If the same key exists in system.properties, that value takes precedence.

Confirming That Authentication Is Enforced

Run the server/discover call from the previous section again, unchanged. Because no token is attached, HTTP 401 is returned along with a WWW-Authenticate: Bearer realm="fess-mcp" header (use curl -i to show headers). In fess_token mode, server/discover also requires authentication.

Next, run the search curl command from the previous section with -H 'Authorization: Bearer <token>' added. Replace <token> with the value shown on the details page. If search results are returned, the setup is complete. A token that does not exist or has expired results in HTTP 401.

Token Permissions and Search Results

In fess_token mode, the token’s permissions are used directly as the roles for the search. Not only search but also get_document is filtered with the same roles, so documents the token has no rights to cannot be retrieved even if you know their doc_id.

Token permissions Searchable documents
Empty Same as a guest (documents with {role}guest)
{role}guest Same as a guest
{role}sales Only documents with {role}sales. documents for guests are not included
{role}sales and {role}guest documents of both

The guest role is added automatically only for tokens with empty permissions. If you want the agent to search both departmental documents and documents for everyone, specify {role}guest as well. For how roles and permissions work, see Controlling Search Results with Roles and Groups.

To verify this, run search for the same word with two tokens that have different permissions, and compare total.

Warning

Do not give an agent’s token {role}admin-api. A token with {role}admin-api can call the entire Fess Admin API. Moreover, a search with a token that has only {role}admin-api returns 0 results, because no document has this role.

Enabling get_index_stats

get_index_stats and fess://index/stats are shown only to callers that have one of the permissions listed in mcp.tools.index_stats.permissions. The default is Radmin-api (the internal notation for {role}admin-api), and in none mode no caller has any permissions, so they are shown to nobody. Callers without the permission get the same error as for a nonexistent tool.

You do not need this tool for searching alone. If you use it, define a dedicated role instead of handing out {role}admin-api, and add that role to the token’s permissions. In system.properties, write it in the internal notation (R for {role}).

mcp.tools.index_stats.permissions=Rmcp-stats

In this example, add {role}mcp-stats to the token’s permissions.

Other Settings

All of these go in system.properties (for the Docker version, -Dfess.system.<key>). For boolean values, only true is treated as true; 1 and yes are treated as false.

Key Default Description
mcp.allowed.origins (empty) When calling from a browser, the allowed Origin values, comma-separated, in the form https://app.example.com. When empty, every request with an Origin header is rejected with HTTP 403. curl and CLI agents do not send Origin, so they are not affected
mcp.rate.limit.per.minute 60 Per-minute limit on tools/call and similar calls for each caller (the token, or the IP address if there is none). When exceeded, HTTP 429 and Retry-After are returned. 0 disables it
mcp.content.max.length 10000 Maximum number of characters of body text returned by search and get_document
mcp.default.page.size 3 Number of results when num is omitted in search
mcp.enabled true When set to false, /mcp returns HTTP 503 for everything
mcp.legacy.protocol.enabled true Also accepts older clients (2025-11-25 / 2025-06-18) that connect with initialize

Unlike mcp.*, the following two are settings in the Fess fess_config.properties (for the Docker version, -Dfess.config.<key>).

  • If calls go through a reverse proxy on another host, add the proxy’s IP address to rate.limit.trusted.proxies (default 127.0.0.1,::1). Otherwise, all callers coming through the proxy share the same limit

  • When calling from a browser on a different origin, in addition to mcp.allowed.origins, add MCP-Protocol-Version, Mcp-Method, and Mcp-Name to api.cors.allow.headers. For details, see “Browser clients” in the README

Connecting from AI Agents

Claude Code

Claude Code can connect directly with 2026-07-28. Register Fess as an HTTP MCP server with claude mcp add and pass the token with --header.

$ claude mcp add --transport http fess http://localhost:8080/mcp \
    --header "Authorization: Bearer <token>"

Running claude mcp list shows the registered fess and lets you check the connection status. When you ask Claude Code something like “Search Fess for the travel expense claim procedure”, the agent calls the search tool with arguments like the following, then calls get_document with the doc_id from the results to read the body.

{
  "name": "search",
  "arguments": {
    "q": "travel expense",
    "num": 5,
    "fields": { "label": ["manual"] }
  }
}

For label in fields, specify the value of a Fess label (omit it if you are not filtering by label). Other search arguments include start (paging), sort (e.g. last_modified.desc), and lang.

Other Clients

Clients that connect with the older protocol (initialize), such as OpenCode, Codex CLI, and Gemini CLI, also work as long as mcp.legacy.protocol.enabled is at its default of true. Clients that only speak 2025-03-26 or earlier cannot connect. Desktop clients that can only launch MCP servers over stdio go through mcp-remote, which relays between stdio and HTTP. Which clients can connect is summarized in “Client compatibility” in the README.

Beware of Sending Search Results Outside

If the LLM used by the agent is a cloud service, the excerpts from search and the bodies from get_document are sent to that service. To narrow what is sent, select only the documents that may be sent through the token’s permissions, and reduce mcp.content.max.length if needed.

Troubleshooting

Symptom Cause and solution
HTTP 400, error code -32020 MCP-Protocol-Version, Mcp-Method, or Mcp-Name is missing or does not match the request body
HTTP 401 In fess_token mode, the token is missing, does not exist, or has expired
HTTP 403 for every request The Origin header is not in mcp.allowed.origins. Or, in none mode, “Login Required” is enabled
The first call fails with -32601 mentioning initialize The client is an older one, and mcp.legacy.protocol.enabled is not true
search returns 0 results The token’s permissions do not include the documents’ roles. If partial in the result is true, the search did not complete (a timeout or an OpenSearch failure), so it does not necessarily mean there are no matches
Tool execution failed (error_code:...) The cause is recorded as a WARN in fess.log. Search the log for the error_code value

Further Reading

References