Skip to main content
Glama

authorize_connection

Authorize connections to live brokerages and data providers for algorithmic trading by providing brokerage-specific credentials.

Instructions

Authorize an external connection with a live brokerage or data provider.

Args: brokerage_id: Brokerage identifier (e.g., "InteractiveBrokersBrokerage") credentials: Dictionary containing brokerage-specific credentials

Returns: Dictionary containing authorization result

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
brokerage_idYes
credentialsYes

Implementation Reference

  • The handler function for the 'authorize_connection' tool. It authorizes a brokerage connection by making an authenticated POST request to the QuantConnect 'live/connection/authorize' endpoint with the provided brokerage_id and credentials.
    @mcp.tool()
    async def authorize_connection(
        brokerage_id: str, 
        credentials: Dict[str, Any]
    ) -> Dict[str, Any]:
        """
        Authorize an external connection with a live brokerage or data provider.
    
        Args:
            brokerage_id: Brokerage identifier (e.g., "InteractiveBrokersBrokerage")
            credentials: Dictionary containing brokerage-specific credentials
    
        Returns:
            Dictionary containing authorization result
        """
        auth = get_auth_instance()
        if auth is None:
            return {
                "status": "error",
                "error": "QuantConnect authentication not configured. Use configure_auth() first.",
            }
    
        try:
            # Prepare request data
            request_data = {
                "id": brokerage_id,
                **credentials  # Spread credentials into the request data
            }
    
            # Make API request
            response = await auth.make_authenticated_request(
                endpoint="live/connection/authorize", method="POST", json=request_data
            )
    
            # Parse response
            if response.status_code == 200:
                data = response.json()
    
                if data.get("success", False):
                    connection = data.get("connection", {})
                    
                    return {
                        "status": "success",
                        "brokerage_id": brokerage_id,
                        "connection": connection,
                        "message": f"Successfully authorized connection to {brokerage_id}",
                    }
                else:
                    # API returned success=false
                    errors = data.get("errors", ["Unknown error"])
                    return {
                        "status": "error",
                        "error": "Failed to authorize connection",
                        "details": errors,
                        "brokerage_id": brokerage_id,
                    }
    
            elif response.status_code == 401:
                return {
                    "status": "error",
                    "error": "Authentication failed. Check your credentials and ensure they haven't expired.",
                }
    
            else:
                return {
                    "status": "error",
                    "error": f"API request failed with status {response.status_code}",
                    "response_text": (
                        response.text[:500]
                        if hasattr(response, "text")
                        else "No response text"
                    ),
                }
    
        except Exception as e:
            return {
                "status": "error",
                "error": f"Failed to authorize connection: {str(e)}",
                "brokerage_id": brokerage_id,
            }
  • Calls register_auth_tools which imports and potentially registers tools from auth_tools.py including authorize_connection via module import.
    register_auth_tools(mcp)
  • Calls register_auth_tools(mcp) to register authentication tools, which imports auth_tools.py containing the authorize_connection tool.
    register_auth_tools(mcp)

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/taylorwilsdon/quantconnect-mcp'

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