Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
427eb241f6 |
No files matched your search
@@ -32,32 +32,15 @@ jobs:
|
|||||||
docker rm -f qdrant-${{ github.run_id }} 2>/dev/null || true
|
docker rm -f qdrant-${{ github.run_id }} 2>/dev/null || true
|
||||||
docker run -d --name qdrant-${{ github.run_id }} \
|
docker run -d --name qdrant-${{ github.run_id }} \
|
||||||
--network "container:$(hostname)" \
|
--network "container:$(hostname)" \
|
||||||
docker.io/qdrant/qdrant:v1.19
|
docker.io/qdrant/qdrant:latest
|
||||||
|
|
||||||
- name: Wait for Qdrant
|
- name: Wait for Qdrant
|
||||||
run: |
|
run: |
|
||||||
# /healthz answers before the storage engine accepts writes, and a cold
|
for i in $(seq 1 30); do
|
||||||
# container on a loaded host can take several seconds to create its
|
curl -s http://localhost:6333/healthz && echo "QDRANT ready" && break
|
||||||
# first collection. Gate on a real write round-trip, not on /healthz.
|
echo "Waiting for Qdrant... ($i/30)"
|
||||||
ready=""
|
|
||||||
for i in $(seq 1 60); do
|
|
||||||
if curl -sf "http://localhost:6333/healthz" > /dev/null 2>&1 \
|
|
||||||
&& curl -sf -X PUT "http://localhost:6333/collections/ci_readiness_probe?timeout=60" \
|
|
||||||
-H 'Content-Type: application/json' \
|
|
||||||
-d '{"vectors":{"size":4,"distance":"Cosine"}}' > /dev/null 2>&1; then
|
|
||||||
curl -sf -X DELETE "http://localhost:6333/collections/ci_readiness_probe" > /dev/null 2>&1 || true
|
|
||||||
ready="yes"
|
|
||||||
echo "QDRANT ready: write path OK (attempt $i)"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
echo "Waiting for Qdrant... ($i/60)"
|
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
if [ -z "$ready" ]; then
|
|
||||||
echo "Qdrant write path never became ready"
|
|
||||||
docker logs --tail 100 qdrant-${{ github.run_id }} || true
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
|
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
|
||||||
with:
|
with:
|
||||||
@@ -70,15 +53,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
QDRANT_URL: http://localhost:6333
|
QDRANT_URL: http://localhost:6333
|
||||||
COLLECTION_NAME: test_mcp_maildir
|
COLLECTION_NAME: test_mcp_maildir
|
||||||
# The qdrant client defaults to a 5s request timeout, which a cold
|
|
||||||
# collection on a shared runner can exceed; this job has no SLA.
|
|
||||||
QDRANT_TIMEOUT: "60"
|
|
||||||
|
|
||||||
- name: Qdrant diagnostics
|
|
||||||
if: failure()
|
|
||||||
run: |
|
|
||||||
docker ps -a || true
|
|
||||||
docker logs --tail 200 qdrant-${{ github.run_id }} || true
|
|
||||||
|
|
||||||
- name: Cleanup Qdrant
|
- name: Cleanup Qdrant
|
||||||
if: always()
|
if: always()
|
||||||
|
|||||||
@@ -22,9 +22,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
python-version: "3.14"
|
python-version: "3.14"
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pip install -r requirements.txt pytest ruff==0.17.1
|
run: pip install -r requirements.txt pytest
|
||||||
- name: Lint (undefined names)
|
|
||||||
run: ruff check src/ tests/ --select F821
|
|
||||||
- name: Run unit tests
|
- name: Run unit tests
|
||||||
run: pytest tests/ -v
|
run: pytest tests/ -v
|
||||||
env:
|
env:
|
||||||
@@ -45,32 +43,17 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
docker run -d --name qdrant-${{ github.run_id }} \
|
docker run -d --name qdrant-${{ github.run_id }} \
|
||||||
--network "container:$(hostname)" \
|
--network "container:$(hostname)" \
|
||||||
docker.io/qdrant/qdrant:v1.19
|
docker.io/qdrant/qdrant:latest
|
||||||
|
|
||||||
- name: Wait for Qdrant
|
- name: Wait for Qdrant
|
||||||
run: |
|
run: |
|
||||||
# /healthz answers before the storage engine accepts writes, and a cold
|
for i in $(seq 1 30); do
|
||||||
# container on a loaded host can take several seconds to create its
|
curl -s http://localhost:6333/healthz \
|
||||||
# first collection. Gate on a real write round-trip, not on /healthz.
|
&& echo "QDRANT ready" && break
|
||||||
ready=""
|
echo "Waiting for Qdrant... ($i/30)"
|
||||||
for i in $(seq 1 60); do
|
|
||||||
if curl -sf "http://localhost:6333/healthz" > /dev/null 2>&1 \
|
|
||||||
&& curl -sf -X PUT "http://localhost:6333/collections/ci_readiness_probe?timeout=60" \
|
|
||||||
-H 'Content-Type: application/json' \
|
|
||||||
-d '{"vectors":{"size":4,"distance":"Cosine"}}' > /dev/null 2>&1; then
|
|
||||||
curl -sf -X DELETE "http://localhost:6333/collections/ci_readiness_probe" > /dev/null 2>&1 || true
|
|
||||||
ready="yes"
|
|
||||||
echo "QDRANT ready: write path OK (attempt $i)"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
echo "Waiting for Qdrant... ($i/60)"
|
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
if [ -z "$ready" ]; then
|
curl -s http://localhost:6333/healthz > /dev/null
|
||||||
echo "Qdrant write path never became ready"
|
|
||||||
docker logs --tail 100 qdrant-${{ github.run_id }} || true
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
|
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
|
||||||
with:
|
with:
|
||||||
@@ -82,15 +65,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
QDRANT_URL: http://localhost:6333
|
QDRANT_URL: http://localhost:6333
|
||||||
COLLECTION_NAME: test_mcp_maildir
|
COLLECTION_NAME: test_mcp_maildir
|
||||||
# The qdrant client defaults to a 5s request timeout, which a cold
|
|
||||||
# collection on a shared runner can exceed; this job has no SLA.
|
|
||||||
QDRANT_TIMEOUT: "60"
|
|
||||||
|
|
||||||
- name: Qdrant diagnostics
|
|
||||||
if: failure()
|
|
||||||
run: |
|
|
||||||
docker ps -a || true
|
|
||||||
docker logs --tail 200 qdrant-${{ github.run_id }} || true
|
|
||||||
|
|
||||||
- name: Cleanup Qdrant
|
- name: Cleanup Qdrant
|
||||||
if: always()
|
if: always()
|
||||||
|
|||||||
@@ -94,23 +94,4 @@ jobs:
|
|||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
pull: true
|
pull: true
|
||||||
|
|
||||||
trigger-renovate:
|
|
||||||
# The deployment repo perso_private/tf-depl-kubernetes pins this image; its
|
|
||||||
# Renovate instance only scans hourly, so this dispatch opens the image bump
|
|
||||||
# PR within minutes of the release instead of up to an hour later.
|
|
||||||
needs: [build-push]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Trigger Renovate on perso_private/tf-depl-kubernetes
|
|
||||||
# needs: build-push — Renovate reads Docker Hub, so a scan started before
|
|
||||||
# the push lands would only see the previous release.
|
|
||||||
# RENOVATE_TOKEN is the org-level secret of this organisation.
|
|
||||||
run: |
|
|
||||||
curl -sS -f -X POST \
|
|
||||||
-u "renovate:${{ secrets.RENOVATE_TOKEN }}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{{"ref":"main"}}' \
|
|
||||||
"https://scm.cabillot.eu/api/v1/repos/perso_private/tf-depl-kubernetes/actions/workflows/renovate.yaml/dispatches"
|
|
||||||
echo "Renovate dispatched on perso_private/tf-depl-kubernetes"
|
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
qdrant:
|
qdrant:
|
||||||
image: docker.io/qdrant/qdrant:v1.19
|
image: docker.io/qdrant/qdrant:latest
|
||||||
container_name: mcp_maildir_qdrant
|
container_name: mcp_maildir_qdrant
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:6333:6333" # REST API
|
- "127.0.0.1:6333:6333" # REST API
|
||||||
@@ -15,7 +15,7 @@ services:
|
|||||||
dockerfile: pkg/Dockerfile
|
dockerfile: pkg/Dockerfile
|
||||||
container_name: mcp_maildir_server
|
container_name: mcp_maildir_server
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8000:8000" # Expose the MCP Streamable HTTP server (/mcp)
|
- "127.0.0.1:8000:8000" # Expose the MCP HTTP (SSE) server
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# 3.13, because with 3.14 it requires gcc (wheels not available)
|
# 3.13, because with 3.14 it requires gcc (wheels not available)
|
||||||
FROM docker.io/library/python:3.15-slim
|
FROM docker.io/library/python:3.14-slim
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|||||||
+11
-6
@@ -1,14 +1,19 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"description": "Hold python (actions/setup-python) at 3.14 until onnxruntime publishes py3.15 wheels — fastembed requires onnxruntime>=1.24.2 on py>=3.14 and there is no cp315 distribution yet (PR #55 CI: ResolutionImpossible). Re-evaluate once onnxruntime ships 3.15 wheels, then remove this rule.",
|
||||||
|
"matchDepNames": ["python"],
|
||||||
|
"matchDatasources": ["github-tags"],
|
||||||
|
"allowedVersions": "/^3\\.1[0-4](\\.|$)/"
|
||||||
|
}
|
||||||
|
],
|
||||||
"customManagers": [
|
"customManagers": [
|
||||||
{
|
{
|
||||||
"customType": "regex",
|
"customType": "regex",
|
||||||
"description": "Track the pinned qdrant/qdrant image in docker-compose.yml and the CI workflows (native manager missed it)",
|
"description": "Track qdrant/qdrant Docker image from docker-compose.yml (native manager missed it)",
|
||||||
"managerFilePatterns": [
|
"managerFilePatterns": ["/^docker-compose\\.ya?ml$/"],
|
||||||
"/^docker-compose\\.ya?ml$/",
|
"matchStrings": ["image:\\s*(?:docker\\.io/)?qdrant/qdrant:(?<currentValue>[^\\s]+)"],
|
||||||
"/^\\.gitea/workflows/.*\\.ya?ml$/"
|
|
||||||
],
|
|
||||||
"matchStrings": ["(?:docker\\.io/)?qdrant/qdrant:(?<currentValue>[^\\s\"']+)"],
|
|
||||||
"depNameTemplate": "qdrant/qdrant",
|
"depNameTemplate": "qdrant/qdrant",
|
||||||
"datasourceTemplate": "docker"
|
"datasourceTemplate": "docker"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,13 +29,6 @@ MAILDIR_FOLDERS = os.environ.get("MAILDIR_FOLDERS", "")
|
|||||||
QDRANT_URL = os.environ.get("QDRANT_URL", "")
|
QDRANT_URL = os.environ.get("QDRANT_URL", "")
|
||||||
COLLECTION_NAME = os.environ.get("COLLECTION_NAME", "")
|
COLLECTION_NAME = os.environ.get("COLLECTION_NAME", "")
|
||||||
|
|
||||||
# Embedding model and batching. EMBEDDING_MODEL_NAME MUST stay in sync with the
|
|
||||||
# one used by server.py: indexer and server have to embed with the same model,
|
|
||||||
# otherwise the vectors stored in Qdrant are not comparable with query vectors.
|
|
||||||
EMBEDDING_MODEL_NAME = os.environ.get("EMBEDDING_MODEL_NAME", "BAAI/bge-small-en-v1.5")
|
|
||||||
BATCH_SIZE = int(os.environ.get("BATCH_SIZE", "100"))
|
|
||||||
EMBEDDING_BATCH_SIZE = int(os.environ.get("EMBEDDING_BATCH_SIZE", "64"))
|
|
||||||
|
|
||||||
METADATA_COLLECTION = "mcp_indexer_metadata"
|
METADATA_COLLECTION = "mcp_indexer_metadata"
|
||||||
INCREMENTAL_DAYS = int(os.environ.get("INCREMENTAL_DAYS", "7"))
|
INCREMENTAL_DAYS = int(os.environ.get("INCREMENTAL_DAYS", "7"))
|
||||||
FORCE_REINDEX = os.environ.get("FORCE_REINDEX", "").lower() in ("1", "true", "yes")
|
FORCE_REINDEX = os.environ.get("FORCE_REINDEX", "").lower() in ("1", "true", "yes")
|
||||||
|
|||||||
+6
-27
@@ -9,7 +9,6 @@ from typing import Any, Optional
|
|||||||
import qdrant_client as qdrant_pkg
|
import qdrant_client as qdrant_pkg
|
||||||
from dateutil import parser as date_parser
|
from dateutil import parser as date_parser
|
||||||
from email.utils import parseaddr
|
from email.utils import parseaddr
|
||||||
import uvicorn
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
from starlette.responses import JSONResponse
|
from starlette.responses import JSONResponse
|
||||||
@@ -37,10 +36,6 @@ COLLECTION_NAME = os.environ.get("COLLECTION_NAME", "")
|
|||||||
EMBEDDING_MODEL_NAME = os.environ.get("EMBEDDING_MODEL_NAME", "BAAI/bge-small-en-v1.5")
|
EMBEDDING_MODEL_NAME = os.environ.get("EMBEDDING_MODEL_NAME", "BAAI/bge-small-en-v1.5")
|
||||||
DEFAULT_LIMIT = int(os.environ.get("SEARCH_LIMIT", "50"))
|
DEFAULT_LIMIT = int(os.environ.get("SEARCH_LIMIT", "50"))
|
||||||
|
|
||||||
# Per-request timeout (seconds) for Qdrant. The client default is 5s, which is
|
|
||||||
# tight for a cold collection or a busy host: unset means keep that default.
|
|
||||||
QDRANT_TIMEOUT = int(os.environ["QDRANT_TIMEOUT"]) if os.environ.get("QDRANT_TIMEOUT") else None
|
|
||||||
|
|
||||||
if not QDRANT_URL:
|
if not QDRANT_URL:
|
||||||
raise ValueError("QDRANT_URL environment variable is required.")
|
raise ValueError("QDRANT_URL environment variable is required.")
|
||||||
if not COLLECTION_NAME:
|
if not COLLECTION_NAME:
|
||||||
@@ -65,8 +60,8 @@ def get_qdrant_client() -> QdrantClient:
|
|||||||
"""Returns a singleton Qdrant client."""
|
"""Returns a singleton Qdrant client."""
|
||||||
global _qdrant_client
|
global _qdrant_client
|
||||||
if _qdrant_client is None:
|
if _qdrant_client is None:
|
||||||
logger.info(f"Connecting to Qdrant at {QDRANT_URL} (timeout={QDRANT_TIMEOUT})")
|
logger.info(f"Connecting to Qdrant at {QDRANT_URL}")
|
||||||
_qdrant_client = QdrantClient(url=QDRANT_URL, timeout=QDRANT_TIMEOUT)
|
_qdrant_client = QdrantClient(url=QDRANT_URL)
|
||||||
return _qdrant_client
|
return _qdrant_client
|
||||||
|
|
||||||
|
|
||||||
@@ -345,23 +340,6 @@ def read_email(message_id: str):
|
|||||||
return {"error": f"read_email failed: {exc}"}
|
return {"error": f"read_email failed: {exc}"}
|
||||||
|
|
||||||
|
|
||||||
# Streamable HTTP is the transport supported by current MCP clients (OpenCode,
|
|
||||||
# Claude, ...). The legacy SSE transport is deprecated and is also a POST
|
|
||||||
# target for clients that only speak Streamable HTTP, which answers 405.
|
|
||||||
MCP_HOST = "0.0.0.0"
|
|
||||||
MCP_PORT = 8000
|
|
||||||
MCP_HTTP_PATH = "/mcp"
|
|
||||||
|
|
||||||
|
|
||||||
def build_app():
|
|
||||||
"""Builds the ASGI app serving the MCP endpoint over Streamable HTTP.
|
|
||||||
|
|
||||||
The MCP endpoint lives at MCP_HTTP_PATH; the custom route declared above
|
|
||||||
keeps serving GET /health for the Kubernetes probes.
|
|
||||||
"""
|
|
||||||
return mcp.http_app(path=MCP_HTTP_PATH)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logger.info("Initializing models before starting server...")
|
logger.info("Initializing models before starting server...")
|
||||||
try:
|
try:
|
||||||
@@ -369,6 +347,7 @@ if __name__ == "__main__":
|
|||||||
logger.info("Models loaded successfully.")
|
logger.info("Models loaded successfully.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to load models: {e}")
|
logger.error(f"Failed to load models: {e}")
|
||||||
|
|
||||||
logger.info(f"Starting Streamable HTTP server on {MCP_HOST}:{MCP_PORT}{MCP_HTTP_PATH}...")
|
logger.info("Starting SSE server on 0.0.0.0:8000...")
|
||||||
uvicorn.run(build_app(), host=MCP_HOST, port=MCP_PORT)
|
# Start the MCP server using SSE (Server-Sent Events) over HTTP
|
||||||
|
mcp.run(transport="sse", host="0.0.0.0", port=8000)
|
||||||
@@ -21,9 +21,6 @@ from indexer import (
|
|||||||
parse_email_message,
|
parse_email_message,
|
||||||
get_recent_keys,
|
get_recent_keys,
|
||||||
METADATA_COLLECTION,
|
METADATA_COLLECTION,
|
||||||
EMBEDDING_MODEL_NAME,
|
|
||||||
BATCH_SIZE,
|
|
||||||
EMBEDDING_BATCH_SIZE,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -230,25 +227,3 @@ class TestGetRecentKeys:
|
|||||||
assert key.split(":")[0] in keys
|
assert key.split(":")[0] in keys
|
||||||
for k in keys:
|
for k in keys:
|
||||||
assert ":" not in k
|
assert ":" not in k
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Regression: module-level constants consumed by main()
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
def test_indexer_module_constants_are_defined():
|
|
||||||
"""Regression (e32806a): the "make indexer importable without env" refactor
|
|
||||||
dropped these three module-level definitions while main() kept using them,
|
|
||||||
so every indexer run died with NameError before touching Qdrant."""
|
|
||||||
assert isinstance(EMBEDDING_MODEL_NAME, str) and EMBEDDING_MODEL_NAME
|
|
||||||
assert isinstance(BATCH_SIZE, int) and BATCH_SIZE > 0
|
|
||||||
assert isinstance(EMBEDDING_BATCH_SIZE, int) and EMBEDDING_BATCH_SIZE > 0
|
|
||||||
|
|
||||||
|
|
||||||
def test_embedding_model_is_the_same_as_the_server_one():
|
|
||||||
"""Indexer and server must embed with the same model, otherwise the vectors
|
|
||||||
stored by the indexer are not comparable with the query vectors."""
|
|
||||||
from server import EMBEDDING_MODEL_NAME as server_embedding_model
|
|
||||||
|
|
||||||
assert EMBEDDING_MODEL_NAME == server_embedding_model
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
"""Transport-level tests for the mcp-maildir ASGI app.
|
|
||||||
|
|
||||||
Current MCP clients (OpenCode, Claude, ...) only speak Streamable HTTP: they
|
|
||||||
POST JSON-RPC to the configured URL. Serving the legacy SSE transport alone
|
|
||||||
makes those clients fail with `405 Method Not Allowed`, so the app built by
|
|
||||||
`server.build_app()` must expose the MCP endpoint at /mcp.
|
|
||||||
|
|
||||||
Env vars are set in tests/conftest.py (shared session-wide).
|
|
||||||
"""
|
|
||||||
|
|
||||||
from server import build_app, MCP_HTTP_PATH
|
|
||||||
|
|
||||||
|
|
||||||
def app_paths() -> set:
|
|
||||||
return {getattr(route, "path", None) for route in build_app().routes}
|
|
||||||
|
|
||||||
|
|
||||||
class TestTransport:
|
|
||||||
def test_mcp_endpoint_is_streamable_http(self):
|
|
||||||
assert MCP_HTTP_PATH == "/mcp"
|
|
||||||
assert MCP_HTTP_PATH in app_paths()
|
|
||||||
|
|
||||||
def test_health_endpoint_is_exposed_for_probes(self):
|
|
||||||
assert "/health" in app_paths()
|
|
||||||
|
|
||||||
def test_legacy_sse_endpoint_is_gone(self):
|
|
||||||
assert "/sse" not in app_paths()
|
|
||||||
Reference in new issue
Block a user