Lazarus Pascal Requires Chilkat v11.6.0+
Lazarus Pascal
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 Lazarus Pascal Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Socket,
Chilkat.Mcp;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mcp: TMcp;
sock: TSocket;
begin
success := False;
mcp := TMcp.Create;
// 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 := TSocket.Create;
sock.HttpProxyHostname := 'proxy.example.com';
sock.HttpProxyPort := 8080;
success := mcp.SetConnectionSettings(sock);
if (success = False) then
begin
WriteLn(mcp.LastErrorText);
Exit;
end;
success := mcp.Connect('https://learn.microsoft.com/api/mcp');
if (success = False) then
begin
WriteLn(mcp.LastErrorText);
Exit;
end;
WriteLn('Connected using the configured connection settings.');
mcp.Free;
sock.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.