mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Feat: mcp server (#7084)
### What problem does this PR solve? Add MCP support with a client example. Issue link: #4344 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -10,6 +10,7 @@ function usage() {
|
||||
echo
|
||||
echo " --disable-webserver Disables the web server (nginx + ragflow_server)."
|
||||
echo " --disable-taskexecutor Disables task executor workers."
|
||||
echo " --enable-mcpserver Enables the MCP server."
|
||||
echo " --consumer-no-beg=<num> Start range for consumers (if using range-based)."
|
||||
echo " --consumer-no-end=<num> End range for consumers (if using range-based)."
|
||||
echo " --workers=<num> Number of task executors to run (if range is not used)."
|
||||
@ -19,15 +20,22 @@ function usage() {
|
||||
echo " $0 --disable-taskexecutor"
|
||||
echo " $0 --disable-webserver --consumer-no-beg=0 --consumer-no-end=5"
|
||||
echo " $0 --disable-webserver --workers=2 --host-id=myhost123"
|
||||
echo " $0 --enable-mcpserver"
|
||||
exit 1
|
||||
}
|
||||
|
||||
ENABLE_WEBSERVER=1 # Default to enable web server
|
||||
ENABLE_TASKEXECUTOR=1 # Default to enable task executor
|
||||
ENABLE_MCP_SERVER=0
|
||||
CONSUMER_NO_BEG=0
|
||||
CONSUMER_NO_END=0
|
||||
WORKERS=1
|
||||
|
||||
MCP_HOST="127.0.0.1"
|
||||
MCP_PORT=9382
|
||||
MCP_BASE_URL="http://127.0.0.1:9380"
|
||||
MCP_SCRIPT_PATH="/ragflow/mcp/server/server.py"
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Host ID logic:
|
||||
# 1. By default, use the system hostname if length <= 32
|
||||
@ -53,6 +61,26 @@ for arg in "$@"; do
|
||||
ENABLE_TASKEXECUTOR=0
|
||||
shift
|
||||
;;
|
||||
--enable-mcpserver)
|
||||
ENABLE_MCP_SERVER=1
|
||||
shift
|
||||
;;
|
||||
--mcp-host=*)
|
||||
MCP_HOST="${arg#*=}"
|
||||
shift
|
||||
;;
|
||||
--mcp-port=*)
|
||||
MCP_PORT="${arg#*=}"
|
||||
shift
|
||||
;;
|
||||
--mcp-base-url=*)
|
||||
MCP_BASE_URL="${arg#*=}"
|
||||
shift
|
||||
;;
|
||||
--mcp-script-path=*)
|
||||
MCP_SCRIPT_PATH="${arg#*=}"
|
||||
shift
|
||||
;;
|
||||
--consumer-no-beg=*)
|
||||
CONSUMER_NO_BEG="${arg#*=}"
|
||||
shift
|
||||
@ -105,6 +133,14 @@ function task_exe() {
|
||||
done
|
||||
}
|
||||
|
||||
function start_mcp_server() {
|
||||
echo "Starting MCP Server on ${MCP_HOST}:${MCP_PORT} with base URL ${MCP_BASE_URL}..."
|
||||
"$PY" "${MCP_SCRIPT_PATH}" \
|
||||
--host="${MCP_HOST}" \
|
||||
--port="${MCP_PORT}" \
|
||||
--base_url="${MCP_BASE_URL}" &
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Start components based on flags
|
||||
# -----------------------------------------------------------------------------
|
||||
@ -119,6 +155,11 @@ if [[ "${ENABLE_WEBSERVER}" -eq 1 ]]; then
|
||||
done &
|
||||
fi
|
||||
|
||||
|
||||
if [[ "${ENABLE_MCP_SERVER}" -eq 1 ]]; then
|
||||
start_mcp_server
|
||||
fi
|
||||
|
||||
if [[ "${ENABLE_TASKEXECUTOR}" -eq 1 ]]; then
|
||||
if [[ "${CONSUMER_NO_END}" -gt "${CONSUMER_NO_BEG}" ]]; then
|
||||
echo "Starting task executors on host '${HOST_ID}' for IDs in [${CONSUMER_NO_BEG}, ${CONSUMER_NO_END})..."
|
||||
|
||||
Reference in New Issue
Block a user