OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
feat: v2 public facing endpoint (#2223)
Jason Dongbb056b7189cb
diff --git a/src/app/routes/__init__.py b/src/app/routes/__init__.pyindex 92f22a2df..6f7167411 100644--- a/src/app/routes/__init__.py+++ b/src/app/routes/__init__.py@@ -9,6 +9,7 @@ from fastapi import FastAPIfrom app.routes.internal import register_internal_routesfrom app.routes.mcp import mount_mcpfrom app.routes.public_v1 import register_public_v1_routes+from app.routes.public_v2 import register_public_v2_routesdef register_all_routes(app: FastAPI):@@ -19,5 +20,6 @@ def register_all_routes(app: FastAPI):"""register_internal_routes(app)register_public_v1_routes(app)+ register_public_v2_routes(app)mcp_lifespan_ctx = mount_mcp(app)return mcp_lifespan_ctxdiff --git a/src/app/routes/public_v2.py b/src/app/routes/public_v2.pynew file mode 100644index 000000000..df8641081--- /dev/null+++ b/src/app/routes/public_v2.py@@ -0,0 +1,80 @@+"""Public /v2/* route registrations (API-key auth)."""++from fastapi import Depends, FastAPI, Query++from api.v2 import files as files_v2+from dependencies import get_file_service_v2, require_api_key_permission+from session_manager import User+++async def _list_files(+ page: int = Query(+ 1, ge=1, description="Page number (for display only; navigation uses after_key cursor)"+ ),+ page_size: int = Query(25, ge=1, le=500, description="Items per page"),+ sort_by: str = Query("filename", description="Sort field"),+ sort_order: str = Query("asc", pattern="^(asc|desc)$", description="Sort order"),+ connector_type: str | None = Query(None, description="Filter by connector type"),+ mimetype: str | None = Query(None, description="Filter by MIME type"),+ owner: str | None = Query(None, description="Filter by owner"),+ search: str | None = Query(None, description="Search filename"),+ after_key: str | None = Query(None, description="Composite pagination cursor (JSON-encoded)"),+ file_service=Depends(get_file_service_v2),+ user: User = Depends(require_api_key_permission("knowledge:read:own")),+):+ """List all ingested files. GET /v2/files"""+ return await files_v2.list_files(+ page=page,+ page_size=page_size,+ sort_by=sort_by,+ sort_order=sort_order,+ connector_type=connector_type,+ mimetype=mimetype,+ owner=owner,+ search=search,+ after_key=after_key,+ file_service=file_service,+ user=user,+ )+++async def _search_files(+ q: str = Query(..., min_length=1, description="Search query"),+ page: int = Query(1, ge=1, description="Page number"),+ page_size: int = Query(25, ge=1, le=500, description="Items per page"),+ connector_type: str | None = Query(None, description="Filter by connector type"),+ mimetype: str | None = Query(None, description="Filter by MIME type"),+ owner: str | None = Query(None, description="Filter by owner"),+ after_key: str | None = Query(None, description="Composite pagination cursor (JSON-encoded)"),+ file_service=Depends(get_file_service_v2),+ user: User = Depends(require_api_key_permission("knowledge:read:own")),+):+ """Search ingested files by name. GET /v2/files/search"""+ return await files_v2.search_files(+ q=q,+ page=page,+ page_size=page_size,+ connector_type=connector_type,+ mimetype=mimetype,+ owner=owner,+ after_key=after_key,+ file_service=file_service,+ user=user,+ )+++def register_public_v2_routes(app: FastAPI):++ # /v2/files/search must be registered before /v2/files to avoid path shadowing+ app.add_api_route(+ "/v2/files/search",+ _search_files,+ methods=["GET"],+ tags=["public"],+ )+ app.add_api_route(+ "/v2/files",+ _list_files,+ methods=["GET"],+ tags=["public"],+ )diff --git a/src/mcp_http/server.py b/src/mcp_http/server.pyindex c248dab5a..f09ed0710 100644--- a/src/mcp_http/server.py+++ b/src/mcp_http/server.py@@ -197,6 +197,14 @@ COMPONENT_CUSTOMIZATIONS: dict[tuple[str, str], dict[str, str]] = {"name": "openrag_search_files","description": "Search files by query parameters.",},+ ("/v2/files", "GET"): {+ "name": "openrag_list_files_v2",+ "description": "lists all ingested files.",+ },+ ("/v2/files/search", "GET"): {+ "name": "openrag_search_files_v2",+ "description": "Search ingested files by file name (case-insensitive).",+ },}@@ -222,14 +230,16 @@ def _customize_mcp_component(def create_mcp_server(app: FastAPI) -> FastMCP:"""- Build a FastMCP server from the FastAPI app, exposing only /v1/ routes as tools.+ Build a FastMCP server from the FastAPI app.Must be called AFTER all routes are registered on `app` so thatFastMCP.from_fastapi() can discover them.Route mapping:+ - POST /v1/documents/ingest → excluded (multipart not supported by FastMCP proxy)- /v1/* routes → MCP tools (GET, POST, PUT, DELETE, PATCH)- - All other routes → excluded+ - GET /v2/files, GET /v2/files/search → MCP tools+ - all other routes → excludedNote: GET endpoints are exposed as TOOLS, not resources/resource templates.The MCP convention is "GET = resource," but most LLM clients in agent mode@@ -250,13 +260,19 @@ def create_mcp_server(app: FastAPI) -> FastMCP:pattern=r"^/v1/documents/ingest$",mcp_type=MCPType.EXCLUDE,),- # Expose all /v1/ routes (read + write) as MCP tools.+ # expose all /v1/ routes as toolsRouteMap(methods=["GET", "POST", "PUT", "DELETE", "PATCH"],pattern=r"^/v1/",mcp_type=MCPType.TOOL,),- # Exclude everything else+ # expose /v2/files and /v2/files/search as tools+ RouteMap(+ methods=["GET"],+ pattern=r"^/v2/files",+ mcp_type=MCPType.TOOL,+ ),+ # exclude everything elseRouteMap(pattern=r".*",mcp_type=MCPType.EXCLUDE,