Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

Add MCP HTTP client config and apply to client

Edwin Josee2bb04abe305
diff --git a/sdks/mcp/README.md b/sdks/mcp/README.md
index b4b1553cd..8034b85f9 100644
--- a/sdks/mcp/README.md
+++ b/sdks/mcp/README.md
@@ -66,6 +66,16 @@ Document ingestion and management tools (`openrag_ingest_file`, `openrag_ingest_
| `OPENRAG_API_KEY` | Your OpenRAG API key | Yes | — |
| `OPENRAG_URL` | Base URL of your OpenRAG instance | No | `http://localhost:3000` |
+**MCP HTTP client (optional):**
+
+| Variable | Description | Required | Default |
+|:---------|:------------|:--------:|:--------|
+| `OPENRAG_MCP_TIMEOUT` | Request timeout in seconds | No | `60.0` |
+| `OPENRAG_MCP_MAX_CONNECTIONS` | Maximum concurrent connections | No | `100` |
+| `OPENRAG_MCP_MAX_KEEPALIVE_CONNECTIONS` | Maximum keepalive connections | No | `20` |
+| `OPENRAG_MCP_MAX_RETRIES` | Maximum retry attempts for failed requests | No | `3` |
+| `OPENRAG_MCP_FOLLOW_REDIRECTS` | Whether to follow HTTP redirects | No | `true` |
+
These must be set in the environment when the MCP server runs (e.g. in the `env` block of your MCP client config).
---
diff --git a/sdks/mcp/src/openrag_mcp/config.py b/sdks/mcp/src/openrag_mcp/config.py
index 4fbeeedd9..b588f34d3 100644
--- a/sdks/mcp/src/openrag_mcp/config.py
+++ b/sdks/mcp/src/openrag_mcp/config.py
@@ -5,6 +5,38 @@ import os
from openrag_sdk import OpenRAGClient
+def _parse_float(key: str, default: float) -> float:
+ """Parse a positive float from environment."""
+ raw = os.environ.get(key)
+ if raw is None:
+ return default
+ try:
+ value = float(raw)
+ return value if value > 0 else default
+ except ValueError:
+ return default
+
+
+def _parse_int(key: str, default: int) -> int:
+ """Parse a positive int from environment."""
+ raw = os.environ.get(key)
+ if raw is None:
+ return default
+ try:
+ value = int(raw)
+ return value if value > 0 else default
+ except ValueError:
+ return default
+
+
+def _parse_bool(key: str, default: bool) -> bool:
+ """Parse a boolean from environment (true/false, 1/0)."""
+ raw = os.environ.get(key)
+ if raw is None:
+ return default
+ return raw.strip().lower() in ("true", "1", "yes")
+
+
class Config:
"""Configuration loaded from environment variables."""
@@ -18,6 +50,15 @@ class Config:
"Create an API key in OpenRAG Settings > API Keys."
)
+ # MCP httpx client configuration (OPENRAG_MCP_*)
+ self.mcp_timeout = _parse_float("OPENRAG_MCP_TIMEOUT", 60.0)
+ self.mcp_max_connections = _parse_int("OPENRAG_MCP_MAX_CONNECTIONS", 100)
+ self.mcp_max_keepalive_connections = _parse_int(
+ "OPENRAG_MCP_MAX_KEEPALIVE_CONNECTIONS", 20
+ )
+ self.mcp_max_retries = _parse_int("OPENRAG_MCP_MAX_RETRIES", 3)
+ self.mcp_follow_redirects = _parse_bool("OPENRAG_MCP_FOLLOW_REDIRECTS", True)
+
@property
def headers(self) -> dict[str, str]:
"""Get HTTP headers for API requests."""
@@ -50,7 +91,7 @@ def get_openrag_client() -> OpenRAGClient:
def get_client():
"""Get an httpx async client configured for OpenRAG.
-
+
This is kept for backward compatibility with operations
not yet supported by the SDK (list_documents, ingest_url).
"""
@@ -60,5 +101,11 @@ def get_client():
return httpx.AsyncClient(
base_url=config.openrag_url,
headers=config.headers,
- timeout=60.0,
+ timeout=config.mcp_timeout,
+ limits=httpx.Limits(
+ max_connections=config.mcp_max_connections,
+ max_keepalive_connections=config.mcp_max_keepalive_connections,
+ ),
+ transport=httpx.AsyncHTTPTransport(retries=config.mcp_max_retries),
+ follow_redirects=config.mcp_follow_redirects,
)