Browse Source

Feat: Enable MCP streamable-http model via docker compose (#9092)

### What problem does this PR solve?

Enable MCP streamable-http model via docker compose

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
tags/v0.20.0
Yongteng Lei 3 months ago
parent
commit
cfc339e4f3
No account linked to committer's email address
3 changed files with 30 additions and 5 deletions
  1. 7
    4
      docker/docker-compose.yml
  2. 19
    1
      docker/entrypoint.sh
  3. 4
    0
      mcp/server/server.py

+ 7
- 4
docker/docker-compose.yml View File


include: include:
- ./docker-compose-base.yml - ./docker-compose-base.yml

# To ensure that the container processes the locally modified `service_conf.yaml.template` instead of the one included in its image, you need to mount the local `service_conf.yaml.template` to the container. # To ensure that the container processes the locally modified `service_conf.yaml.template` instead of the one included in its image, you need to mount the local `service_conf.yaml.template` to the container.
services: services:
ragflow: ragflow:
# - --mcp-base-url=http://127.0.0.1:9380 # - --mcp-base-url=http://127.0.0.1:9380
# - --mcp-script-path=/ragflow/mcp/server/server.py # - --mcp-script-path=/ragflow/mcp/server/server.py
# - --mcp-mode=self-host # - --mcp-mode=self-host
# - --mcp-host-api-key=ragflow-xxxxxxx
# - --mcp-host-api-key=ragflow-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Optional transport flags for MCP (customize if needed).
# Host mode need to combined with --no-transport-streamable-http-enabled flag, namely, host+streamable-http is not supported yet.
# The following are enabled by default unless explicitly disabled with --no-<flag>.
# - --no-transport-sse-enabled # Disable legacy SSE endpoints (/sse and /messages/)
# - --no-transport-streamable-http-enabled # Disable Streamable HTTP transport (/mcp endpoint)
# - --no-json-response # Disable JSON response mode in Streamable HTTP transport (instead of SSE over HTTP)
container_name: ragflow-server container_name: ragflow-server
ports: ports:
- ${SVR_HTTP_PORT}:9380 - ${SVR_HTTP_PORT}:9380
- ../history_data_agent:/ragflow/history_data_agent - ../history_data_agent:/ragflow/history_data_agent
- ./service_conf.yaml.template:/ragflow/conf/service_conf.yaml.template - ./service_conf.yaml.template:/ragflow/conf/service_conf.yaml.template
- ./entrypoint.sh:/ragflow/entrypoint.sh - ./entrypoint.sh:/ragflow/entrypoint.sh

env_file: .env env_file: .env
environment: environment:
- TZ=${TIMEZONE} - TZ=${TIMEZONE}

+ 19
- 1
docker/entrypoint.sh View File

MCP_SCRIPT_PATH="/ragflow/mcp/server/server.py" MCP_SCRIPT_PATH="/ragflow/mcp/server/server.py"
MCP_MODE="self-host" MCP_MODE="self-host"
MCP_HOST_API_KEY="" MCP_HOST_API_KEY=""
MCP_TRANSPORT_SSE_FLAG="--transport-sse-enabled"
MCP_TRANSPORT_STREAMABLE_HTTP_FLAG="--transport-streamable-http-enabled"
MCP_JSON_RESPONSE_FLAG="--json-response"


# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Host ID logic: # Host ID logic:
MCP_SCRIPT_PATH="${arg#*=}" MCP_SCRIPT_PATH="${arg#*=}"
shift shift
;; ;;
--no-transport-sse-enabled)
MCP_TRANSPORT_SSE_FLAG="--no-transport-sse-enabled"
shift
;;
--no-transport-streamable-http-enabled)
MCP_TRANSPORT_STREAMABLE_HTTP_FLAG="--no-transport-streamable-http-enabled"
shift
;;
--no-json-response)
MCP_JSON_RESPONSE_FLAG="--no-json-response"
shift
;;
--consumer-no-beg=*) --consumer-no-beg=*)
CONSUMER_NO_BEG="${arg#*=}" CONSUMER_NO_BEG="${arg#*=}"
shift shift
--port="${MCP_PORT}" \ --port="${MCP_PORT}" \
--base-url="${MCP_BASE_URL}" \ --base-url="${MCP_BASE_URL}" \
--mode="${MCP_MODE}" \ --mode="${MCP_MODE}" \
--api-key="${MCP_HOST_API_KEY}" &
--api-key="${MCP_HOST_API_KEY}" \
"${MCP_TRANSPORT_SSE_FLAG}" \
"${MCP_TRANSPORT_STREAMABLE_HTTP_FLAG}" \
"${MCP_JSON_RESPONSE_FLAG}" &
} }


# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------

+ 4
- 0
mcp/server/server.py View File

print(f"MCP port: {PORT}", flush=True) print(f"MCP port: {PORT}", flush=True)
print(f"MCP base_url: {BASE_URL}", flush=True) print(f"MCP base_url: {BASE_URL}", flush=True)


if not any([TRANSPORT_SSE_ENABLED, TRANSPORT_STREAMABLE_HTTP_ENABLED]):
print("At least one transport should be enabled, enable streamable-http automatically", flush=True)
TRANSPORT_STREAMABLE_HTTP_ENABLED = True

if TRANSPORT_SSE_ENABLED: if TRANSPORT_SSE_ENABLED:
print("SSE transport enabled: yes", flush=True) print("SSE transport enabled: yes", flush=True)
print("SSE endpoint available at /sse", flush=True) print("SSE endpoint available at /sse", flush=True)

Loading…
Cancel
Save