MCPClient Class

Properties   Methods   Events   Config Settings   Errors  

Provides an easy way to retrieve prompts, resources, and invoke tools from Model Context Protocol (MCP) servers.

Class Name

MCPSDK_MCPClient

Procedural Interface

 mcpsdk_mcpclient_open();
 mcpsdk_mcpclient_close($res);
 mcpsdk_mcpclient_register_callback($res, $id, $function);
 mcpsdk_mcpclient_get_last_error($res);
 mcpsdk_mcpclient_get_last_error_code($res);
 mcpsdk_mcpclient_set($res, $id, $index, $value);
 mcpsdk_mcpclient_get($res, $id, $index);
 mcpsdk_mcpclient_do_addpromptparam($res, $name, $value);
 mcpsdk_mcpclient_do_addtoolparam($res, $name, $value);
 mcpsdk_mcpclient_do_config($res, $configurationstring);
 mcpsdk_mcpclient_do_connect($res);
 mcpsdk_mcpclient_do_disconnect($res);
 mcpsdk_mcpclient_do_getprompt($res, $name);
 mcpsdk_mcpclient_do_invoketool($res, $name);
 mcpsdk_mcpclient_do_listprompts($res);
 mcpsdk_mcpclient_do_listresources($res);
 mcpsdk_mcpclient_do_listtools($res);
 mcpsdk_mcpclient_do_readresource($res, $uri);

Remarks

The MCPClient class provides a simple way to communicate with MCP Servers.

Connecting to a Server

When the Transport property is set to ttStdio, the LocalServerPath property must first be set to a file path pointing to a server executable. The Timeout property can be used to specify a timeout when connecting to the server. To initiate the connection, the Connect method should be used.

If successful, the class will then launch the server executable as a subprocess and will be able to send and receive MCP requests.

// Server executable. client.LocalServerPath = @"PATH\\TO\\SERVER\\EXE"; // Launches the server .exe as a subprocess and connects to it. client.Connect();

Key Features

The MCPClient class supports all major MCP functionality, including tools, prompts, resources, and sampling.

Tools

Tools provide an opportunity for LLM clients to execute custom code, interact with external systems, and access dynamic or external data. Anything for which a function can be written can also be exposed as a tool. Common examples include database queries, file operations, or computations.

Listing Tools

Before a client can begin invoking tools, it should first know which tools are available on the server. A client can retrieve a list of valid tools via the ListTools method. When called, the Tools properties will be automatically cleared and populated with the retrieved tools.

Each tool contains a , which acts as a unique identifier that can be used to reference the tool.

// Request a list of tools on the server. client.ListTools(); // Display the name of each tool. foreach (var tool in client.Tools) { // A unique identifier for the tool. string name = tool.Name; // A natural language description of the tool. This is often used to allow LLMs to reason over. string description = tool.Description; // Write to 'stderr' as 'stdio' is reserved for client/server communications. Console.Error.WriteLine($"Tool name: {name}"); Console.Error.WriteLine($"Tool description: {description}"); }

Invoking Tools

Once a tool has been identified, it can be invoked using the InvokeTool method. The server will then reply with a list of individual tool messages that can be retrieved via the ToolMessages properties.

Each tool message contains a indicating the type of response and a , which is typically plain text (e.g., a string result or a base64-encoded image).

// Invoke a tool named 'get-weather'. client.InvokeTool("get-weather"); // Write to 'stderr' as 'stdio' is reserved for client/server communications. foreach (var message in client.ToolMessages) { Console.Error.WriteLine($"message.Value"); }

Tool Parameters

Some server implementations allow tools to receive runtime parameters, allowing clients to provide additional data or context at the time of invocation. These parameters can be specified by calling the AddToolParam method prior to calling the InvokeTool method. Each parameter consists of a Name and a Value, which are then passed along to the server with the tool request.

// Set up parameters for the 'get-weather' tool. client.AddToolParam("location", "New York"); client.AddToolParam("units", "metric"); // Invoke the tool with the specified parameters. client.InvokeTool("get-weather"); // The response will contain the weather information for New York in metric units. // Write to 'stderr' as 'stdio' is reserved for client/server communications. foreach (var message in client.ToolMessages) { Console.Error.WriteLine($"Tool response: {message.Value}"); }

Prompts

Prompts are predefined conversation starters or instructions that can be quickly inserted into the LLM's context to guide specific interactions or workflows. Prompts serve as standardized templates for common conversational patterns and allow for consistent responses for tasks like reviewing code, analyzing data, or answering specific types of questions.

Listing Prompts

Before a client can begin retrieving prompts, it should first know which prompts are available on the server. A client can retrieve a list of available prompts via the ListPrompts method. When called, the Prompts properties will be automatically cleared and populated with the retrieved prompts.

client.ListPrompts(); // Write to 'stderr' as 'stdio' is reserved for client/server communications. foreach (var prompt in client.Prompts) { Console.Error.WriteLine($"Prompt name: {prompt.Name}"); Console.Error.WriteLine($"Description: {prompt.Description}"); }

Retrieving Prompts

Once a prompt has been identified, it can be requested using the GetPrompt method. The server will then reply with a list of individual prompt messages that will be available via the PromptMessages properties.

Each prompt message consists of and a . A Role identifies the speaker or author of a given message, and its Text represents a natural language instruction that can be fed into a language model.

client.GetPrompt("review-code"); // Write to 'stderr' as 'stdio' is reserved for client/server communications. for (var message in client.PromptMessages) { // A role of '0' indicates a prompt message coming from a 'user'. // A value of '1' indicates that it comes from an 'assistant'. string direction = (message.Role == 0) ? "User" : "Assistant"; Console.Error.WriteLine($"Message from {direction}: {message.Text}"); }

Prompt Parameters

Some server implementations support runtime arguments. These parameters allow prompts to be customized with client-specific data before execution. Prompt parameters can be specified by calling the AddPromptParam method before calling the GetPrompt method.

Each parameter consists of a Name and a Value, which are then passed along to the server with the prompt request.

// Request a prompt named 'review-code', passing along the following parameters: // code-language: 'javascript' // code-to-review: 'var a = 5;' client.AddPromptParam("code-language", "javascript"); client.AddPromptParam("code-to-review", "var a = 5;"); client.GetPrompt("review-code"); // The server would then return a code review of the javascript code 'var a = 5;'. // Write to 'stderr' as 'stdio' is reserved for client/server communications. Console.Error.WriteLine($"{client.PromptMessages[0].Text}");

Resources

Resources provide persistent, read-only content that can be requested once by the user and reused throughout the session. These are typically static files such as documentation, source code, or other reference materials that help provide context for LLM interactions.

Listing Resources

Before a client can begin retrieving resources, it should first know which resources are available on the server. A client can retrieve a list of available resources via the ListResources method. When called, the Resources properties will be automatically cleared and populated with the retrieved resources.

Each resource contains a , which acts as a unique identifier that can be used to fetch its contents. Resources may also have a and a natural language , which are typically used to provide language models context over what each resource represents.

client.ListResources(); // Write to 'stderr' as 'stdio' is reserved for client/server communications. foreach (var resource in client.Resources) { Console.Error.WriteLine($"Resource name: {resource.Name}"); Console.Error.WriteLine($"Description: {resource.Description}"); Console.Error.WriteLine($"URI: {resource.Uri}"); }

Retrieving Resources

Once a resource has been identified, its contents can be retrieved using the ReadResource method. The server will then reply with the resource contents that can be retrieved via the ResourceContents properties.

// Resources are identified by URIs. In this case, this resource can be identified with 'file:///docs/reference.txt'. client.ReadResource("file:///docs/reference.txt"); // Write to 'stderr' as 'stdio' is reserved for client/server communications. foreach (var content in client.ResourceContents) { Console.Error.WriteLine($"Resource content (text): {content.Data}"); }

Disconnecting from a Server

To disconnect from the server, the Disconnect method should be used. When the Transport property is set to ttStdio, the client will drop the underlying connection and the server subprocess will be automatically terminated. client.Disconnect();

Property List


The following is the full list of the properties of the class with short descriptions. Click on the links for further details.

LocalServerPathThe path to the local MCP server executable.
PromptMessageCountThe number of records in the PromptMessage arrays.
PromptMessageRoleThe speaker or author of the message.
PromptMessageTextThe instruction that can be passed into the client's language model.
PromptCountThe number of records in the Prompt arrays.
PromptDescriptionThe brief, human-readable description of what the prompt does.
PromptNameThe unique name associated with the prompt.
ResourceContentCountThe number of records in the ResourceContent arrays.
ResourceContentDataThe data included in the resource content.
ResourceContentMimeTypeThe MIME type of the resource content data.
ResourceContentUriThe unique resource identifier that corresponds to the content received from the server.
ResourceCountThe number of records in the Resource arrays.
ResourceDescriptionThe brief, human-readable description of the purpose of the resource as well as appropriate use cases.
ResourceMimetypeThe media type of the resource content.
ResourceNameThe display name associated with the resource.
ResourceSizeThe size of the resource content, in bytes.
ResourceUriThe unique resource identifier associated with the resource.
SamplingMessageCountThe number of records in the SamplingMessage arrays.
SamplingMessageRoleThe speaker or author of the message.
SamplingMessageTextThe instruction that can be passed into the client's language model.
TimeoutThe timeout for operations in seconds.
ToolMessageCountThe number of records in the ToolMessage arrays.
ToolMessageMessageTypeThe data type of the message.
ToolMessageValueThe raw data included in the message.
ToolCountThe number of records in the Tool arrays.
ToolDescriptionThe brief, human-readable description of what the tool does.
ToolNameThe unique name associated with the tool.
TransportThe transport mechanism used for communication.

Method List


The following is the full list of the methods of the class with short descriptions. Click on the links for further details.

AddPromptParamAdds a prompt parameter.
AddToolParamAdds a tool parameter.
ConfigSets or retrieves a configuration setting.
ConnectConnects to a MCP server.
DisconnectDisconnects from a MCP server.
GetPromptRetrieves a prompt from the server.
InvokeToolInvokes a tool from the server.
ListPromptsRetrieves the list of prompts available on the server.
ListResourcesRetrieves the list of resources available on the server.
ListToolsRetrieves the list of tools available on the server.
ReadResourceReads a resource from the server.

Event List


The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.

ErrorFires when an error occurs during operation.
LogThis event is fired once for each log message.
SamplingRequestFires when the server requests language model generation.

Config Settings


The following is a list of config settings for the class with short descriptions. Click on the links for further details.

LogLevelSpecifies the level of detail that is logged.
BuildInfoInformation about the product's build.
CodePageThe system code page used for Unicode to Multibyte translations.
LicenseInfoInformation about the current license.
MaskSensitiveDataWhether sensitive data is masked in log messages.
ProcessIdleEventsWhether the class uses its internal event loop to process events when the main thread is idle.
SelectWaitMillisThe length of time in milliseconds the class will wait when DoEvents is called if there are no events to process.
UseInternalSecurityAPIWhether or not to use the system security libraries or an internal implementation.

LocalServerPath Property (MCPSDK_MCPClient Class)

The path to the local MCP server executable.

Object Oriented Interface

public function getLocalServerPath();
public function setLocalServerPath($value);

Procedural Interface

mcpsdk_mcpclient_get($res, 1 );
mcpsdk_mcpclient_set($res, 1, $value );

Default Value

''

Remarks

When the Transport property is set to ttStdio, this property is used to specify the full path to the local MCP server executable that the class will launch and connect to. When set, the class will start the server process at the specified path and establish a connection for MCP operations.

The supplied path must point to a valid MCP server executable file. If the path is empty or invalid, the class will not attempt to start a local server process.

Data Type

String

PromptMessageCount Property (MCPSDK_MCPClient Class)

The number of records in the PromptMessage arrays.

Object Oriented Interface

public function getPromptMessageCount();
public function setPromptMessageCount($value);

Procedural Interface

mcpsdk_mcpclient_get($res, 2 );
mcpsdk_mcpclient_set($res, 2, $value );

Default Value

0

Remarks

This property controls the size of the following arrays:

The array indices start at 0 and end at PromptMessageCount - 1.

This property is not available at design time.

Data Type

Integer

PromptMessageRole Property (MCPSDK_MCPClient Class)

The speaker or author of the message.

Object Oriented Interface

public function getPromptMessageRole($promptmessageindex);
public function setPromptMessageRole($promptmessageindex, $value);

Procedural Interface

mcpsdk_mcpclient_get($res, 3 , $promptmessageindex);
mcpsdk_mcpclient_set($res, 3, $value , $promptmessageindex);

Possible Values

MCPCLIENT_PROMPTMESSAGEROLE_USER(0), 
MCPCLIENT_PROMPTMESSAGEROLE_ASSISTANT(1)

Default Value

0

Remarks

The speaker or author of the message.

This property indicates who authored each message and helps provide conversational context to language models. Valid roles include:

0 (rtUser) Message from the end user requesting assistance.
1 (rtAssistant) Message from the client providing responses.

The $promptmessageindex parameter specifies the index of the item in the array. The size of the array is controlled by the PromptMessageCount property.

This property is not available at design time.

Data Type

Integer

PromptMessageText Property (MCPSDK_MCPClient Class)

The instruction that can be passed into the client's language model.

Object Oriented Interface

public function getPromptMessageText($promptmessageindex);
public function setPromptMessageText($promptmessageindex, $value);

Procedural Interface

mcpsdk_mcpclient_get($res, 4 , $promptmessageindex);
mcpsdk_mcpclient_set($res, 4, $value , $promptmessageindex);

Default Value

''

Remarks

The instruction that can be passed into the client's language model.

This property contains natural language describing an instruction that can be passed into the client's language model (e.g., Review python code, Summarize an article, or Provide an example of using the /n software MCP SDK).

The $promptmessageindex parameter specifies the index of the item in the array. The size of the array is controlled by the PromptMessageCount property.

This property is not available at design time.

Data Type

String

PromptCount Property (MCPSDK_MCPClient Class)

The number of records in the Prompt arrays.

Object Oriented Interface

public function getPromptCount();

Procedural Interface

mcpsdk_mcpclient_get($res, 5 );

Default Value

0

Remarks

This property controls the size of the following arrays:

The array indices start at 0 and end at PromptCount - 1.

This property is read-only and not available at design time.

Data Type

Integer

PromptDescription Property (MCPSDK_MCPClient Class)

The brief, human-readable description of what the prompt does.

Object Oriented Interface

public function getPromptDescription($promptindex);

Procedural Interface

mcpsdk_mcpclient_get($res, 6 , $promptindex);

Default Value

''

Remarks

The brief, human-readable description of what the prompt does.

This property holds a brief, human-readable description of what the prompt does, which is critical in helping the client to understand the purpose and functionality of the prompt.

The $promptindex parameter specifies the index of the item in the array. The size of the array is controlled by the PromptCount property.

This property is read-only and not available at design time.

Data Type

String

PromptName Property (MCPSDK_MCPClient Class)

The unique name associated with the prompt.

Object Oriented Interface

public function getPromptName($promptindex);

Procedural Interface

mcpsdk_mcpclient_get($res, 7 , $promptindex);

Default Value

''

Remarks

The unique name associated with the prompt.

This property identifies the unique name associated with the prompt.

The $promptindex parameter specifies the index of the item in the array. The size of the array is controlled by the PromptCount property.

This property is read-only and not available at design time.

Data Type

String

ResourceContentCount Property (MCPSDK_MCPClient Class)

The number of records in the ResourceContent arrays.

Object Oriented Interface

public function getResourceContentCount();
public function setResourceContentCount($value);

Procedural Interface

mcpsdk_mcpclient_get($res, 8 );
mcpsdk_mcpclient_set($res, 8, $value );

Default Value

0

Remarks

This property controls the size of the following arrays:

The array indices start at 0 and end at ResourceContentCount - 1.

This property is not available at design time.

Data Type

Integer

ResourceContentData Property (MCPSDK_MCPClient Class)

The data included in the resource content.

Object Oriented Interface

public function getResourceContentData($resourcecontentindex);
public function setResourceContentData($resourcecontentindex, $value);

Procedural Interface

mcpsdk_mcpclient_get($res, 9 , $resourcecontentindex);
mcpsdk_mcpclient_set($res, 9, $value , $resourcecontentindex);

Default Value

''

Remarks

The data included in the resource content.

This property contains the data included in the resource content. Its format depends on the value in the ResourceMimeType property.

The $resourcecontentindex parameter specifies the index of the item in the array. The size of the array is controlled by the ResourceContentCount property.

This property is not available at design time.

Data Type

Binary String

ResourceContentMimeType Property (MCPSDK_MCPClient Class)

The MIME type of the resource content data.

Object Oriented Interface

public function getResourceContentMimeType($resourcecontentindex);
public function setResourceContentMimeType($resourcecontentindex, $value);

Procedural Interface

mcpsdk_mcpclient_get($res, 10 , $resourcecontentindex);
mcpsdk_mcpclient_set($res, 10, $value , $resourcecontentindex);

Default Value

''

Remarks

The MIME type of the resource content data.

This property identifies the MIME type of the resource content data and informs the client of how the data in the ResourceData property should be interpreted and processed.

The $resourcecontentindex parameter specifies the index of the item in the array. The size of the array is controlled by the ResourceContentCount property.

This property is not available at design time.

Data Type

String

ResourceContentUri Property (MCPSDK_MCPClient Class)

The unique resource identifier that corresponds to the content received from the server.

Object Oriented Interface

public function getResourceContentUri($resourcecontentindex);
public function setResourceContentUri($resourcecontentindex, $value);

Procedural Interface

mcpsdk_mcpclient_get($res, 11 , $resourcecontentindex);
mcpsdk_mcpclient_set($res, 11, $value , $resourcecontentindex);

Default Value

''

Remarks

The unique resource identifier that corresponds to the content received from the server.

This property identifies the individual resource content's unique resource identifier and may differ from the one corresponding to the overall resource.

For example, a client may request a resource with a URI of file:///test, and the server may then return two individual resource contents with the following URIs: file:///file/test/desc.txt, and file:///file/test/data.json.

The $resourcecontentindex parameter specifies the index of the item in the array. The size of the array is controlled by the ResourceContentCount property.

This property is not available at design time.

Data Type

String

ResourceCount Property (MCPSDK_MCPClient Class)

The number of records in the Resource arrays.

Object Oriented Interface

public function getResourceCount();

Procedural Interface

mcpsdk_mcpclient_get($res, 12 );

Default Value

0

Remarks

This property controls the size of the following arrays:

The array indices start at 0 and end at ResourceCount - 1.

This property is read-only and not available at design time.

Data Type

Integer

ResourceDescription Property (MCPSDK_MCPClient Class)

The brief, human-readable description of the purpose of the resource as well as appropriate use cases.

Object Oriented Interface

public function getResourceDescription($resourceindex);

Procedural Interface

mcpsdk_mcpclient_get($res, 13 , $resourceindex);

Default Value

''

Remarks

The brief, human-readable description of the purpose of the resource as well as appropriate use cases.

This property holds a brief, human-readable description of the purpose of the resource as well as appropriate use cases.

The $resourceindex parameter specifies the index of the item in the array. The size of the array is controlled by the ResourceCount property.

This property is read-only and not available at design time.

Data Type

String

ResourceMimetype Property (MCPSDK_MCPClient Class)

The media type of the resource content.

Object Oriented Interface

public function getResourceMimetype($resourceindex);

Procedural Interface

mcpsdk_mcpclient_get($res, 14 , $resourceindex);

Default Value

''

Remarks

The media type of the resource content.

This property holds the media type of resource content (e.g., text/plain, image/png, etc.) and helps clients interpret the resource correctly and determine how it should be processed or displayed.

The $resourceindex parameter specifies the index of the item in the array. The size of the array is controlled by the ResourceCount property.

This property is read-only and not available at design time.

Data Type

String

ResourceName Property (MCPSDK_MCPClient Class)

The display name associated with the resource.

Object Oriented Interface

public function getResourceName($resourceindex);

Procedural Interface

mcpsdk_mcpclient_get($res, 15 , $resourceindex);

Default Value

''

Remarks

The display name associated with the resource.

This property indicates the display associated with the resource that is shown to end users by the client.

The $resourceindex parameter specifies the index of the item in the array. The size of the array is controlled by the ResourceCount property.

This property is read-only and not available at design time.

Data Type

String

ResourceSize Property (MCPSDK_MCPClient Class)

The size of the resource content, in bytes.

Object Oriented Interface

public function getResourceSize($resourceindex);

Procedural Interface

mcpsdk_mcpclient_get($res, 16 , $resourceindex);

Default Value

0

Remarks

The size of the resource content, in bytes.

This property indicates the size of the resource content, in bytes.

The $resourceindex parameter specifies the index of the item in the array. The size of the array is controlled by the ResourceCount property.

This property is read-only and not available at design time.

Data Type

Integer

ResourceUri Property (MCPSDK_MCPClient Class)

The unique resource identifier associated with the resource.

Object Oriented Interface

public function getResourceUri($resourceindex);

Procedural Interface

mcpsdk_mcpclient_get($res, 17 , $resourceindex);

Default Value

''

Remarks

The unique resource identifier associated with the resource.

This property identifies the unique resource identifier associated with the resource.

The $resourceindex parameter specifies the index of the item in the array. The size of the array is controlled by the ResourceCount property.

This property is read-only and not available at design time.

Data Type

String

SamplingMessageCount Property (MCPSDK_MCPClient Class)

The number of records in the SamplingMessage arrays.

Object Oriented Interface

public function getSamplingMessageCount();
public function setSamplingMessageCount($value);

Procedural Interface

mcpsdk_mcpclient_get($res, 18 );
mcpsdk_mcpclient_set($res, 18, $value );

Default Value

0

Remarks

This property controls the size of the following arrays:

The array indices start at 0 and end at SamplingMessageCount - 1.

This property is not available at design time.

Data Type

Integer

SamplingMessageRole Property (MCPSDK_MCPClient Class)

The speaker or author of the message.

Object Oriented Interface

public function getSamplingMessageRole($samplingmessageindex);

Procedural Interface

mcpsdk_mcpclient_get($res, 19 , $samplingmessageindex);

Possible Values

MCPCLIENT_SAMPLINGMESSAGEROLE_USER(0), 
MCPCLIENT_SAMPLINGMESSAGEROLE_ASSISTANT(1)

Default Value

0

Remarks

The speaker or author of the message.

This property indicates who authored each message and helps provide conversational context to language models. Valid roles include:

0 (rtUser) Message from the end user requesting assistance.
1 (rtAssistant) Message from the client providing responses.

The $samplingmessageindex parameter specifies the index of the item in the array. The size of the array is controlled by the SamplingMessageCount property.

This property is read-only and not available at design time.

Data Type

Integer

SamplingMessageText Property (MCPSDK_MCPClient Class)

The instruction that can be passed into the client's language model.

Object Oriented Interface

public function getSamplingMessageText($samplingmessageindex);
public function setSamplingMessageText($samplingmessageindex, $value);

Procedural Interface

mcpsdk_mcpclient_get($res, 20 , $samplingmessageindex);
mcpsdk_mcpclient_set($res, 20, $value , $samplingmessageindex);

Default Value

''

Remarks

The instruction that can be passed into the client's language model.

This property contains natural language describing an instruction that can be passed into the client's language model (e.g., Review python code, Summarize an article, or Provide an example of using the /n software MCP SDK).

The $samplingmessageindex parameter specifies the index of the item in the array. The size of the array is controlled by the SamplingMessageCount property.

This property is not available at design time.

Data Type

String

Timeout Property (MCPSDK_MCPClient Class)

The timeout for operations in seconds.

Object Oriented Interface

public function getTimeout();
public function setTimeout($value);

Procedural Interface

mcpsdk_mcpclient_get($res, 21 );
mcpsdk_mcpclient_set($res, 21, $value );

Default Value

10

Remarks

This property specifies the timeout period in seconds for operations performed by the class.

If this is set to 0, all operations will run uninterrupted until successful completion or an error condition is encountered.

If this is set to a positive value, the class will wait for the operation to complete before returning control. If the timeout expires before the operation completes, the class throws an exception.

Note that all timeouts are inactivity timeouts, meaning the timeout period is extended by value specified in this property when any amount of data is successfully sent or received.

This property is not available at design time.

Data Type

Integer

ToolMessageCount Property (MCPSDK_MCPClient Class)

The number of records in the ToolMessage arrays.

Object Oriented Interface

public function getToolMessageCount();
public function setToolMessageCount($value);

Procedural Interface

mcpsdk_mcpclient_get($res, 22 );
mcpsdk_mcpclient_set($res, 22, $value );

Default Value

0

Remarks

This property controls the size of the following arrays:

The array indices start at 0 and end at ToolMessageCount - 1.

This property is not available at design time.

Data Type

Integer

ToolMessageMessageType Property (MCPSDK_MCPClient Class)

The data type of the message.

Object Oriented Interface

public function getToolMessageMessageType($toolmessageindex);

Procedural Interface

mcpsdk_mcpclient_get($res, 23 , $toolmessageindex);

Possible Values

MCPCLIENT_TOOLMESSAGEMESSAGETYPE_TEXT(0), 
MCPCLIENT_TOOLMESSAGEMESSAGETYPE_AUDIO(1),
MCPCLIENT_TOOLMESSAGEMESSAGETYPE_IMAGE(2),
MCPCLIENT_TOOLMESSAGEMESSAGETYPE_RESOURCE(3)

Default Value

0

Remarks

The data type of the message.

This property indicates the data type of the message. Valid data types include:

0 (mtText) Natural language text data.
1 (mtAudio) A base64-encoded string representing audio data (e.g., MP3 or WAV).
2 (mtImage) A base64-encoded string representing image data (e.g., PNG or JPEG).
3 (mtResource) A string message representing the contents of a text-based resource (e.g., file://logs/output.txt).

The $toolmessageindex parameter specifies the index of the item in the array. The size of the array is controlled by the ToolMessageCount property.

This property is read-only and not available at design time.

Data Type

Integer

ToolMessageValue Property (MCPSDK_MCPClient Class)

The raw data included in the message.

Object Oriented Interface

public function getToolMessageValue($toolmessageindex);
public function setToolMessageValue($toolmessageindex, $value);

Procedural Interface

mcpsdk_mcpclient_get($res, 24 , $toolmessageindex);
mcpsdk_mcpclient_set($res, 24, $value , $toolmessageindex);

Default Value

''

Remarks

The raw data included in the message.

This property contains the raw data included in the message. Its format depends on the value in the ToolMessageType property.

The $toolmessageindex parameter specifies the index of the item in the array. The size of the array is controlled by the ToolMessageCount property.

This property is not available at design time.

Data Type

String

ToolCount Property (MCPSDK_MCPClient Class)

The number of records in the Tool arrays.

Object Oriented Interface

public function getToolCount();

Procedural Interface

mcpsdk_mcpclient_get($res, 25 );

Default Value

0

Remarks

This property controls the size of the following arrays:

The array indices start at 0 and end at ToolCount - 1.

This property is read-only and not available at design time.

Data Type

Integer

ToolDescription Property (MCPSDK_MCPClient Class)

The brief, human-readable description of what the tool does.

Object Oriented Interface

public function getToolDescription($toolindex);

Procedural Interface

mcpsdk_mcpclient_get($res, 26 , $toolindex);

Default Value

''

Remarks

The brief, human-readable description of what the tool does.

This property holds a brief, human-readable description of what the tool does, which is critical in helping the client to understand when the tool should be invoked.

The $toolindex parameter specifies the index of the item in the array. The size of the array is controlled by the ToolCount property.

This property is read-only and not available at design time.

Data Type

String

ToolName Property (MCPSDK_MCPClient Class)

The unique name associated with the tool.

Object Oriented Interface

public function getToolName($toolindex);

Procedural Interface

mcpsdk_mcpclient_get($res, 27 , $toolindex);

Default Value

''

Remarks

The unique name associated with the tool.

This property identifies the unique name associated with the tool.

The $toolindex parameter specifies the index of the item in the array. The size of the array is controlled by the ToolCount property.

This property is read-only and not available at design time.

Data Type

String

Transport Property (MCPSDK_MCPClient Class)

The transport mechanism used for communication.

Object Oriented Interface

public function getTransport();
public function setTransport($value);

Procedural Interface

mcpsdk_mcpclient_get($res, 28 );
mcpsdk_mcpclient_set($res, 28, $value );

Possible Values

MCPCLIENT_TRANSPORT_STDIO(1), 
MCPCLIENT_TRANSPORT_HTTP(2)

Default Value

1

Remarks

This property indicates whether the class operates via the standard input/output or HTTP transport mechanism. Possible values are as follows:

  • ttStdio (1, default): Enables communication through standard input and output streams, but the class is limited to serving a single client at once due to the server acting as a subprocess of a client application.
  • ttHTTP (2): Enables communication via HTTP requests and responses, and allows the class to serve multiple clients at once.

This property is not available at design time.

Data Type

Integer

AddPromptParam Method (MCPSDK_MCPClient Class)

Adds a prompt parameter.

Object Oriented Interface

public function doAddPromptParam($name, $value);

Procedural Interface

mcpsdk_mcpclient_do_addpromptparam($res, $name, $value);

Remarks

This method is used to add a parameter to be passed into the next prompt request. When called, the specified parameter value will be included in the next prompt requested via the GetPrompt method.

Name specifies the unique name identifier of the parameter.

Value specifies the value of the parameter that will be included in the prompt request.

Example: client.AddPromptParam("code-to-review", "var a = 5;"); client.GetPrompt("review-code"); // Write to 'stderr' as 'stdio' is reserved for client/server communications. Console.Error.WriteLine(client.PromptMessages[0].Text);

AddToolParam Method (MCPSDK_MCPClient Class)

Adds a tool parameter.

Object Oriented Interface

public function doAddToolParam($name, $value);

Procedural Interface

mcpsdk_mcpclient_do_addtoolparam($res, $name, $value);

Remarks

This method is used to add a parameter to be passed into the next tool invocation. When called, the specified parameter value will be included in the next tool invoked via the InvokeTool method.

Name specifies the unique name identifier of the parameter.

Value specifies the value of the parameter that will be included in the tool request.

Example: client.AddToolParam("location", "New York"); // The 'get-weather' tool will receive a 'location' parameter with a value of 'New York'. client.InvokeTool("get-weather"); // Write to 'stderr' as 'stdio' is reserved for client/server communications. Console.Error.WriteLine(client.ToolMessages[0].Value);

Config Method (MCPSDK_MCPClient Class)

Sets or retrieves a configuration setting.

Object Oriented Interface

public function doConfig($configurationstring);

Procedural Interface

mcpsdk_mcpclient_do_config($res, $configurationstring);

Remarks

Config is a generic method available in every class. It is used to set and retrieve configuration settings for the class.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

Connect Method (MCPSDK_MCPClient Class)

Connects to a MCP server.

Object Oriented Interface

public function doConnect();

Procedural Interface

mcpsdk_mcpclient_do_connect($res);

Remarks

This method is used to establish a connection to a MCP server and initializes the communication channel. After establishing the connection, the initialize request is automatically sent to the server.

If the Transport property is set to ttStdio, this method will start the server as a subprocess using the path specified in the LocalServerPath property and enable communication through standard input/output streams.

This method will throw an exception if the connection cannot be established or if the server initialization fails.

Disconnect Method (MCPSDK_MCPClient Class)

Disconnects from a MCP server.

Object Oriented Interface

public function doDisconnect();

Procedural Interface

mcpsdk_mcpclient_do_disconnect($res);

Remarks

This method is used to close the connection to a MCP server and terminates the communication channel. All active operations will be canceled and any pending requests will be discarded.

If the Transport property is set to ttStdio, this method will also terminate the server subprocess that was started during connection.

GetPrompt Method (MCPSDK_MCPClient Class)

Retrieves a prompt from the server.

Object Oriented Interface

public function doGetPrompt($name);

Procedural Interface

mcpsdk_mcpclient_do_getprompt($res, $name);

Remarks

This method is used to request a prompt from the server. When called, the PromptMessages properties will be cleared and populated with the individual messages that make up the requested prompt.

Name specifies the unique name identifier of the prompt that will be retrieved.

InvokeTool Method (MCPSDK_MCPClient Class)

Invokes a tool from the server.

Object Oriented Interface

public function doInvokeTool($name);

Procedural Interface

mcpsdk_mcpclient_do_invoketool($res, $name);

Remarks

This method is used to invoke a tool from the server. When called, the server will execute the requested tool and the ToolMessages properties will be cleared and populated with a list of response messages associated with the tool.

Name specifies the unique name identifier of the tool that will be invoked.

ListPrompts Method (MCPSDK_MCPClient Class)

Retrieves the list of prompts available on the server.

Object Oriented Interface

public function doListPrompts();

Procedural Interface

mcpsdk_mcpclient_do_listprompts($res);

Remarks

This method is used to request a listing of all of the prompts available on the server. When called, the Prompts properties will be cleared and populated with the retrieved prompts.

This method is typically called during the client's initialization phase or when the client needs to retrieve the latest list of prompts it can request via the GetPrompt method.

ListResources Method (MCPSDK_MCPClient Class)

Retrieves the list of resources available on the server.

Object Oriented Interface

public function doListResources();

Procedural Interface

mcpsdk_mcpclient_do_listresources($res);

Remarks

This method is used to request a listing of all of the resources available on the server. When called, the Resources properties will be cleared and populated with the retrieved resources.

This method is typically used during the client's initialization phase, or when the client needs to retrieve the latest list of resources it can request via the ReadResource method.

ListTools Method (MCPSDK_MCPClient Class)

Retrieves the list of tools available on the server.

Object Oriented Interface

public function doListTools();

Procedural Interface

mcpsdk_mcpclient_do_listtools($res);

Remarks

This method is used to request a listing of all of the tools available on the server. When called, the Tools properties will be cleared and populated with the retrieved tools.

This method is typically used during the client's initialization phase, or when the client needs to retrieve the latest list of tools it can invoke via the InvokeTool method.

ReadResource Method (MCPSDK_MCPClient Class)

Reads a resource from the server.

Object Oriented Interface

public function doReadResource($uri);

Procedural Interface

mcpsdk_mcpclient_do_readresource($res, $uri);

Remarks

This method is used to request a resource from the server. When called, the ResourceContents properties will be cleared and populated with the data of the requested resource.

Uri specifies the unique identifier for the resource, of which common formats include file:///filename.ext for files, standard HTTP/HTTPS URLs for web resources, or custom schemes like db://table_name.

Error Event (MCPSDK_MCPClient Class)

Fires when an error occurs during operation.

Object Oriented Interface

public function fireError($param);

Procedural Interface

mcpsdk_mcpclient_register_callback($res, 1, array($this, 'fireError'));

Parameter List

 'connectionid'
'errorcode'
'description'

Remarks

This event is fired when an unhandled exception is caught by the class, providing information about the error.

ConnectionId identifies the connection associated with the error.

ErrorCode contains the numeric error code representing the specific error condition.

Description contains a textual description of the error that occurred.

Log Event (MCPSDK_MCPClient Class)

This event is fired once for each log message.

Object Oriented Interface

public function fireLog($param);

Procedural Interface

mcpsdk_mcpclient_register_callback($res, 2, array($this, 'fireLog'));

Parameter List

 'loglevel'
'message'
'logtype'

Remarks

This event fires once for each log message generated by the class. The verbosity is controlled by the LogLevel configuration.

LogLevel indicates the detail level of the message. Possible values are:

0 (None) No messages are logged.
1 (Info - Default) Informational events are logged.
2 (Verbose) Detailed data is logged.
3 (Debug) Debug data including all sent and received NFS operations are logged.

Message is the log message.

LogType identifies the type of log entry. Possible values are as follows:

  • NFS

SamplingRequest Event (MCPSDK_MCPClient Class)

Fires when the server requests language model generation.

Object Oriented Interface

public function fireSamplingRequest($param);

Procedural Interface

mcpsdk_mcpclient_register_callback($res, 3, array($this, 'fireSamplingRequest'));

Parameter List

 'responsetext'
'systemprompt'
'role'
'model'
'intelligencepriority'
'speedpriority'

Remarks

When the Transport property is set to ttStdio, this event is fired when the server requests to sample the client's language model. When fired, the messages that make up the server's prompt will be available via the SamplingMessages properties.

To successfully handle the event, a client should construct a prompt from the messages in SamplingMessages and generate a response using the client's language model.

ResponseText should be set to the text output generated by the model when fed the messages in SamplingMessages.

SystemPrompt contains a natural language instruction or directive used to guide the model's behavior during generation. It is typically used to establish context, define tone, or specify how the model should respond.

Role should be set to the role used by the language model when generating ResponseText. Valid roles include:

0 (rtUser) Message from the end user requesting assistance.
1 (rtAssistant) Message from the client providing responses.

Model should be set to the name of the model used to generate ResponseText.

IntelligencePriority specifies how much the client should prioritize advanced capabilities when generating ResponseText. Its value is a decimal number ranging from 0.0 to 1.0. Higher values prefer more capable models.

SpeedPriority specifies how much the client should prioritize low latency when generating ResponseText. Its value is a decimal number ranging from 0.0 to 1.0. Higher values prefer faster models.

Config Settings (MCPClient Class)

The class accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the Config method.

MCPClient Config Settings

LogLevel:   Specifies the level of detail that is logged.

This configuration controls the level of detail that is logged through the Log event. Possible values are:

0 (None)No messages are logged.
1 (Info - Default)Informational events are logged.
2 (Verbose)Detailed data is logged.
3 (Debug)Debug data including all relevant sent and received NFS operations are logged.

Base Config Settings

BuildInfo:   Information about the product's build.

When queried, this setting will return a string containing information about the product's build.

CodePage:   The system code page used for Unicode to Multibyte translations.

The default code page is Unicode UTF-8 (65001).

The following is a list of valid code page identifiers:

IdentifierName
037IBM EBCDIC - U.S./Canada
437OEM - United States
500IBM EBCDIC - International
708Arabic - ASMO 708
709Arabic - ASMO 449+, BCON V4
710Arabic - Transparent Arabic
720Arabic - Transparent ASMO
737OEM - Greek (formerly 437G)
775OEM - Baltic
850OEM - Multilingual Latin I
852OEM - Latin II
855OEM - Cyrillic (primarily Russian)
857OEM - Turkish
858OEM - Multilingual Latin I + Euro symbol
860OEM - Portuguese
861OEM - Icelandic
862OEM - Hebrew
863OEM - Canadian-French
864OEM - Arabic
865OEM - Nordic
866OEM - Russian
869OEM - Modern Greek
870IBM EBCDIC - Multilingual/ROECE (Latin-2)
874ANSI/OEM - Thai (same as 28605, ISO 8859-15)
875IBM EBCDIC - Modern Greek
932ANSI/OEM - Japanese, Shift-JIS
936ANSI/OEM - Simplified Chinese (PRC, Singapore)
949ANSI/OEM - Korean (Unified Hangul Code)
950ANSI/OEM - Traditional Chinese (Taiwan; Hong Kong SAR, PRC)
1026IBM EBCDIC - Turkish (Latin-5)
1047IBM EBCDIC - Latin 1/Open System
1140IBM EBCDIC - U.S./Canada (037 + Euro symbol)
1141IBM EBCDIC - Germany (20273 + Euro symbol)
1142IBM EBCDIC - Denmark/Norway (20277 + Euro symbol)
1143IBM EBCDIC - Finland/Sweden (20278 + Euro symbol)
1144IBM EBCDIC - Italy (20280 + Euro symbol)
1145IBM EBCDIC - Latin America/Spain (20284 + Euro symbol)
1146IBM EBCDIC - United Kingdom (20285 + Euro symbol)
1147IBM EBCDIC - France (20297 + Euro symbol)
1148IBM EBCDIC - International (500 + Euro symbol)
1149IBM EBCDIC - Icelandic (20871 + Euro symbol)
1200Unicode UCS-2 Little-Endian (BMP of ISO 10646)
1201Unicode UCS-2 Big-Endian
1250ANSI - Central European
1251ANSI - Cyrillic
1252ANSI - Latin I
1253ANSI - Greek
1254ANSI - Turkish
1255ANSI - Hebrew
1256ANSI - Arabic
1257ANSI - Baltic
1258ANSI/OEM - Vietnamese
1361Korean (Johab)
10000MAC - Roman
10001MAC - Japanese
10002MAC - Traditional Chinese (Big5)
10003MAC - Korean
10004MAC - Arabic
10005MAC - Hebrew
10006MAC - Greek I
10007MAC - Cyrillic
10008MAC - Simplified Chinese (GB 2312)
10010MAC - Romania
10017MAC - Ukraine
10021MAC - Thai
10029MAC - Latin II
10079MAC - Icelandic
10081MAC - Turkish
10082MAC - Croatia
12000Unicode UCS-4 Little-Endian
12001Unicode UCS-4 Big-Endian
20000CNS - Taiwan
20001TCA - Taiwan
20002Eten - Taiwan
20003IBM5550 - Taiwan
20004TeleText - Taiwan
20005Wang - Taiwan
20105IA5 IRV International Alphabet No. 5 (7-bit)
20106IA5 German (7-bit)
20107IA5 Swedish (7-bit)
20108IA5 Norwegian (7-bit)
20127US-ASCII (7-bit)
20261T.61
20269ISO 6937 Non-Spacing Accent
20273IBM EBCDIC - Germany
20277IBM EBCDIC - Denmark/Norway
20278IBM EBCDIC - Finland/Sweden
20280IBM EBCDIC - Italy
20284IBM EBCDIC - Latin America/Spain
20285IBM EBCDIC - United Kingdom
20290IBM EBCDIC - Japanese Katakana Extended
20297IBM EBCDIC - France
20420IBM EBCDIC - Arabic
20423IBM EBCDIC - Greek
20424IBM EBCDIC - Hebrew
20833IBM EBCDIC - Korean Extended
20838IBM EBCDIC - Thai
20866Russian - KOI8-R
20871IBM EBCDIC - Icelandic
20880IBM EBCDIC - Cyrillic (Russian)
20905IBM EBCDIC - Turkish
20924IBM EBCDIC - Latin-1/Open System (1047 + Euro symbol)
20932JIS X 0208-1990 & 0121-1990
20936Simplified Chinese (GB2312)
21025IBM EBCDIC - Cyrillic (Serbian, Bulgarian)
21027Extended Alpha Lowercase
21866Ukrainian (KOI8-U)
28591ISO 8859-1 Latin I
28592ISO 8859-2 Central Europe
28593ISO 8859-3 Latin 3
28594ISO 8859-4 Baltic
28595ISO 8859-5 Cyrillic
28596ISO 8859-6 Arabic
28597ISO 8859-7 Greek
28598ISO 8859-8 Hebrew
28599ISO 8859-9 Latin 5
28605ISO 8859-15 Latin 9
29001Europa 3
38598ISO 8859-8 Hebrew
50220ISO 2022 Japanese with no halfwidth Katakana
50221ISO 2022 Japanese with halfwidth Katakana
50222ISO 2022 Japanese JIS X 0201-1989
50225ISO 2022 Korean
50227ISO 2022 Simplified Chinese
50229ISO 2022 Traditional Chinese
50930Japanese (Katakana) Extended
50931US/Canada and Japanese
50933Korean Extended and Korean
50935Simplified Chinese Extended and Simplified Chinese
50936Simplified Chinese
50937US/Canada and Traditional Chinese
50939Japanese (Latin) Extended and Japanese
51932EUC - Japanese
51936EUC - Simplified Chinese
51949EUC - Korean
51950EUC - Traditional Chinese
52936HZ-GB2312 Simplified Chinese
54936Windows XP: GB18030 Simplified Chinese (4 Byte)
57002ISCII Devanagari
57003ISCII Bengali
57004ISCII Tamil
57005ISCII Telugu
57006ISCII Assamese
57007ISCII Oriya
57008ISCII Kannada
57009ISCII Malayalam
57010ISCII Gujarati
57011ISCII Punjabi
65000Unicode UTF-7
65001Unicode UTF-8
The following is a list of valid code page identifiers for Mac OS only:
IdentifierName
1ASCII
2NEXTSTEP
3JapaneseEUC
4UTF8
5ISOLatin1
6Symbol
7NonLossyASCII
8ShiftJIS
9ISOLatin2
10Unicode
11WindowsCP1251
12WindowsCP1252
13WindowsCP1253
14WindowsCP1254
15WindowsCP1250
21ISO2022JP
30MacOSRoman
10UTF16String
0x90000100UTF16BigEndian
0x94000100UTF16LittleEndian
0x8c000100UTF32String
0x98000100UTF32BigEndian
0x9c000100UTF32LittleEndian
65536Proprietary

LicenseInfo:   Information about the current license.

When queried, this setting will return a string containing information about the license this instance of a class is using. It will return the following information:

  • Product: The product the license is for.
  • Product Key: The key the license was generated from.
  • License Source: Where the license was found (e.g., RuntimeLicense, License File).
  • License Type: The type of license installed (e.g., Royalty Free, Single Server).
  • Last Valid Build: The last valid build number for which the license will work.
MaskSensitiveData:   Whether sensitive data is masked in log messages.

In certain circumstances it may be beneficial to mask sensitive data, like passwords, in log messages. Set this to true to mask sensitive data. The default is true.

ProcessIdleEvents:   Whether the class uses its internal event loop to process events when the main thread is idle.

If set to False, the class will not fire internal idle events. Set this to False to use the class in a background thread on Mac OS. By default, this setting is True.

SelectWaitMillis:   The length of time in milliseconds the class will wait when DoEvents is called if there are no events to process.

If there are no events to process when DoEvents is called, the class will wait for the amount of time specified here before returning. The default value is 20.

UseInternalSecurityAPI:   Whether or not to use the system security libraries or an internal implementation.

When set to false, the class will use the system security libraries by default to perform cryptographic functions where applicable.

Setting this configuration setting to true tells the class to use the internal implementation instead of using the system security libraries.

On Windows, this setting is set to false by default. On Linux/macOS, this setting is set to true by default.

To use the system security libraries for Linux, OpenSSL support must be enabled. For more information on how to enable OpenSSL, please refer to the OpenSSL Notes section.

Trappable Errors (MCPClient Class)

MCPClient Errors

104   The class is already listening.