Sample code for 30+ languages & platforms
PureBasic 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 PureBasic Downloads

PureBasic
IncludeFile "CkSocket.pb"
IncludeFile "CkMcp.pb"

Procedure ChilkatExample()

    success.i = 0

    mcp.i = CkMcp::ckCreate()
    If mcp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  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.
    sock.i = CkSocket::ckCreate()
    If sock.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkSocket::setCkHttpProxyHostname(sock, "proxy.example.com")
    CkSocket::setCkHttpProxyPort(sock, 8080)

    success = CkMcp::ckSetConnectionSettings(mcp,sock)
    If success = 0
        Debug CkMcp::ckLastErrorText(mcp)
        CkMcp::ckDispose(mcp)
        CkSocket::ckDispose(sock)
        ProcedureReturn
    EndIf

    success = CkMcp::ckConnect(mcp,"https://learn.microsoft.com/api/mcp")
    If success = 0
        Debug CkMcp::ckLastErrorText(mcp)
        CkMcp::ckDispose(mcp)
        CkSocket::ckDispose(sock)
        ProcedureReturn
    EndIf

    Debug "Connected using the configured connection settings."


    CkMcp::ckDispose(mcp)
    CkSocket::ckDispose(sock)


    ProcedureReturn
EndProcedure