@pipeworx/mcp-amplitude 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pipeworx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # mcp-amplitude
2
+
3
+ Amplitude MCP Pack
4
+
5
+ Part of the [Pipeworx](https://pipeworx.io) open MCP gateway.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+ | `amp_get_events` | Get event segmentation data from Amplitude for a date range. Returns event counts and breakdowns. |
12
+ | `amp_get_active_users` | Get daily/weekly/monthly active user counts for a date range. |
13
+ | `amp_get_retention` | Get retention data for a date range. Shows how many users return over time. |
14
+ | `amp_user_search` | Search for a user by user property or user ID. Returns matching Amplitude user profiles. |
15
+ | `amp_get_user_activity` | Get recent event activity for a specific user by their Amplitude ID. |
16
+
17
+ ## Quick Start
18
+
19
+ Add to your MCP client config:
20
+
21
+ ```json
22
+ {
23
+ "mcpServers": {
24
+ "amplitude": {
25
+ "url": "https://gateway.pipeworx.io/amplitude/mcp"
26
+ }
27
+ }
28
+ }
29
+ ```
30
+
31
+ Or use the CLI:
32
+
33
+ ```bash
34
+ npx pipeworx use amplitude
35
+ ```
36
+
37
+ ## License
38
+
39
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-amplitude",
3
+ "version": "0.1.0",
4
+ "description": "Amplitude MCP Pack",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "amplitude"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-amplitude"
13
+ },
14
+ "scripts": {
15
+ "typecheck": "tsc --noEmit"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.7.0"
19
+ }
20
+ }
package/server.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.pipeworx-io/amplitude",
4
+ "title": "amplitude",
5
+ "description": "Amplitude MCP Pack",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/amplitude",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-amplitude",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/amplitude/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,184 @@
1
+ interface McpToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ inputSchema: {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ };
9
+ }
10
+
11
+ interface McpToolExport {
12
+ tools: McpToolDefinition[];
13
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
14
+ }
15
+
16
+ /**
17
+ * Amplitude MCP Pack
18
+ *
19
+ * BYO key: pass your Amplitude API key and secret key as _apiKey and _secretKey.
20
+ * Uses Basic auth (apiKey:secretKey) against the Amplitude Dashboard REST API.
21
+ */
22
+
23
+
24
+ const API = 'https://amplitude.com/api/2';
25
+
26
+ async function ampFetch(apiKey: string, secretKey: string, path: string, params: Record<string, string> = {}) {
27
+ const credentials = btoa(`${apiKey}:${secretKey}`);
28
+ const qs = new URLSearchParams(params);
29
+ const url = Object.keys(params).length > 0 ? `${API}${path}?${qs}` : `${API}${path}`;
30
+ const res = await fetch(url, {
31
+ headers: {
32
+ Authorization: `Basic ${credentials}`,
33
+ },
34
+ });
35
+ if (!res.ok) {
36
+ const text = await res.text();
37
+ throw new Error(`Amplitude API error (${res.status}): ${text}`);
38
+ }
39
+ return res.json();
40
+ }
41
+
42
+ const tools: McpToolExport['tools'] = [
43
+ {
44
+ name: 'amp_get_events',
45
+ description: 'Get event segmentation data from Amplitude for a date range. Returns event counts and breakdowns.',
46
+ inputSchema: {
47
+ type: 'object' as const,
48
+ properties: {
49
+ _apiKey: { type: 'string', description: 'Amplitude API key' },
50
+ _secretKey: { type: 'string', description: 'Amplitude secret key' },
51
+ event_type: { type: 'string', description: 'Event name to query (e.g., "Page View", "Button Click")' },
52
+ start: { type: 'string', description: 'Start date (YYYYMMDD)' },
53
+ end: { type: 'string', description: 'End date (YYYYMMDD)' },
54
+ group_by: { type: 'string', description: 'Property to group by (optional)' },
55
+ },
56
+ required: ['_apiKey', '_secretKey', 'event_type', 'start', 'end'],
57
+ },
58
+ },
59
+ {
60
+ name: 'amp_get_active_users',
61
+ description: 'Get daily/weekly/monthly active user counts for a date range.',
62
+ inputSchema: {
63
+ type: 'object' as const,
64
+ properties: {
65
+ _apiKey: { type: 'string', description: 'Amplitude API key' },
66
+ _secretKey: { type: 'string', description: 'Amplitude secret key' },
67
+ start: { type: 'string', description: 'Start date (YYYYMMDD)' },
68
+ end: { type: 'string', description: 'End date (YYYYMMDD)' },
69
+ m: { type: 'string', description: 'Metric: "active" (DAU), "new", or "returning" (default "active")' },
70
+ },
71
+ required: ['_apiKey', '_secretKey', 'start', 'end'],
72
+ },
73
+ },
74
+ {
75
+ name: 'amp_get_retention',
76
+ description: 'Get retention data for a date range. Shows how many users return over time.',
77
+ inputSchema: {
78
+ type: 'object' as const,
79
+ properties: {
80
+ _apiKey: { type: 'string', description: 'Amplitude API key' },
81
+ _secretKey: { type: 'string', description: 'Amplitude secret key' },
82
+ start: { type: 'string', description: 'Start date (YYYYMMDD)' },
83
+ end: { type: 'string', description: 'End date (YYYYMMDD)' },
84
+ re: { type: 'string', description: 'Retention type: "rolling" or "bracket" (default "rolling")' },
85
+ },
86
+ required: ['_apiKey', '_secretKey', 'start', 'end'],
87
+ },
88
+ },
89
+ {
90
+ name: 'amp_user_search',
91
+ description: 'Search for a user by user property or user ID. Returns matching Amplitude user profiles.',
92
+ inputSchema: {
93
+ type: 'object' as const,
94
+ properties: {
95
+ _apiKey: { type: 'string', description: 'Amplitude API key' },
96
+ _secretKey: { type: 'string', description: 'Amplitude secret key' },
97
+ user: { type: 'string', description: 'User search term (email, user_id, or Amplitude ID)' },
98
+ },
99
+ required: ['_apiKey', '_secretKey', 'user'],
100
+ },
101
+ },
102
+ {
103
+ name: 'amp_get_user_activity',
104
+ description: 'Get recent event activity for a specific user by their Amplitude ID.',
105
+ inputSchema: {
106
+ type: 'object' as const,
107
+ properties: {
108
+ _apiKey: { type: 'string', description: 'Amplitude API key' },
109
+ _secretKey: { type: 'string', description: 'Amplitude secret key' },
110
+ amplitude_id: { type: 'string', description: 'Amplitude internal user ID (from amp_user_search results)' },
111
+ offset: { type: 'number', description: 'Pagination offset (default 0)' },
112
+ limit: { type: 'number', description: 'Max events to return (default 100, max 1000)' },
113
+ },
114
+ required: ['_apiKey', '_secretKey', 'amplitude_id'],
115
+ },
116
+ },
117
+ ];
118
+
119
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
120
+ delete args._context;
121
+ const apiKey = args._apiKey as string | undefined;
122
+ const secretKey = args._secretKey as string | undefined;
123
+ delete args._apiKey;
124
+ delete args._secretKey;
125
+
126
+ if (!apiKey || !secretKey) {
127
+ return { error: 'credentials_required', message: 'Pass your Amplitude API key as _apiKey and secret key as _secretKey' };
128
+ }
129
+
130
+ switch (name) {
131
+ case 'amp_get_events': {
132
+ const params: Record<string, string> = {
133
+ e: JSON.stringify({ event_type: args.event_type as string }),
134
+ start: args.start as string,
135
+ end: args.end as string,
136
+ };
137
+ if (args.group_by) {
138
+ params.g = args.group_by as string;
139
+ }
140
+ return ampFetch(apiKey, secretKey, '/events/segmentation', params);
141
+ }
142
+
143
+ case 'amp_get_active_users': {
144
+ const params: Record<string, string> = {
145
+ start: args.start as string,
146
+ end: args.end as string,
147
+ m: (args.m as string) ?? 'active',
148
+ };
149
+ return ampFetch(apiKey, secretKey, '/users', params);
150
+ }
151
+
152
+ case 'amp_get_retention': {
153
+ const params: Record<string, string> = {
154
+ se: JSON.stringify({ event_type: 'Any Event' }),
155
+ re: JSON.stringify({ event_type: 'Any Event' }),
156
+ start: args.start as string,
157
+ end: args.end as string,
158
+ };
159
+ if (args.re) {
160
+ params.rt = args.re as string;
161
+ }
162
+ return ampFetch(apiKey, secretKey, '/retention', params);
163
+ }
164
+
165
+ case 'amp_user_search':
166
+ return ampFetch(apiKey, secretKey, '/usersearch', {
167
+ user: args.user as string,
168
+ });
169
+
170
+ case 'amp_get_user_activity': {
171
+ const params: Record<string, string> = {
172
+ user: args.amplitude_id as string,
173
+ };
174
+ if (args.offset != null) params.offset = String(args.offset);
175
+ if (args.limit != null) params.limit = String(args.limit);
176
+ return ampFetch(apiKey, secretKey, '/useractivity', params);
177
+ }
178
+
179
+ default:
180
+ throw new Error(`Unknown tool: ${name}`);
181
+ }
182
+ }
183
+
184
+ export default { tools, callTool, meter: { credits: 15 } } satisfies McpToolExport;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true
12
+ },
13
+ "include": ["src"]
14
+ }