Spaces:
Runtime error
Runtime error
Update core_mcp.py
Browse files- core_mcp.py +16 -0
core_mcp.py
CHANGED
|
@@ -204,6 +204,22 @@ def generate_transaction_id() -> str:
|
|
| 204 |
random_suffix = uuid.uuid4().hex[:4].upper()
|
| 205 |
return f"{timestamp}-{random_suffix}"
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
def execute_tool(tool_name: str, params: Dict[str, str]) -> Dict[str, any]:
|
| 208 |
transaction_id = generate_transaction_id()
|
| 209 |
timestamp = datetime.now().isoformat()
|
|
|
|
| 204 |
random_suffix = uuid.uuid4().hex[:4].upper()
|
| 205 |
return f"{timestamp}-{random_suffix}"
|
| 206 |
|
| 207 |
+
def sanitize_error_message(error_msg: str) -> str:
|
| 208 |
+
"""
|
| 209 |
+
Scrub API keys and sensitive URLs from error messages.
|
| 210 |
+
Removes everything after '?' in URLs to prevent API key exposure.
|
| 211 |
+
"""
|
| 212 |
+
import re
|
| 213 |
+
|
| 214 |
+
# Pattern to match URLs with query parameters (containing API keys)
|
| 215 |
+
# This will find "for url: https://...?key=..." and remove everything after the ?
|
| 216 |
+
pattern = r'(for url: https?://[^\s?]+)\?[^\s]*'
|
| 217 |
+
|
| 218 |
+
# Replace with just the base URL without query parameters
|
| 219 |
+
sanitized = re.sub(pattern, r'\1', error_msg)
|
| 220 |
+
|
| 221 |
+
return sanitized
|
| 222 |
+
|
| 223 |
def execute_tool(tool_name: str, params: Dict[str, str]) -> Dict[str, any]:
|
| 224 |
transaction_id = generate_transaction_id()
|
| 225 |
timestamp = datetime.now().isoformat()
|