Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 978f715

Browse files
committed
add logs tools
1 parent 7becc17 commit 978f715

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

src/core/tools.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export function registerTools(server: FastMCP) {
1111
tools.registerContractTools(server);
1212
tools.registerTransactionsTools(server);
1313
tools.registerBlocksTools(server);
14+
tools.registerLogsTools(server);
1415
}

src/core/tools/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './accountsTools.js';
22
export * from './contractsTools.js';
33
export * from './transactionsTools.js';
44
export * from './blocksTools.js';
5+
export * from './logsTools.js';

src/core/tools/logsTools.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { FastMCP } from "fastmcp";
2+
import { z } from "zod";
3+
import { apiCall } from "./utils.js";
4+
5+
export function registerLogsTools(server: FastMCP) {
6+
// Get Event Logs by Address
7+
server.addTool({
8+
name: "logs/getLogsByAddress",
9+
description: "Returns the event logs from an address, with optional filtering by block range.",
10+
parameters: z.object({
11+
address: z.string().describe("the `string` representing the address to check for logs"),
12+
fromBlock: z.string().optional().describe("the `integer` block number to start searching for logs eg. `12878196`"),
13+
toBlock: z.string().optional().describe("the `integer` block number to stop searching for logs eg. `12879196`"),
14+
page: z.string().optional().describe("the `integer` page number, if pagination is enabled"),
15+
offset: z.string().optional().describe("the number of transactions displayed per page limited to **1000 records** per query, use the `page` parameter for subsequent records")
16+
}),
17+
execute: async (params) => {
18+
const fullParams = { ...params, module: "logs", action: "getLogs" };
19+
return await apiCall(fullParams);
20+
}
21+
});
22+
23+
// Get Event Logs by Topics
24+
server.addTool({
25+
name: "logs/getLogsByTopics",
26+
description: "Returns the events log in a block range, filtered by topics.",
27+
parameters: z.object({
28+
fromBlock: z.string().describe("the `integer` block number to start searching for logs eg. `12878196`"),
29+
toBlock: z.string().describe("the `integer` block number to stop searching for logs eg. `12879196`"),
30+
topic0: z.string().optional().describe("the topic numbers to search for limited to`topic0`, `topic1`, `topic2`, `topic3`"),
31+
topic1: z.string().optional().describe("the topic numbers to search for limited to`topic0`, `topic1`, `topic2`, `topic3`"),
32+
topic2: z.string().optional().describe("the topic numbers to search for limited to`topic0`, `topic1`, `topic2`, `topic3`"),
33+
topic3: z.string().optional().describe("the topic numbers to search for limited to`topic0`, `topic1`, `topic2`, `topic3`"),
34+
topic0_1_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
35+
topic1_2_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
36+
topic2_3_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
37+
topic0_2_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
38+
topic0_3_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
39+
topic1_3_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
40+
page: z.string().optional().describe("the `integer` page number, if pagination is enabled"),
41+
offset: z.string().optional().describe("the number of transactions displayed per page limited to **1000 records** per query, use the `page` parameter for subsequent records")
42+
}),
43+
execute: async (params) => {
44+
const fullParams = { ...params, module: "logs", action: "getLogs" };
45+
return await apiCall(fullParams);
46+
}
47+
});
48+
49+
// Get Event Logs by Address filtered by Topics
50+
server.addTool({
51+
name: "logs/getLogsByAddressAndTopics",
52+
description: "Returns the event logs from an address, filtered by topics and block range.",
53+
parameters: z.object({
54+
fromBlock: z.string().describe("the `integer` block number to start searching for logs eg. `12878196`"),
55+
toBlock: z.string().describe("the `integer` block number to stop searching for logs eg. `12879196`"),
56+
address: z.string().describe("the `string` representing the address to check for logs"),
57+
topic0: z.string().optional().describe("the topic numbers to search for limited to`topic0`, `topic1`, `topic2`, `topic3`"),
58+
topic1: z.string().optional().describe("the topic numbers to search for limited to`topic0`, `topic1`, `topic2`, `topic3`"),
59+
topic2: z.string().optional().describe("the topic numbers to search for limited to`topic0`, `topic1`, `topic2`, `topic3`"),
60+
topic3: z.string().optional().describe("the topic numbers to search for limited to`topic0`, `topic1`, `topic2`, `topic3`"),
61+
topic0_1_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
62+
topic1_2_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
63+
topic2_3_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
64+
topic0_2_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
65+
topic0_3_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
66+
topic1_3_opr: z.string().optional().describe("the topic operator when multiple topic combinations are used limited to `and` or `or`"),
67+
page: z.string().optional().describe("the `integer` page number, if pagination is enabled"),
68+
offset: z.string().optional().describe("the number of transactions displayed per page limited to **1000 records** per query, use the `page` parameter for subsequent records")
69+
}),
70+
execute: async (params) => {
71+
const fullParams = { ...params, module: "logs", action: "getLogs" };
72+
return await apiCall(fullParams);
73+
}
74+
});
75+
}

0 commit comments

Comments
 (0)