Skip to content

Commit 4997fb4

Browse files
committed
fix: resolve code formatting and linting issues
- Fix black formatting for server.py and test_custom_endpoints.py - Remove unused import (patch) from test file - Add noqa comment for acceptable long line in f-string - All linting checks now pass (black, isort, flake8) - Tests still passing (92 passed, 2 skipped, 96% coverage)
1 parent 1057750 commit 4997fb4

File tree

2 files changed

+71
-72
lines changed

2 files changed

+71
-72
lines changed

src/kong_mcp_server/server.py

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,24 @@
1818
@mcp.custom_route("/api", methods=["GET"])
1919
async def api_discovery(request: Request) -> JSONResponse:
2020
"""Standard MCP API discovery endpoint."""
21-
return JSONResponse({
22-
"name": "Kong Rate Limiter MCP Server",
23-
"version": "0.1.2",
24-
"protocol_version": "2025-06-18",
25-
"capabilities": {
26-
"tools": True,
27-
"resources": False,
28-
"prompts": False,
29-
"sampling": False
30-
},
31-
"endpoints": {
32-
"sse": "/sse/",
33-
"ping": "/sse/ping",
34-
"request": "/sse/request"
21+
return JSONResponse(
22+
{
23+
"name": "Kong Rate Limiter MCP Server",
24+
"version": "0.1.2",
25+
"protocol_version": "2025-06-18",
26+
"capabilities": {
27+
"tools": True,
28+
"resources": False,
29+
"prompts": False,
30+
"sampling": False,
31+
},
32+
"endpoints": {
33+
"sse": "/sse/",
34+
"ping": "/sse/ping",
35+
"request": "/sse/request",
36+
},
3537
}
36-
})
38+
)
3739

3840

3941
@mcp.custom_route("/apis", methods=["GET"])
@@ -45,52 +47,53 @@ async def apis_discovery(request: Request) -> JSONResponse:
4547
@mcp.custom_route("/sse/ping", methods=["GET", "POST"])
4648
async def sse_ping(request: Request) -> JSONResponse:
4749
"""SSE ping endpoint for health checks."""
48-
return JSONResponse({
49-
"jsonrpc": "2.0",
50-
"method": "ping",
51-
"result": {
52-
"status": "ok",
53-
"timestamp": time.time()
50+
return JSONResponse(
51+
{
52+
"jsonrpc": "2.0",
53+
"method": "ping",
54+
"result": {"status": "ok", "timestamp": time.time()},
5455
}
55-
})
56+
)
5657

5758

5859
@mcp.custom_route("/sse/request", methods=["POST"])
5960
async def sse_request(request: Request) -> JSONResponse:
6061
"""SSE request endpoint for MCP JSON-RPC messages."""
6162
try:
6263
body = await request.json()
63-
64+
6465
# Handle tool calls
6566
if body.get("method") == "tools/call":
6667
tool_name = body.get("params", {}).get("name")
6768
if tool_name:
68-
return JSONResponse({
69-
"jsonrpc": "2.0",
70-
"id": body.get("id"),
71-
"result": {
72-
"content": [
73-
{"type": "text", "text": f"Tool {tool_name} executed via SSE request"}
74-
]
69+
return JSONResponse(
70+
{
71+
"jsonrpc": "2.0",
72+
"id": body.get("id"),
73+
"result": {
74+
"content": [
75+
{
76+
"type": "text",
77+
"text": f"Tool {tool_name} executed via SSE request", # noqa: E501
78+
}
79+
]
80+
},
7581
}
76-
})
77-
82+
)
83+
7884
# Default response for other requests
79-
return JSONResponse({
80-
"jsonrpc": "2.0",
81-
"id": body.get("id"),
82-
"result": {"status": "received"}
83-
})
84-
85+
return JSONResponse(
86+
{"jsonrpc": "2.0", "id": body.get("id"), "result": {"status": "received"}}
87+
)
88+
8589
except Exception as e:
86-
return JSONResponse({
87-
"jsonrpc": "2.0",
88-
"error": {
89-
"code": -32603,
90-
"message": "Internal error",
91-
"data": str(e)
92-
}
93-
}, status_code=500)
90+
return JSONResponse(
91+
{
92+
"jsonrpc": "2.0",
93+
"error": {"code": -32603, "message": "Internal error", "data": str(e)},
94+
},
95+
status_code=500,
96+
)
9497

9598

9699
def load_tools_config() -> Dict[str, Any]:

tests/test_custom_endpoints.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests for custom MCP endpoints added to the server."""
22

33
import json
4-
from unittest.mock import Mock, patch
4+
from unittest.mock import Mock
55

66
import pytest
77
from starlette.requests import Request
@@ -15,10 +15,10 @@ async def test_api_discovery():
1515
"""Test /api discovery endpoint."""
1616
request = Mock(spec=Request)
1717
response = await api_discovery(request)
18-
18+
1919
assert isinstance(response, JSONResponse)
2020
assert response.status_code == 200
21-
21+
2222
# Parse response body
2323
body = json.loads(response.body)
2424
assert body["name"] == "Kong Rate Limiter MCP Server"
@@ -33,7 +33,7 @@ async def test_apis_discovery():
3333
"""Test /apis alternative discovery endpoint."""
3434
request = Mock(spec=Request)
3535
response = await apis_discovery(request)
36-
36+
3737
# Should be identical to api_discovery
3838
api_response = await api_discovery(request)
3939
assert response.body == api_response.body
@@ -44,10 +44,10 @@ async def test_sse_ping():
4444
"""Test /sse/ping endpoint."""
4545
request = Mock(spec=Request)
4646
response = await sse_ping(request)
47-
47+
4848
assert isinstance(response, JSONResponse)
4949
assert response.status_code == 200
50-
50+
5151
body = json.loads(response.body)
5252
assert body["jsonrpc"] == "2.0"
5353
assert body["method"] == "ping"
@@ -59,21 +59,17 @@ async def test_sse_ping():
5959
async def test_sse_request_default():
6060
"""Test /sse/request endpoint with default request."""
6161
request = Mock(spec=Request)
62-
62+
6363
async def mock_json():
64-
return {
65-
"jsonrpc": "2.0",
66-
"method": "test_method",
67-
"id": 1
68-
}
69-
64+
return {"jsonrpc": "2.0", "method": "test_method", "id": 1}
65+
7066
request.json = mock_json
71-
67+
7268
response = await sse_request(request)
73-
69+
7470
assert isinstance(response, JSONResponse)
7571
assert response.status_code == 200
76-
72+
7773
body = json.loads(response.body)
7874
assert body["jsonrpc"] == "2.0"
7975
assert body["id"] == 1
@@ -84,22 +80,22 @@ async def mock_json():
8480
async def test_sse_request_tool_call():
8581
"""Test /sse/request endpoint with tool call."""
8682
request = Mock(spec=Request)
87-
83+
8884
async def mock_json():
8985
return {
9086
"jsonrpc": "2.0",
9187
"method": "tools/call",
9288
"params": {"name": "test_tool"},
93-
"id": 1
89+
"id": 1,
9490
}
95-
91+
9692
request.json = mock_json
97-
93+
9894
response = await sse_request(request)
99-
95+
10096
assert isinstance(response, JSONResponse)
10197
assert response.status_code == 200
102-
98+
10399
body = json.loads(response.body)
104100
assert body["jsonrpc"] == "2.0"
105101
assert body["id"] == 1
@@ -112,13 +108,13 @@ async def test_sse_request_error_handling():
112108
"""Test /sse/request endpoint error handling."""
113109
request = Mock(spec=Request)
114110
request.json = Mock(side_effect=Exception("Invalid JSON"))
115-
111+
116112
response = await sse_request(request)
117-
113+
118114
assert isinstance(response, JSONResponse)
119115
assert response.status_code == 500
120-
116+
121117
body = json.loads(response.body)
122118
assert body["jsonrpc"] == "2.0"
123119
assert "error" in body
124-
assert body["error"]["code"] == -32603
120+
assert body["error"]["code"] == -32603

0 commit comments

Comments
 (0)