Skip to content

Commit 0dba245

Browse files
add integration test
1 parent 3faddb0 commit 0dba245

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

libs/providers/langchain-anthropic/src/chat_models.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,13 @@ function isBuiltinTool(tool: unknown): tool is AnthropicBuiltInToolUnion {
173173
"code_execution_",
174174
"memory_",
175175
"tool_search_",
176+
"mcp_toolset",
176177
];
177178
return (
178179
typeof tool === "object" &&
179180
tool !== null &&
180181
"type" in tool &&
181-
"name" in tool &&
182+
("name" in tool || "mcp_server_name" in tool) &&
182183
typeof tool.type === "string" &&
183184
builtInToolPrefixes.some(
184185
(prefix) => typeof tool.type === "string" && tool.type.startsWith(prefix)
@@ -1067,6 +1068,7 @@ export class ChatAnthropicMessages<
10671068
container: options?.container,
10681069
betas: _combineBetas(this.betas, options?.betas, toolBetas ?? []),
10691070
output_format: options?.output_format,
1071+
mcp_servers: options?.mcp_servers,
10701072
};
10711073

10721074
if (this.thinking.type === "enabled") {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { expect, it, describe } from "vitest";
2+
import { HumanMessage } from "@langchain/core/messages";
3+
import { ContentBlock } from "@langchain/core/messages";
4+
5+
import { ChatAnthropic } from "../../chat_models.js";
6+
import { tools } from "../index.js";
7+
8+
const createModel = () =>
9+
new ChatAnthropic({
10+
model: "claude-sonnet-4-5-20250929",
11+
temperature: 0,
12+
});
13+
14+
describe("Anthropic MCP Toolset Integration Tests", () => {
15+
it("mcpToolset can connect to MCP server and run a tool", async () => {
16+
const llm = createModel();
17+
18+
const mcpToolset = tools.mcpToolset_20251120({
19+
serverName: "test-server",
20+
});
21+
22+
const llmWithTools = llm.bindTools([mcpToolset]);
23+
24+
const response = await llmWithTools.invoke(
25+
[
26+
new HumanMessage(
27+
"Please use any available tool from the MCP server to demonstrate it works."
28+
),
29+
],
30+
{
31+
mcp_servers: [
32+
{
33+
type: "url",
34+
url: "https://docs.mcp.cloudflare.com/mcp",
35+
name: "test-server",
36+
},
37+
],
38+
}
39+
);
40+
41+
expect(Array.isArray(response.content)).toBe(true);
42+
expect(
43+
(response.content as ContentBlock.Multimodal.Data[]).find(
44+
(block) => block.type === "mcp_tool_use"
45+
)
46+
).toBeDefined();
47+
expect(
48+
(response.content as ContentBlock.Multimodal.Data[]).find(
49+
(block) => block.type === "mcp_tool_result"
50+
)
51+
).toBeDefined();
52+
}, 60000);
53+
});

0 commit comments

Comments
 (0)