---
product: Chilkat
product_version: 11.7.0
language: sqlserver
language_label: SQL Server
class: Mcp
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/sqlserver_McpRef.html
---
# Chilkat Mcp — SQL Server — v11.7.0

> Chilkat 11.7.0 · language=sqlserver · 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/sqlserver/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**

```sql
DECLARE @hr int
DECLARE @mcp int
EXEC @hr = sp_OACreate 'Chilkat.Mcp', @mcp OUT
IF @hr <> 0
BEGIN
    PRINT 'Failed to create ActiveX component'
    RETURN
END

-- ... use @mcp ...

EXEC @hr = sp_OADestroy @mcp
```

T-SQL uses the Chilkat ActiveX through the OLE Automation stored procedures. They must be enabled once on the server (`EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE;`), and the Chilkat ActiveX registered must match the bitness of the SQL Server instance (64-bit for a 64-bit SQL Server). To bind to a specific major version of Chilkat, append the major version number to the ProgID, such as `sp_OACreate 'Chilkat.Mcp.11'` for Chilkat v11.\*.\*.

`sp_OACreate` returns an object token (an `int`) that is passed as the first argument of every `sp_OAMethod`, `sp_OAGetProperty` and `sp_OASetProperty` call, and released with `sp_OADestroy`. Objects returned by methods (such as an `HttpResponse` or `JsonObject`) are also tokens received through an `int` OUT parameter; they must likewise be destroyed, and the OUT parameter is `NULL` when the method fails to return an object. Objects passed as arguments are passed by their token. When an OLE Automation procedure itself fails (non-zero `@hr`), `sp_OAGetErrorInfo` describes the error.

Data types: strings are `nvarchar(4000)`; integers, booleans (1 or 0) and object tokens are `int`; dates are `datetime`. In the signatures on this page, `@success`, `@iResult`, `@sResult` and the like are the OUT variables receiving a method's return value, `@iValue` / `@sValue` receive or supply a property value, and the remaining `@` variables are the method's arguments in order.

A string returned through an OUT parameter is limited to 4000 characters. For longer values, retrieve the result as a result set into a table variable instead of an OUT parameter, for example `DECLARE @tmp TABLE (outputLine ntext)` followed by `INSERT INTO @tmp EXEC sp_OAGetProperty @mcp, 'LastErrorText'`. See [string length limitations for strings returned by sp_OAMethod calls](https://www.chilkatsoft.com/sql_server_nvarchar_max_limitation.asp).

Methods that pass or return raw byte arrays are not shown on this page, because `varbinary(max)` values cannot be exchanged through `sp_OAMethod` (see [varbinary(max) limitation](https://www.chilkatsoft.com/sql_server_varbinary_max_limitation.asp)). Use the `BinData`-based alternatives (methods ending in *Bd*) or the base64 / hex string-encoded variants instead. Binary *properties* (such as `LastBinaryResult`) can be retrieved as a result set into a table variable, as shown in their signatures. Asynchronous (*\*Async*) methods and event callbacks are not available from SQL Server.

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 SQL Server.

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` | `EXEC sp_OAGetProperty @mcp, 'DebugLogFilePath', @sValue OUT EXEC sp_OASetProperty @mcp, 'DebugLogFilePath', @sValue` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastBinaryResult` | `INSERT INTO @tmp EXEC sp_OAGetProperty @mcp, 'LastBinaryResult'` | read-only | This property is mainly used in SQL Server stored procedures to retrieve binary data from the last method call that returned binary data. |
| `LastErrorHtml` | `EXEC sp_OAGetProperty @mcp, 'LastErrorHtml', @sValue OUT` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `EXEC sp_OAGetProperty @mcp, 'LastErrorText', @sValue OUT` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `EXEC sp_OAGetProperty @mcp, 'LastErrorXml', @sValue OUT` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `EXEC sp_OAGetProperty @mcp, 'LastMethodSuccess', @iValue OUT EXEC sp_OASetProperty @mcp, 'LastMethodSuccess', @iValue` | read/write | Indicates the success or failure of the most recent method call: `1` means success, `0` means failure. |
| `LastStringResult` | `EXEC sp_OAGetProperty @mcp, 'LastStringResult', @sValue OUT` | read-only | In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. |
| `LastStringResultLen` | `EXEC sp_OAGetProperty @mcp, 'LastStringResultLen', @iValue OUT` | read-only | The length, in characters, of the string contained in the LastStringResult property. |
| `VerboseLogging` | `EXEC sp_OAGetProperty @mcp, 'VerboseLogging', @iValue OUT EXEC sp_OASetProperty @mcp, 'VerboseLogging', @iValue` | read/write | If set to `1`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `EXEC sp_OAGetProperty @mcp, 'Version', @sValue OUT` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `AuthToken` | property, read/write | `EXEC sp_OAGetProperty @mcp, 'AuthToken', @sValue OUT EXEC sp_OASetProperty @mcp, 'AuthToken', @sValue` |
| `Connected` | property, read-only | `EXEC sp_OAGetProperty @mcp, 'Connected', @iValue OUT` |
| `ConnectTimeoutMs` | property, read/write | `EXEC sp_OAGetProperty @mcp, 'ConnectTimeoutMs', @iValue OUT EXEC sp_OASetProperty @mcp, 'ConnectTimeoutMs', @iValue` |
| `IdleTimeoutMs` | property, read/write | `EXEC sp_OAGetProperty @mcp, 'IdleTimeoutMs', @iValue OUT EXEC sp_OASetProperty @mcp, 'IdleTimeoutMs', @iValue` |
| `ProtocolVersion` | property, read/write | `EXEC sp_OAGetProperty @mcp, 'ProtocolVersion', @sValue OUT EXEC sp_OASetProperty @mcp, 'ProtocolVersion', @sValue` |
| `ServerInstructions` | property, read-only | `EXEC sp_OAGetProperty @mcp, 'ServerInstructions', @sValue OUT` |
| `ServerName` | property, read-only | `EXEC sp_OAGetProperty @mcp, 'ServerName', @sValue OUT` |
| `ServerVersion` | property, read-only | `EXEC sp_OAGetProperty @mcp, 'ServerVersion', @sValue OUT` |
| `SessionId` | property, read-only | `EXEC sp_OAGetProperty @mcp, 'SessionId', @sValue OUT` |
| `CallTool` | method | `EXEC sp_OAMethod @mcp, 'CallTool', @success OUT, @name, @argsJson, @resultJson` |
| `Close` | method | `EXEC sp_OAMethod @mcp, 'Close', @success OUT` |
| `Connect` | method | `EXEC sp_OAMethod @mcp, 'Connect', @success OUT, @url` |
| `GetLastJsonData` | method | `EXEC sp_OAMethod @mcp, 'GetLastJsonData', NULL, @json` |
| `GetPrompt` | method | `EXEC sp_OAMethod @mcp, 'GetPrompt', @success OUT, @name, @argsJson, @json` |
| `ListPrompts` | method | `EXEC sp_OAMethod @mcp, 'ListPrompts', @success OUT, @json` |
| `ListResources` | method | `EXEC sp_OAMethod @mcp, 'ListResources', @success OUT, @json` |
| `ListTools` | method | `EXEC sp_OAMethod @mcp, 'ListTools', @success OUT, @json` |
| `ReadResource` | method | `EXEC sp_OAMethod @mcp, 'ReadResource', @success OUT, @uri, @json` |
| `SetConnectionSettings` | method | `EXEC sp_OAMethod @mcp, 'SetConnectionSettings', @success OUT, @sock` |

## Properties

### Mcp.AuthToken

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

```sql
EXEC sp_OAGetProperty @mcp, 'AuthToken', @sValue OUT
EXEC sp_OASetProperty @mcp, 'AuthToken', @sValue
```

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 · sqlserver · Mcp · Connected · property · read-only · since 11.6.0`

```sql
EXEC sp_OAGetProperty @mcp, 'Connected', @iValue OUT
```

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

### Mcp.ConnectTimeoutMs

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

```sql
EXEC sp_OAGetProperty @mcp, 'ConnectTimeoutMs', @iValue OUT
EXEC sp_OASetProperty @mcp, 'ConnectTimeoutMs', @iValue
```

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

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

```sql
EXEC sp_OAGetProperty @mcp, 'IdleTimeoutMs', @iValue OUT
EXEC sp_OASetProperty @mcp, 'IdleTimeoutMs', @iValue
```

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 · sqlserver · Mcp · ProtocolVersion · property · read/write · since 11.6.0`

```sql
EXEC sp_OAGetProperty @mcp, 'ProtocolVersion', @sValue OUT
EXEC sp_OASetProperty @mcp, 'ProtocolVersion', @sValue
```

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 · sqlserver · Mcp · ServerInstructions · property · read-only · since 11.6.0`

```sql
EXEC sp_OAGetProperty @mcp, 'ServerInstructions', @sValue OUT
```

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 · sqlserver · Mcp · ServerName · property · read-only · since 11.6.0`

```sql
EXEC sp_OAGetProperty @mcp, 'ServerName', @sValue OUT
```

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

### Mcp.ServerVersion

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

```sql
EXEC sp_OAGetProperty @mcp, 'ServerVersion', @sValue OUT
```

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

### Mcp.SessionId

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

```sql
EXEC sp_OAGetProperty @mcp, 'SessionId', @sValue OUT
```

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 · sqlserver · Mcp · CallTool · method · since 11.6.0`

```sql
EXEC sp_OAMethod @mcp, 'CallTool', @success OUT, @name, @argsJson, @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 `1` here with `isError` set to `1` in `resultJson` (the failure message is typically carried in the `content` array). The return value is `0` only for transport- or protocol-level failures.

`Connect` must be called first.

Returns 1 for success, 0 for failure.

### Mcp.Close

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

```sql
EXEC sp_OAMethod @mcp, 'Close', @success OUT
```

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 1 for success, 0 for failure.

### Mcp.Connect

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

```sql
EXEC sp_OAMethod @mcp, 'Connect', @success OUT, @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 `1`.

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 1 for success, 0 for failure.

### Mcp.GetLastJsonData

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

```sql
EXEC sp_OAMethod @mcp, 'GetLastJsonData', NULL, @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 · sqlserver · Mcp · GetPrompt · method · since 11.6.0`

```sql
EXEC sp_OAMethod @mcp, 'GetPrompt', @success OUT, @name, @argsJson, @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 1 for success, 0 for failure.

### Mcp.ListPrompts

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

```sql
EXEC sp_OAMethod @mcp, 'ListPrompts', @success OUT, @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 1 for success, 0 for failure.

### Mcp.ListResources

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

```sql
EXEC sp_OAMethod @mcp, 'ListResources', @success OUT, @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 1 for success, 0 for failure.

### Mcp.ListTools

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

```sql
EXEC sp_OAMethod @mcp, 'ListTools', @success OUT, @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 1 for success, 0 for failure.

### Mcp.ReadResource

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

```sql
EXEC sp_OAMethod @mcp, 'ReadResource', @success OUT, @uri, @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 1 for success, 0 for failure.

### Mcp.SetConnectionSettings

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

```sql
EXEC sp_OAMethod @mcp, 'SetConnectionSettings', @success OUT, @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 1 for success, 0 for failure.

## Events and callbacks

This binding has no event callbacks.

## Related classes

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

