-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.ts
More file actions
48 lines (41 loc) · 1.36 KB
/
quickstart.ts
File metadata and controls
48 lines (41 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { MultiServerMCPClient } from "@langchain/mcp-adapters";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { ChatAnthropic } from "@langchain/anthropic";
const client = new MultiServerMCPClient({
mcpServers: {
browserless: {
transport: "http",
url: "https://mcp.browserless.io/mcp",
headers: { Authorization: `Bearer ${process.env.BROWSERLESS_TOKEN}` },
},
},
});
const tools = await client.getTools();
console.log(`Loaded ${tools.length} tools:`);
for (const t of tools) console.log(` - ${t.name}`);
const smartscraper = tools.find((t) => t.name === "browserless_smartscraper")!;
const scraped = await smartscraper.invoke({
url: "https://example.com",
formats: ["markdown"],
});
console.log("\n--- direct smartscraper call ---\n");
console.log(scraped);
const statelessTools = tools.filter(
(t) => !["browserless_agent", "browserless_skill"].includes(t.name),
);
const agent = createReactAgent({
llm: new ChatAnthropic({ model: "claude-sonnet-4-6" }),
tools: statelessTools,
});
console.log("\n--- ReAct agent: top 5 HN headlines ---\n");
const out = await agent.invoke({
messages: [
{
role: "user",
content:
"Scrape https://news.ycombinator.com and list the top 5 headlines as a markdown bullet list.",
},
],
});
console.log(out.messages.at(-1)?.content);
await client.close();