Skip to content

Commit b1edc43

Browse files
committed
fix: validate transport, add lint+coverage to MCP CI job
- server.py: unknown transport now prints error and exits non-zero instead of silently falling back to stdio - .flake8: new config matching backend (bugs-only, 120 char lines) - ci.yml: MCP job now runs flake8 lint + pytest with --cov
1 parent dd040c4 commit b1edc43

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,21 @@ jobs:
126126
working-directory: ./mcp-server
127127
run: |
128128
python -m pip install --upgrade pip
129+
pip install pytest-cov flake8
129130
pip install -r requirements.txt
130131
132+
- name: Lint (flake8)
133+
working-directory: ./mcp-server
134+
run: |
135+
flake8 .
136+
131137
- name: Run tests
132138
working-directory: ./mcp-server
133139
env:
134140
API_KEY: "test-key"
135141
BACKEND_API_URL: "http://localhost:8000"
136142
run: |
137-
pytest tests/ -v
143+
pytest tests/ -v --cov=. --cov-report=term-missing
138144
139145
security-scan:
140146
name: Security Scan

mcp-server/.flake8

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[flake8]
2+
max-line-length = 120
3+
4+
# Match backend config: only check for real bugs, not style.
5+
select = E9,F,W6
6+
7+
exclude =
8+
.git,
9+
__pycache__,
10+
venv,
11+
.venv
12+
13+
per-file-ignores =
14+
# handlers.py imports formatters after logger (intentional grouping)
15+
handlers.py:E402
16+
# Test files may import pytest for fixtures/marks even if not directly referenced
17+
tests/*.py:F401

mcp-server/server.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def _get_http_app():
6969
return app
7070

7171

72+
_VALID_TRANSPORTS = {"stdio", "streamable-http", "http"}
73+
74+
7275
def main():
7376
"""Run with configured transport."""
7477
transport = TRANSPORT
@@ -77,8 +80,15 @@ def main():
7780
if "--transport" in sys.argv:
7881
idx = sys.argv.index("--transport")
7982
if idx + 1 < len(sys.argv):
80-
arg = sys.argv[idx + 1]
81-
transport = "streamable-http" if arg in ("http", "streamable-http") else arg
83+
transport = sys.argv[idx + 1]
84+
85+
# Normalize alias
86+
if transport == "http":
87+
transport = "streamable-http"
88+
89+
if transport not in ("stdio", "streamable-http"):
90+
print(f"Error: unknown transport '{transport}'. Use 'stdio' or 'http'.")
91+
sys.exit(1)
8292

8393
if transport == "streamable-http":
8494
import uvicorn

0 commit comments

Comments
 (0)