Spaces:
Sleeping
Sleeping
Commit
Β·
78b6d7b
1
Parent(s):
f09fda0
all the thing
Browse files- FILE_STRUCTURE.md +10 -15
- TESTING_GUIDE.md +2 -11
- check_rag_database.py +3 -3
- env.example +5 -1
- start.bat +24 -6
- verify_tenant_isolation.py +2 -2
FILE_STRUCTURE.md
CHANGED
|
@@ -29,18 +29,12 @@ IntegraChat/
|
|
| 29 |
β β β βββ tool_selector.py # Multi-tool selection logic
|
| 30 |
β β βββ utils/
|
| 31 |
β β βββ text_extractor.py # Text extraction utilities
|
| 32 |
-
β βββ
|
| 33 |
-
β β βββ
|
| 34 |
-
β β βββ
|
| 35 |
-
β β βββ
|
| 36 |
-
β β βββ
|
| 37 |
-
β β
|
| 38 |
-
β β βββ web_server.py # Web search MCP server (English results)
|
| 39 |
-
β β βββ models/
|
| 40 |
-
β β βββ __init__.py
|
| 41 |
-
β β βββ admin.py # Admin request models
|
| 42 |
-
β β βββ rag.py # RAG request models
|
| 43 |
-
β β βββ web.py # Web search request models
|
| 44 |
β βββ tests/
|
| 45 |
β β βββ conftest.py # Pytest configuration
|
| 46 |
β β βββ test_agent_orchestrator.py # Orchestrator tests
|
|
@@ -64,9 +58,10 @@ IntegraChat/
|
|
| 64 |
- **`redflag_detector.py`** - Detects policy violations
|
| 65 |
|
| 66 |
### MCP Servers
|
| 67 |
-
- **`
|
| 68 |
-
- **`
|
| 69 |
-
- **`
|
|
|
|
| 70 |
|
| 71 |
### API Routes
|
| 72 |
- **`agent.py`** - Main chat/agent endpoint
|
|
|
|
| 29 |
β β β βββ tool_selector.py # Multi-tool selection logic
|
| 30 |
β β βββ utils/
|
| 31 |
β β βββ text_extractor.py # Text extraction utilities
|
| 32 |
+
β βββ mcp_server/
|
| 33 |
+
β β βββ server.py # Unified MCP entrypoint (rag/web/admin)
|
| 34 |
+
β β βββ rag/ # RAG tool handlers (search/ingest/delete)
|
| 35 |
+
β β βββ web/ # Web search tool handler
|
| 36 |
+
β β βββ admin/ # Admin rules + violations tools
|
| 37 |
+
β β βββ common/ # Shared tenant/logging/utils helpers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
β βββ tests/
|
| 39 |
β β βββ conftest.py # Pytest configuration
|
| 40 |
β β βββ test_agent_orchestrator.py # Orchestrator tests
|
|
|
|
| 58 |
- **`redflag_detector.py`** - Detects policy violations
|
| 59 |
|
| 60 |
### MCP Servers
|
| 61 |
+
- **`backend/mcp_server/server.py`** - Unified MCP entrypoint (rag/web/admin tools)
|
| 62 |
+
- **`backend/mcp_server/rag/*.py`** - RAG tool handlers (search/ingest/delete)
|
| 63 |
+
- **`backend/mcp_server/web/search.py`** - DuckDuckGo handler
|
| 64 |
+
- **`backend/mcp_server/admin/*.py`** - Admin rules & violations tools
|
| 65 |
|
| 66 |
### API Routes
|
| 67 |
- **`agent.py`** - Main chat/agent endpoint
|
TESTING_GUIDE.md
CHANGED
|
@@ -264,17 +264,8 @@ python test_api_manual.py
|
|
| 264 |
cd backend/api
|
| 265 |
uvicorn main:app --port 8000 --reload
|
| 266 |
|
| 267 |
-
# Terminal 2: Start
|
| 268 |
-
|
| 269 |
-
python main.py # or uvicorn main:app --port 8001
|
| 270 |
-
|
| 271 |
-
# Terminal 3: Start Web MCP server
|
| 272 |
-
cd backend/mcp_servers
|
| 273 |
-
python web_server.py # or uvicorn web_server:app --port 8002
|
| 274 |
-
|
| 275 |
-
# Terminal 4: Start Admin MCP server
|
| 276 |
-
cd backend/mcp_servers
|
| 277 |
-
python admin_server.py # or uvicorn admin_server:app --port 8003
|
| 278 |
|
| 279 |
# Optional: Start Ollama for LLM
|
| 280 |
ollama serve
|
|
|
|
| 264 |
cd backend/api
|
| 265 |
uvicorn main:app --port 8000 --reload
|
| 266 |
|
| 267 |
+
# Terminal 2: Start unified MCP server (rag/web/admin tools)
|
| 268 |
+
python backend/mcp_server/server.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
|
| 270 |
# Optional: Start Ollama for LLM
|
| 271 |
ollama serve
|
check_rag_database.py
CHANGED
|
@@ -18,7 +18,7 @@ def check_database():
|
|
| 18 |
print("="*60)
|
| 19 |
|
| 20 |
try:
|
| 21 |
-
from
|
| 22 |
import psycopg2.extras
|
| 23 |
|
| 24 |
conn = get_connection()
|
|
@@ -65,8 +65,8 @@ def check_database():
|
|
| 65 |
|
| 66 |
# Test search_vectors function directly
|
| 67 |
print("\n4. Testing search_vectors function directly...")
|
| 68 |
-
from
|
| 69 |
-
from
|
| 70 |
|
| 71 |
# Search for tenant1's secret as tenant1
|
| 72 |
query = "TENANT1_SECRET"
|
|
|
|
| 18 |
print("="*60)
|
| 19 |
|
| 20 |
try:
|
| 21 |
+
from mcp_server.common.database import get_connection
|
| 22 |
import psycopg2.extras
|
| 23 |
|
| 24 |
conn = get_connection()
|
|
|
|
| 65 |
|
| 66 |
# Test search_vectors function directly
|
| 67 |
print("\n4. Testing search_vectors function directly...")
|
| 68 |
+
from mcp_server.common.embeddings import embed_text
|
| 69 |
+
from mcp_server.common.database import search_vectors
|
| 70 |
|
| 71 |
# Search for tenant1's secret as tenant1
|
| 72 |
query = "TENANT1_SECRET"
|
env.example
CHANGED
|
@@ -21,12 +21,16 @@ OLLAMA_MODEL=llama3.1:latest
|
|
| 21 |
LLM_BACKEND=ollama
|
| 22 |
|
| 23 |
# =============================================================
|
| 24 |
-
# MCP SERVER
|
| 25 |
# =============================================================
|
|
|
|
| 26 |
RAG_MCP_URL=http://localhost:8001
|
| 27 |
WEB_MCP_URL=http://localhost:8002
|
| 28 |
ADMIN_MCP_URL=http://localhost:8003
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
# =============================================================
|
| 31 |
# BACKEND CONFIG
|
| 32 |
# =============================================================
|
|
|
|
| 21 |
LLM_BACKEND=ollama
|
| 22 |
|
| 23 |
# =============================================================
|
| 24 |
+
# MCP SERVER CONFIG
|
| 25 |
# =============================================================
|
| 26 |
+
# Legacy FastAPI endpoints (remove once all callers use the unified MCP server)
|
| 27 |
RAG_MCP_URL=http://localhost:8001
|
| 28 |
WEB_MCP_URL=http://localhost:8002
|
| 29 |
ADMIN_MCP_URL=http://localhost:8003
|
| 30 |
|
| 31 |
+
# Unified MCP server identifier (namespaced tools)
|
| 32 |
+
MCP_SERVER_ID=integrachat
|
| 33 |
+
|
| 34 |
# =============================================================
|
| 35 |
# BACKEND CONFIG
|
| 36 |
# =============================================================
|
start.bat
CHANGED
|
@@ -87,13 +87,31 @@ if not exist "%VENV_PYTHON%" (
|
|
| 87 |
exit /b 1
|
| 88 |
)
|
| 89 |
|
| 90 |
-
REM Launch MCP
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
echo.
|
| 92 |
-
echo Launching MCP
|
| 93 |
-
start "
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
echo MCP servers started. Close their windows or press Ctrl+C inside them to stop.
|
| 97 |
echo.
|
| 98 |
|
| 99 |
REM Start the FastAPI server
|
|
|
|
| 87 |
exit /b 1
|
| 88 |
)
|
| 89 |
|
| 90 |
+
REM Launch unified MCP server (in its own window so you can see logs)
|
| 91 |
+
if not exist "backend\mcp_server\server.py" (
|
| 92 |
+
echo ERROR: backend\mcp_server\server.py not found!
|
| 93 |
+
pause
|
| 94 |
+
exit /b 1
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
REM Configure default MCP endpoints if not provided
|
| 98 |
+
if "%MCP_PORT%"=="" (
|
| 99 |
+
set "MCP_PORT=8900"
|
| 100 |
+
)
|
| 101 |
+
if "%RAG_MCP_URL%"=="" (
|
| 102 |
+
set "RAG_MCP_URL=http://localhost:%MCP_PORT%/rag"
|
| 103 |
+
)
|
| 104 |
+
if "%WEB_MCP_URL%"=="" (
|
| 105 |
+
set "WEB_MCP_URL=http://localhost:%MCP_PORT%/web"
|
| 106 |
+
)
|
| 107 |
+
if "%ADMIN_MCP_URL%"=="" (
|
| 108 |
+
set "ADMIN_MCP_URL=http://localhost:%MCP_PORT%/admin"
|
| 109 |
+
)
|
| 110 |
echo.
|
| 111 |
+
echo Launching unified MCP server (rag/web/admin)...
|
| 112 |
+
start "Unified MCP" cmd /k ""%VENV_PYTHON%" -m backend.mcp_server.server"
|
| 113 |
+
timeout /t 2 >nul
|
| 114 |
+
echo Unified MCP server window opened (titled 'Unified MCP'). Close it manually to stop the MCP server.
|
|
|
|
| 115 |
echo.
|
| 116 |
|
| 117 |
REM Start the FastAPI server
|
verify_tenant_isolation.py
CHANGED
|
@@ -319,7 +319,7 @@ def verify_rag_isolation():
|
|
| 319 |
except requests.exceptions.ConnectionError:
|
| 320 |
print("\nβ οΈ Cannot connect to API/RAG server. Make sure they're running:")
|
| 321 |
print(" uvicorn backend.api.main:app --port 8000")
|
| 322 |
-
print(" python
|
| 323 |
return None
|
| 324 |
except Exception as e:
|
| 325 |
print(f"\nβ Error: {e}")
|
|
@@ -435,7 +435,7 @@ def main():
|
|
| 435 |
if total == 0:
|
| 436 |
print("\nβ οΈ No tests could run. Make sure services are running:")
|
| 437 |
print(" - API: uvicorn backend.api.main:app --port 8000")
|
| 438 |
-
print(" -
|
| 439 |
elif failed == 0 and passed > 0:
|
| 440 |
print("\nβ
All tenant isolation tests PASSED!")
|
| 441 |
elif failed > 0:
|
|
|
|
| 319 |
except requests.exceptions.ConnectionError:
|
| 320 |
print("\nβ οΈ Cannot connect to API/RAG server. Make sure they're running:")
|
| 321 |
print(" uvicorn backend.api.main:app --port 8000")
|
| 322 |
+
print(" python backend/mcp_server/server.py")
|
| 323 |
return None
|
| 324 |
except Exception as e:
|
| 325 |
print(f"\nβ Error: {e}")
|
|
|
|
| 435 |
if total == 0:
|
| 436 |
print("\nβ οΈ No tests could run. Make sure services are running:")
|
| 437 |
print(" - API: uvicorn backend.api.main:app --port 8000")
|
| 438 |
+
print(" - MCP Server: python backend/mcp_server/server.py")
|
| 439 |
elif failed == 0 and passed > 0:
|
| 440 |
print("\nβ
All tenant isolation tests PASSED!")
|
| 441 |
elif failed > 0:
|