Skip to content

Commit a4da230

Browse files
committed
Fix UrlRedactingFilter to keep arguments the type that they are + only filter out *mcp.gumloop.com* URLs
1 parent cd643c9 commit a4da230

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "gumloop-mcp"
3-
version = "0.1.13"
3+
version = "0.1.14"
44
description = "guMCP (Gumloop Model Context Protocol) SDK"
55
readme = "README.md"
66
requires-python = ">=3.10"

src/mcp/shared/logging_utils.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,58 @@
99

1010
class UrlRedactingFilter(logging.Filter):
1111
"""Redacts URLs in log messages to prevent credential leaks."""
12-
13-
URL_PATTERN = re.compile(r'https?://[^\s]+')
14-
12+
13+
# Matches http/https, optional subdomains, mcp.gumloop.com, and the rest of the path
14+
# (?:[a-zA-Z0-9-]+\.)* matches optional subdomains before mcp.gumloop.com
15+
URL_PATTERN = re.compile(r"https?://(?:[a-zA-Z0-9-]+\.)*mcp\.gumloop\.com[^\s]*")
16+
1517
@staticmethod
1618
def _redact_url(match):
1719
"""Redact a URL to only show scheme and netloc."""
1820
url = match.group(0)
1921
parsed = urlparse(url)
2022
return f"{parsed.scheme}://{parsed.netloc}"
21-
23+
2224
def filter(self, record: logging.LogRecord) -> bool:
2325
if isinstance(record.msg, str):
2426
record.msg = self.URL_PATTERN.sub(self._redact_url, record.msg)
25-
27+
2628
if record.args:
2729
if isinstance(record.args, dict):
28-
record.args = {
29-
k: self.URL_PATTERN.sub(self._redact_url, str(v))
30-
for k, v in record.args.items()
31-
}
30+
new_args = {}
31+
for k, v in record.args.items():
32+
if isinstance(v, str):
33+
new_args[k] = self.URL_PATTERN.sub(self._redact_url, v)
34+
else:
35+
new_args[k] = v
36+
record.args = new_args
3237
else:
3338
record.args = tuple(
34-
self.URL_PATTERN.sub(self._redact_url, str(arg))
39+
(
40+
self.URL_PATTERN.sub(self._redact_url, arg)
41+
if isinstance(arg, str)
42+
else arg
43+
)
3544
for arg in record.args
3645
)
37-
46+
3847
# Sanitize exception info if present
3948
if record.exc_info and record.exc_info[1]:
4049
exc = record.exc_info[1]
41-
if hasattr(exc, 'args') and exc.args:
50+
if hasattr(exc, "args") and exc.args:
4251
redacted_args = tuple(
43-
self.URL_PATTERN.sub(self._redact_url, str(arg)) if isinstance(arg, str) else arg
52+
(
53+
self.URL_PATTERN.sub(self._redact_url, arg)
54+
if isinstance(arg, str)
55+
else arg
56+
)
4457
for arg in exc.args
4558
)
4659
exc.args = redacted_args
47-
60+
4861
return True
4962

5063

5164
def redact_url_logs(logger: logging.Logger) -> None:
5265
"""Add URL redacting filter to logger to strip paths and credentials from URLs."""
5366
logger.addFilter(UrlRedactingFilter())
54-

0 commit comments

Comments
 (0)