# Class: AppKitMcpClient

Lightweight MCP client for Databricks-hosted MCP servers.

Uses raw fetch() with JSON-RPC 2.0 over HTTP — no @modelcontextprotocol/sdk or LangChain dependency. Supports the Streamable HTTP transport only (POST with JSON-RPC request, single JSON-RPC response). Implements exactly four methods: `initialize`, `notifications/initialized`, `tools/list`, `tools/call`. No prompts/resources/completion/sampling.

All outbound URLs are gated by an McpHostPolicy: unallowlisted hosts are rejected before the first byte is sent, and workspace credentials are only forwarded to the same-origin workspace. See `mcp-host-policy.ts`.

Rationale for hand-rolling JSON-RPC instead of `@modelcontextprotocol/sdk`: see the file-level comment at the top of this module.

## Constructors[​](#constructors "Direct link to Constructors")

### Constructor[​](#constructor "Direct link to Constructor")

```ts
new AppKitMcpClient(
   workspaceHost: string, 
   authenticate: () => Promise<Record<string, string>>, 
   policy: McpHostPolicy, 
   options: {
  dnsLookup?: DnsLookup;
  fetchImpl?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
}): AppKitMcpClient;

```

#### Parameters[​](#parameters "Direct link to Parameters")

| Parameter            | Type                                                                                                                                     |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `workspaceHost`      | `string`                                                                                                                                 |
| `authenticate`       | () => `Promise`<`Record`<`string`, `string`>>                                                                                            |
| `policy`             | `McpHostPolicy`                                                                                                                          |
| `options`            | { `dnsLookup?`: `DnsLookup`; `fetchImpl?`: (`input`: `string` \| `URL` \| `Request`, `init?`: `RequestInit`) => `Promise`<`Response`>; } |
| `options.dnsLookup?` | `DnsLookup`                                                                                                                              |
| `options.fetchImpl?` | (`input`: `string` \| `URL` \| `Request`, `init?`: `RequestInit`) => `Promise`<`Response`>                                               |

#### Returns[​](#returns "Direct link to Returns")

`AppKitMcpClient`

## Methods[​](#methods "Direct link to Methods")

### callTool()[​](#calltool "Direct link to callTool()")

```ts
callTool(
   qualifiedName: string, 
   args: unknown, 
   authHeaders?: Record<string, string>, 
callerSignal?: AbortSignal): Promise<string>;

```

#### Parameters[​](#parameters-1 "Direct link to Parameters")

| Parameter       | Type                         |
| --------------- | ---------------------------- |
| `qualifiedName` | `string`                     |
| `args`          | `unknown`                    |
| `authHeaders?`  | `Record`<`string`, `string`> |
| `callerSignal?` | `AbortSignal`                |

#### Returns[​](#returns-1 "Direct link to Returns")

`Promise`<`string`>

***

### canForwardWorkspaceAuth()[​](#canforwardworkspaceauth "Direct link to canForwardWorkspaceAuth()")

```ts
canForwardWorkspaceAuth(serverName: string): boolean;

```

Whether the named MCP server may receive workspace-scoped auth headers (e.g., an OBO bearer token from an end-user request). Callers should gate auth-forwarding decisions on this to prevent credential exfiltration to non-workspace hosts.

#### Parameters[​](#parameters-2 "Direct link to Parameters")

| Parameter    | Type     |
| ------------ | -------- |
| `serverName` | `string` |

#### Returns[​](#returns-2 "Direct link to Returns")

`boolean`

***

### close()[​](#close "Direct link to close()")

```ts
close(): Promise<void>;

```

#### Returns[​](#returns-3 "Direct link to Returns")

`Promise`<`void`>

***

### connect()[​](#connect "Direct link to connect()")

```ts
connect(endpoint: McpEndpointConfig): Promise<void>;

```

#### Parameters[​](#parameters-3 "Direct link to Parameters")

| Parameter  | Type                |
| ---------- | ------------------- |
| `endpoint` | `McpEndpointConfig` |

#### Returns[​](#returns-4 "Direct link to Returns")

`Promise`<`void`>

***

### connectAll()[​](#connectall "Direct link to connectAll()")

```ts
connectAll(endpoints: McpEndpointConfig[]): Promise<McpConnectAllResult>;

```

Connects every endpoint in parallel and returns a structured summary so callers can distinguish "all connected" from "some failed".

Returning the result instead of throwing is deliberate: one misconfigured MCP server should not take down the entire agents plugin at boot, and the agents plugin uses the summary to warn at startup with the failed-endpoint names. Errors are also logged here so a caller that ignores the return still gets per-endpoint diagnostics.

#### Parameters[​](#parameters-4 "Direct link to Parameters")

| Parameter   | Type                   |
| ----------- | ---------------------- |
| `endpoints` | `McpEndpointConfig`\[] |

#### Returns[​](#returns-5 "Direct link to Returns")

`Promise`<[`McpConnectAllResult`](./docs/api/appkit/Interface.McpConnectAllResult.md)>

`connected` lists the endpoint names that initialised successfully; `failed` carries `{ name, error }` for the rest.

***

### getAllToolDefinitions()[​](#getalltooldefinitions "Direct link to getAllToolDefinitions()")

```ts
getAllToolDefinitions(): AgentToolDefinition[];

```

#### Returns[​](#returns-6 "Direct link to Returns")

[`AgentToolDefinition`](./docs/api/appkit/Interface.AgentToolDefinition.md)\[]
