refactor(mcp): restore E305 spacing after squeeze

This commit is contained in:
Teknium
2026-09-02 16:01:37 -07:00
parent d9f6d9eda0
commit 410e95e100
4 changed files with 13 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ class _OriginProxy:
return getattr(mcp_tool, name)
_core = _OriginProxy()
_MISSING = object()
@@ -41,6 +42,7 @@ def mcp_field(obj, snake: str, camel: str, default=None):
value = getattr(obj, camel, _MISSING)
return default if value is _MISSING else value
_DEFAULT_TOOL_TIMEOUT = 300 # seconds for tool calls
@@ -61,6 +63,7 @@ def _resolve_tool_timeout(config: dict) -> float:
logger.debug("mcp.tool_call timeout resolution failed", exc_info=True)
return _DEFAULT_TOOL_TIMEOUT
# Jitter on reconnect backoff so servers that lost the same backend don't
# retry in lockstep (thundering herd, synchronized log bursts).
_BACKOFF_JITTER = 0.2 # +/-20%
@@ -70,6 +73,7 @@ def _jittered(seconds: float) -> float:
"""``seconds`` with +/-20% uniform jitter, floored at 0."""
return max(0.0, seconds * random.uniform(1.0 - _BACKOFF_JITTER, 1.0 + _BACKOFF_JITTER))
# Credential patterns to strip from error messages.
_CREDENTIAL_PATTERN = re.compile(
r"(?:"
@@ -131,6 +135,7 @@ def _safe_numeric(value, default, coerce=int, minimum=1):
except (TypeError, ValueError, OverflowError):
return default
_TRUE_WORDS = frozenset({"true", "1", "yes", "on"})
_FALSE_WORDS = frozenset({"false", "0", "no", "off"})

View File

@@ -55,6 +55,7 @@ def _write_stderr_log_header(server_name: str) -> None:
except Exception:
pass
# Env vars safe to pass to stdio subprocesses (no secrets).
_SAFE_ENV_KEYS = frozenset({"PATH", "HOME", "USER", "LANG", "LC_ALL", "TERM", "SHELL", "TMPDIR"})
@@ -91,6 +92,7 @@ def _workspace_basename() -> str:
root = _core._workspace_folder()
return os.path.basename(root.rstrip("/\\")) or root
# Cursor's case-sensitive context vars -> resolver.
_CONTEXT_VAR_RESOLVERS = {
"userHome": lambda: os.path.expanduser("~"),
@@ -225,6 +227,7 @@ def _interpolate_env_vars(value):
return [_interpolate_env_vars(v) for v in value]
return value
# (server_name, dotted key path) pairs already warned about; config loads
# happen on every discovery pass, so warn once per process.
_whitespace_warned: Set[Tuple[str, str]] = set()

View File

@@ -57,6 +57,7 @@ def _snapshot_child_pids() -> set:
return set()
# argv markers of non-MCP gateway children that can race into the snapshot
# delta during an MCP spawn (defense-in-depth; LSP/slash_worker already use
# start_new_session). Matched against argv[1:] because Python/Java children

View File

@@ -43,6 +43,7 @@ def _scan_mcp_description(server_name: str, tool_name: str, description: str) ->
)
return findings
_EMPTY_OBJECT_SCHEMA = {"type": "object", "properties": {}}
@@ -123,6 +124,7 @@ def sanitize_mcp_name_component(value: str) -> str:
the historical behavior) so generated names pass provider validation."""
return re.sub(r"[^A-Za-z0-9_]", "_", str(value or ""))
# ``mcp__<server>__<tool>``: the convention shared by Claude Code, Codex and
# OpenCode. The double underscore disambiguates the server/tool boundary even
# when either contains underscores, and matches the Anthropic-OAuth wire form.
@@ -145,6 +147,7 @@ def _convert_mcp_schema(server_name: str, mcp_tool) -> dict:
"parameters": _normalize_mcp_input_schema(mcp_field(mcp_tool, "input_schema", "inputSchema")),
}
# Utility tools generated per server: handler_key -> (description template,
# parameter properties, required names). Schemas are FROZEN wire bytes — the
# key order emitted by ``_build_utility_schemas`` must not change.
@@ -206,6 +209,7 @@ def matches_name_filter(tool_name: str, patterns: set[str]) -> bool:
return True
return any(fnmatch.fnmatchcase(tool_name, p) for p in patterns if "*" in p or "?" in p or "[" in p)
# Utility handler -> ClientSession method it needs (legacy gate when no
# initialize_result was captured).
_UTILITY_CAPABILITY_METHODS = {key: key for key, *_ in _UTILITY_TOOL_SPECS}