aminghadersohi opened a new pull request, #38401:
URL: https://github.com/apache/superset/pull/38401

   ### SUMMARY
   
   The MCP SDK captures Python warnings via the `warnings` module and forwards 
them to clients as `mcp.server.lowlevel.server:Warning:` log entries. This 
caused marshmallow `RemovedInMarshmallow4Warning` and google.api_core 
`FutureWarning` deprecation warnings to leak into MCP tool responses.
   
   **Impact:**
   - Pollutes MCP tool responses with irrelevant internal warnings
   - Wastes LLM tokens processing these warnings  
   - LLM clients may try to "fix" or act on these warnings
   - Happens on code paths that trigger marshmallow schema instantiation (e.g., 
`get_chart_preview` when database connection schemas are loaded)
   
   **Fix:**
   Added `warnings.filterwarnings()` calls in two places:
   1. **`app.py`** (before tool imports) - Suppresses import-time warnings 
triggered during tool/schema registration
   2. **`server.py`** (`_suppress_third_party_warnings()` called at server 
startup) - Suppresses runtime warnings during tool execution
   
   Suppressed warning categories:
   - `DeprecationWarning` from `marshmallow.*` modules (marshmallow 4 migration 
notices)
   - `FutureWarning` from `google.*` modules (Python version support notices)
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   **Before** (server logs during `get_chart_preview`):
   ```
   2026-02-26 13:37:00,082:INFO:mcp.server.lowlevel.server:Warning: 
FutureWarning: You are using a Python version (3.10.16) which Google will stop 
supporting...
   2026-02-26 13:37:00,083:INFO:mcp.server.lowlevel.server:Warning: 
RemovedInMarshmallow4Warning: Passing field metadata as keyword arguments is 
deprecated...
   (7 more marshmallow warnings)
   ```
   
   **After**: No deprecation warnings in MCP client responses.
   
   ### TESTING INSTRUCTIONS
   
   1. Run the new test:
      ```bash
      pytest 
tests/unit_tests/mcp_service/test_mcp_server.py::test_suppress_third_party_warnings
 -v
      ```
   2. Start the MCP server and call `get_chart_preview` - verify no 
`mcp.server.lowlevel.server:Warning:` entries for marshmallow or google 
warnings in the response
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to