Skip to content

Commit 0cb91bf

Browse files
committed
Rebased
Signed-off-by: Mihai Criveti <[email protected]>
1 parent 5090875 commit 0cb91bf

File tree

9 files changed

+41
-651
lines changed

9 files changed

+41
-651
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""merge passthrough headers and tags support
2+
3+
Revision ID: eb17fd368f9d
4+
Revises: 3b17fdc40a8d, cc7b95fec5d9
5+
Create Date: 2025-08-08 05:31:10.857718
6+
7+
"""
8+
9+
# Standard
10+
from typing import Sequence, Union
11+
12+
# revision identifiers, used by Alembic.
13+
revision: str = "eb17fd368f9d"
14+
down_revision: Union[str, Sequence[str], None] = ("3b17fdc40a8d", "cc7b95fec5d9")
15+
branch_labels: Union[str, Sequence[str], None] = None
16+
depends_on: Union[str, Sequence[str], None] = None
17+
18+
19+
def upgrade() -> None:
20+
"""Upgrade schema."""
21+
22+
23+
def downgrade() -> None:
24+
"""Downgrade schema."""

mcpgateway/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ class Gateway(Base):
11131113
reachable: Mapped[bool] = mapped_column(default=True)
11141114
last_seen: Mapped[Optional[datetime]]
11151115
tags: Mapped[List[str]] = mapped_column(JSON, default=list, nullable=False)
1116-
1116+
11171117
# Header passthrough configuration
11181118
passthrough_headers: Mapped[Optional[List[str]]] = mapped_column(JSON, nullable=True) # Store list of strings as JSON array
11191119

mcpgateway/services/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Gateway coordination
1313
"""
1414

15+
# First-Party
1516
from mcpgateway.services.gateway_service import GatewayError, GatewayService
1617
from mcpgateway.services.prompt_service import PromptError, PromptService
1718
from mcpgateway.services.resource_service import ResourceError, ResourceService

mcpgateway/services/tool_service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,9 @@ async def register_tool(self, db: Session, tool: ToolCreate) -> ToolRead:
333333
except Exception as ex:
334334
raise ToolError(f"Failed to register tool: {str(ex)}")
335335

336-
async def list_tools(self, db: Session, include_inactive: bool = False, cursor: Optional[str] = None, tags: Optional[List[str]] = None, request_headers: Optional[Dict[str, str]] = None) -> List[ToolRead]:
336+
async def list_tools(
337+
self, db: Session, include_inactive: bool = False, cursor: Optional[str] = None, tags: Optional[List[str]] = None, request_headers: Optional[Dict[str, str]] = None
338+
) -> List[ToolRead]:
337339
"""
338340
Retrieve a list of registered tools from the database.
339341

tests/unit/mcpgateway/services/test_tag_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ async def test_update_stats(tag_service):
411411

412412
# Test invalid entity type (should not crash or increment)
413413
tag_service._update_stats(stats, "invalid")
414-
assert stats.total == 5 # Should remain unchanged
414+
assert stats.total == 5 # Should remain unmodified
415415

416416

417417
@pytest.mark.asyncio

tests/unit/mcpgateway/utils/test_passthrough_headers.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ def test_authorization_conflict_basic_auth(self, caplog):
9999

100100
# Authorization should be blocked, X-Tenant-Id should pass through
101101
expected = {
102-
"Content-Type": "application/json",
102+
"Content-Type": "application/json",
103103
"X-Tenant-Id": "acme-corp"
104104
}
105105
assert result == expected
106-
106+
107107
# Check warning was logged
108-
assert any("Skipping Authorization header passthrough due to basic auth" in record.message
108+
assert any("Skipping Authorization header passthrough due to basic auth" in record.message
109109
for record in caplog.records)
110110

111111
def test_authorization_conflict_bearer_auth(self, caplog):
@@ -158,7 +158,7 @@ def test_base_header_conflict_prevention(self, caplog):
158158
assert result == expected
159159

160160
# Check conflict warning was logged
161-
assert any("conflicts with pre-defined headers" in record.message
161+
assert any("conflicts with pre-defined headers" in record.message
162162
for record in caplog.records)
163163

164164
def test_case_insensitive_header_matching(self):
@@ -170,7 +170,7 @@ def test_case_insensitive_header_matching(self):
170170

171171
# Request headers are expected to be normalized to lowercase
172172
request_headers = {
173-
"x-tenant-id": "mixed-case-value", # Lowercase key
173+
"x-tenant-id": "mixed-case-value", # Lowercase key
174174
"authorization": "bearer lowercase-header"
175175
}
176176
base_headers = {}
@@ -237,7 +237,7 @@ def test_none_allowed_headers(self):
237237
# Mock settings fallback
238238
with patch('mcpgateway.utils.passthrough_headers.settings') as mock_settings:
239239
mock_settings.default_passthrough_headers = ["X-Default"]
240-
240+
241241
result = get_passthrough_headers(request_headers, base_headers, mock_db)
242242

243243
# Should fall back to settings, but request doesn't have X-Default
@@ -255,7 +255,7 @@ def test_no_global_config_fallback_to_settings(self):
255255
# Mock settings fallback
256256
with patch('mcpgateway.utils.passthrough_headers.settings') as mock_settings:
257257
mock_settings.default_passthrough_headers = ["X-Default"]
258-
258+
259259
result = get_passthrough_headers(request_headers, base_headers, mock_db)
260260

261261
expected = {
@@ -311,7 +311,7 @@ def test_base_headers_not_modified(self):
311311

312312
# Original base_headers should not be modified
313313
assert base_headers == original_base
314-
314+
315315
# Result should include both base and passthrough headers
316316
assert "Content-Type" in result
317317
assert "X-Tenant-Id" in result
@@ -328,7 +328,7 @@ def test_multiple_auth_type_conflicts(self, caplog):
328328

329329
# Test with different auth types
330330
auth_types = ["basic", "bearer", "api-key", None]
331-
331+
332332
for auth_type in auth_types:
333333
caplog.clear()
334334
mock_gateway = Mock(spec=DbGateway)
@@ -418,8 +418,8 @@ def test_logging_levels(self, caplog):
418418

419419
# Should have warnings for: missing header, auth conflict, base header conflict
420420
warning_messages = [record.message for record in caplog.records if record.levelno == logging.WARNING]
421-
421+
422422
assert len(warning_messages) == 3
423423
assert any("not found in request headers" in msg for msg in warning_messages)
424424
assert any("due to basic auth" in msg for msg in warning_messages)
425-
assert any("conflicts with pre-defined headers" in msg for msg in warning_messages)
425+
assert any("conflicts with pre-defined headers" in msg for msg in warning_messages)

todo/before.md

Lines changed: 0 additions & 227 deletions
This file was deleted.

0 commit comments

Comments
 (0)