Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.6.0+

Configure MCP Connection Settings

See more MCP Client Examples

Demonstrates Mcp.SetConnectionSettings, which copies connection settings -- such as an HTTP proxy, SOCKS proxy, bind IP address, and TLS options -- from a Socket and applies them before connecting.

Background. This is optional; if not used, a direct connection is made. It is useful when the MCP server must be reached through a proxy or with specific TLS settings.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMcp
    Variant vSock
    Handle hoSock
    String sTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatMcp)) To hoMcp
    If (Not(IsComObjectCreated(hoMcp))) Begin
        Send CreateComObject of hoMcp
    End

    //  Configure connection settings on a Socket -- such as an HTTP proxy, SOCKS proxy, bind IP address,
    //  or TLS options -- and apply them to the MCP client before connecting.  This is optional; if not
    //  used, a direct connection is made.
    Get Create (RefClass(cComChilkatSocket)) To hoSock
    If (Not(IsComObjectCreated(hoSock))) Begin
        Send CreateComObject of hoSock
    End
    Set ComHttpProxyHostname Of hoSock To "proxy.example.com"
    Set ComHttpProxyPort Of hoSock To 8080

    Get pvComObject of hoSock to vSock
    Get ComSetConnectionSettings Of hoMcp vSock To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMcp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComConnect Of hoMcp "https://learn.microsoft.com/api/mcp" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMcp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Connected using the configured connection settings."


End_Procedure