[Feat] MCP Oauth2 Fixes - Add support for MCP M2M Oauth2 support (#20788)
* add has_client_credentials
* MCPOAuth2TokenCache
* init MCP Oauth2 constants
* MCPOAuth2TokenCache
* resolve_mcp_auth
* test fixes
* docs fix
* address greptile review: min TTL, env-configurable constants, tests, docs
- Fix zero-TTL edge case: floor at MCP_OAUTH2_TOKEN_CACHE_MIN_TTL (10s)
- Make all MCP OAuth2 constants env-configurable via os.getenv()
- Move test file to follow 1:1 mapping convention (test_oauth2_token_cache.py)
- Add MCP OAuth doc page (mcp_oauth.md) with M2M and PKCE sections
- Update FAQ in mcp.md to reflect M2M support
- Add E2E test script and config
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix mypy lint
* fix oauth2
* remove old files
* docs fix
* address greptile comments
* fix: atomic lock creation + validate JSON response shape
- Use dict.setdefault() for atomic per-server lock creation
- Add isinstance(body, dict) check before accessing token response fields
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: replace asserts with proper guards, wrap HTTP errors with context
- Replace `assert` statements with `if/raise ValueError` (asserts can be
disabled with python -O in production)
- Wrap `httpx.HTTPStatusError` to provide a clear error message with
server_id and status code
- Add tests for HTTP error and non-dict JSON response error paths
- Remove unused imports
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>