Skip to main content
Glama
response.py1.36 kB
from typing import Any, Dict, Optional import os API_VERSION = "1.0.0" def format_response(data: Any, meta: Optional[Dict[str, Any]] = None) -> Dict[str, Any]: """ Format a successful response with standard metadata. """ response = { "data": data, "_meta": { "version": API_VERSION, "status": "success" } } if meta: response["_meta"].update(meta) return response def format_error(code: str, message: str, details: Optional[Dict[str, Any]] = None) -> Dict[str, Any]: """ Format an error response with standard metadata. This is useful for returning "soft errors" that don't throw an exception, allowing the agent to handle the failure gracefully. """ error_obj = { "code": code, "message": message } if details: error_obj["details"] = details return { "error": error_obj, "_meta": { "version": API_VERSION, "status": "error" } } class MCPError(Exception): """Base exception for application errors that should be reported to the agent.""" def __init__(self, code: str, message: str, details: Optional[Dict[str, Any]] = None): self.code = code self.message = message self.details = details super().__init__(message)

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/StarGazer1995/mcp-stargazing'

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