Fix GET /mcp 405 log spam and resolve_account email matching
Add a custom GET /mcp health route so health checks and client polling return 200 instead of flooding logs with 405. Also allow resolve_account to match by email address (from_address, imap_username, smtp_username) in addition to account ID.
This commit is contained in:
+1
-1
@@ -22,6 +22,6 @@ EXPOSE 3000
|
|||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||||
CMD python -c "import httpx; r = httpx.get('http://localhost:3000/mcp', timeout=5); assert r.status_code == 405" || exit 1
|
CMD python -c "import httpx; r = httpx.get('http://localhost:3000/mcp', timeout=5); assert r.status_code == 200" || exit 1
|
||||||
|
|
||||||
CMD ["python", "src/server.py"]
|
CMD ["python", "src/server.py"]
|
||||||
|
|||||||
@@ -117,6 +117,14 @@ def resolve_account(accounts: list[dict], account_id: Optional[str] = None) -> d
|
|||||||
for acc in accounts:
|
for acc in accounts:
|
||||||
if acc["id"] == account_id:
|
if acc["id"] == account_id:
|
||||||
return acc
|
return acc
|
||||||
|
# Fallback: match by email address (from_address, imap_username, smtp_username)
|
||||||
|
for acc in accounts:
|
||||||
|
if account_id in (
|
||||||
|
acc.get("from_address"),
|
||||||
|
acc.get("imap_username"),
|
||||||
|
acc.get("smtp_username"),
|
||||||
|
):
|
||||||
|
return acc
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Unknown account_id: {account_id}. Available: {[a['id'] for a in accounts]}"
|
f"Unknown account_id: {account_id}. Available: {[a['id'] for a in accounts]}"
|
||||||
)
|
)
|
||||||
@@ -493,6 +501,13 @@ if not mcp_api_key:
|
|||||||
mcp = FastMCP("poke-mail", lifespan=lifespan, auth=auth)
|
mcp = FastMCP("poke-mail", lifespan=lifespan, auth=auth)
|
||||||
|
|
||||||
|
|
||||||
|
@mcp.custom_route("/mcp", methods=["GET"])
|
||||||
|
async def health(request):
|
||||||
|
from starlette.responses import JSONResponse
|
||||||
|
|
||||||
|
return JSONResponse({"status": "ok"})
|
||||||
|
|
||||||
|
|
||||||
@mcp.tool(
|
@mcp.tool(
|
||||||
description="Search emails by criteria. Returns a list of matching emails with metadata."
|
description="Search emails by criteria. Returns a list of matching emails with metadata."
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user