list_events
Find and filter available events by search term or location to discover relevant activities.
Instructions
List all available events. Optionally filter by search term or location.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| search | No | Search term to filter events by title or description | |
| location | No | Filter events by location |
Implementation Reference
- src/index.ts:62-83 (handler)The asynchronous handler function that implements the core logic of the 'list_events' tool. It fetches events from the API client using provided search and location filters, formats the results, and returns them as MCP content or an error response.async ({ search, location }) => { try { const apiClient = getClient(); const events = await apiClient.listEvents({ search, location }); if (events.length === 0) { return { content: [{ type: 'text', text: 'No events found matching your criteria.' }] }; } const formatted = events.map(formatEvent).join('\n\n---\n\n'); return { content: [{ type: 'text', text: `Found ${events.length} event(s):\n\n${formatted}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
- src/index.ts:58-61 (schema)Zod schema defining the input parameters for the 'list_events' tool: optional search string and location filter.{ search: z.string().optional().describe('Search term to filter events by title or description'), location: z.string().optional().describe('Filter events by location') },
- src/index.ts:55-84 (registration)The server.tool() call that registers the 'list_events' MCP tool with name, description, input schema, and handler function.server.tool( 'list_events', 'List all available events. Optionally filter by search term or location.', { search: z.string().optional().describe('Search term to filter events by title or description'), location: z.string().optional().describe('Filter events by location') }, async ({ search, location }) => { try { const apiClient = getClient(); const events = await apiClient.listEvents({ search, location }); if (events.length === 0) { return { content: [{ type: 'text', text: 'No events found matching your criteria.' }] }; } const formatted = events.map(formatEvent).join('\n\n---\n\n'); return { content: [{ type: 'text', text: `Found ${events.length} event(s):\n\n${formatted}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
- src/api-client.ts:112-119 (helper)Supporting API client method 'listEvents' invoked by the tool handler to fetch events from the backend API.async listEvents(params: EventListParams = {}): Promise<Event[]> { try { const response: AxiosResponse<Event[]> = await this.client.get('/api/events/', { params }); return response.data; } catch (error) { throw new Error(`Failed to list events: ${getErrorMessage(error)}`); } }
- src/index.ts:29-38 (helper)Helper function to format an individual Event object into a human-readable string for the tool's output.function formatEvent(event: Event): string { return `Event: ${event.title} (ID: ${event.id}) Description: ${event.description} Location: ${event.location} Start: ${event.start_time} End: ${event.end_time} Capacity: ${event.capacity} Organizer: ${event.organizer.username} Registered: ${event.is_registered ? 'Yes' : 'No'}`; }