fix: suppress platform string output to stdout on macOS
This commit is contained in:
17
main.py
17
main.py
@@ -1,3 +1,4 @@
|
||||
import io
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
@@ -6,6 +7,13 @@ import sys
|
||||
from importlib import metadata, import_module
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Prevent any stray output (e.g. platform identifiers like "darwin" on macOS)
|
||||
# from corrupting the MCP JSON-RPC handshake on stdout. We capture anything
|
||||
# written to stdout during module-level initialisation and replay it to stderr
|
||||
# so that diagnostic information is not lost.
|
||||
_original_stdout = sys.stdout
|
||||
sys.stdout = io.StringIO()
|
||||
|
||||
# Check for CLI mode early - before loading oauth_config
|
||||
# CLI mode requires OAuth 2.0 since there's no MCP session context
|
||||
_CLI_MODE = "--cli" in sys.argv
|
||||
@@ -117,12 +125,21 @@ def narrow_permissions_to_services(
|
||||
}
|
||||
|
||||
|
||||
def _restore_stdout():
|
||||
"""Restore the real stdout and replay any captured output to stderr."""
|
||||
captured = sys.stdout.getvalue()
|
||||
sys.stdout = _original_stdout
|
||||
if captured:
|
||||
print(captured, end="", file=sys.stderr)
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main entry point for the Google Workspace MCP server.
|
||||
Uses FastMCP's native streamable-http transport.
|
||||
Supports CLI mode for direct tool invocation without running the server.
|
||||
"""
|
||||
_restore_stdout()
|
||||
# Check if CLI mode is enabled - suppress startup messages
|
||||
if _CLI_MODE:
|
||||
# Suppress logging output in CLI mode for clean output
|
||||
|
||||
Reference in New Issue
Block a user