Skip to content

Commit 76b4c8e

Browse files
committed
linting
1 parent f29df0f commit 76b4c8e

File tree

2 files changed

+6
-63
lines changed

2 files changed

+6
-63
lines changed

mcpgateway/schemas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def assemble_auth(cls, values: Dict[str, Any]) -> Dict[str, Any]:
319319
auth_type = values.get("auth_type")
320320
if auth_type:
321321
if auth_type.lower() == "basic":
322-
creds = base64.b64encode(f'{values.get("auth_username", "")}:{values.get("auth_password", "")}'.encode("utf-8")).decode()
322+
creds = base64.b64encode(f"{values.get('auth_username', '')}:{values.get('auth_password', '')}".encode("utf-8")).decode()
323323
encoded_auth = encode_auth({"Authorization": f"Basic {creds}"})
324324
values["auth"] = {"auth_type": "basic", "auth_value": encoded_auth}
325325
elif auth_type.lower() == "bearer":
@@ -378,7 +378,7 @@ def assemble_auth(cls, values: Dict[str, Any]) -> Dict[str, Any]:
378378
auth_type = values.get("auth_type")
379379
if auth_type:
380380
if auth_type.lower() == "basic":
381-
creds = base64.b64encode(f'{values.get("auth_username", "")}:{values.get("auth_password", "")}'.encode("utf-8")).decode()
381+
creds = base64.b64encode(f"{values.get('auth_username', '')}:{values.get('auth_password', '')}".encode("utf-8")).decode()
382382
encoded_auth = encode_auth({"Authorization": f"Basic {creds}"})
383383
values["auth"] = {"auth_type": "basic", "auth_value": encoded_auth}
384384
elif auth_type.lower() == "bearer":

mcpgateway/transports/streamablehttp_transport.py

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from typing import List, Union
2626
from uuid import uuid4
2727

28-
import mcp.types as types
28+
from mcp import types
2929
from fastapi.security.utils import get_authorization_scheme_param
3030
from mcp.server.lowlevel import Server
3131
from mcp.server.streamable_http import (
@@ -38,7 +38,6 @@
3838
from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
3939
from mcp.types import JSONRPCMessage
4040
from starlette.datastructures import Headers
41-
from starlette.middleware.base import BaseHTTPMiddleware
4241
from starlette.responses import JSONResponse
4342
from starlette.status import HTTP_401_UNAUTHORIZED
4443
from starlette.types import Receive, Scope, Send
@@ -201,15 +200,15 @@ async def list_tools() -> List[types.Tool]:
201200
tools = await tool_service.list_server_tools(db, server_id)
202201
return [types.Tool(name=tool.name, description=tool.description, inputSchema=tool.input_schema) for tool in tools]
203202
except Exception as e:
204-
logger.exception("Error listing tools")
203+
logger.exception(f"Error listing tools:{e}")
205204
return []
206205
else:
207206
try:
208207
async with get_db() as db:
209208
tools = await tool_service.list_tools(db)
210209
return [types.Tool(name=tool.name, description=tool.description, inputSchema=tool.input_schema) for tool in tools]
211210
except Exception as e:
212-
logger.exception("Error listing tools")
211+
logger.exception(f"Error listing tools:{e}")
213212
return []
214213

215214

@@ -274,68 +273,12 @@ async def handle_streamable_http(self, scope: Scope, receive: Receive, send: Sen
274273
try:
275274
await self.session_manager.handle_request(scope, receive, send)
276275
except Exception as e:
277-
logger.exception("Error handling streamable HTTP request")
276+
logger.exception(f"Error handling streamable HTTP request: {e}")
278277
raise
279278

280279

281280
## ------------------------- Authentication for /mcp routes ------------------------------
282281

283-
# async def streamable_http_auth(scope, receive, send):
284-
# """
285-
# Perform authentication check in middleware context (ASGI scope).
286-
287-
# If path does not end with "/mcp", just continue (return True).
288-
289-
# If auth fails, sends 401 JSONResponse and returns False.
290-
291-
# If auth succeeds or not required, returns True.
292-
# """
293-
294-
# path = scope.get("path", "")
295-
# if not path.endswith("/mcp"):
296-
# # No auth needed for other paths in this middleware usage
297-
# return True
298-
299-
# headers = Headers(scope=scope)
300-
# authorization = headers.get("authorization")
301-
# cookie_header = headers.get("cookie", "")
302-
303-
# token = None
304-
# if authorization:
305-
# scheme, credentials = get_authorization_scheme_param(authorization)
306-
# if scheme.lower() == "bearer" and credentials:
307-
# token = credentials
308-
309-
# if not token:
310-
# # parse cookie header manually
311-
# for cookie in cookie_header.split(";"):
312-
# if cookie.strip().startswith("jwt_token="):
313-
# token = cookie.strip().split("=", 1)[1]
314-
# break
315-
316-
# if settings.auth_required and not token:
317-
# response = JSONResponse(
318-
# {"detail": "Not authenticated"},
319-
# status_code=HTTP_401_UNAUTHORIZED,
320-
# headers={"WWW-Authenticate": "Bearer"},
321-
# )
322-
# await response(scope, receive, send)
323-
# return False
324-
325-
# if token:
326-
# try:
327-
# await verify_credentials(token)
328-
# except Exception:
329-
# response = JSONResponse(
330-
# {"detail": "Authentication failed"},
331-
# status_code=HTTP_401_UNAUTHORIZED,
332-
# headers={"WWW-Authenticate": "Bearer"},
333-
# )
334-
# await response(scope, receive, send)
335-
# return False
336-
337-
# return True
338-
339282

340283
async def streamable_http_auth(scope, receive, send):
341284
"""

0 commit comments

Comments
 (0)