Skip to main content
Glama
variable_manager.py1.09 kB
import re import json from typing import Any class VariableManager: def __init__(self): self._vars: dict[str, str] = {} def set(self, key: str, value: str) -> None: self._vars[key] = value def get(self, key: str) -> str: return self._vars.get(key, "") def get_all(self) -> dict[str, str]: return dict(self._vars) def substitute(self, text: str) -> str: def replacer(match): key = match.group(1) return self._vars.get(key, match.group(0)) return re.sub(r'\{\{(\w+)\}\}', replacer, text) def apply_to_request(self, headers: dict, body: Any, path: str) -> tuple[dict, Any, str]: new_headers = {k: self.substitute(v) for k, v in headers.items()} new_path = self.substitute(path) if isinstance(body, str): new_body = self.substitute(body) elif isinstance(body, dict): new_body = json.loads(self.substitute(json.dumps(body))) else: new_body = body return new_headers, new_body, new_path

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fellowabhi/ControlAPI-openapi-to-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server