Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

launch_mcp_server.md 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. ---
  2. sidebar_position: 1
  3. slug: /launch_mcp_server
  4. ---
  5. # Launch RAGFlow MCP server
  6. Launch an MCP server from source or via Docker.
  7. ---
  8. A RAGFlow Model Context Protocol (MCP) server is designed as an independent component to complement the RAGFlow server. Note that an MCP server must operate alongside a properly functioning RAGFlow server.
  9. An MCP server can start up in either self-host mode (default) or host mode:
  10. - **Self-host mode**:
  11. When launching an MCP server in self-host mode, you must provide an API key to authenticate the MCP server with the RAGFlow server. In this mode, the MCP server can access *only* the datasets (knowledge bases) of a specified tenant on the RAGFlow server.
  12. - **Host mode**:
  13. In host mode, each MCP client can access their own knowledge bases on the RAGFlow server. However, each client request must include a valid API key to authenticate the client with the RAGFlow server.
  14. Once a connection is established, an MCP server communicates with its client in MCP HTTP+SSE (Server-Sent Events) mode, unidirectionally pushing responses from the RAGFlow server to its client in real time.
  15. ## Prerequisites
  16. 1. Ensure RAGFlow is upgraded to v0.18.0 or later.
  17. 2. Have your RAGFlow API key ready. See [Acquire a RAGFlow API key](../acquire_ragflow_api_key.md).
  18. :::tip INFO
  19. If you wish to try out our MCP server without upgrading RAGFlow, community contributor [yiminghub2024](https://github.com/yiminghub2024) 👏 shares their recommended steps [here](#launch-an-mcp-server-without-upgrading-ragflow).
  20. :::
  21. ## Launch an MCP server
  22. You can start an MCP server either from source code or via Docker.
  23. ### Launch from source code
  24. 1. Ensure that a RAGFlow server v0.18.0+ is properly running.
  25. 2. Launch the MCP server:
  26. ```bash
  27. # Launch the MCP server to work in self-host mode, run either of the following
  28. uv run mcp/server/server.py --host=127.0.0.1 --port=9382 --base-url=http://127.0.0.1:9380 --api-key=ragflow-xxxxx
  29. # uv run mcp/server/server.py --host=127.0.0.1 --port=9382 --base-url=http://127.0.0.1:9380 --mode=self-host --api-key=ragflow-xxxxx
  30. # To launch the MCP server to work in host mode, run the following instead:
  31. # uv run mcp/server/server.py --host=127.0.0.1 --port=9382 --base-url=http://127.0.0.1:9380 --mode=host
  32. ```
  33. Where:
  34. - `host`: The MCP server's host address.
  35. - `port`: The MCP server's listening port.
  36. - `base_url`: The address of the running RAGFlow server.
  37. - `mode`: The launch mode.
  38. - `self-host`: (default) self-host mode.
  39. - `host`: host mode.
  40. - `api_key`: Required in self-host mode to authenticate the MCP server with the RAGFlow server. See [here](../acquire_ragflow_api_key.md) for instructions on acquiring an API key.
  41. ### Transports
  42. The RAGFlow MCP server supports two transports: the legacy SSE transport (served at `/sse`), introduced on November 5, 2024 and deprecated on March 26, 2025, and the streamable-HTTP transport (served at `/mcp`). The legacy SSE transport and the streamable HTTP transport with JSON responses are enabled by default. To disable either transport, use the flags `--no-transport-sse-enabled` or `--no-transport-streamable-http-enabled`. To disable JSON responses for the streamable HTTP transport, use the `--no-json-response` flag.
  43. ### Launch from Docker
  44. #### 1. Enable MCP server
  45. The MCP server is designed as an optional component that complements the RAGFlow server and disabled by default. To enable MCP server:
  46. 1. Navigate to **docker/docker-compose.yml**.
  47. 2. Uncomment the `services.ragflow.command` section as shown below:
  48. ```yaml {6-13}
  49. services:
  50. ragflow:
  51. ...
  52. image: ${RAGFLOW_IMAGE}
  53. # Example configuration to set up an MCP server:
  54. command:
  55. - --enable-mcpserver
  56. - --mcp-host=0.0.0.0
  57. - --mcp-port=9382
  58. - --mcp-base-url=http://127.0.0.1:9380
  59. - --mcp-script-path=/ragflow/mcp/server/server.py
  60. - --mcp-mode=self-host
  61. - --mcp-host-api-key=ragflow-xxxxxxx
  62. # Optional transport flags for the RAGFlow MCP server.
  63. # If you set `mcp-mode` to `host`, you must add the --no-transport-streamable-http-enabled flag, because the streamable-HTTP transport is not yet supported in host mode.
  64. # The legacy SSE transport and the streamable-HTTP transport with JSON responses are enabled by default.
  65. # To disable a specific transport or JSON responses for the streamable-HTTP transport, use the corresponding flag(s):
  66. # - --no-transport-sse-enabled # Disables the legacy SSE endpoint (/sse)
  67. # - --no-transport-streamable-http-enabled # Disables the streamable-HTTP transport (served at the /mcp endpoint)
  68. # - --no-json-response # Disables JSON responses for the streamable-HTTP transport
  69. ```
  70. Where:
  71. - `mcp-host`: The MCP server's host address.
  72. - `mcp-port`: The MCP server's listening port.
  73. - `mcp-base_url`: The address of the running RAGFlow server.
  74. - `mcp-script-path`: The file path to the MCP server’s main script.
  75. - `mcp-mode`: The launch mode.
  76. - `self-host`: (default) self-host mode.
  77. - `host`: host mode.
  78. - `mcp-host-api_key`: Required in self-host mode to authenticate the MCP server with the RAGFlow server. See [here](../acquire_ragflow_api_key.md) for instructions on acquiring an API key.
  79. :::tip INFO
  80. If you set `mcp-mode` to `host`, you must add the `--no-transport-streamable-http-enabled` flag, because the streamable-HTTP transport is not yet supported in host mode.
  81. :::
  82. #### 2. Launch a RAGFlow server with an MCP server
  83. Run `docker compose -f docker-compose.yml up` to launch the RAGFlow server together with the MCP server.
  84. *The following ASCII art confirms a successful launch:*
  85. ```bash
  86. ragflow-server | Starting MCP Server on 0.0.0.0:9382 with base URL http://127.0.0.1:9380...
  87. ragflow-server | Starting 1 task executor(s) on host 'dd0b5e07e76f'...
  88. ragflow-server | 2025-04-18 15:41:18,816 INFO 27 ragflow_server log path: /ragflow/logs/ragflow_server.log, log levels: {'peewee': 'WARNING', 'pdfminer': 'WARNING', 'root': 'INFO'}
  89. ragflow-server |
  90. ragflow-server | __ __ ____ ____ ____ _____ ______ _______ ____
  91. ragflow-server | | \/ |/ ___| _ \ / ___|| ____| _ \ \ / / ____| _ \
  92. ragflow-server | | |\/| | | | |_) | \___ \| _| | |_) \ \ / /| _| | |_) |
  93. ragflow-server | | | | | |___| __/ ___) | |___| _ < \ V / | |___| _ <
  94. ragflow-server | |_| |_|\____|_| |____/|_____|_| \_\ \_/ |_____|_| \_\
  95. ragflow-server |
  96. ragflow-server | MCP launch mode: self-host
  97. ragflow-server | MCP host: 0.0.0.0
  98. ragflow-server | MCP port: 9382
  99. ragflow-server | MCP base_url: http://127.0.0.1:9380
  100. ragflow-server | INFO: Started server process [26]
  101. ragflow-server | INFO: Waiting for application startup.
  102. ragflow-server | INFO: Application startup complete.
  103. ragflow-server | INFO: Uvicorn running on http://0.0.0.0:9382 (Press CTRL+C to quit)
  104. ragflow-server | 2025-04-18 15:41:20,469 INFO 27 found 0 gpus
  105. ragflow-server | 2025-04-18 15:41:23,263 INFO 27 init database on cluster mode successfully
  106. ragflow-server | 2025-04-18 15:41:25,318 INFO 27 load_model /ragflow/rag/res/deepdoc/det.onnx uses CPU
  107. ragflow-server | 2025-04-18 15:41:25,367 INFO 27 load_model /ragflow/rag/res/deepdoc/rec.onnx uses CPU
  108. ragflow-server | ____ ___ ______ ______ __
  109. ragflow-server | / __ \ / | / ____// ____// /____ _ __
  110. ragflow-server | / /_/ // /| | / / __ / /_ / // __ \| | /| / /
  111. ragflow-server | / _, _// ___ |/ /_/ // __/ / // /_/ /| |/ |/ /
  112. ragflow-server | /_/ |_|/_/ |_|\____//_/ /_/ \____/ |__/|__/
  113. ragflow-server |
  114. ragflow-server |
  115. ragflow-server | 2025-04-18 15:41:29,088 INFO 27 RAGFlow version: v0.18.0-285-gb2c299fa full
  116. ragflow-server | 2025-04-18 15:41:29,088 INFO 27 project base: /ragflow
  117. ragflow-server | 2025-04-18 15:41:29,088 INFO 27 Current configs, from /ragflow/conf/service_conf.yaml:
  118. ragflow-server | ragflow: {'host': '0.0.0.0', 'http_port': 9380}
  119. ...
  120. ragflow-server | * Running on all addresses (0.0.0.0)
  121. ragflow-server | * Running on http://127.0.0.1:9380
  122. ragflow-server | * Running on http://172.19.0.6:9380
  123. ragflow-server | ______ __ ______ __
  124. ragflow-server | /_ __/___ ______/ /__ / ____/ _____ _______ __/ /_____ _____
  125. ragflow-server | / / / __ `/ ___/ //_/ / __/ | |/_/ _ \/ ___/ / / / __/ __ \/ ___/
  126. ragflow-server | / / / /_/ (__ ) ,< / /____> </ __/ /__/ /_/ / /_/ /_/ / /
  127. ragflow-server | /_/ \__,_/____/_/|_| /_____/_/|_|\___/\___/\__,_/\__/\____/_/
  128. ragflow-server |
  129. ragflow-server | 2025-04-18 15:41:34,501 INFO 32 TaskExecutor: RAGFlow version: v0.18.0-285-gb2c299fa full
  130. ragflow-server | 2025-04-18 15:41:34,501 INFO 32 Use Elasticsearch http://es01:9200 as the doc engine.
  131. ...
  132. ```
  133. #### Launch an MCP server without upgrading RAGFlow
  134. :::info KUDOS
  135. This section is contributed by our community contributor [yiminghub2024](https://github.com/yiminghub2024). 👏
  136. :::
  137. 1. Prepare all MCP-specific files and directories.
  138. i. Copy the [mcp/](https://github.com/infiniflow/ragflow/tree/main/mcp) directory to your local working directory.
  139. ii. Copy [docker/docker-compose.yml](https://github.com/infiniflow/ragflow/blob/main/docker/docker-compose.yml) locally.
  140. iii. Copy [docker/entrypoint.sh](https://github.com/infiniflow/ragflow/blob/main/docker/entrypoint.sh) locally.
  141. iv. Install the required dependencies using `uv`:
  142. - Run `uv add mcp` or
  143. - Copy [pyproject.toml](https://github.com/infiniflow/ragflow/blob/main/pyproject.toml) locally and run `uv sync --python 3.10 --all-extras`.
  144. 2. Edit **docker-compose.yml** to enable MCP (disabled by default).
  145. 3. Launch the MCP server:
  146. ```bash
  147. docker compose -f docker-compose.yml up -d
  148. ```
  149. ### Check MCP server status
  150. Run the following to check the logs the RAGFlow server and the MCP server:
  151. ```bash
  152. docker logs ragflow-server
  153. ```
  154. ## Security considerations
  155. As MCP technology is still at early stage and no official best practices for authentication or authorization have been established, RAGFlow currently uses [API key](./acquire_ragflow_api_key.md) to validate identity for the operations described earlier. However, in public environments, this makeshift solution could expose your MCP server to potential network attacks. Therefore, when running a local SSE server, it is recommended to bind only to localhost (`127.0.0.1`) rather than to all interfaces (`0.0.0.0`).
  156. For further guidance, see the [official MCP documentation](https://modelcontextprotocol.io/docs/concepts/transports#security-considerations).
  157. ## Frequently asked questions
  158. ### When to use an API key for authentication?
  159. The use of an API key depends on the operating mode of your MCP server.
  160. - **Self-host mode** (default):
  161. When starting the MCP server in self-host mode, you should provide an API key when launching it to authenticate it with the RAGFlow server:
  162. - If launching from source, include the API key in the command.
  163. - If launching from Docker, update the API key in **docker/docker-compose.yml**.
  164. - **Host mode**:
  165. If your RAGFlow MCP server is working in host mode, include the API key in the `headers` of your client requests to authenticate your client with the RAGFlow server. An example is available [here](https://github.com/infiniflow/ragflow/blob/main/mcp/client/client.py).