get_analytics_data
Access visitor statistics and popularity trends for BioOntology, with optional filtering by month, year, or specific ontology, to analyze usage patterns and insights.
Instructions
Get visitor statistics and popularity trends with optional date filtering
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| month | No | Month (1-12) for specific data | |
| ontology | No | Specific ontology acronym (optional) | |
| year | No | Year for specific data (2013+) |
Implementation Reference
- src/index.ts:680-692 (registration)Registers the 'get_analytics_data' tool with the MCP server, including its description and detailed input schema for parameters like month, year, and optional ontology.{ name: 'get_analytics_data', description: 'Get visitor statistics and popularity trends with optional date filtering', inputSchema: { type: 'object', properties: { month: { type: 'number', description: 'Month (1-12) for specific data', minimum: 1, maximum: 12 }, year: { type: 'number', description: 'Year for specific data (2013+)', minimum: 2013 }, ontology: { type: 'string', description: 'Specific ontology acronym (optional)' }, }, required: [], }, },
- src/index.ts:1110-1149 (handler)The primary handler function for the get_analytics_data tool. Validates input args, builds the API request to the BioOntology analytics endpoint (global or ontology-specific), fetches data, and returns formatted JSON response or error content.private async handleGetAnalyticsData(args: any) { if (!isValidGetAnalyticsArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid analytics data arguments'); } try { const params: any = { apikey: this.apiKey, }; if (args.month !== undefined) params.month = args.month; if (args.year !== undefined) params.year = args.year; let endpoint = '/analytics'; if (args.ontology) { endpoint = `/ontologies/${args.ontology}/analytics`; } const response = await this.apiClient.get(endpoint, { params }); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error: any) { return { content: [ { type: 'text', text: `Error fetching analytics data: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], isError: true, }; } }
- src/index.ts:238-248 (schema)Input validation schema as a type guard function that checks arguments conform to expected types and ranges for month (1-12), year (>=2013), and optional ontology string.const isValidGetAnalyticsArgs = ( args: any ): args is { month?: number; year?: number; ontology?: string } => { return ( typeof args === 'object' && args !== null && (args.month === undefined || (typeof args.month === 'number' && args.month >= 1 && args.month <= 12)) && (args.year === undefined || (typeof args.year === 'number' && args.year >= 2013)) && (args.ontology === undefined || typeof args.ontology === 'string') ); };
- src/index.ts:722-723 (registration)Dispatcher switch case in the CallToolRequestHandler that maps tool name 'get_analytics_data' to its handler method.case 'get_analytics_data': return this.handleGetAnalyticsData(args);