-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.mjs
More file actions
82 lines (70 loc) · 3.29 KB
/
example.mjs
File metadata and controls
82 lines (70 loc) · 3.29 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* ForgeMCP SDK — Usage Examples
* Run: node example.mjs
*/
import ForgeMCP from "./index.js";
const forge = new ForgeMCP({ apiKey: process.env.FORGEMCP_KEY || "bk_forge_test" });
async function examples() {
// ─── Web Search ───────────────────────────────────────────
console.log("\n🔍 Web Search:");
const search = await forge.web_search({ query: "MCP model context protocol 2026" });
console.log(JSON.stringify(search, null, 2));
// ─── URL Fetch ─────────────────────────────────────────────
console.log("\n🌐 URL Fetch:");
const page = await forge.url_fetch({
url: "https://modelcontextprotocol.io",
maxChars: 2000,
});
console.log(`Title: ${page.title}`);
console.log(`Content: ${page.excerpt}`);
// ─── Code Execute ───────────────────────────────────────────
console.log("\n⚡ Code Execute:");
const result = await forge.code_execute({
code: `
const data = [
{ name: 'Alice', score: 92 },
{ name: 'Bob', score: 78 },
{ name: 'Carol', score: 95 }
];
const avg = data.reduce((sum, d) => sum + d.score, 0) / data.length;
const top = data.filter(d => d.score > avg).map(d => d.name);
JSON.stringify({ average: avg, aboveAverage: top }, null, 2);
`,
});
console.log(result.result);
// ─── Data Store ─────────────────────────────────────────────
console.log("\n💾 Data Store:");
await forge.data_store({
operation: "set",
key: "research_session",
value: { topic: "AI agents", date: new Date().toISOString() },
});
const stored = await forge.data_store({
operation: "get",
key: "research_session",
});
console.log("Retrieved:", JSON.stringify(stored.value));
// ─── Analytics Track ─────────────────────────────────────────
console.log("\n📊 Analytics:");
await forge.analytics_track({
operation: "track",
event: "example_run",
properties: { source: "docs_example", language: "nodejs" },
});
const stats = await forge.analytics_track({
operation: "stats",
days: 7,
});
console.log("Event counts:", JSON.stringify(stats.stats));
// ─── Weather ─────────────────────────────────────────────────
console.log("\n🌤️ Weather:");
const weather = await forge.weather({ location: "Cottage Grove, MN" });
console.log(`${weather.location}: ${weather.temp}°F, ${weather.conditions}`);
// ─── Account ────────────────────────────────────────────────
console.log("\n👤 Usage Stats:");
const usage = await forge.usage();
console.log(
`Tier: ${usage.tier} | Used: ${usage.currentMonth.requestsUsed}/${usage.currentMonth.requestsLimit} requests`
);
}
examples().catch(console.error);