Skip to content

Commit 09d06ab

Browse files
niechenclaude
andcommitted
Fix code formatting and linting issues
- Format all code with ruff formatter - Fix test imports to use updated MCPMProxyFactory constructor - Remove deprecated RouterConfig usage in tests - Fix import ordering and line length issues - Add missing newlines and remove trailing whitespace 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 5a6e1e2 commit 09d06ab

File tree

11 files changed

+95
-66
lines changed

11 files changed

+95
-66
lines changed

src/mcpm/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from mcpm import __version__
1111
from mcpm.clients.client_config import ClientConfigManager
12-
from mcpm.utils.logging_config import setup_logging
1312
from mcpm.commands import (
1413
add,
1514
client,
@@ -27,6 +26,7 @@
2726
usage,
2827
)
2928
from mcpm.commands.share import share
29+
from mcpm.utils.logging_config import setup_logging
3030

3131
console = Console()
3232
client_config_manager = ClientConfigManager()

src/mcpm/clients/client_registry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class ClientRegistry:
4949
}
5050

5151
@classmethod
52-
def get_client_manager(cls, client_name: str, config_path_override: Optional[str] = None) -> Optional[BaseClientManager]:
52+
def get_client_manager(
53+
cls, client_name: str, config_path_override: Optional[str] = None
54+
) -> Optional[BaseClientManager]:
5355
"""
5456
Get the client manager for a given client name
5557

src/mcpm/commands/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ def list_clients(verbose):
217217
@client.command(name="edit", context_settings=dict(help_option_names=["-h", "--help"]))
218218
@click.argument("client_name")
219219
@click.option("-e", "--external", is_flag=True, help="Open config file in external editor instead of interactive mode")
220-
@click.option("-f", "--file", "config_path_override", type=click.Path(), help="Specify a custom path to the client's config file.")
220+
@click.option(
221+
"-f", "--file", "config_path_override", type=click.Path(), help="Specify a custom path to the client's config file."
222+
)
221223
def edit_client(client_name, external, config_path_override):
222224
"""Enable/disable MCPM-managed servers in the specified client configuration.
223225

src/mcpm/commands/profile/run.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
from mcpm.fastmcp_integration.proxy import create_mcpm_proxy
1010
from mcpm.profile.profile_config import ProfileConfigManager
1111
from mcpm.utils.config import DEFAULT_PORT
12-
from mcpm.utils.logging_config import setup_dependency_logging, ensure_dependency_logging_suppressed, get_uvicorn_log_level
12+
from mcpm.utils.logging_config import (
13+
ensure_dependency_logging_suppressed,
14+
get_uvicorn_log_level,
15+
setup_dependency_logging,
16+
)
1317

1418
profile_config_manager = ProfileConfigManager()
1519
logger = logging.getLogger(__name__)
@@ -50,10 +54,10 @@ async def run_profile_fastmcp(profile_servers, profile_name, http_mode=False, po
5054
)
5155

5256
logger.debug(f"FastMCP proxy initialized with: {[s.name for s in profile_servers]}")
53-
57+
5458
# Set up dependency logging for FastMCP/MCP libraries
5559
setup_dependency_logging()
56-
60+
5761
# Re-suppress library logging after FastMCP initialization
5862
ensure_dependency_logging_suppressed()
5963

@@ -72,18 +76,20 @@ async def run_profile_fastmcp(profile_servers, profile_name, http_mode=False, po
7276
http_url = f"http://127.0.0.1:{actual_port}/mcp/"
7377
console.print(f"[bold green]Profile '{profile_name}' is now running at:[/]")
7478
console.print(f"[cyan]{http_url}[/]")
75-
79+
7680
# Show servers in the profile
77-
console.print(f"[bold green]Servers:[/]")
81+
console.print("[bold green]Servers:[/]")
7882
for server_config in profile_servers:
7983
console.print(f" • [cyan]{server_config.name}[/]")
80-
84+
8185
console.print("[dim]Press Ctrl+C to stop the profile[/]")
82-
86+
8387
logger.debug(f"Starting FastMCP proxy for profile '{profile_name}' on port {actual_port}")
8488

8589
# Run the aggregated proxy over HTTP with uvicorn logging control
86-
await proxy.run_http_async(host="127.0.0.1", port=actual_port, uvicorn_config={"log_level": get_uvicorn_log_level()})
90+
await proxy.run_http_async(
91+
host="127.0.0.1", port=actual_port, uvicorn_config={"log_level": get_uvicorn_log_level()}
92+
)
8793
else:
8894
# Run the aggregated proxy over stdio (default)
8995
logger.info(f"Starting profile '{profile_name}' over stdio")
@@ -116,7 +122,7 @@ def run(profile_name, http, port):
116122
mcpm profile run web-dev # Run over stdio (default)
117123
mcpm profile run --http web-dev # Run over HTTP on port 6276
118124
mcpm profile run --http --port 9000 ai # Run over HTTP on port 9000
119-
125+
120126
Debug logging: Set MCPM_DEBUG=1 for verbose output
121127
"""
122128
# Validate profile name

src/mcpm/commands/profile/share.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
from mcpm.core.tunnel import Tunnel
1111
from mcpm.fastmcp_integration.proxy import create_mcpm_proxy
1212
from mcpm.profile.profile_config import ProfileConfigManager
13-
from mcpm.utils.config import DEFAULT_SHARE_ADDRESS, DEFAULT_PORT
14-
from mcpm.utils.logging_config import setup_dependency_logging, ensure_dependency_logging_suppressed, get_uvicorn_log_level
13+
from mcpm.utils.config import DEFAULT_PORT, DEFAULT_SHARE_ADDRESS
14+
from mcpm.utils.logging_config import (
15+
ensure_dependency_logging_suppressed,
16+
get_uvicorn_log_level,
17+
setup_dependency_logging,
18+
)
1519

1620
console = Console()
1721
profile_config_manager = ProfileConfigManager()
@@ -42,6 +46,7 @@ async def share_profile_fastmcp(profile_servers, profile_name, port, address, ht
4246
api_key = None
4347
if not no_auth:
4448
from mcpm.utils.config import ConfigManager
49+
4550
config_manager = ConfigManager()
4651
auth_config = config_manager.get_auth_config()
4752
api_key = auth_config.get("api_key")
@@ -63,10 +68,10 @@ async def share_profile_fastmcp(profile_servers, profile_name, port, address, ht
6368
)
6469

6570
logger.debug(f"FastMCP proxy created with {server_count} server(s)")
66-
71+
6772
# Set up dependency logging for FastMCP/MCP libraries
6873
setup_dependency_logging()
69-
74+
7075
# Re-suppress library logging after FastMCP initialization
7176
ensure_dependency_logging_suppressed()
7277

@@ -79,7 +84,11 @@ async def share_profile_fastmcp(profile_servers, profile_name, port, address, ht
7984
logger.debug(f"Starting HTTP server on port {actual_port}")
8085

8186
# Start the FastMCP proxy as a streamable HTTP server in a background task
82-
server_task = asyncio.create_task(proxy.run_http_async(host="127.0.0.1", port=actual_port, uvicorn_config={"log_level": get_uvicorn_log_level()}))
87+
server_task = asyncio.create_task(
88+
proxy.run_http_async(
89+
host="127.0.0.1", port=actual_port, uvicorn_config={"log_level": get_uvicorn_log_level()}
90+
)
91+
)
8392

8493
# Wait a moment for server to start
8594
await asyncio.sleep(2)
@@ -113,17 +122,17 @@ async def share_profile_fastmcp(profile_servers, profile_name, port, address, ht
113122
http_url = f"{public_url}/mcp/"
114123
console.print(f"[bold green]Profile '{profile_name}' is now shared at:[/]")
115124
console.print(f"[cyan]{http_url}[/]")
116-
125+
117126
if not no_auth and api_key:
118127
console.print(f"[bold green]API Key:[/] [cyan]{api_key}[/]")
119128
else:
120129
console.print("[bold red]Warning:[/] Anyone with the URL can access your servers.")
121-
122-
# Show available servers
123-
console.print(f"[bold green]Shared servers:[/]")
130+
131+
# Show available servers
132+
console.print("[bold green]Shared servers:[/]")
124133
for server_config in profile_servers:
125134
console.print(f" • [cyan]{server_config.name}[/]")
126-
135+
127136
console.print("[dim]Press Ctrl+C to stop sharing[/]")
128137

129138
# Keep running until interrupted

src/mcpm/commands/run.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
from mcpm.fastmcp_integration.proxy import create_mcpm_proxy
1313
from mcpm.global_config import GlobalConfigManager
1414
from mcpm.utils.config import DEFAULT_PORT
15-
from mcpm.utils.logging_config import setup_dependency_logging, ensure_dependency_logging_suppressed, get_uvicorn_log_level
15+
from mcpm.utils.logging_config import (
16+
ensure_dependency_logging_suppressed,
17+
get_uvicorn_log_level,
18+
setup_dependency_logging,
19+
)
1620

1721
global_config_manager = GlobalConfigManager()
1822
logger = logging.getLogger(__name__)
@@ -98,10 +102,10 @@ async def run_server_with_fastmcp(server_config, server_name, http_mode=False, p
98102
name=f"mcpm-run-{server_name}",
99103
stdio_mode=not http_mode, # stdio_mode=False for HTTP
100104
)
101-
105+
102106
# Set up dependency logging for FastMCP/MCP libraries
103107
setup_dependency_logging()
104-
108+
105109
# Re-suppress library logging after FastMCP initialization
106110
ensure_dependency_logging_suppressed()
107111

@@ -116,11 +120,13 @@ async def run_server_with_fastmcp(server_config, server_name, http_mode=False, p
116120
console.print(f"[bold green]Server '{server_name}' is now running at:[/]")
117121
console.print(f"[cyan]{http_url}[/]")
118122
console.print("[dim]Press Ctrl+C to stop the server[/]")
119-
123+
120124
logger.debug(f"Starting FastMCP proxy for server '{server_name}' on port {actual_port}")
121125

122126
# Run FastMCP proxy in HTTP mode with uvicorn logging control
123-
await proxy.run_http_async(host="127.0.0.1", port=actual_port, uvicorn_config={"log_level": get_uvicorn_log_level()})
127+
await proxy.run_http_async(
128+
host="127.0.0.1", port=actual_port, uvicorn_config={"log_level": get_uvicorn_log_level()}
129+
)
124130
else:
125131
# Run FastMCP proxy in stdio mode (default)
126132
logger.info(f"Starting server '{server_name}' over stdio")

src/mcpm/commands/share.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
from mcpm.core.tunnel import Tunnel
1515
from mcpm.fastmcp_integration.proxy import create_mcpm_proxy
1616
from mcpm.global_config import GlobalConfigManager
17-
from mcpm.utils.config import DEFAULT_SHARE_ADDRESS, DEFAULT_PORT
18-
from mcpm.utils.logging_config import setup_dependency_logging, ensure_dependency_logging_suppressed, get_uvicorn_log_level
17+
from mcpm.utils.config import DEFAULT_PORT, DEFAULT_SHARE_ADDRESS
18+
from mcpm.utils.logging_config import (
19+
ensure_dependency_logging_suppressed,
20+
get_uvicorn_log_level,
21+
setup_dependency_logging,
22+
)
1923

2024
console = Console()
2125
global_config_manager = GlobalConfigManager()
@@ -49,7 +53,9 @@ async def find_available_port(preferred_port, max_attempts=10):
4953
return preferred_port
5054

5155

52-
async def start_fastmcp_proxy(server_config, server_name, port: Optional[int] = None, auth_enabled: bool = True, api_key: Optional[str] = None) -> int:
56+
async def start_fastmcp_proxy(
57+
server_config, server_name, port: Optional[int] = None, auth_enabled: bool = True, api_key: Optional[str] = None
58+
) -> int:
5359
"""
5460
Start FastMCP proxy in HTTP mode for sharing a single server.
5561
@@ -89,10 +95,10 @@ async def start_fastmcp_proxy(server_config, server_name, port: Optional[int] =
8995
)
9096

9197
logger.debug(f"FastMCP proxy ready on port {actual_port}")
92-
98+
9399
# Set up dependency logging for FastMCP/MCP libraries
94100
setup_dependency_logging()
95-
101+
96102
# Re-suppress library logging after FastMCP initialization
97103
ensure_dependency_logging_suppressed()
98104

@@ -182,6 +188,7 @@ async def _share_async(server_config, server_name, port, remote_host, remote_por
182188

183189
if not no_auth:
184190
from mcpm.utils.config import ConfigManager
191+
185192
config_manager = ConfigManager()
186193
auth_config = config_manager.get_auth_config()
187194
api_key = auth_config.get("api_key")
@@ -193,10 +200,14 @@ async def _share_async(server_config, server_name, port, remote_host, remote_por
193200
try:
194201
# Start FastMCP proxy
195202
logger.debug(f"Starting FastMCP proxy to share server '{server_name}'")
196-
actual_port, proxy = await start_fastmcp_proxy(server_config, server_name, port, auth_enabled=not no_auth, api_key=api_key)
203+
actual_port, proxy = await start_fastmcp_proxy(
204+
server_config, server_name, port, auth_enabled=not no_auth, api_key=api_key
205+
)
197206

198207
# Start the FastMCP proxy as an HTTP server in a background task
199-
server_task = asyncio.create_task(proxy.run_http_async(port=actual_port, uvicorn_config={"log_level": get_uvicorn_log_level()}))
208+
server_task = asyncio.create_task(
209+
proxy.run_http_async(port=actual_port, uvicorn_config={"log_level": get_uvicorn_log_level()})
210+
)
200211

201212
# Wait a moment for server to start
202213
await asyncio.sleep(2)
@@ -223,12 +234,12 @@ async def _share_async(server_config, server_name, port, remote_host, remote_por
223234
http_url = f"{share_url}/mcp/"
224235
console.print(f"[bold green]Server '{server_name}' is now shared at:[/]")
225236
console.print(f"[cyan]{http_url}[/]")
226-
237+
227238
if not no_auth and api_key:
228239
console.print(f"[bold green]API Key:[/] [cyan]{api_key}[/]")
229240
else:
230241
console.print("[bold red]Warning:[/] Anyone with the URL can access your server.")
231-
242+
232243
console.print("[dim]Press Ctrl+C to stop sharing[/]")
233244

234245
# Keep running until interrupted

src/mcpm/core/tunnel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,4 @@ def _raise_tunnel_error():
188188

189189
if self.http:
190190
url = url.replace("https://", "http://")
191-
return url
191+
return url

src/mcpm/fastmcp_integration/middleware.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,31 +115,32 @@ async def on_request(self, context, call_next):
115115
# Multiple approaches to get headers
116116
headers = None
117117
auth_header = None
118-
118+
119119
# Method 1: Try FastMCP's built-in helper
120120
try:
121121
from fastmcp.server.dependencies import get_http_headers
122+
122123
headers = get_http_headers()
123124
auth_header = headers.get("authorization") or headers.get("Authorization")
124125
except (RuntimeError, ImportError):
125126
pass
126-
127+
127128
# Method 2: Try accessing from context
128-
if not auth_header and hasattr(context, 'request'):
129+
if not auth_header and hasattr(context, "request"):
129130
request = context.request
130-
if hasattr(request, 'headers'):
131+
if hasattr(request, "headers"):
131132
auth_header = request.headers.get("Authorization") or request.headers.get("authorization")
132-
133+
133134
# Method 3: Try direct context headers
134-
if not auth_header and hasattr(context, 'headers'):
135+
if not auth_header and hasattr(context, "headers"):
135136
headers = context.headers
136137
auth_header = headers.get("Authorization") or headers.get("authorization")
137-
138+
138139
# Method 4: Check for auth in context metadata
139-
if not auth_header and hasattr(context, 'metadata'):
140+
if not auth_header and hasattr(context, "metadata"):
140141
metadata = context.metadata
141142
auth_header = metadata.get("authorization") or metadata.get("Authorization")
142-
143+
143144
if not auth_header:
144145
# For debugging: print available context attributes
145146
# print(f"DEBUG: Context type: {type(context)}, attrs: {dir(context)}")

0 commit comments

Comments
 (0)