You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: libs/langchain-mcp-adapters/README.md
+121-7Lines changed: 121 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -223,16 +223,84 @@ When loading MCP tools either directly through `loadMcpTools` or via `MultiServe
223
223
|`throwOnLoadError`| boolean |`true`| Whether to throw an error if a tool fails to load |
224
224
|`prefixToolNameWithServerName`| boolean |`true`| If true, prefixes all tool names with the server name (e.g., `serverName__toolName`) |
225
225
|`additionalToolNamePrefix`| string |`mcp`| Additional prefix to add to tool names (e.g., `prefix__serverName__toolName`) |
226
+
|`useStandardContentBlocks`| boolean |`false`| If true, uses LangChain's standard multimodal content blocks. Defaults to false for backward compatibility; recommended to set true for new applications |
226
227
227
-
## Response Handling
228
+
## Tool Timeout Configuration
228
229
229
-
MCP tools return results in the `content_and_artifact` format which can include:
230
+
MCP tools support timeout configuration through LangChain's standard `RunnableConfig` interface. This allows you to set custom timeouts on a per-tool-call basis:
230
231
231
-
-**Text content**: Plain text responses
232
-
-**Image content**: Base64-encoded images with MIME type
233
-
-**Embedded resources**: Files, structured data, or other resources
Timeouts can be configured using the following `RunnableConfig` fields:
270
+
271
+
| Parameter | Type | Default | Description |
272
+
| --------- | ---- | ------- | ----------- |
273
+
|`timeout`| number | 60000 | Timeout in milliseconds for the tool call |
274
+
|`signal`| AbortSignal | undefined | An AbortSignal that, when asserted, will cancel the tool call |
275
+
276
+
## Reading Tool Outputs
277
+
278
+
The tools returned by `client.getTools` and `loadMcpTools` are LangChain tools that return ordinary LangChain `ToolMessage` objects. See the table below for the different types of tool output supported by MCP, and how we map them into the LangChain `ToolMessage` object:
|**Text content**| Added to `ToolMessage.content`| See [Content Block Formats](#content-block-formats) for format details |
283
+
|**Image content**| Added to `ToolMessage.content`| See [Content Block Formats](#content-block-formats) for format details |
284
+
|**Audio content**| Added to `ToolMessage.content`| See [Content Block Formats](#content-block-formats) for format details |
285
+
|**Embedded resources**| Added to `ToolMessage.artifact` array | Embedded resources are not transformed in any way before adding them to the arfifact array |
286
+
287
+
### Content Block Formats
288
+
289
+
The `useStandardContentBlocks` option controls how content blocks returned by tools are formatted in the `ToolMessage.content` field. This option defaults to `false` for backward compatibility with existing applications, but **new applications should set this to `true`** to use LangChain's standard multimodal content blocks.
290
+
291
+
**When `useStandardContentBlocks` is `false` (default for backward compatibility):**
292
+
-**Images**: Returned as [`MessageContentImageUrl`](https://v03.api.js.langchain.com/types/_langchain_core.messages.MessageContentImageUrl.html) objects with base64 data URLs (`data:image/png;base64,<data>`)
293
+
-**Audio**: Returned as [`StandardAudioBlock`](https://v03.api.js.langchain.com/types/_langchain_core.messages.StandardAudioBlock.html) objects.
294
+
-**Text**: Returned as [`MessageContentText`](https://v03.api.js.langchain.com/types/_langchain_core.messages.MessageContentText.html) objects.
234
295
235
-
Example for handling different content types:
296
+
**When `useStandardContentBlocks` is `true` (recommended for new applications):**
297
+
-**Images**: Returned as base64 [`StandardImageBlock`](https://v03.api.js.langchain.com/types/_langchain_core.messages.StandardImageBlock.html) objects.
298
+
-**Audio**: Returned as base64 [`StandardAudioBlock`](https://v03.api.js.langchain.com/types/_langchain_core.messages.StandardAudioBlock.html) objects.
299
+
-**Text**: Returned as [`StandardTextBlock`](https://v03.api.js.langchain.com/types/_langchain_core.messages.StandardTextBlock.html) objects.
300
+
301
+
**Note**: The `useStandardContentBlocks` does not impact embedded resources. Embedded resources are always assigned to `ToolMessage.artifact` as an array of MCP `EmbeddedResource` objects, regardless of whether their MIME type indicates one of the formats specified above.
const [content, artifacts] =awaitimageTool.invoke({ prompt: "a cat" });
365
+
// content structure:
366
+
[
367
+
{
368
+
type: "text",
369
+
source_type: "text",
370
+
text: "Generated an image of a cat"
371
+
},
372
+
{
373
+
type: "image",
374
+
source_type: "base64",
375
+
data: "iVBORw0KGgoAAAANSUhEUgAA...",
376
+
mime_type: "image/png"
377
+
}
378
+
]
379
+
```
380
+
267
381
## OAuth 2.0 Authentication
268
382
269
383
For secure MCP servers that require OAuth 2.0 authentication, you can use the `authProvider` option instead of manually managing headers. This provides automatic token refresh, error handling, and standards-compliant OAuth flows.
0 commit comments