Mcp Delphi DLL Reference Documentation

Mcp

Current Version: 11.6.0

Chilkat.Mcp

A client for the Model Context Protocol (MCP).

Chilkat.Mcp connects to an MCP server and gives an application access to the server's tools, resources, and prompts over a single, unified API. MCP is an open protocol that standardizes how applications supply context and callable tools to AI models.

Connect & handshake

Connect opens a Streamable HTTP session and performs the MCP initialize handshake, negotiating the protocol version and establishing a session id.

Tools

List the server's tools with ListTools and invoke them with CallTool.

Resources & prompts

Read resources with ListResources and ReadResource, and fetch prompts with ListPrompts and GetPrompt.

Use with Chilkat.Ai

Pass a connected Chilkat.Mcp to Chilkat.Ai.UseMcp to register the server's tools with an AI model. During a conversation the model's tool calls are routed to the MCP server automatically.

Transport: This class uses the MCP Streamable HTTP transport (protocol version 2025-06-18). A server response may arrive as a single JSON object or as a Server-Sent-Events stream; both are handled transparently. The stdio transport is not supported.
Authentication: If the MCP server requires authorization, set the AuthToken property before calling Connect. Chilkat then sends it as an Authorization: Bearer <token> header on every request. Leave it unset for servers that do not require authentication.
Pagination: When a server has more items than fit in a single response, the tools/list, resources/list, and prompts/list results include a nextCursor string. In this release the list methods return the first page only and do not accept a cursor argument, so nextCursor is informational.

Create/Dispose

var
myObject: HCkMcp;

begin
myObject := CkMcp_Create();

// ...

CkMcp_Dispose(myObject);
end;
function CkMcp_Create: HCkMcp; stdcall;

Creates an instance of the HCkMcp object and returns a handle (i.e. a Pointer). The handle is passed in the 1st argument for the functions listed on this page.

procedure CkMcp_Dispose(handle: HCkMcp); stdcall;

Objects created by calling CkMcp_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.

Properties

AuthToken
procedure CkMcp_getAuthToken(objHandle: HCkMcp; outPropVal: HCkString); stdcall;
procedure CkMcp_putAuthToken(objHandle: HCkMcp; newPropVal: PWideChar); stdcall;
function CkMcp__authToken(objHandle: HCkMcp): PWideChar; stdcall;
Introduced in version 11.6.0

An optional bearer token for authenticating to the MCP server. When set, it is sent as an Authorization: Bearer <token> header on every request. The default is the empty string.

See the notes about PWideChar memory ownership and validity.

top
Connected
function CkMcp_getConnected(objHandle: HCkMcp): wordbool; stdcall;
Introduced in version 11.6.0

Read-only. True after a successful Connect (the initialize handshake completed).

top
ConnectTimeoutMs
function CkMcp_getConnectTimeoutMs(objHandle: HCkMcp): Integer; stdcall;
procedure CkMcp_putConnectTimeoutMs(objHandle: HCkMcp; newPropVal: Integer); stdcall;
Introduced in version 11.6.0

The maximum amount of time, in milliseconds, to wait to establish the TCP/TLS connection to the MCP server. The default value is 30000 (30 seconds).

top
DebugLogFilePath
procedure CkMcp_getDebugLogFilePath(objHandle: HCkMcp; outPropVal: HCkString); stdcall;
procedure CkMcp_putDebugLogFilePath(objHandle: HCkMcp; newPropVal: PWideChar); stdcall;
function CkMcp__debugLogFilePath(objHandle: HCkMcp): PWideChar; stdcall;

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top
HeartbeatMs
function CkMcp_getHeartbeatMs(objHandle: HCkMcp): Integer; stdcall;
procedure CkMcp_putHeartbeatMs(objHandle: HCkMcp; newPropVal: Integer); stdcall;
Introduced in version 11.6.0

The interval in milliseconds between each AbortCheck event callback, which enables an application to abort a method before it completes. By default, HeartbeatMs is 0, meaning no AbortCheck event callbacks fire.

top
IdleTimeoutMs
function CkMcp_getIdleTimeoutMs(objHandle: HCkMcp): Integer; stdcall;
procedure CkMcp_putIdleTimeoutMs(objHandle: HCkMcp; newPropVal: Integer); stdcall;
Introduced in version 11.6.0

The maximum amount of time, in milliseconds, to wait for additional incoming data when receiving a response has paused. This is not a total timeout. The default value is 180000 (180 seconds).

top
LastErrorHtml
procedure CkMcp_getLastErrorHtml(objHandle: HCkMcp; outPropVal: HCkString); stdcall;
function CkMcp__lastErrorHtml(objHandle: HCkMcp): PWideChar; stdcall;

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

See the notes about PWideChar memory ownership and validity.

top
LastErrorText
procedure CkMcp_getLastErrorText(objHandle: HCkMcp; outPropVal: HCkString); stdcall;
function CkMcp__lastErrorText(objHandle: HCkMcp): PWideChar; stdcall;

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

See the notes about PWideChar memory ownership and validity.

top
LastErrorXml
procedure CkMcp_getLastErrorXml(objHandle: HCkMcp; outPropVal: HCkString); stdcall;
function CkMcp__lastErrorXml(objHandle: HCkMcp): PWideChar; stdcall;

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

See the notes about PWideChar memory ownership and validity.

top
LastMethodSuccess
function CkMcp_getLastMethodSuccess(objHandle: HCkMcp): wordbool; stdcall;
procedure CkMcp_putLastMethodSuccess(objHandle: HCkMcp; newPropVal: wordbool); stdcall;

Indicates the success or failure of the most recent method call: True means success, False means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
ProtocolVersion
procedure CkMcp_getProtocolVersion(objHandle: HCkMcp; outPropVal: HCkString); stdcall;
procedure CkMcp_putProtocolVersion(objHandle: HCkMcp; newPropVal: PWideChar); stdcall;
function CkMcp__protocolVersion(objHandle: HCkMcp): PWideChar; stdcall;
Introduced in version 11.6.0

The MCP protocol version. May be set before Connect to request a specific version; after Connect it reflects the version negotiated with the server and is sent in the MCP-Protocol-Version header of each request. The default is 2025-06-18.

See the notes about PWideChar memory ownership and validity.

top
ServerInstructions
procedure CkMcp_getServerInstructions(objHandle: HCkMcp; outPropVal: HCkString); stdcall;
function CkMcp__serverInstructions(objHandle: HCkMcp): PWideChar; stdcall;
Introduced in version 11.6.0

Read-only. Optional usage instructions provided by the server in the initialize result (may be the empty string), available after Connect.

See the notes about PWideChar memory ownership and validity.

top
ServerName
procedure CkMcp_getServerName(objHandle: HCkMcp; outPropVal: HCkString); stdcall;
function CkMcp__serverName(objHandle: HCkMcp): PWideChar; stdcall;
Introduced in version 11.6.0

Read-only. The server name reported in the initialize result, available after Connect.

See the notes about PWideChar memory ownership and validity.

top
ServerVersion
procedure CkMcp_getServerVersion(objHandle: HCkMcp; outPropVal: HCkString); stdcall;
function CkMcp__serverVersion(objHandle: HCkMcp): PWideChar; stdcall;
Introduced in version 11.6.0

Read-only. The server version reported in the initialize result, available after Connect.

See the notes about PWideChar memory ownership and validity.

top
SessionId
procedure CkMcp_getSessionId(objHandle: HCkMcp; outPropVal: HCkString); stdcall;
function CkMcp__sessionId(objHandle: HCkMcp): PWideChar; stdcall;
Introduced in version 11.6.0

Read-only. The Mcp-Session-Id assigned by the server during the Connect handshake, or the empty string if the server is stateless. Chilkat automatically includes this session id on all subsequent requests.

See the notes about PWideChar memory ownership and validity.

top
VerboseLogging
function CkMcp_getVerboseLogging(objHandle: HCkMcp): wordbool; stdcall;
procedure CkMcp_putVerboseLogging(objHandle: HCkMcp; newPropVal: wordbool); stdcall;

If set to True, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is False. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
procedure CkMcp_getVersion(objHandle: HCkMcp; outPropVal: HCkString); stdcall;
function CkMcp__version(objHandle: HCkMcp): PWideChar; stdcall;

Version of the component/library, such as "10.1.0"

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top

Methods

CallTool
function CkMcp_CallTool(objHandle: HCkMcp;
    name: PWideChar;
    arguments: HCkJsonObject;
    result: HCkJsonObject): wordbool; stdcall;
Introduced in version 11.6.0

Calls the MCP tools/call method for the tool named name, passing the JSON arguments object in arguments. The members of arguments are the tool's input arguments and should match the tool's inputSchema as returned by ListTools. For example, a weather tool might be called with the arguments { "location": "Boston, MA", "units": "fahrenheit" }. Pass an empty JSON object (not a null) for a tool that takes no arguments.

On success, the tool result is placed in result. It contains a content array, an isError boolean, and optionally a structuredContent object. Each element of the content array has a type ("text", "image", "audio", or "resource"); for a "text" element the value is in its text member. A typical result looks like:

{
  "content": [ { "type": "text", "text": "The weather in Boston is 72F and sunny." } ],
  "isError": false
}
Thus the text of the first content item is at JSON path content[0].text.

Note: A tool that executes but reports a failure returns True here with isError set to True in result (the failure message is typically carried in the content array). The return value is False only for transport- or protocol-level failures.

Connect must be called first.

Returns True for success, False for failure.

More Information and Examples
top
CallToolAsync (1)
function CkMcp_CallToolAsync(objHandle: HCkMcp;
    name: PWideChar;
    arguments: HCkJsonObject;
    result: HCkJsonObject): HCkTask; stdcall;
Introduced in version 11.6.0

Creates an asynchronous task to call the CallTool method with the arguments provided.

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

top
Close
function CkMcp_Close(objHandle: HCkMcp): wordbool; stdcall;
Introduced in version 11.6.0

Explicitly terminates the MCP session by sending an HTTP DELETE with the Mcp-Session-Id header, then releases the connection. It is safe to call this method when not connected (it simply releases any transport). A server that does not permit client-terminated sessions responds with HTTP 405, which is not treated as an error.

Returns True for success, False for failure.

More Information and Examples
top
CloseAsync (1)
function CkMcp_CloseAsync(objHandle: HCkMcp): HCkTask; stdcall;
Introduced in version 11.6.0

Creates an asynchronous task to call the Close method with the arguments provided.

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

top
Connect
function CkMcp_Connect(objHandle: HCkMcp;
    url: PWideChar): wordbool; stdcall;
Introduced in version 11.6.0

Connects to the MCP (Model Context Protocol) server at the Streamable HTTP endpoint URL in url (for example https://example.com/mcp) and performs the MCP initialize handshake.

On success, the SessionId, ProtocolVersion, ServerName, ServerVersion, and ServerInstructions properties are populated, and Connected becomes True.

If an AuthToken is set, it is sent as a bearer token on the request. The URL must begin with http:// or https://; the host, port, and path are taken from it. Only the Streamable HTTP transport is supported; the stdio transport is not.

Returns True for success, False for failure.

More Information and Examples
top
ConnectAsync (1)
function CkMcp_ConnectAsync(objHandle: HCkMcp;
    url: PWideChar): HCkTask; stdcall;
Introduced in version 11.6.0

Creates an asynchronous task to call the Connect method with the arguments provided.

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

top
GetLastJsonData
procedure CkMcp_GetLastJsonData(objHandle: HCkMcp;
    json: HCkJsonObject) stdcall;
Introduced in version 11.6.0

Returns, in json, the complete JSON-RPC response envelope from the most recent request (the jsonrpc, id, and result or error members), for diagnostics and logging. Note that this is the full JSON-RPC envelope, whereas ListTools, CallTool, ReadResource, and GetPrompt each return only the inner result object.

top
GetPrompt
function CkMcp_GetPrompt(objHandle: HCkMcp;
    name: PWideChar;
    arguments: HCkJsonObject;
    json: HCkJsonObject): wordbool; stdcall;
Introduced in version 11.6.0

Calls the MCP prompts/get method for the prompt named name, passing the JSON arguments object in arguments (pass an empty object for a prompt that takes no arguments). On success, the result is placed in json, consisting of an optional description and a messages array in which each message has a role and content.

Connect must be called first.

Returns True for success, False for failure.

More Information and Examples
top
GetPromptAsync (1)
function CkMcp_GetPromptAsync(objHandle: HCkMcp;
    name: PWideChar;
    arguments: HCkJsonObject;
    json: HCkJsonObject): HCkTask; stdcall;
Introduced in version 11.6.0

Creates an asynchronous task to call the GetPrompt method with the arguments provided.

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

top
ListPrompts
function CkMcp_ListPrompts(objHandle: HCkMcp;
    json: HCkJsonObject): wordbool; stdcall;
Introduced in version 11.6.0

Calls the MCP prompts/list method. On success, the server's result object is placed in json, containing a prompts array in which each prompt has a name, optionally a description, and an arguments array, and possibly a nextCursor for pagination.

Connect must be called first.

Returns True for success, False for failure.

More Information and Examples
top
ListPromptsAsync (1)
function CkMcp_ListPromptsAsync(objHandle: HCkMcp;
    json: HCkJsonObject): HCkTask; stdcall;
Introduced in version 11.6.0

Creates an asynchronous task to call the ListPrompts method with the arguments provided.

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

top
ListResources
function CkMcp_ListResources(objHandle: HCkMcp;
    json: HCkJsonObject): wordbool; stdcall;
Introduced in version 11.6.0

Calls the MCP resources/list method. On success, the server's result object is placed in json, containing a resources array in which each resource has a uri, a name, and optionally a description and mimeType, and possibly a nextCursor for pagination.

Connect must be called first.

Returns True for success, False for failure.

More Information and Examples
top
ListResourcesAsync (1)
function CkMcp_ListResourcesAsync(objHandle: HCkMcp;
    json: HCkJsonObject): HCkTask; stdcall;
Introduced in version 11.6.0

Creates an asynchronous task to call the ListResources method with the arguments provided.

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

top
ListTools
function CkMcp_ListTools(objHandle: HCkMcp;
    json: HCkJsonObject): wordbool; stdcall;
Introduced in version 11.6.0

Calls the MCP tools/list method. On success, the server's result object is placed in json, containing a tools array in which each tool has a name, a description, and an inputSchema (a JSON Schema describing the tool's arguments), and possibly a nextCursor for pagination.

Connect must be called first.

Returns True for success, False for failure.

More Information and Examples
top
ListToolsAsync (1)
function CkMcp_ListToolsAsync(objHandle: HCkMcp;
    json: HCkJsonObject): HCkTask; stdcall;
Introduced in version 11.6.0

Creates an asynchronous task to call the ListTools method with the arguments provided.

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

top
ReadResource
function CkMcp_ReadResource(objHandle: HCkMcp;
    uri: PWideChar;
    json: HCkJsonObject): wordbool; stdcall;
Introduced in version 11.6.0

Calls the MCP resources/read method for the resource identified by the URI in uri. On success, the result is placed in json, containing a contents array whose entries carry a uri, a mimeType, and either text (for text resources) or blob (base64 for binary resources).

Connect must be called first.

Returns True for success, False for failure.

More Information and Examples
top
ReadResourceAsync (1)
function CkMcp_ReadResourceAsync(objHandle: HCkMcp;
    uri: PWideChar;
    json: HCkJsonObject): HCkTask; stdcall;
Introduced in version 11.6.0

Creates an asynchronous task to call the ReadResource method with the arguments provided.

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

top
SetConnectionSettings
function CkMcp_SetConnectionSettings(objHandle: HCkMcp;
    sock: HCkSocket): wordbool; stdcall;
Introduced in version 11.6.0

Copies connection settings, including HTTP proxy, SOCKS proxy, bind (network interface) IP address, and TLS options, from sock. This is optional; if not used, default settings apply. Call this method before Connect.

Returns True for success, False for failure.

More Information and Examples
top

Events

AbortCheck
function MyAbortCheck(): Integer; cdecl;
Introduced in version 9.5.0.82

Enables a method call to be aborted by triggering the AbortCheck event at intervals defined by the HeartbeatMs property. If HeartbeatMs is set to its default value of 0, no events will occur. For instance, set HeartbeatMs to 200 to trigger 5 AbortCheck events per second. Return True to abort; return False to continue (not abort)

More Information and Examples
top
PercentDone
function MyPercentDone(pctDone: Integer): Integer; cdecl;
Introduced in version 9.5.0.82

This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The pctDone argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have pctDone equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).

The PercentDone callback also acts as an AbortCheck event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.

Return True to abort; return False to continue (not abort)

More Information and Examples
top
ProgressInfo
procedure MyProgressInfo(name: PWideChar; value: PWideChar) cdecl;
Introduced in version 9.5.0.82

This event callback provides tag name/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.

Note: Some Chilkat methods don't fire any ProgressInfo events.

More Information and Examples
top
TaskCompleted
procedure MyTaskCompleted(task: HCkTask) cdecl;
Introduced in version 9.5.0.82

Called from the background thread when an asynchronous task completes.

top