---
product: Chilkat
product_version: 11.7.0
language: csharp
language_label: C#
class: Mcp
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/csMcpRef.html
---
# Chilkat Mcp — C# — v11.7.0

> Chilkat 11.7.0 · language=csharp · class=Mcp
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/Mcp.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/csharp/guide.md`.

## Purpose

**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.

## Object creation, unlocking and error handling

**Object Creation**

```csharp
Chilkat.Mcp obj = new Chilkat.Mcp();
```

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in C#.

Minimal complete program:

```csharp
// Required once per process. Any string unlocks a 30-day trial; use your purchased code in production.
Chilkat.Global glob = new Chilkat.Global();
if (!glob.UnlockBundle("Anything for 30-day trial"))
{
    Console.WriteLine(glob.LastErrorText);
    return;
}

Chilkat.Mcp mcp = new Chilkat.Mcp();

bool success = mcp.Connect("<url>");
if (!success)
{
    Console.WriteLine(mcp.LastErrorText);   // full diagnostic of what went wrong
    return;
}
```

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `public string DebugLogFilePath {get; set; }` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastErrorHtml` | `public string LastErrorHtml {get; }` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `public string LastErrorText {get; }` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `public string LastErrorXml {get; }` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `public bool LastMethodSuccess {get; set; }` | read/write | Indicates the success or failure of the most recent method call: `true` means success, `false` means failure. |
| `VerboseLogging` | `public bool VerboseLogging {get; set; }` | read/write | If set to `true`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `public string Version {get; }` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `AuthToken` | property, read/write | `public string AuthToken {get; set; }` |
| `Connected` | property, read-only | `public bool Connected {get; }` |
| `ConnectTimeoutMs` | property, read/write | `public int ConnectTimeoutMs {get; set; }` |
| `HeartbeatMs` | property, read/write | `public int HeartbeatMs {get; set; }` |
| `IdleTimeoutMs` | property, read/write | `public int IdleTimeoutMs {get; set; }` |
| `ProtocolVersion` | property, read/write | `public string ProtocolVersion {get; set; }` |
| `ServerInstructions` | property, read-only | `public string ServerInstructions {get; }` |
| `ServerName` | property, read-only | `public string ServerName {get; }` |
| `ServerVersion` | property, read-only | `public string ServerVersion {get; }` |
| `SessionId` | property, read-only | `public string SessionId {get; }` |
| `CallTool` | method | `public bool CallTool(string name, JsonObject argsJson, JsonObject resultJson);` |
| `Close` | method | `public bool Close();` |
| `Connect` | method | `public bool Connect(string url);` |
| `GetLastJsonData` | method | `public void GetLastJsonData(JsonObject json);` |
| `GetPrompt` | method | `public bool GetPrompt(string name, JsonObject argsJson, JsonObject json);` |
| `ListPrompts` | method | `public bool ListPrompts(JsonObject json);` |
| `ListResources` | method | `public bool ListResources(JsonObject json);` |
| `ListTools` | method | `public bool ListTools(JsonObject json);` |
| `ReadResource` | method | `public bool ReadResource(string uri, JsonObject json);` |
| `SetConnectionSettings` | method | `public bool SetConnectionSettings(Socket sock);` |

## Properties

### Mcp.AuthToken

`Chilkat 11.7.0 · csharp · Mcp · AuthToken · property · read/write · since 11.6.0`

```csharp
public string AuthToken {get; set; }
```

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.

### Mcp.Connected

`Chilkat 11.7.0 · csharp · Mcp · Connected · property · read-only · since 11.6.0`

```csharp
public bool Connected {get; }
```

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

### Mcp.ConnectTimeoutMs

`Chilkat 11.7.0 · csharp · Mcp · ConnectTimeoutMs · property · read/write · since 11.6.0`

```csharp
public int ConnectTimeoutMs {get; set; }
```

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).

### Mcp.HeartbeatMs

`Chilkat 11.7.0 · csharp · Mcp · HeartbeatMs · property · read/write · since 11.6.0`

```csharp
public int HeartbeatMs {get; set; }
```

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.**

### Mcp.IdleTimeoutMs

`Chilkat 11.7.0 · csharp · Mcp · IdleTimeoutMs · property · read/write · since 11.6.0`

```csharp
public int IdleTimeoutMs {get; set; }
```

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).

### Mcp.ProtocolVersion

`Chilkat 11.7.0 · csharp · Mcp · ProtocolVersion · property · read/write · since 11.6.0`

```csharp
public string ProtocolVersion {get; set; }
```

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`.

### Mcp.ServerInstructions

`Chilkat 11.7.0 · csharp · Mcp · ServerInstructions · property · read-only · since 11.6.0`

```csharp
public string ServerInstructions {get; }
```

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

### Mcp.ServerName

`Chilkat 11.7.0 · csharp · Mcp · ServerName · property · read-only · since 11.6.0`

```csharp
public string ServerName {get; }
```

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

### Mcp.ServerVersion

`Chilkat 11.7.0 · csharp · Mcp · ServerVersion · property · read-only · since 11.6.0`

```csharp
public string ServerVersion {get; }
```

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

### Mcp.SessionId

`Chilkat 11.7.0 · csharp · Mcp · SessionId · property · read-only · since 11.6.0`

```csharp
public string SessionId {get; }
```

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.

## Methods

### Mcp.CallTool

`Chilkat 11.7.0 · csharp · Mcp · CallTool · method · since 11.6.0`

```csharp
public bool CallTool(string name, JsonObject argsJson, JsonObject resultJson);
```

Calls the MCP `tools/call` method for the tool named `name`, passing the JSON arguments object in `argsJson`. The members of `argsJson` 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 `resultJson`. 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 `resultJson` (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.

Async variant: `CallToolAsync` — same arguments, returns a `Task` (see Async variants below).

### Mcp.Close

`Chilkat 11.7.0 · csharp · Mcp · Close · method · since 11.6.0`

```csharp
public bool Close();
```

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.

Async variant: `CloseAsync` — same arguments, returns a `Task` (see Async variants below).

### Mcp.Connect

`Chilkat 11.7.0 · csharp · Mcp · Connect · method · since 11.6.0`

```csharp
public bool Connect(string url);
```

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.

Async variant: `ConnectAsync` — same arguments, returns a `Task` (see Async variants below).

### Mcp.GetLastJsonData

`Chilkat 11.7.0 · csharp · Mcp · GetLastJsonData · method · since 11.6.0`

```csharp
public void GetLastJsonData(JsonObject json);
```

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.

### Mcp.GetPrompt

`Chilkat 11.7.0 · csharp · Mcp · GetPrompt · method · since 11.6.0`

```csharp
public bool GetPrompt(string name, JsonObject argsJson, JsonObject json);
```

Calls the MCP `prompts/get` method for the prompt named `name`, passing the JSON arguments object in `argsJson` (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.

Async variant: `GetPromptAsync` — same arguments, returns a `Task` (see Async variants below).

### Mcp.ListPrompts

`Chilkat 11.7.0 · csharp · Mcp · ListPrompts · method · since 11.6.0`

```csharp
public bool ListPrompts(JsonObject json);
```

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.

Async variant: `ListPromptsAsync` — same arguments, returns a `Task` (see Async variants below).

### Mcp.ListResources

`Chilkat 11.7.0 · csharp · Mcp · ListResources · method · since 11.6.0`

```csharp
public bool ListResources(JsonObject json);
```

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.

Async variant: `ListResourcesAsync` — same arguments, returns a `Task` (see Async variants below).

### Mcp.ListTools

`Chilkat 11.7.0 · csharp · Mcp · ListTools · method · since 11.6.0`

```csharp
public bool ListTools(JsonObject json);
```

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.

Async variant: `ListToolsAsync` — same arguments, returns a `Task` (see Async variants below).

### Mcp.ReadResource

`Chilkat 11.7.0 · csharp · Mcp · ReadResource · method · since 11.6.0`

```csharp
public bool ReadResource(string uri, JsonObject json);
```

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.

Async variant: `ReadResourceAsync` — same arguments, returns a `Task` (see Async variants below).

### Mcp.SetConnectionSettings

`Chilkat 11.7.0 · csharp · Mcp · SetConnectionSettings · method · since 11.6.0`

```csharp
public bool SetConnectionSettings(Socket sock);
```

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.

## Events and callbacks

### Mcp.AbortCheck (event)

`Chilkat 11.7.0 · csharp · Mcp · AbortCheck · event`

```csharp
public event AbortCheckEventHandler OnAbortCheck;
```

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.

### Chilkat .NET Framework Event Implementation

Args are passed using Chilkat.AbortCheckEventArgs

**Event callback implementation:**

```csharp
private void mcp_OnAbortCheck(object sender, Chilkat.AbortCheckEventArgs args)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.Mcp mcp = new Chilkat.Mcp();
mcp.OnAbortCheck += mcp_OnAbortCheck;
```

### Chilkat .NET Core Event Implementation

**Event callback implementation:**

```csharp
public void handleAbortCheck(out bool abort)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.Mcp mcp = new Chilkat.Mcp();
// ...
Chilkat.Mcp.AbortCheck abortCheck = new Chilkat.Mcp.AbortCheck(handleAbortCheck);
mcp.setAbortCheckCb(abortCheck);
```

### Mcp.PercentDone (event)

`Chilkat 11.7.0 · csharp · Mcp · PercentDone · event`

```csharp
public event PercentDoneEventHandler OnPercentDone;
```

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.

To abort the operation, set the `abort` output argument to `true`. This will cause the method to terminate and return a failure status or corresponding failure value.

### Chilkat .NET Framework Event Implementation

Args are passed using Chilkat.PercentDoneEventArgs

**Event callback implementation:**

```csharp
private void mcp_OnPercentDone(object sender, Chilkat.PercentDoneEventArgs args)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.Mcp mcp = new Chilkat.Mcp();
mcp.OnPercentDone += mcp_OnPercentDone;
```

### Chilkat .NET Core Event Implementation

**Event callback implementation:**

```csharp
public void handlePercentDone(int pctDone, out bool abort)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.Mcp mcp = new Chilkat.Mcp();
// ...
Chilkat.Mcp.PercentDone percentDone = new Chilkat.Mcp.PercentDone(handlePercentDone);
mcp.setPercentDoneCb(percentDone);
```

### Mcp.ProgressInfo (event)

`Chilkat 11.7.0 · csharp · Mcp · ProgressInfo · event`

```csharp
public event ProgressInfoEventHandler OnProgressInfo;
```

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.

### Chilkat .NET Framework Event Implementation

Args are passed using Chilkat.ProgressInfoEventArgs

**Event callback implementation:**

```csharp
private void mcp_OnProgressInfo(object sender, Chilkat.ProgressInfoEventArgs args)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.Mcp mcp = new Chilkat.Mcp();
mcp.OnProgressInfo += mcp_OnProgressInfo;
```

### Chilkat .NET Core Event Implementation

**Event callback implementation:**

```csharp
public void handleProgressInfo(string name, string value)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.Mcp mcp = new Chilkat.Mcp();
// ...
Chilkat.Mcp.ProgressInfo progressInfo = new Chilkat.Mcp.ProgressInfo(handleProgressInfo);
mcp.setProgressInfoCb(progressInfo);
```

### Mcp.TaskCompleted (event)

`Chilkat 11.7.0 · csharp · Mcp · TaskCompleted · event`

```csharp
public event TaskCompletedEventHandler OnTaskCompleted;
```

Called from the background thread when an asynchronous task completes.

### Chilkat .NET Framework Event Implementation

Args are passed using Chilkat.TaskCompletedEventArgs

**Event callback implementation:**

```csharp
private void mcp_OnTaskCompleted(object sender, Chilkat.TaskCompletedEventArgs args)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.Mcp mcp = new Chilkat.Mcp();
mcp.OnTaskCompleted += mcp_OnTaskCompleted;
```

### Chilkat .NET Core Event Implementation

**Event callback implementation:**

```csharp
public void handleTaskIdCompleted(int taskId)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.Mcp mcp = new Chilkat.Mcp();
// ...
Chilkat.Mcp.TaskIdCompleted taskIdCompleted = new Chilkat.Mcp.TaskIdCompleted(handleTaskIdCompleted);
mcp.setTaskIdCompletedCb(taskIdCompleted);
```

## Async variants

Each returns a `Task` instead of the result and takes the same arguments as the synchronous method; run the task, wait for `Finished`, then read the result from the task. No new Async methods are added from 11.7.0 on.

```csharp
public Task CallToolAsync(string name, JsonObject argsJson, JsonObject resultJson);
public Task CloseAsync();
public Task ConnectAsync(string url);
public Task GetPromptAsync(string name, JsonObject argsJson, JsonObject json);
public Task ListPromptsAsync(JsonObject json);
public Task ListResourcesAsync(JsonObject json);
public Task ListToolsAsync(JsonObject json);
public Task ReadResourceAsync(string uri, JsonObject json);
```

## Related classes

[`JsonObject`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/csharp/classes/JsonObject.md), [`Socket`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/csharp/classes/Socket.md)

