Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

ChatMCPOptions.md

81 lines1.9 KB

1---
2id: ChatMCPOptions
3title: ChatMCPOptions
4---
5​
6Defined in: [packages/ai/src/activities/chat/mcp/types.ts:55](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/mcp/types.ts#L55)
7​
8Options controlling MCP tool discovery and lifecycle for a `chat()` call.
9​
10## Properties
11​
12### clients
13​
14```ts
15clients: MCPToolSource[];
16```
17​
18Defined in: [packages/ai/src/activities/chat/mcp/types.ts:59](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/mcp/types.ts#L59)
19​
20The MCP clients or client pools to discover tools from and manage.
21​
22***
23​
24### connection?
25​
26```ts
27optional connection?: MCPConnectionPolicy;
28```
29​
30Defined in: [packages/ai/src/activities/chat/mcp/types.ts:66](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/mcp/types.ts#L66)
31​
32Connection lifecycle policy applied to all clients when the run ends.
33​
34Defaults to `'close'`.
35​
36***
37​
38### lazyTools?
39​
40```ts
41optional lazyTools?: boolean;
42```
43​
44Defined in: [packages/ai/src/activities/chat/mcp/types.ts:74](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/mcp/types.ts#L74)
45​
46When `true`, tool schemas are fetched lazily (forwarded to
47`tools({ lazy: true })`).
48​
49Defaults to `false`.
50​
51***
52​
53### onDiscoveryError?
54​
55```ts
56optional onDiscoveryError?: (error, source) => void | Promise<void>;
57```
58​
59Defined in: [packages/ai/src/activities/chat/mcp/types.ts:85](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/mcp/types.ts#L85)
60​
61Called when tool discovery fails for a single source.
62​
63- Throw (or re-throw) from this handler to fail the entire chat call fast.
64- Return normally to skip that source and continue with remaining clients.
65- Omit this handler entirely to rethrow the error (fail-fast by default).
66​
67Async handlers are awaited, so a rejected promise also fails fast.
68​
69#### Parameters
70​
71##### error
72​
73`unknown`
74​
75##### source
76​
77[`MCPToolSource`](MCPToolSource.md)
78​
79#### Returns
80​
81`void` \| `Promise`\<`void`\>