Skip to content

fix: MCP startup timeout, Pydantic crash, proxy support, and encoding#3

Open
bennylii wants to merge 1 commit into
groq:mainfrom
bennylii:fix/windows-startup-and-encoding
Open

fix: MCP startup timeout, Pydantic crash, proxy support, and encoding#3
bennylii wants to merge 1 commit into
groq:mainfrom
bennylii:fix/windows-startup-and-encoding

Conversation

@bennylii

@bennylii bennylii commented May 4, 2026

Copy link
Copy Markdown

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=False approach for the vision tools) and adds several additional fixes.

Issues fixed

1. Pydantic crash on vision tools (same as PR #2)

Added structured_output=False to analyze_image and analyze_image_json so the MCP SDK skips schema generation for the Image return 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.py created a module-level groq_client that was never used — the functions called httpx.post() directly. Removed the dead client. Also migrated httpx.post() calls to use the lazy _get_client() to get proxy support.

4. Proxy support

None of the modules respected HTTP_PROXY / HTTPS_PROXY environment 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.py used open(file, "w") without encoding — on non-UTF-8 systems (Chinese Windows, etc.) this causes UnicodeEncodeError when writing analysis results. Changed to open(file, "w", encoding="utf-8").

6. Unsafe stdout write

Removed print("Starting Groq TTS server") from main() — printing to stdout is unsafe for MCP stdio transport.

Files changed

File Changes
server.py +2 structured_output=False, -1 print
src/groq_tts.py lazy client + proxy, → _get_client()
src/groq_stt.py lazy client + proxy, → _get_client(), remove dead groq_client
src/groq_vision.py lazy client + proxy, → _get_client(), encoding="utf-8"

Tested

  • Windows 10, Python 3.12, mcp 1.27.0, pydantic 2.12.5, httpx 0.28.1
  • Import time: ~15s → ~2s
  • Server starts under Claude Desktop / Claude Code stdio transport
  • Vision analysis with analyze_image confirmed working through proxy (HTTP_PROXY)

CC @OctavioCriollo — this extends your PR #2 with additional fixes I found while debugging Windows startup.

@
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.
@
@mashkovtsevlx

Copy link
Copy Markdown

Confirming the Pydantic crash reproduces on macOS (Python 3.11, mcp[cli] latest), so it isn't Windows-specific — the server fails at import for everyone on a recent MCP SDK:

pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'mcp.server.fastmcp.utilities.types.Image'>

The structured_output=False change in this PR fixes it. As a stopgap for anyone blocked right now, pinning mcp[cli]==1.6.0 also avoids the crash. Would be great to get this merged.

cc @janzheng (maintainer) — thanks @bennylii for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants