forked from dheerajjha/mcp-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathr012_logging_set_level_removed.py
More file actions
45 lines (38 loc) · 2.16 KB
/
Copy pathr012_logging_set_level_removed.py
File metadata and controls
45 lines (38 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import re
from .base import Finding, Project, Rule, wire_method
# `SetLevelRequest`/`SetLevelRequestParams` are the MCP SDK's own model
# names for this request -- distinctive, no false-positive risk.
SET_LEVEL_CODE_RX = re.compile(r"\bSetLevelRequest(?:Params|Schema|Result|ResultSchema)?\b")
TS_SET_LEVEL_CODE_RX = re.compile(r"\bSetLevelRequest(?:Params|Schema|Result|ResultSchema)?\b")
SET_LEVEL_WIRE_RX = wire_method("logging/setLevel")
class LoggingSetLevelRemoved(Rule):
id = "R012"
title = "Implements the removed logging/setLevel request"
severity = "breaking"
spec_ref = "SEP-2575 https://modelcontextprotocol.io/specification/2026-07-28/changelog"
fix = (
"logging/setLevel is gone. Log level is now per-request: read it off "
"`_meta[\"io.modelcontextprotocol/logLevel\"]` on each incoming request instead "
"of tracking one process-wide level."
)
languages = ("python", "typescript")
CODE_MESSAGE = "References the removed SetLevelRequest / logging/setLevel handler."
WIRE_MESSAGE = "References the removed logging/setLevel JSON-RPC method."
def check(self, project: Project) -> list[Finding]:
if project.language == "typescript":
out: list[Finding] = []
for f, line, text in project.search_code(TS_SET_LEVEL_CODE_RX.pattern):
out.append(self.finding(self.CODE_MESSAGE, f, line, text))
for f, line, text in project.search_wire(SET_LEVEL_WIRE_RX):
out.append(self.finding(self.WIRE_MESSAGE, f, line, text))
return out
out: list[Finding] = []
for f, line, text in project.search_code(SET_LEVEL_CODE_RX.pattern):
out.append(self.finding(self.CODE_MESSAGE, f, line, text))
# `logging/setLevel` is a JSON-RPC method string, not a valid bare
# identifier -- like notifications/initialized in r009, it can only
# ever appear inside a STRING token, so search_code would never
# find it. Scan the raw text for the literal instead.
for f, line, text in project.search_wire(SET_LEVEL_WIRE_RX):
out.append(self.finding(self.WIRE_MESSAGE, f, line, text))
return out