fix(mcp-server): address Copilot PR review comments

- SSL verification now defaults to enabled; set WEKNORA_VERIFY_SSL=false to
  opt out (with a logged warning). Fixes MITM risk from default-off TLS.
- WEKNORA_CHAT_TIMEOUT parse is now guarded with try/except ValueError so a
  bad env value falls back to 300s instead of crashing at import.
- SSE streaming response is now closed via context manager (with response:)
  to guarantee connection pool return even on early break.
- Replace asyncio.get_event_loop() (deprecated) with asyncio.get_running_loop()
  in both chat and agent_chat handlers.
- create_session now calls resolve_kb_id() so KB names are accepted in addition
  to UUIDs (consistent with chat / hybrid_search).
- knowledge_base_ids description changed from REQUIRED to Strongly recommended
  to match actual schema optionality.
- run_sse() handle_sse rewritten as raw ASGI callable (scope, receive, send) to
  avoid accessing Starlette private _send attribute.
- Fix main.py comment: http transport is Streamable HTTP (MCP spec), not long-polling.
This commit is contained in:
mileslai
2026-05-29 11:48:19 +08:00
committed by lyingbug
parent 835148626b
commit b603b1dcfa
2 changed files with 55 additions and 43 deletions
+1 -1
View File
@@ -138,7 +138,7 @@ async def main():
# Select transport mode based on CLI argument or MCP_TRANSPORT env var
# - stdio: Default, used by VS Code Copilot for local integration
# - sse: Server-Sent Events over HTTP, suitable for cloud/remote deployments
# - http: HTTP long-polling, compatible with various client architectures
# - http: Streamable HTTP sessions (MCP 2025-03-26 spec), compatible with REST clients
if args.transport == "stdio":
# Stdio mode: communication via stdin/stdout pipes (typical for CLI integrations)
await run_stdio()