Skip to content

Conversation

@maxisbey
Copy link
Contributor

Move inline imports to the top of files for consistency.

Changes

  • server/fastmcp/server.py: Move create_auth_routes, build_resource_metadata_url, create_protected_resource_routes from mcp.server.auth.routes to top-level imports
  • server/lowlevel/server.py: Move importlib.metadata.version to top-level (renamed to importlib_version to avoid shadowing)
  • server/main.py: Move warnings import to top-level
  • client/main.py: Move warnings import to top-level
  • client/auth/extensions/client_credentials.py: Move warnings import to top-level

Intentionally kept as inline imports

The following patterns were intentionally left as inline imports:

  • Optional dependencies: uvicorn, rich, typer, dotenv, jsonschema (lazy-loaded to avoid import errors when not installed)
  • Platform-specific: win32 imports (only imported on Windows)
  • TYPE_CHECKING blocks: Imports inside if TYPE_CHECKING: (for type hints only, not runtime)
  • Circular import avoidance: context_injection.py importing Context from server.py

Move inline imports to the top of files for consistency.

## src/ changes
- server/fastmcp/server.py: Move auth routes and Middleware imports
- server/lowlevel/server.py: Move importlib.metadata.version import
- server/__main__.py: Move warnings import
- client/__main__.py: Move warnings import
- client/auth/extensions/client_credentials.py: Move warnings import

## tests/ changes
- test_examples.py: Move example imports, rename to avoid conflicts
- test_error_handling.py: Move base64, hashlib, secrets, settings imports
- test_protected_resource.py: Move urlparse import
- test_func_metadata.py: Move InvalidSignature and NamedTuple imports
- test_server.py: Move Starlette and ToolError imports
- test_integration.py: Move type imports
- test_url_elicitation.py: Move elicit_url and pydantic imports
- test_auth_integration.py: Remove duplicate base64 imports
- test_streamable_http.py: Move traceback import
- test_ws.py: Move urlparse import
- test_auth_utils.py: Move HttpUrl import
- test_sampling_callback.py: Move FastMCP import
- test_list_roots_callback.py: Move FastMCP import
- test_logging_callback.py: Move FastMCP import
- test_auth.py: Consolidate urllib.parse and add auth imports
- test_stdio.py: Move _terminate_process_tree import
- test_http_unicode.py: Move server-related imports (keep uvicorn inline)
- test_session_group.py: Move httpx import
- test_output_schema_validation.py: Move jsonschema and inspect imports
- test_client_credentials.py: Move warnings import

## Intentionally kept as inline imports
- Optional deps (uvicorn, rich, typer, dotenv, jsonschema in src/)
- Platform-specific (win32)
- TYPE_CHECKING blocks
- Circular import avoidance (context_injection.py)

Claude-Generated-By: Claude Code (cli/claude-opus-4-5=100%)
Claude-Steers: 0
Claude-Permission-Prompts: 2
Claude-Escapes: 0
@maxisbey maxisbey force-pushed the refactor/move-inline-imports-to-top branch from afbae45 to fbf8461 Compare January 16, 2026 14:22
Reverting changes to src/mcp/server/fastmcp/server.py as these
are being handled in a separate branch.

Claude-Generated-By: Claude Code (cli/claude-opus-4-5=100%)
Claude-Steers: 0
Claude-Permission-Prompts: 1
Claude-Escapes: 0
@maxisbey maxisbey enabled auto-merge (squash) January 16, 2026 14:24
Kludex
Kludex previously approved these changes Jan 16, 2026
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
@maxisbey maxisbey merged commit 5d80f4e into main Jan 16, 2026
26 checks passed
@maxisbey maxisbey deleted the refactor/move-inline-imports-to-top branch January 16, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants