matomo-mcp 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +270 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +314 -0
- package/dist/index.js.map +1 -0
- package/dist/matomo-client.d.ts +97 -0
- package/dist/matomo-client.d.ts.map +1 -0
- package/dist/matomo-client.js +77 -0
- package/dist/matomo-client.js.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Matomo MCP Server
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server that provides access to Matomo analytics data through AI assistants like Cursor, Claude Desktop, and Claude Code.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Website Analytics**: Get visits, page views, bounce rates, and visitor statistics
|
|
8
|
+
- **Real-time Data**: Access live visitor counters and current activity
|
|
9
|
+
- **Top Pages**: Retrieve most visited pages with detailed metrics
|
|
10
|
+
- **Date Ranges**: Query data for specific periods or date ranges
|
|
11
|
+
- **Secure**: API credentials stored in environment variables
|
|
12
|
+
- **Extensible**: Easy to add more Matomo features as needed
|
|
13
|
+
|
|
14
|
+
## Available Tools
|
|
15
|
+
|
|
16
|
+
### `get-visits-summary`
|
|
17
|
+
Get comprehensive website analytics summary including visits, page views, bounce rate, and more.
|
|
18
|
+
|
|
19
|
+
**Parameters:**
|
|
20
|
+
- `period` (optional): Time period - `day`, `week`, `month`, or `year` (default: `day`)
|
|
21
|
+
- `date` (optional): Date - `yesterday`, `today`, `YYYY-MM-DD`, `last7`, `last30`, etc. (default: `yesterday`)
|
|
22
|
+
|
|
23
|
+
### `get-live-counters`
|
|
24
|
+
Get real-time visitor counters for the last 30 minutes.
|
|
25
|
+
|
|
26
|
+
**Parameters:** None
|
|
27
|
+
|
|
28
|
+
### `get-top-pages`
|
|
29
|
+
Get the most visited pages on the website.
|
|
30
|
+
|
|
31
|
+
**Parameters:**
|
|
32
|
+
- `period` (optional): Time period - `day`, `week`, `month`, or `year` (default: `day`)
|
|
33
|
+
- `date` (optional): Date - `yesterday`, `today`, `YYYY-MM-DD`, `last7`, `last30`, etc. (default: `yesterday`)
|
|
34
|
+
- `limit` (optional): Maximum number of pages to return (1-100, default: 10)
|
|
35
|
+
|
|
36
|
+
### `get-visits-summary-range`
|
|
37
|
+
Get website analytics summary for a date range.
|
|
38
|
+
|
|
39
|
+
**Parameters:**
|
|
40
|
+
- `period` (optional): Time period - `day`, `week`, `month`, or `year` (default: `day`)
|
|
41
|
+
- `date` (optional): Date range - `last7`, `last30`, `last90`, etc. (default: `last7`)
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
1. **Clone or download this repository**
|
|
46
|
+
```bash
|
|
47
|
+
git clone <repository-url>
|
|
48
|
+
cd matomo-mcp
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
2. **Install dependencies**
|
|
52
|
+
```bash
|
|
53
|
+
npm install
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
3. **Configure environment variables**
|
|
57
|
+
```bash
|
|
58
|
+
cp .env.example .env
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Edit `.env` with your Matomo credentials:
|
|
62
|
+
```
|
|
63
|
+
MATOMO_URL=https://your-matomo-instance.com
|
|
64
|
+
MATOMO_API_KEY=your_api_key_here
|
|
65
|
+
MATOMO_SITE_ID=your_site_id
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
4. **Build the project**
|
|
69
|
+
```bash
|
|
70
|
+
npm run build
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Configuration
|
|
74
|
+
|
|
75
|
+
### For Cursor
|
|
76
|
+
|
|
77
|
+
1. Open Cursor settings
|
|
78
|
+
2. Navigate to MCP Servers configuration
|
|
79
|
+
3. Add the following configuration:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"mcpServers": {
|
|
84
|
+
"matomo": {
|
|
85
|
+
"command": "node",
|
|
86
|
+
"args": ["/path/to/matomo-mcp/dist/index.js"],
|
|
87
|
+
"env": {
|
|
88
|
+
"MATOMO_URL": "https://your-matomo-instance.com",
|
|
89
|
+
"MATOMO_API_KEY": "your_api_key_here",
|
|
90
|
+
"MATOMO_SITE_ID": "your_site_id"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### For Claude Desktop
|
|
98
|
+
|
|
99
|
+
1. Open Claude Desktop settings
|
|
100
|
+
2. Navigate to MCP Servers
|
|
101
|
+
3. Add a new server with the same configuration as above
|
|
102
|
+
|
|
103
|
+
### For Claude Code CLI
|
|
104
|
+
|
|
105
|
+
Claude Code supports MCP servers through project-level configuration files.
|
|
106
|
+
|
|
107
|
+
**Setup:**
|
|
108
|
+
|
|
109
|
+
1. Ensure your `.env` file is configured with your Matomo credentials
|
|
110
|
+
2. The project includes a `.mcp.json` file that references environment variables:
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"mcpServers": {
|
|
114
|
+
"matomo": {
|
|
115
|
+
"command": "node",
|
|
116
|
+
"args": ["${PWD}/dist/index.js"],
|
|
117
|
+
"env": {
|
|
118
|
+
"MATOMO_URL": "${MATOMO_URL}",
|
|
119
|
+
"MATOMO_API_KEY": "${MATOMO_API_KEY}",
|
|
120
|
+
"MATOMO_SITE_ID": "${MATOMO_SITE_ID}"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
3. When you start Claude Code in this project directory, you'll be prompted to approve the MCP server
|
|
127
|
+
4. After approval, Claude Code can access your Matomo analytics directly
|
|
128
|
+
|
|
129
|
+
**Verify Configuration:**
|
|
130
|
+
```bash
|
|
131
|
+
# List configured MCP servers
|
|
132
|
+
claude mcp list
|
|
133
|
+
|
|
134
|
+
# Get details about the Matomo server
|
|
135
|
+
claude mcp get matomo
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Security Note:** The `.mcp.json` file uses environment variable references (`${MATOMO_API_KEY}`) instead of hardcoded values, making it safe to commit to version control. Your actual credentials remain in `.env` which is excluded from git.
|
|
139
|
+
|
|
140
|
+
## Usage Examples
|
|
141
|
+
|
|
142
|
+
Once configured, you can ask your AI assistant questions like:
|
|
143
|
+
|
|
144
|
+
- "Show me yesterday's website analytics"
|
|
145
|
+
- "What are the top 5 pages from last week?"
|
|
146
|
+
- "How many visitors are currently on the site?"
|
|
147
|
+
- "Give me a summary of visits for the last 7 days"
|
|
148
|
+
- "What's the bounce rate for this month?"
|
|
149
|
+
|
|
150
|
+
## Development
|
|
151
|
+
|
|
152
|
+
### Project Structure
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
matomo-mcp/
|
|
156
|
+
├── src/
|
|
157
|
+
│ ├── index.ts # Main MCP server implementation
|
|
158
|
+
│ └── matomo-client.ts # Matomo API client wrapper
|
|
159
|
+
├── config/ # Client configuration examples
|
|
160
|
+
├── dist/ # Compiled JavaScript (after build)
|
|
161
|
+
├── .mcp.json # Claude Code CLI configuration (project-level)
|
|
162
|
+
├── .env # Your credentials (DO NOT commit)
|
|
163
|
+
├── .env.example # Environment variables template
|
|
164
|
+
├── claude.md # Claude-specific integration guide
|
|
165
|
+
└── README.md # This file
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Adding New Tools
|
|
169
|
+
|
|
170
|
+
To add new Matomo features:
|
|
171
|
+
|
|
172
|
+
1. **Add API method to MatomoClient** (`src/matomo-client.ts`):
|
|
173
|
+
```typescript
|
|
174
|
+
async getNewFeature(params: any): Promise<NewFeatureData> {
|
|
175
|
+
return this.makeApiCall<NewFeatureData>('NewModule.getMethod', params);
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
2. **Add tool definition** in `src/index.ts`:
|
|
180
|
+
```typescript
|
|
181
|
+
{
|
|
182
|
+
name: 'get-new-feature',
|
|
183
|
+
description: 'Description of the new feature',
|
|
184
|
+
inputSchema: {
|
|
185
|
+
type: 'object',
|
|
186
|
+
properties: {
|
|
187
|
+
// Define parameters
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
3. **Add tool handler** in the `CallToolRequestSchema` handler:
|
|
194
|
+
```typescript
|
|
195
|
+
case 'get-new-feature': {
|
|
196
|
+
const data = await this.matomoClient.getNewFeature(args);
|
|
197
|
+
return {
|
|
198
|
+
content: [{
|
|
199
|
+
type: 'text',
|
|
200
|
+
text: formatData(data),
|
|
201
|
+
}],
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Building and Testing
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# Build the project
|
|
210
|
+
npm run build
|
|
211
|
+
|
|
212
|
+
# Run in development mode
|
|
213
|
+
npm run dev
|
|
214
|
+
|
|
215
|
+
# Run the built server
|
|
216
|
+
npm start
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Security
|
|
220
|
+
|
|
221
|
+
- API credentials are stored in environment variables
|
|
222
|
+
- Never commit `.env` files to version control
|
|
223
|
+
- Use HTTPS for your Matomo instance
|
|
224
|
+
- Consider using read-only API keys for security
|
|
225
|
+
|
|
226
|
+
## Troubleshooting
|
|
227
|
+
|
|
228
|
+
### Common Issues
|
|
229
|
+
|
|
230
|
+
1. **"Missing required environment variables"**
|
|
231
|
+
- Ensure `.env` file exists and contains all required variables
|
|
232
|
+
- Check that variable names match exactly
|
|
233
|
+
|
|
234
|
+
2. **"Matomo API error: 401"**
|
|
235
|
+
- Verify your API key is correct
|
|
236
|
+
- Check that the API key has proper permissions
|
|
237
|
+
|
|
238
|
+
3. **"Matomo API error: 404"**
|
|
239
|
+
- Verify your Matomo URL is correct
|
|
240
|
+
- Ensure the site ID exists
|
|
241
|
+
|
|
242
|
+
4. **Server not starting**
|
|
243
|
+
- Run `npm run build` to compile TypeScript
|
|
244
|
+
- Check that all dependencies are installed
|
|
245
|
+
|
|
246
|
+
### Debug Mode
|
|
247
|
+
|
|
248
|
+
To enable debug logging, set the environment variable:
|
|
249
|
+
```bash
|
|
250
|
+
DEBUG=matomo-mcp
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Contributing
|
|
254
|
+
|
|
255
|
+
1. Fork the repository
|
|
256
|
+
2. Create a feature branch
|
|
257
|
+
3. Make your changes
|
|
258
|
+
4. Add tests if applicable
|
|
259
|
+
5. Submit a pull request
|
|
260
|
+
|
|
261
|
+
## License
|
|
262
|
+
|
|
263
|
+
ISC License - see LICENSE file for details
|
|
264
|
+
|
|
265
|
+
## Support
|
|
266
|
+
|
|
267
|
+
For issues and questions:
|
|
268
|
+
1. Check the troubleshooting section above
|
|
269
|
+
2. Review Matomo API documentation
|
|
270
|
+
3. Open an issue in this repository
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
5
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
6
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
7
|
+
const matomo_client_js_1 = require("./matomo-client.js");
|
|
8
|
+
class MatomoMCPServer {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.server = new index_js_1.Server({
|
|
11
|
+
name: 'matomo-mcp',
|
|
12
|
+
version: '2.0.0',
|
|
13
|
+
}, {
|
|
14
|
+
capabilities: {
|
|
15
|
+
tools: {},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
this.matomoClient = new matomo_client_js_1.MatomoClient();
|
|
19
|
+
this.setupToolHandlers();
|
|
20
|
+
}
|
|
21
|
+
setupToolHandlers() {
|
|
22
|
+
// Shared schema fragments
|
|
23
|
+
const siteIdParam = {
|
|
24
|
+
type: 'string',
|
|
25
|
+
description: 'Matomo site ID. Use list-sites to see available sites. Defaults to env MATOMO_SITE_ID.',
|
|
26
|
+
};
|
|
27
|
+
const segmentParam = {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'Matomo segment filter (e.g., "customVariableValue1==us-east-1"). See Matomo segment docs for syntax.',
|
|
30
|
+
};
|
|
31
|
+
const periodParam = {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'Time period (day, week, month, year)',
|
|
34
|
+
enum: ['day', 'week', 'month', 'year'],
|
|
35
|
+
default: 'day',
|
|
36
|
+
};
|
|
37
|
+
const dateParam = {
|
|
38
|
+
type: 'string',
|
|
39
|
+
description: 'Date or range (yesterday, today, YYYY-MM-DD, last7, last30, etc.)',
|
|
40
|
+
default: 'yesterday',
|
|
41
|
+
};
|
|
42
|
+
// List available tools
|
|
43
|
+
this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
44
|
+
return {
|
|
45
|
+
tools: [
|
|
46
|
+
{
|
|
47
|
+
name: 'list-sites',
|
|
48
|
+
description: 'List all Matomo sites you have access to, with their IDs and URLs',
|
|
49
|
+
inputSchema: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'get-visits-summary',
|
|
56
|
+
description: 'Get website analytics summary — visits, page views, bounce rate, and more. Use date like "yesterday" for a single period or "last7"/"last30" for a daily breakdown over a range.',
|
|
57
|
+
inputSchema: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {
|
|
60
|
+
period: periodParam,
|
|
61
|
+
date: dateParam,
|
|
62
|
+
site_id: siteIdParam,
|
|
63
|
+
segment: segmentParam,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'get-live-counters',
|
|
69
|
+
description: 'Get real-time visitor counters for the last 30 minutes',
|
|
70
|
+
inputSchema: {
|
|
71
|
+
type: 'object',
|
|
72
|
+
properties: {
|
|
73
|
+
site_id: siteIdParam,
|
|
74
|
+
segment: segmentParam,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'get-top-pages',
|
|
80
|
+
description: 'Get the most visited pages on a website',
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
period: periodParam,
|
|
85
|
+
date: dateParam,
|
|
86
|
+
limit: {
|
|
87
|
+
type: 'number',
|
|
88
|
+
description: 'Maximum number of pages to return',
|
|
89
|
+
default: 10,
|
|
90
|
+
minimum: 1,
|
|
91
|
+
maximum: 100,
|
|
92
|
+
},
|
|
93
|
+
site_id: siteIdParam,
|
|
94
|
+
segment: segmentParam,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'get-referrers',
|
|
100
|
+
description: 'Get traffic sources — channel overview (Direct, Search, Social, etc.) or campaign breakdown. Set type to "campaigns" to see campaign names and metrics.',
|
|
101
|
+
inputSchema: {
|
|
102
|
+
type: 'object',
|
|
103
|
+
properties: {
|
|
104
|
+
period: periodParam,
|
|
105
|
+
date: dateParam,
|
|
106
|
+
type: {
|
|
107
|
+
type: 'string',
|
|
108
|
+
description: 'Omit for channel overview, set to "campaigns" for campaign breakdown',
|
|
109
|
+
enum: ['campaigns'],
|
|
110
|
+
},
|
|
111
|
+
site_id: siteIdParam,
|
|
112
|
+
segment: segmentParam,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'get-events',
|
|
118
|
+
description: 'Get event analytics — categories overview or actions within a specific category. Useful for tracking feature adoption, user interactions, and custom events.',
|
|
119
|
+
inputSchema: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
period: periodParam,
|
|
123
|
+
date: dateParam,
|
|
124
|
+
category: {
|
|
125
|
+
type: 'string',
|
|
126
|
+
description: 'Event category to drill into (e.g., "Chat", "UI v2", "Feature"). Omit to see all categories.',
|
|
127
|
+
},
|
|
128
|
+
site_id: siteIdParam,
|
|
129
|
+
segment: segmentParam,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
// Handle tool calls
|
|
137
|
+
this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
138
|
+
const { name, arguments: args } = request.params;
|
|
139
|
+
const a = (args || {});
|
|
140
|
+
try {
|
|
141
|
+
switch (name) {
|
|
142
|
+
case 'list-sites': {
|
|
143
|
+
const sites = await this.matomoClient.listSites();
|
|
144
|
+
let text = '## Available Matomo Sites\n\n';
|
|
145
|
+
sites.forEach((site) => {
|
|
146
|
+
text += `- **Site ${site.idsite}**: ${site.name} — ${site.main_url}\n`;
|
|
147
|
+
});
|
|
148
|
+
return { content: [{ type: 'text', text }] };
|
|
149
|
+
}
|
|
150
|
+
case 'get-visits-summary': {
|
|
151
|
+
const period = a.period || 'day';
|
|
152
|
+
const date = a.date || 'yesterday';
|
|
153
|
+
const data = await this.matomoClient.getVisitsSummary(period, date, a.site_id, a.segment);
|
|
154
|
+
// Range mode: date like "last7", "last30" returns { "2024-01-01": {...}, ... }
|
|
155
|
+
const isRange = typeof data === 'object' && !('nb_visits' in data);
|
|
156
|
+
if (isRange) {
|
|
157
|
+
const rangeData = data;
|
|
158
|
+
let text = `## Analytics Summary (${period}: ${date})\n\n`;
|
|
159
|
+
for (const [dateKey, dayData] of Object.entries(rangeData)) {
|
|
160
|
+
const uv = dayData.nb_uniq_visitors || dayData.nb_visitors || 0;
|
|
161
|
+
text += `**${dateKey}**: ${dayData.nb_visits.toLocaleString()} visits, ${dayData.nb_actions.toLocaleString()} page views, ${uv.toLocaleString()} unique visitors, ${dayData.bounce_rate} bounce rate\n`;
|
|
162
|
+
}
|
|
163
|
+
return { content: [{ type: 'text', text }] };
|
|
164
|
+
}
|
|
165
|
+
// Single period mode
|
|
166
|
+
const d = data;
|
|
167
|
+
const uniqueVisitors = d.nb_uniq_visitors || d.nb_visitors || 0;
|
|
168
|
+
const avgActionsPerVisit = d.nb_actions_per_visit || (d.nb_visits > 0 ? (d.nb_actions / d.nb_visits) : 0);
|
|
169
|
+
const avgVisitDuration = d.avg_time_on_site || (d.nb_visits > 0 ? Math.round(d.sum_visit_length / d.nb_visits) : 0);
|
|
170
|
+
const conversions = d.nb_conversions || d.nb_visits_converted || 0;
|
|
171
|
+
const revenue = d.revenue || 0;
|
|
172
|
+
return {
|
|
173
|
+
content: [{
|
|
174
|
+
type: 'text',
|
|
175
|
+
text: `## Analytics Summary (${period}: ${date})\n\n` +
|
|
176
|
+
`- **Visits**: ${d.nb_visits.toLocaleString()}\n` +
|
|
177
|
+
`- **Page Views**: ${d.nb_actions.toLocaleString()}\n` +
|
|
178
|
+
`- **Unique Visitors**: ${uniqueVisitors.toLocaleString()}\n` +
|
|
179
|
+
`- **Bounce Rate**: ${d.bounce_rate}\n` +
|
|
180
|
+
`- **Avg Actions/Visit**: ${typeof avgActionsPerVisit === 'number' ? avgActionsPerVisit.toFixed(2) : avgActionsPerVisit}\n` +
|
|
181
|
+
`- **Avg Visit Duration**: ${avgVisitDuration}s\n` +
|
|
182
|
+
`- **Conversions**: ${conversions}\n` +
|
|
183
|
+
`- **Revenue**: $${revenue.toFixed(2)}`,
|
|
184
|
+
}],
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
case 'get-live-counters': {
|
|
188
|
+
const data = await this.matomoClient.getLiveCounters(a.site_id, a.segment);
|
|
189
|
+
const visitsConverted = data.visitsConverted || data.visits_conv || 0;
|
|
190
|
+
return {
|
|
191
|
+
content: [{
|
|
192
|
+
type: 'text',
|
|
193
|
+
text: `## Live Visitors (Last 30 min)\n\n` +
|
|
194
|
+
`- **Visitors**: ${data.visitors}\n` +
|
|
195
|
+
`- **Visits**: ${data.visits}\n` +
|
|
196
|
+
`- **Actions**: ${data.actions}\n` +
|
|
197
|
+
`- **Converted Visits**: ${visitsConverted}`,
|
|
198
|
+
}],
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
case 'get-top-pages': {
|
|
202
|
+
const period = a.period || 'day';
|
|
203
|
+
const date = a.date || 'yesterday';
|
|
204
|
+
const limit = a.limit || 10;
|
|
205
|
+
const data = await this.matomoClient.getTopPages(period, date, limit, a.site_id, a.segment);
|
|
206
|
+
let text = `## Top Pages (${period}: ${date})\n\n`;
|
|
207
|
+
data.forEach((page, index) => {
|
|
208
|
+
text += `${index + 1}. **${page.label}**\n` +
|
|
209
|
+
` - Visits: ${page.nb_visits.toLocaleString()} | Views: ${page.nb_hits.toLocaleString()}\n` +
|
|
210
|
+
` - Bounce: ${page.bounce_rate} | Exit: ${page.exit_rate} | Avg Time: ${Math.round(page.avg_time_on_page)}s\n` +
|
|
211
|
+
` - ${page.url}\n\n`;
|
|
212
|
+
});
|
|
213
|
+
return { content: [{ type: 'text', text }] };
|
|
214
|
+
}
|
|
215
|
+
case 'get-referrers': {
|
|
216
|
+
const period = a.period || 'day';
|
|
217
|
+
const date = a.date || 'yesterday';
|
|
218
|
+
if (a.type === 'campaigns') {
|
|
219
|
+
const data = await this.matomoClient.getCampaigns(period, date, a.site_id, a.segment);
|
|
220
|
+
let text = `## Campaigns (${period}: ${date})\n\n`;
|
|
221
|
+
if (!data.length) {
|
|
222
|
+
text += 'No campaign data found for this period.\n';
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
data.forEach((campaign) => {
|
|
226
|
+
text += `- **${campaign.label}**: ${campaign.nb_visits.toLocaleString()} visits, ${campaign.nb_actions.toLocaleString()} actions`;
|
|
227
|
+
if (campaign.bounce_rate)
|
|
228
|
+
text += `, ${campaign.bounce_rate} bounce`;
|
|
229
|
+
text += '\n';
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return { content: [{ type: 'text', text }] };
|
|
233
|
+
}
|
|
234
|
+
// Default: channel overview
|
|
235
|
+
const data = await this.matomoClient.getReferrerTypes(period, date, a.site_id, a.segment);
|
|
236
|
+
let text = `## Traffic Sources (${period}: ${date})\n\n`;
|
|
237
|
+
if (!data.length) {
|
|
238
|
+
text += 'No referrer data found for this period.\n';
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
data.forEach((ref) => {
|
|
242
|
+
text += `- **${ref.label}**: ${ref.nb_visits.toLocaleString()} visits, ${ref.nb_actions.toLocaleString()} actions`;
|
|
243
|
+
if (ref.bounce_rate)
|
|
244
|
+
text += `, ${ref.bounce_rate} bounce`;
|
|
245
|
+
text += '\n';
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return { content: [{ type: 'text', text }] };
|
|
249
|
+
}
|
|
250
|
+
case 'get-events': {
|
|
251
|
+
const period = a.period || 'day';
|
|
252
|
+
const date = a.date || 'yesterday';
|
|
253
|
+
if (a.category) {
|
|
254
|
+
const data = await this.matomoClient.getEventActions(period, date, a.category, a.site_id, a.segment);
|
|
255
|
+
let text = `## Event Actions — ${a.category} (${period}: ${date})\n\n`;
|
|
256
|
+
if (!data.length) {
|
|
257
|
+
text += `No actions found for category "${a.category}" in this period.\n`;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
data.forEach((event) => {
|
|
261
|
+
text += `- **${event.label}**: ${event.nb_events} events, ${event.nb_visits} visits`;
|
|
262
|
+
if (event.avg_event_value != null)
|
|
263
|
+
text += `, avg value: ${event.avg_event_value}`;
|
|
264
|
+
text += '\n';
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return { content: [{ type: 'text', text }] };
|
|
268
|
+
}
|
|
269
|
+
// Default: category overview
|
|
270
|
+
const data = await this.matomoClient.getEventCategories(period, date, a.site_id, a.segment);
|
|
271
|
+
let text = `## Event Categories (${period}: ${date})\n\n`;
|
|
272
|
+
if (!data.length) {
|
|
273
|
+
text += 'No event data found for this period.\n';
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
data.forEach((event) => {
|
|
277
|
+
text += `- **${event.label}**: ${event.nb_events} events, ${event.nb_visits} visits`;
|
|
278
|
+
if (event.avg_event_value != null)
|
|
279
|
+
text += `, avg value: ${event.avg_event_value}`;
|
|
280
|
+
text += '\n';
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
return { content: [{ type: 'text', text }] };
|
|
284
|
+
}
|
|
285
|
+
default:
|
|
286
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
return {
|
|
291
|
+
content: [
|
|
292
|
+
{
|
|
293
|
+
type: 'text',
|
|
294
|
+
text: `Error: ${error instanceof Error ? error.message : 'Unknown error occurred'}`,
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
isError: true,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
async run() {
|
|
303
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
304
|
+
await this.server.connect(transport);
|
|
305
|
+
console.error('Matomo MCP server running on stdio');
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
// Start the server
|
|
309
|
+
const server = new MatomoMCPServer();
|
|
310
|
+
server.run().catch((error) => {
|
|
311
|
+
console.error('Fatal error in Matomo MCP server:', error);
|
|
312
|
+
process.exit(1);
|
|
313
|
+
});
|
|
314
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,wEAAmE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I,EAAE,UAAU,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,EAAE;yBACpF;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;QAC7C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACrC,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACtD,CAAC;CACF;AAED,mBAAmB;AACnB,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;AACrC,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC3B,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;IAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export interface VisitsSummaryData {
|
|
2
|
+
nb_visits: number;
|
|
3
|
+
nb_actions: number;
|
|
4
|
+
nb_uniq_visitors?: number;
|
|
5
|
+
nb_visitors?: number;
|
|
6
|
+
nb_users?: number;
|
|
7
|
+
max_actions: number;
|
|
8
|
+
bounce_rate: string;
|
|
9
|
+
nb_visits_converted: number;
|
|
10
|
+
sum_visit_length: number;
|
|
11
|
+
bounce_rate_returning?: string;
|
|
12
|
+
nb_actions_returning?: number;
|
|
13
|
+
max_actions_returning?: number;
|
|
14
|
+
sum_visit_length_returning?: number;
|
|
15
|
+
nb_visits_converted_returning?: number;
|
|
16
|
+
revenue?: number;
|
|
17
|
+
revenue_returning?: number;
|
|
18
|
+
nb_conversions?: number;
|
|
19
|
+
nb_conversions_returning?: number;
|
|
20
|
+
conversions?: number;
|
|
21
|
+
conversions_returning?: number;
|
|
22
|
+
nb_visits_new?: number;
|
|
23
|
+
bounces?: number;
|
|
24
|
+
bounce_count?: number;
|
|
25
|
+
sum_visit_length_new?: number;
|
|
26
|
+
nb_actions_new?: number;
|
|
27
|
+
max_actions_new?: number;
|
|
28
|
+
bounce_rate_new?: string;
|
|
29
|
+
nb_visits_converted_new?: number;
|
|
30
|
+
revenue_new?: number;
|
|
31
|
+
nb_conversions_new?: number;
|
|
32
|
+
conversions_new?: number;
|
|
33
|
+
nb_actions_per_visit?: number;
|
|
34
|
+
avg_time_on_site?: number;
|
|
35
|
+
}
|
|
36
|
+
export interface LiveCountersData {
|
|
37
|
+
visits: number;
|
|
38
|
+
actions: number;
|
|
39
|
+
visitors: number;
|
|
40
|
+
visitsConverted?: number;
|
|
41
|
+
visits_conv?: number;
|
|
42
|
+
actions_conv?: number;
|
|
43
|
+
visitors_conv?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface TopPagesData {
|
|
46
|
+
label: string;
|
|
47
|
+
nb_visits: number;
|
|
48
|
+
nb_hits: number;
|
|
49
|
+
sum_time_spent: number;
|
|
50
|
+
bounce_rate: string;
|
|
51
|
+
exit_rate: string;
|
|
52
|
+
avg_time_on_page: number;
|
|
53
|
+
url: string;
|
|
54
|
+
}
|
|
55
|
+
export interface SiteData {
|
|
56
|
+
idsite: string;
|
|
57
|
+
name: string;
|
|
58
|
+
main_url: string;
|
|
59
|
+
}
|
|
60
|
+
export interface ReferrerData {
|
|
61
|
+
label: string;
|
|
62
|
+
nb_visits: number;
|
|
63
|
+
nb_actions: number;
|
|
64
|
+
nb_uniq_visitors?: number;
|
|
65
|
+
bounce_rate?: string;
|
|
66
|
+
revenue?: number;
|
|
67
|
+
}
|
|
68
|
+
export interface EventData {
|
|
69
|
+
label: string;
|
|
70
|
+
nb_visits: number;
|
|
71
|
+
nb_events: number;
|
|
72
|
+
nb_uniq_visitors?: number;
|
|
73
|
+
sum_event_value?: number;
|
|
74
|
+
avg_event_value?: number;
|
|
75
|
+
}
|
|
76
|
+
export interface MatomoApiResponse<T> {
|
|
77
|
+
value: T;
|
|
78
|
+
date: string;
|
|
79
|
+
period: string;
|
|
80
|
+
segment: string;
|
|
81
|
+
}
|
|
82
|
+
export declare class MatomoClient {
|
|
83
|
+
private baseUrl;
|
|
84
|
+
private apiKey;
|
|
85
|
+
private defaultSiteId;
|
|
86
|
+
constructor();
|
|
87
|
+
private makeApiCall;
|
|
88
|
+
listSites(): Promise<SiteData[]>;
|
|
89
|
+
getVisitsSummary(period?: string, date?: string, siteId?: string, segment?: string): Promise<VisitsSummaryData | Record<string, VisitsSummaryData>>;
|
|
90
|
+
getLiveCounters(siteId?: string, segment?: string): Promise<LiveCountersData>;
|
|
91
|
+
getTopPages(period?: string, date?: string, limit?: number, siteId?: string, segment?: string): Promise<TopPagesData[]>;
|
|
92
|
+
getReferrerTypes(period?: string, date?: string, siteId?: string, segment?: string): Promise<ReferrerData[]>;
|
|
93
|
+
getCampaigns(period?: string, date?: string, siteId?: string, segment?: string): Promise<ReferrerData[]>;
|
|
94
|
+
getEventCategories(period?: string, date?: string, siteId?: string, segment?: string): Promise<EventData[]>;
|
|
95
|
+
getEventActions(period: string | undefined, date: string | undefined, category: string, siteId?: string, segment?: string): Promise<EventData[]>;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=matomo-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matomo-client.d.ts","sourceRoot":"","sources":["../src/matomo-client.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MA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od : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MatomoClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
class MatomoClient {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.baseUrl = process.env.MATOMO_URL || '';
|
|
11
|
+
this.apiKey = process.env.MATOMO_API_KEY || '';
|
|
12
|
+
this.defaultSiteId = process.env.MATOMO_SITE_ID || '';
|
|
13
|
+
if (!this.baseUrl || !this.apiKey || !this.defaultSiteId) {
|
|
14
|
+
throw new Error('Missing required environment variables: MATOMO_URL, MATOMO_API_KEY, MATOMO_SITE_ID');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async makeApiCall(method, params = {}, siteId, segment) {
|
|
18
|
+
try {
|
|
19
|
+
const callParams = {
|
|
20
|
+
module: 'API',
|
|
21
|
+
method,
|
|
22
|
+
idSite: siteId || this.defaultSiteId,
|
|
23
|
+
format: 'JSON',
|
|
24
|
+
token_auth: this.apiKey,
|
|
25
|
+
...Object.fromEntries(Object.entries(params).map(([key, value]) => [key, String(value)])),
|
|
26
|
+
};
|
|
27
|
+
if (segment) {
|
|
28
|
+
callParams.segment = segment;
|
|
29
|
+
}
|
|
30
|
+
const formData = new URLSearchParams(callParams);
|
|
31
|
+
const response = await axios_1.default.post(`${this.baseUrl}/index.php`, formData, {
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return response.data;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
40
|
+
const errorMsg = error.response?.data?.message || error.response?.statusText;
|
|
41
|
+
throw new Error(`Matomo API error: ${error.response?.status} - ${errorMsg}`);
|
|
42
|
+
}
|
|
43
|
+
throw new Error(`Failed to call Matomo API: ${error}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async listSites() {
|
|
47
|
+
return this.makeApiCall('SitesManager.getAllSites');
|
|
48
|
+
}
|
|
49
|
+
async getVisitsSummary(period = 'day', date = 'yesterday', siteId, segment) {
|
|
50
|
+
return this.makeApiCall('VisitsSummary.get', { period, date }, siteId, segment);
|
|
51
|
+
}
|
|
52
|
+
async getLiveCounters(siteId, segment) {
|
|
53
|
+
const result = await this.makeApiCall('Live.getCounters', { lastMinutes: 30 }, siteId, segment);
|
|
54
|
+
// API returns an array with one object
|
|
55
|
+
return Array.isArray(result) ? result[0] : result;
|
|
56
|
+
}
|
|
57
|
+
async getTopPages(period = 'day', date = 'yesterday', limit = 10, siteId, segment) {
|
|
58
|
+
return this.makeApiCall('Actions.getPageUrls', { period, date, expanded: 1, filter_limit: limit }, siteId, segment);
|
|
59
|
+
}
|
|
60
|
+
async getReferrerTypes(period = 'day', date = 'yesterday', siteId, segment) {
|
|
61
|
+
return this.makeApiCall('Referrers.getReferrerType', { period, date }, siteId, segment);
|
|
62
|
+
}
|
|
63
|
+
async getCampaigns(period = 'day', date = 'yesterday', siteId, segment) {
|
|
64
|
+
return this.makeApiCall('Referrers.getCampaigns', { period, date }, siteId, segment);
|
|
65
|
+
}
|
|
66
|
+
async getEventCategories(period = 'day', date = 'yesterday', siteId, segment) {
|
|
67
|
+
return this.makeApiCall('Events.getCategory', { period, date }, siteId, segment);
|
|
68
|
+
}
|
|
69
|
+
async getEventActions(period = 'day', date = 'yesterday', category, siteId, segment) {
|
|
70
|
+
// Filter to a specific category using Matomo's segment syntax
|
|
71
|
+
const categorySegment = `eventCategory==${category}`;
|
|
72
|
+
const fullSegment = segment ? `${segment};${categorySegment}` : categorySegment;
|
|
73
|
+
return this.makeApiCall('Events.getAction', { period, date }, siteId, fullSegment);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.MatomoClient = MatomoClient;
|
|
77
|
+
//# sourceMappingURL=matomo-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|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AM,EAAE,IAAI,EAAE,EAChB,MAAM,EACN,WAAW,CACZ,CAAC;IACJ,CAAC;CACF;AA7JD,oCA6JC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "matomo-mcp",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "MCP server that gives Claude access to Matomo analytics — visits, pages, referrers, events, and more",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"matomo-mcp": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"prepublishOnly": "npm run build",
|
|
15
|
+
"start": "node dist/index.js",
|
|
16
|
+
"dev": "ts-node src/index.ts",
|
|
17
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
18
|
+
},
|
|
19
|
+
"keywords": ["mcp", "matomo", "analytics", "model-context-protocol"],
|
|
20
|
+
"author": "amazee.io",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/bonus414/matomo-mcp"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@modelcontextprotocol/sdk": "^1.20.1",
|
|
28
|
+
"axios": "^1.12.2",
|
|
29
|
+
"dotenv": "^17.2.3"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^24.8.1",
|
|
33
|
+
"ts-node": "^10.9.2",
|
|
34
|
+
"typescript": "^5.9.3"
|
|
35
|
+
}
|
|
36
|
+
}
|