Skip to main content
Glama

set-api-key

Configure authentication for carbon emissions calculations by setting your Climatiq API key to enable authorized access to climate impact data.

Instructions

Set the Climatiq API key for authentication. This allows the server to make authorized requests to the Climatiq API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
api_keyYesYour Climatiq API key obtained from app.climatiq.io

Implementation Reference

  • The handler function that extracts the api_key from arguments, validates it by making a test API request to Climatiq, stores it in the config if valid, and returns a success message.
    async def set_api_key_tool(config, arguments, server, climatiq_request): """ Set the Climatiq API key for authentication with the API. This tool configures the Climatiq API key used for all subsequent API calls. The key is stored in memory for the duration of the server session. """ api_key = arguments.get("api_key") if not api_key: raise ValueError("API key is required") # Validate API key by making a test request test_headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } try: # Use httpx directly as we can't use climatiq_request yet async with httpx.AsyncClient(timeout=10.0) as client: response = await client.get(f"{config['base_url']}/data/v1/search", params={"query": "electricity", "data_version": config["data_version"]}, headers=test_headers) if response.status_code != 200: error_detail = "Invalid API key or API connection issue" try: error_json = response.json() if "error" in error_json: error_detail = error_json["error"] elif "message" in error_json: error_detail = error_json["message"] except: pass raise ValueError(f"API key validation failed: {error_detail}") # If we get here, the API key is valid config["api_key"] = api_key return "Climatiq API key configured successfully. You can now use other tools to calculate emissions." except httpx.RequestError as e: raise ValueError(f"Failed to connect to Climatiq API: {str(e)}") except Exception as e: raise ValueError(f"Error validating API key: {str(e)}")
  • The input schema definition specifying that the tool requires a string 'api_key' parameter.
    inputSchema={ "type": "object", "properties": { "api_key": {"type": "string", "description": "Your Climatiq API key obtained from app.climatiq.io"}, }, "required": ["api_key"], },
  • The tool registration in get_tool_definitions() list, including name, description, and input schema.
    types.Tool( name="set-api-key", description="Set the Climatiq API key for authentication. This allows the server to make authorized requests to the Climatiq API.", inputSchema={ "type": "object", "properties": { "api_key": {"type": "string", "description": "Your Climatiq API key obtained from app.climatiq.io"}, }, "required": ["api_key"], }, ),
  • The dispatch logic in handle_call_tool() that routes 'set-api-key' calls to the set_api_key_tool handler.
    if name == "set-api-key": result_text = await set_api_key_tool(config, arguments, server, climatiq_request)
  • The list_tools() handler returns the tool definitions from tools.get_tool_definitions(), which includes 'set-api-key'.
    return get_tool_definitions()

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/jagan-shanmugam/climatiq-mcp-server'

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