MCPcopy Create free account
hub / github.com/IBM/mcp-cli / _resolve_string

Function _resolve_string

src/mcp_cli/planning/executor.py:919–936  ·  view source on GitHub ↗

Resolve ${var} references in a string value.

(value: str, variables: dict[str, Any])

Source from the content-addressed store, hash-verified

917
918
919def _resolve_string(value: str, variables: dict[str, Any]) -> Any:
920 """Resolve ${var} references in a string value."""
921 if not value or "${" not in value:
922 return value
923
924 # Single variable reference: "${var}" → return the value directly (preserves type)
925 if value.startswith("${") and value.endswith("}") and value.count("${") == 1:
926 var_path = value[2:-1]
927 resolved = _resolve_path(var_path, variables)
928 return resolved if resolved is not None else value
929
930 # Template string: "text ${var} more" → string interpolation
931 def replacer(match: re.Match) -> str:
932 var_path = match.group(1)
933 resolved = _resolve_path(var_path, variables)
934 return str(resolved) if resolved is not None else match.group(0)
935
936 return re.sub(r"\$\{([^}]+)}", replacer, value)
937
938
939def _resolve_path(var_path: str, variables: dict[str, Any]) -> Any:

Callers 1

_resolve_valueFunction · 0.85

Calls 2

_resolve_pathFunction · 0.85
countMethod · 0.80

Tested by

no test coverage detected