Skip to content

Commit a50bc9e

Browse files
ChrisPC-39Sebastiancrivetimihai
authored
Flake8 and lint files (#500)
* Add classmethods in db.py Signed-off-by: Sebastian <[email protected]> * flake8 mcpgateway/models.py and mcpgateway/schemas.py Signed-off-by: Sebastian <[email protected]> * Pylint mcpgateway/bootstrap_db.py Signed-off-by: Sebastian <[email protected]> * Pylint mcpgateway/services/tool_service.py Signed-off-by: Sebastian <[email protected]> * flake8 mcpgateway/services/tool_service.py Signed-off-by: Sebastian <[email protected]> * lint Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: Sebastian <[email protected]> Signed-off-by: Mihai Criveti <[email protected]> Co-authored-by: Sebastian <[email protected]> Co-authored-by: Mihai Criveti <[email protected]>
1 parent 8663b17 commit a50bc9e

File tree

6 files changed

+30
-19
lines changed

6 files changed

+30
-19
lines changed

mcpgateway/db.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ def name(self, value):
402402
self._computed_name = value
403403

404404
@name.expression
405-
def name(cls): # pylint: disable=no-self-argument
405+
@classmethod
406+
def name(cls):
406407
"""
407408
SQL expression used when the hybrid appears in a filter/order_by.
408409
Simply forwards to the ``_computed_name`` column; the Python-side
@@ -425,7 +426,8 @@ def gateway_slug(self):
425426
return self.gateway.slug if self.gateway else None
426427

427428
@gateway_slug.expression
428-
def gateway_slug(cls): # pylint: disable=no-self-argument
429+
@classmethod
430+
def gateway_slug(cls):
429431
"""For database queries - auto-joins to get current slug
430432
431433
Returns:
@@ -445,8 +447,7 @@ def execution_count(self) -> int:
445447
return len(self.metrics)
446448

447449
@execution_count.expression
448-
# method is intentionally a class-level expression, so no `self`
449-
# pylint: disable=no-self-argument
450+
@classmethod
450451
def execution_count(cls):
451452
"""
452453
SQL expression to compute the execution count for the tool.

mcpgateway/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ class Tool(BaseModel):
388388
name: str
389389
url: AnyHttpUrl
390390
description: Optional[str] = None
391-
integrationType: str = "MCP"
392-
requestType: str = "SSE"
391+
integration_type: str = "MCP"
392+
request_type: str = "SSE"
393393
headers: Dict[str, Any] = Field(default_factory=dict)
394394
input_schema: Dict[str, Any] = Field(default_factory=lambda: {"type": "object", "properties": {}})
395395
annotations: Optional[Dict[str, Any]] = Field(default_factory=dict, description="Tool annotations for behavior hints")

mcpgateway/schemas.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ def validate_request_type(cls, v: str, info: ValidationInfo) -> str:
421421
return v
422422

423423
@model_validator(mode="before")
424+
@classmethod
424425
def assemble_auth(cls, values: Dict[str, Any]) -> Dict[str, Any]:
425426
"""
426427
Assemble authentication information from separate keys if provided.
@@ -566,6 +567,7 @@ def validate_request_type(cls, v: str, values: Dict[str, Any]) -> str:
566567
return v
567568

568569
@model_validator(mode="before")
570+
@classmethod
569571
def assemble_auth(cls, values: Dict[str, Any]) -> Dict[str, Any]:
570572
"""
571573
Assemble authentication information from separate keys if provided.
@@ -1253,6 +1255,7 @@ def validate_description(cls, v: Optional[str]) -> Optional[str]:
12531255
return SecurityValidator.sanitize_display_text(v, "Description")
12541256

12551257
@field_validator("auth_value", mode="before")
1258+
@classmethod
12561259
def create_auth_value(cls, v, info):
12571260
"""
12581261
This validator will run before the model is fully instantiated (mode="before")
@@ -1397,6 +1400,7 @@ def validate_description(cls, v: Optional[str]) -> Optional[str]:
13971400
return SecurityValidator.sanitize_display_text(v, "Description")
13981401

13991402
@field_validator("auth_value", mode="before")
1403+
@classmethod
14001404
def create_auth_value(cls, v, info):
14011405
"""
14021406
This validator will run before the model is fully instantiated (mode="before")
@@ -1773,6 +1777,7 @@ class AdminToolCreate(BaseModelWithConfigDict):
17731777
input_schema: Optional[str] = None # JSON string
17741778

17751779
@field_validator("headers", "input_schema")
1780+
@classmethod
17761781
def validate_json(cls, v: Optional[str]) -> Optional[Dict[str, Any]]:
17771782
"""
17781783
Validate and parse JSON string inputs.
@@ -1910,6 +1915,7 @@ def validate_icon(cls, v: Optional[str]) -> Optional[str]:
19101915
return SecurityValidator.validate_url(v, "Icon URL")
19111916

19121917
@field_validator("associated_tools", "associated_resources", "associated_prompts", mode="before")
1918+
@classmethod
19131919
def split_comma_separated(cls, v):
19141920
"""
19151921
Splits a comma-separated string into a list of strings if needed.
@@ -1987,6 +1993,7 @@ def validate_icon(cls, v: Optional[str]) -> Optional[str]:
19871993
return SecurityValidator.validate_url(v, "Icon URL")
19881994

19891995
@field_validator("associated_tools", "associated_resources", "associated_prompts", mode="before")
1996+
@classmethod
19901997
def split_comma_separated(cls, v):
19911998
"""
19921999
Splits a comma-separated string into a list of strings if needed.
@@ -2026,6 +2033,7 @@ class ServerRead(BaseModelWithConfigDict):
20262033
metrics: ServerMetrics
20272034

20282035
@model_validator(mode="before")
2036+
@classmethod
20292037
def populate_associated_ids(cls, values):
20302038
"""
20312039
Pre-validation method that converts associated objects to their 'id'.

mcpgateway/services/tool_service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ async def register_tool(self, db: Session, tool: ToolCreate) -> ToolRead:
229229
if not tool.gateway_id:
230230
existing_tool = db.execute(select(DbTool).where(DbTool.name == tool.name)).scalar_one_or_none()
231231
else:
232-
existing_tool = db.execute(select(DbTool).where(DbTool.name == tool.name).where(DbTool.gateway_id == tool.gateway_id)).scalar_one_or_none()
232+
existing_tool = db.execute(select(DbTool).where(DbTool.name == tool.name).where(DbTool.gateway_id == tool.gateway_id)).scalar_one_or_none() # pylint: disable=comparison-with-callable
233233
if existing_tool:
234234
raise ToolNameConflictError(
235235
existing_tool.name,
@@ -506,6 +506,7 @@ async def invoke_tool(self, db: Session, name: str, arguments: Dict[str, Any]) -
506506
>>> isinstance(result, object)
507507
True
508508
"""
509+
# pylint: disable=comparison-with-callable
509510
tool = db.execute(select(DbTool).where(DbTool.name == name).where(DbTool.enabled)).scalar_one_or_none()
510511
if not tool:
511512
inactive_tool = db.execute(select(DbTool).where(DbTool.name == name).where(not_(DbTool.enabled))).scalar_one_or_none()
@@ -674,6 +675,7 @@ async def update_tool(self, db: Session, tool_id: str, tool_update: ToolUpdate)
674675
if not tool:
675676
raise ToolNotFoundError(f"Tool not found: {tool_id}")
676677
if tool_update.name is not None and not (tool_update.name == tool.name and tool_update.gateway_id == tool.gateway_id):
678+
# pylint: disable=comparison-with-callable
677679
existing_tool = db.execute(select(DbTool).where(DbTool.name == tool_update.name).where(DbTool.gateway_id == tool_update.gateway_id).where(DbTool.id != tool_id)).scalar_one_or_none()
678680
if existing_tool:
679681
raise ToolNameConflictError(

tests/unit/mcpgateway/test_models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ def test_tool(self):
534534
name="example-tool",
535535
url="http://localhost:8000/tool",
536536
description="An example tool",
537-
integrationType="MCP",
538-
requestType="SSE",
537+
integration_type="MCP",
538+
request_type="SSE",
539539
headers={"Content-Type": "application/json"},
540540
input_schema={"type": "object", "properties": {"query": {"type": "string"}}},
541541
auth_type="bearer",
@@ -544,8 +544,8 @@ def test_tool(self):
544544
assert tool.name == "example-tool"
545545
assert str(tool.url) == "http://localhost:8000/tool"
546546
assert tool.description == "An example tool"
547-
assert tool.integrationType == "MCP"
548-
assert tool.requestType == "SSE"
547+
assert tool.integration_type == "MCP"
548+
assert tool.request_type == "SSE"
549549
assert tool.headers == {"Content-Type": "application/json"}
550550
assert tool.input_schema == {"type": "object", "properties": {"query": {"type": "string"}}}
551551
assert tool.auth_type == "bearer"
@@ -559,8 +559,8 @@ def test_tool(self):
559559
assert minimal.name == "minimal-tool"
560560
assert str(minimal.url) == "http://localhost:8000/minimal"
561561
assert minimal.description is None
562-
assert minimal.integrationType == "MCP" # Default value
563-
assert minimal.requestType == "SSE" # Default value
562+
assert minimal.integration_type == "MCP" # Default value
563+
assert minimal.request_type == "SSE" # Default value
564564
assert minimal.headers == {} # Default value
565565
assert minimal.input_schema == {"type": "object", "properties": {}} # Default value
566566
assert minimal.auth_type is None

tests/unit/mcpgateway/test_schemas.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ def test_tool(self):
548548
name="example-tool",
549549
url="http://localhost:8000/tool",
550550
description="An example tool",
551-
integrationType="MCP",
552-
requestType="SSE",
551+
integration_type="MCP",
552+
request_type="SSE",
553553
headers={"Content-Type": "application/json"},
554554
input_schema={"type": "object", "properties": {"query": {"type": "string"}}},
555555
auth_type="bearer",
@@ -558,8 +558,8 @@ def test_tool(self):
558558
assert tool.name == "example-tool"
559559
assert str(tool.url) == "http://localhost:8000/tool"
560560
assert tool.description == "An example tool"
561-
assert tool.integrationType == "MCP"
562-
assert tool.requestType == "SSE"
561+
assert tool.integration_type == "MCP"
562+
assert tool.request_type == "SSE"
563563
assert tool.headers == {"Content-Type": "application/json"}
564564
assert tool.input_schema == {"type": "object", "properties": {"query": {"type": "string"}}}
565565
assert tool.auth_type == "bearer"
@@ -573,8 +573,8 @@ def test_tool(self):
573573
assert minimal.name == "minimal-tool"
574574
assert str(minimal.url) == "http://localhost:8000/minimal"
575575
assert minimal.description is None
576-
assert minimal.integrationType == "MCP" # Default value
577-
assert minimal.requestType == "SSE" # Default value
576+
assert minimal.integration_type == "MCP" # Default value
577+
assert minimal.request_type == "SSE" # Default value
578578
assert minimal.headers == {} # Default value
579579
assert minimal.input_schema == {"type": "object", "properties": {}} # Default value
580580
assert minimal.auth_type is None

0 commit comments

Comments
 (0)