Skip to main content
Glama
thichcode

Matomo MCP Server

by thichcode

matomo_get_visits_summary

Retrieve a summary of site visits, including metrics like unique visitors and page views, for a specified date and period using the Matomo Analytics API. Input site ID, date, and period for analysis.

Instructions

Lấy tổng quan lượt truy cập của site

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateYesNgày cần lấy dữ liệu (YYYY-MM-DD)
periodNoChu kỳ (day, week, month, year)day
siteIdYesID của site

Implementation Reference

  • Core handler implementation that makes the API call to Matomo's VisitsSummary.get endpoint to retrieve visits summary data.
    async getVisitsSummary(siteId: number, date: string, period: string = 'day'): Promise<any> { return await this.makeRequest('VisitsSummary.get', { idSite: siteId, date, period, }); }
  • MCP server wrapper handler that checks connection, invokes the service method, and formats the response as MCP content.
    private async handleGetVisitsSummary(args: { siteId: number; date: string; period?: string }) { if (!this.matomoService) { throw new Error('Chưa kết nối đến Matomo. Vui lòng sử dụng matomo_connect trước.'); } const summary = await this.matomoService.getVisitsSummary(args.siteId, args.date, args.period); return { content: [ { type: 'text', text: `Tổng quan lượt truy cập:\n${JSON.stringify(summary, null, 2)}`, }, ], }; }
  • Tool schema definition including name, description, and input schema for validation in the ListTools response.
    { name: 'matomo_get_visits_summary', description: 'Lấy tổng quan lượt truy cập của site', inputSchema: { type: 'object', properties: { siteId: { type: 'number', description: 'ID của site', }, date: { type: 'string', description: 'Ngày cần lấy dữ liệu (YYYY-MM-DD)', }, period: { type: 'string', description: 'Chu kỳ (day, week, month, year)', default: 'day', }, }, required: ['siteId', 'date'], }, },
  • src/index.ts:284-286 (registration)
    Dispatch registration in the CallToolRequest switch statement that routes to the handler.
    case 'matomo_get_visits_summary': return await this.handleGetVisitsSummary(args as { siteId: number; date: string; period?: string });
  • Helper method used by getVisitsSummary to make authenticated HTTP requests to the Matomo API.
    private async makeRequest(method: string, params: Record<string, any> = {}): Promise<any> { const requestParams = { module: 'API', format: 'JSON', token_auth: this.config.tokenAuth, ...params, }; try { const response = await this.client.get('', { params: requestParams }); return response.data; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`Matomo API error: ${error.response?.data?.message || error.message}`); } throw error; } }

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/thichcode/matomo_mcp'

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