fix: MCP startup timeout, Pydantic crash, proxy support, and encoding#3
Open
bennylii wants to merge 1 commit into
Open
fix: MCP startup timeout, Pydantic crash, proxy support, and encoding#3bennylii wants to merge 1 commit into
bennylii wants to merge 1 commit into
Conversation
fix: MCP startup timeout and encoding issues on Windows - Add structured_output=False to vision tools to fix Pydantic crash - Convert httpx.Client to lazy initialization (~6s startup saving on Windows) - Remove unused groq_client from groq_stt.py (dead code ~2s waste) - Add HTTP_PROXY/HTTPS_PROXY support to all three API modules - Add encoding="utf-8" to vision output file writes - Remove stdout print from main() (unsafe for MCP stdio transport) Claude Desktop MCP startup time drops from ~15s to under 2s. @
|
Confirming the Pydantic crash reproduces on macOS (Python 3.11, The |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the remaining issues that prevent the MCP server from working on Windows and in proxied environments. Builds on PR #2 (@OctavioCriollo's
structured_output=Falseapproach for the vision tools) and adds several additional fixes.Issues fixed
1. Pydantic crash on vision tools (same as PR #2)
Added
structured_output=Falsetoanalyze_imageandanalyze_image_jsonso the MCP SDK skips schema generation for theImagereturn type.2. MCP startup timeout (~15s → ~2s)
httpx.Client()instantiation on Windows takes ~2 seconds per call due to SSL/certificate store overhead. All three modules (groq_tts.py,groq_stt.py,groq_vision.py) created their clients at module level, adding ~6s+ to import time. Converted to lazy_get_client()pattern — clients are created on first API call instead of at import.3. Dead code in groq_stt.py
groq_stt.pycreated a module-levelgroq_clientthat was never used — the functions calledhttpx.post()directly. Removed the dead client. Also migratedhttpx.post()calls to use the lazy_get_client()to get proxy support.4. Proxy support
None of the modules respected
HTTP_PROXY/HTTPS_PROXYenvironment variables. The lazy_get_client()functions now read these env vars and configure the httpx client accordingly.5. UTF-8 encoding on output files
groq_vision.pyusedopen(file, "w")without encoding — on non-UTF-8 systems (Chinese Windows, etc.) this causesUnicodeEncodeErrorwhen writing analysis results. Changed toopen(file, "w", encoding="utf-8").6. Unsafe stdout write
Removed
print("Starting Groq TTS server")frommain()— printing to stdout is unsafe for MCP stdio transport.Files changed
server.pystructured_output=False, -1 printsrc/groq_tts.py_get_client()src/groq_stt.py_get_client(), remove deadgroq_clientsrc/groq_vision.py_get_client(),encoding="utf-8"Tested
analyze_imageconfirmed working through proxy (HTTP_PROXY)CC @OctavioCriollo — this extends your PR #2 with additional fixes I found while debugging Windows startup.