Skip to main content
Glama
Bankless

Bankless Onchain MCP Server

Official
by Bankless

get_events

Retrieve blockchain event logs by specifying network, contract addresses, and topic filters. Access detailed on-chain activity data for analysis and monitoring purposes.

Instructions

Fetches event logs for a given network and filter criteria

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressesYesList of contract addresses to filter events
fromBlockNoBlock number to start fetching logs from
networkYesThe blockchain network (e.g., "ethereum", "base")
optionalTopicsNoOptional additional topics
toBlockNoBlock number to stop fetching logs at
topicYesPrimary topic to filter events

Implementation Reference

  • The core handler function that fetches event logs from the Bankless API using the provided parameters.
    /**
     * Fetches event logs for a given network and filter criteria.
     */
    export async function getEvents(
        network: string,
        addresses: string[],
        topic: string,
        optionalTopics: (string | null)[] = [],
        fromBlock?: number,
        toBlock?: number
    ): Promise<EthLog> {
        const token = process.env.BANKLESS_API_TOKEN;
    
        if (!token) {
            throw new BanklessAuthenticationError('BANKLESS_API_TOKEN environment variable is not set');
        }
    
        const endpoint = `${BASE_URL}/chains/${network}/events/logs`;
    
        try {
            const response = await axios.post(
                endpoint,
                {
                    addresses,
                    topic,
                    optionalTopics: optionalTopics || [],
                    fromBlock,
                    toBlock,
                    fetchAll: false,
                },
                {
                    headers: {
                        'Content-Type': 'application/json',
                        'X-BANKLESS-TOKEN': `${token}`
                    }
                }
            );
    
            return response.data;
        } catch (error) {
            if (axios.isAxiosError(error)) {
                const statusCode = error.response?.status || 'unknown';
                const errorMessage = error.response?.data?.message || error.message;
    
                if (statusCode === 401 || statusCode === 403) {
                    throw new BanklessAuthenticationError(`Authentication Failed: ${errorMessage}`);
                } else if (statusCode === 404) {
                    throw new BanklessResourceNotFoundError(`Not Found: ${errorMessage}`);
                } else if (statusCode === 422) {
                    throw new BanklessValidationError(`Validation Error: ${errorMessage}`, error.response?.data);
                } else if (statusCode === 429) {
                    // Extract reset timestamp or default to 60 seconds from now
                    const resetAt = new Date();
                    resetAt.setSeconds(resetAt.getSeconds() + 60);
                    throw new BanklessRateLimitError(`Rate Limit Exceeded: ${errorMessage}`, resetAt);
                }
    
                throw new Error(`Bankless API Error (${statusCode}): ${errorMessage}`);
            }
            throw new Error(`Failed to fetch event logs: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
  • Zod schema defining the input validation for the get_events tool.
    export const GetEventLogsSchema = z.object({
        network: z.string().describe('The blockchain network (e.g., "ethereum", "base")'),
        addresses: z.array(z.string()).describe('List of contract addresses to filter events'),
        topic: z.string().describe('Primary topic to filter events'),
        optionalTopics: z.array(z.string().nullable()).optional().describe('Optional additional topics'),
        fromBlock: z.number().optional().describe("Block number to start fetching logs from"),
        toBlock: z.number().optional().describe("Block number to stop fetching logs at")
    });
  • src/index.ts:100-103 (registration)
    Registration of the get_events tool in the MCP server's list of tools, referencing the input schema.
        name: "get_events",
        description: "Fetches event logs for a given network and filter criteria",
        inputSchema: zodToJsonSchema(events.GetEventLogsSchema),
    },
  • Dispatch handler in the MCP server that parses arguments and calls the getEvents implementation.
    case "get_events": {
        const args = events.GetEventLogsSchema.parse(request.params.arguments);
        const result = await events.getEvents(
            args.network,
            args.addresses,
            args.topic,
            args.optionalTopics,
            args.fromBlock,
            args.toBlock
        );
        return {
            content: [{type: "text", text: JSON.stringify(result, null, 2)}],
        };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool 'fetches' event logs, implying a read-only operation, but doesn't cover critical aspects like rate limits, authentication needs, pagination, error handling, or what the fetched logs include (e.g., format, fields). This leaves significant gaps for a tool with multiple parameters and no output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary words. It directly communicates the tool's function and scope, making it easy to parse and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (6 parameters, no output schema, no annotations), the description is inadequate. It lacks details on behavioral traits, output format, and usage context, leaving the agent with insufficient information to effectively invoke the tool beyond basic parameter mapping.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 6 parameters. The description adds minimal value by mentioning 'filter criteria,' which aligns with parameters like addresses and topic, but doesn't provide additional context beyond what's in the schema. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('fetches') and resource ('event logs') with specific scope ('for a given network and filter criteria'), which distinguishes it from general data retrieval tools. However, it doesn't explicitly differentiate from sibling tools like 'get_transaction_history_for_user' or 'get_block_info', which might also involve event-related data.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, such as 'get_transaction_history_for_user' for user-specific events or 'get_block_info' for block-level data. It mentions filter criteria but doesn't specify scenarios or exclusions, leaving usage context implied at best.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Bankless/onchain-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server