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

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const mcp = try chilkat.Mcp.init();
    defer mcp.deinit();

    // 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.
    const sock = try chilkat.Socket.init();
    defer sock.deinit();
    sock.setHttpProxyHostname("proxy.example.com");
    sock.setHttpProxyPort(8080);

    mcp.setConnectionSettings(sock) catch {
        std.debug.print("{s}\n", .{try mcp.getLastErrorText(alloc)});
        return;
    };

    mcp.connect("https://learn.microsoft.com/api/mcp") catch {
        std.debug.print("{s}\n", .{try mcp.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Connected using the configured connection settings.\n", .{});
}