cubeapm-mcp 1.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/LICENSE +21 -0
- package/README.md +239 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +248 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 TechnicalRhino
|
|
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,239 @@
|
|
|
1
|
+
# CubeAPM MCP Server
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/cubeapm-mcp)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
A [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server for [CubeAPM](https://cubeapm.com) - enabling AI assistants like Claude to query your observability data including traces, metrics, and logs.
|
|
7
|
+
|
|
8
|
+
## What is this?
|
|
9
|
+
|
|
10
|
+
This MCP server connects AI assistants (like Claude) to your CubeAPM instance, allowing you to:
|
|
11
|
+
|
|
12
|
+
- **Query logs** using natural language that gets translated to LogsQL
|
|
13
|
+
- **Analyze metrics** with PromQL-compatible queries
|
|
14
|
+
- **Search and inspect traces** to debug distributed systems
|
|
15
|
+
- **Monitor your services** through conversational interfaces
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### From NPM (Recommended)
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g cubeapm-mcp
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### From Source
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/TechnicalRhino/cubeapm-mcp.git
|
|
29
|
+
cd cubeapm-mcp
|
|
30
|
+
npm install
|
|
31
|
+
npm run build
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
### 1. Configure Claude Code
|
|
37
|
+
|
|
38
|
+
Add to your Claude Code settings (`~/.claude/settings.json`):
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"mcpServers": {
|
|
43
|
+
"cubeapm": {
|
|
44
|
+
"command": "npx",
|
|
45
|
+
"args": ["-y", "cubeapm-mcp"],
|
|
46
|
+
"env": {
|
|
47
|
+
"CUBEAPM_HOST": "your-cubeapm-server.com"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 2. Restart Claude Code
|
|
55
|
+
|
|
56
|
+
After updating the settings, restart Claude Code to load the MCP server.
|
|
57
|
+
|
|
58
|
+
### 3. Start Querying
|
|
59
|
+
|
|
60
|
+
You can now ask Claude questions like:
|
|
61
|
+
|
|
62
|
+
- *"Show me error logs from the payment-service in the last hour"*
|
|
63
|
+
- *"What's the p99 latency for the checkout API?"*
|
|
64
|
+
- *"Find traces where duration > 5s in production"*
|
|
65
|
+
- *"Get the full trace for trace ID abc123def456"*
|
|
66
|
+
|
|
67
|
+
## Configuration
|
|
68
|
+
|
|
69
|
+
| Environment Variable | Default | Description |
|
|
70
|
+
|---------------------|---------|-------------|
|
|
71
|
+
| `CUBEAPM_HOST` | `localhost` | CubeAPM server hostname or IP |
|
|
72
|
+
| `CUBEAPM_QUERY_PORT` | `3140` | Port for querying APIs (traces, metrics, logs) |
|
|
73
|
+
| `CUBEAPM_INGEST_PORT` | `3130` | Port for ingestion APIs |
|
|
74
|
+
|
|
75
|
+
### Example Configurations
|
|
76
|
+
|
|
77
|
+
**Local Development:**
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"mcpServers": {
|
|
81
|
+
"cubeapm": {
|
|
82
|
+
"command": "npx",
|
|
83
|
+
"args": ["-y", "cubeapm-mcp"],
|
|
84
|
+
"env": {
|
|
85
|
+
"CUBEAPM_HOST": "localhost"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Production:**
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"mcpServers": {
|
|
96
|
+
"cubeapm": {
|
|
97
|
+
"command": "npx",
|
|
98
|
+
"args": ["-y", "cubeapm-mcp"],
|
|
99
|
+
"env": {
|
|
100
|
+
"CUBEAPM_HOST": "cubeapm.internal.company.com",
|
|
101
|
+
"CUBEAPM_QUERY_PORT": "3140"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Available Tools
|
|
109
|
+
|
|
110
|
+
### Logs
|
|
111
|
+
|
|
112
|
+
| Tool | Description |
|
|
113
|
+
|------|-------------|
|
|
114
|
+
| `query_logs` | Query logs using LogsQL syntax with time range and limit |
|
|
115
|
+
|
|
116
|
+
**Parameters:**
|
|
117
|
+
- `query` - LogsQL query string (e.g., `{service="api"} error`)
|
|
118
|
+
- `start` - Start time (RFC3339 or Unix timestamp)
|
|
119
|
+
- `end` - End time (RFC3339 or Unix timestamp)
|
|
120
|
+
- `limit` - Maximum entries to return (default: 100)
|
|
121
|
+
|
|
122
|
+
### Metrics
|
|
123
|
+
|
|
124
|
+
| Tool | Description |
|
|
125
|
+
|------|-------------|
|
|
126
|
+
| `query_metrics_instant` | Execute a PromQL query at a single point in time |
|
|
127
|
+
| `query_metrics_range` | Execute a PromQL query over a time range |
|
|
128
|
+
|
|
129
|
+
**Instant Query Parameters:**
|
|
130
|
+
- `query` - PromQL expression
|
|
131
|
+
- `time` - Evaluation timestamp
|
|
132
|
+
- `step` - Optional time window in seconds
|
|
133
|
+
|
|
134
|
+
**Range Query Parameters:**
|
|
135
|
+
- `query` - PromQL expression
|
|
136
|
+
- `start` / `end` - Time range
|
|
137
|
+
- `step` - Resolution in seconds
|
|
138
|
+
|
|
139
|
+
### Traces
|
|
140
|
+
|
|
141
|
+
| Tool | Description |
|
|
142
|
+
|------|-------------|
|
|
143
|
+
| `search_traces` | Search traces by service, environment, or custom query |
|
|
144
|
+
| `get_trace` | Fetch complete trace details by trace ID |
|
|
145
|
+
|
|
146
|
+
**Search Parameters:**
|
|
147
|
+
- `query` - Optional search query
|
|
148
|
+
- `env` - Environment filter (e.g., `production`)
|
|
149
|
+
- `service` - Service name filter
|
|
150
|
+
- `start` / `end` - Time range
|
|
151
|
+
- `limit` - Maximum results (default: 20)
|
|
152
|
+
|
|
153
|
+
**Get Trace Parameters:**
|
|
154
|
+
- `trace_id` - Hex-encoded trace ID
|
|
155
|
+
- `start` / `end` - Time range to search within
|
|
156
|
+
|
|
157
|
+
### Ingestion
|
|
158
|
+
|
|
159
|
+
| Tool | Description |
|
|
160
|
+
|------|-------------|
|
|
161
|
+
| `ingest_metrics_prometheus` | Send metrics in Prometheus text exposition format |
|
|
162
|
+
|
|
163
|
+
## Example Queries
|
|
164
|
+
|
|
165
|
+
### Logs
|
|
166
|
+
```
|
|
167
|
+
"Find all ERROR logs from auth-service in the last 30 minutes"
|
|
168
|
+
"Show me logs containing 'connection refused' from the database service"
|
|
169
|
+
"Query logs where trace_id matches xyz123"
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Metrics
|
|
173
|
+
```
|
|
174
|
+
"What's the average request duration for the API gateway?"
|
|
175
|
+
"Show me CPU usage for all services over the last 6 hours"
|
|
176
|
+
"Graph the error rate for checkout-service with 1-minute resolution"
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Traces
|
|
180
|
+
```
|
|
181
|
+
"Find slow traces (>2s) from the order-service"
|
|
182
|
+
"Show me traces with errors in the production environment"
|
|
183
|
+
"Get the full waterfall for trace ID abc123"
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Development
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Clone the repository
|
|
190
|
+
git clone https://github.com/TechnicalRhino/cubeapm-mcp.git
|
|
191
|
+
cd cubeapm-mcp
|
|
192
|
+
|
|
193
|
+
# Install dependencies
|
|
194
|
+
npm install
|
|
195
|
+
|
|
196
|
+
# Run in development mode (with hot reload)
|
|
197
|
+
npm run dev
|
|
198
|
+
|
|
199
|
+
# Build for production
|
|
200
|
+
npm run build
|
|
201
|
+
|
|
202
|
+
# Test the build
|
|
203
|
+
npm start
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## How It Works
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
┌─────────────────┐ MCP Protocol ┌─────────────────┐ HTTP API ┌─────────────────┐
|
|
210
|
+
│ Claude / AI │◄───────────────────►│ cubeapm-mcp │◄────────────────►│ CubeAPM │
|
|
211
|
+
│ Assistant │ (stdio transport) │ MCP Server │ (REST calls) │ Server │
|
|
212
|
+
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The MCP server:
|
|
216
|
+
1. Receives tool calls from the AI assistant via stdio
|
|
217
|
+
2. Translates them to CubeAPM HTTP API requests
|
|
218
|
+
3. Returns formatted results back to the assistant
|
|
219
|
+
|
|
220
|
+
## Requirements
|
|
221
|
+
|
|
222
|
+
- **Node.js** 18+
|
|
223
|
+
- **CubeAPM** instance (self-hosted or cloud)
|
|
224
|
+
- **Claude Code** or any MCP-compatible client
|
|
225
|
+
|
|
226
|
+
## Related Links
|
|
227
|
+
|
|
228
|
+
- [CubeAPM Documentation](https://docs.cubeapm.com)
|
|
229
|
+
- [CubeAPM HTTP APIs](https://docs.cubeapm.com/http-apis)
|
|
230
|
+
- [Model Context Protocol](https://modelcontextprotocol.io)
|
|
231
|
+
- [Claude Code](https://claude.ai/code)
|
|
232
|
+
|
|
233
|
+
## Contributing
|
|
234
|
+
|
|
235
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
// Configuration from environment variables
|
|
6
|
+
const CUBEAPM_HOST = process.env.CUBEAPM_HOST || "localhost";
|
|
7
|
+
const CUBEAPM_QUERY_PORT = process.env.CUBEAPM_QUERY_PORT || "3140";
|
|
8
|
+
const CUBEAPM_INGEST_PORT = process.env.CUBEAPM_INGEST_PORT || "3130";
|
|
9
|
+
const queryBaseUrl = `http://${CUBEAPM_HOST}:${CUBEAPM_QUERY_PORT}`;
|
|
10
|
+
const ingestBaseUrl = `http://${CUBEAPM_HOST}:${CUBEAPM_INGEST_PORT}`;
|
|
11
|
+
// Create the MCP server
|
|
12
|
+
const server = new McpServer({
|
|
13
|
+
name: "cubeapm-mcp",
|
|
14
|
+
version: "1.0.0",
|
|
15
|
+
});
|
|
16
|
+
// ============================================
|
|
17
|
+
// LOGS APIs
|
|
18
|
+
// ============================================
|
|
19
|
+
server.tool("query_logs", "Query logs from CubeAPM using LogsQL syntax. Returns log entries matching the query.", {
|
|
20
|
+
query: z.string().describe("The log search query including stream filters (LogsQL syntax)"),
|
|
21
|
+
start: z.string().describe("Start time in RFC3339 format (e.g., 2024-01-01T00:00:00Z) or Unix timestamp in seconds"),
|
|
22
|
+
end: z.string().describe("End time in RFC3339 format or Unix timestamp in seconds"),
|
|
23
|
+
limit: z.number().optional().default(100).describe("Maximum log entries to return (default: 100)"),
|
|
24
|
+
}, async ({ query, start, end, limit }) => {
|
|
25
|
+
const params = new URLSearchParams({
|
|
26
|
+
query,
|
|
27
|
+
start,
|
|
28
|
+
end,
|
|
29
|
+
limit: String(limit),
|
|
30
|
+
});
|
|
31
|
+
const response = await fetch(`${queryBaseUrl}/api/logs/select/logsql/query`, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: {
|
|
34
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
35
|
+
},
|
|
36
|
+
body: params.toString(),
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
return {
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
type: "text",
|
|
43
|
+
text: `Error querying logs: ${response.status} ${response.statusText}`,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
isError: true,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const text = await response.text();
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: "text",
|
|
54
|
+
text: text || "No logs found matching the query",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
// ============================================
|
|
60
|
+
// METRICS APIs
|
|
61
|
+
// ============================================
|
|
62
|
+
server.tool("query_metrics_instant", "Execute an instant query against CubeAPM metrics at a single point in time. Uses PromQL-compatible syntax.", {
|
|
63
|
+
query: z.string().describe("The metrics query expression (PromQL syntax)"),
|
|
64
|
+
time: z.string().describe("Evaluation timestamp in RFC3339 format or Unix timestamp in seconds"),
|
|
65
|
+
step: z.number().optional().describe("Time window in seconds for processing data"),
|
|
66
|
+
}, async ({ query, time, step }) => {
|
|
67
|
+
const params = new URLSearchParams({ query, time });
|
|
68
|
+
if (step)
|
|
69
|
+
params.append("step", String(step));
|
|
70
|
+
const response = await fetch(`${queryBaseUrl}/api/metrics/api/v1/query`, {
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: {
|
|
73
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
74
|
+
},
|
|
75
|
+
body: params.toString(),
|
|
76
|
+
});
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
return {
|
|
79
|
+
content: [
|
|
80
|
+
{
|
|
81
|
+
type: "text",
|
|
82
|
+
text: `Error querying metrics: ${response.status} ${response.statusText}`,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
isError: true,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const data = await response.json();
|
|
89
|
+
return {
|
|
90
|
+
content: [
|
|
91
|
+
{
|
|
92
|
+
type: "text",
|
|
93
|
+
text: JSON.stringify(data, null, 2),
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
server.tool("query_metrics_range", "Execute a range query against CubeAPM metrics over a time range. Returns time series data.", {
|
|
99
|
+
query: z.string().describe("The metrics query expression (PromQL syntax)"),
|
|
100
|
+
start: z.string().describe("Start timestamp in RFC3339 format or Unix timestamp"),
|
|
101
|
+
end: z.string().describe("End timestamp in RFC3339 format or Unix timestamp"),
|
|
102
|
+
step: z.number().describe("Resolution step width in seconds"),
|
|
103
|
+
}, async ({ query, start, end, step }) => {
|
|
104
|
+
const params = new URLSearchParams({
|
|
105
|
+
query,
|
|
106
|
+
start,
|
|
107
|
+
end,
|
|
108
|
+
step: String(step),
|
|
109
|
+
});
|
|
110
|
+
const response = await fetch(`${queryBaseUrl}/api/metrics/api/v1/query_range`, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: {
|
|
113
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
114
|
+
},
|
|
115
|
+
body: params.toString(),
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
return {
|
|
119
|
+
content: [
|
|
120
|
+
{
|
|
121
|
+
type: "text",
|
|
122
|
+
text: `Error querying metrics range: ${response.status} ${response.statusText}`,
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
isError: true,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const data = await response.json();
|
|
129
|
+
return {
|
|
130
|
+
content: [
|
|
131
|
+
{
|
|
132
|
+
type: "text",
|
|
133
|
+
text: JSON.stringify(data, null, 2),
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
// ============================================
|
|
139
|
+
// TRACES APIs
|
|
140
|
+
// ============================================
|
|
141
|
+
server.tool("search_traces", "Search for traces in CubeAPM matching the specified criteria. Returns trace snippets with key spans.", {
|
|
142
|
+
query: z.string().optional().describe("The traces search query"),
|
|
143
|
+
env: z.string().optional().describe("Environment name to filter by"),
|
|
144
|
+
service: z.string().optional().describe("Service name to filter by"),
|
|
145
|
+
start: z.string().describe("Start timestamp in RFC3339 format or Unix seconds"),
|
|
146
|
+
end: z.string().describe("End timestamp in RFC3339 format or Unix seconds"),
|
|
147
|
+
limit: z.number().optional().default(20).describe("Maximum number of traces to return"),
|
|
148
|
+
}, async ({ query, env, service, start, end, limit }) => {
|
|
149
|
+
const params = new URLSearchParams({ start, end, limit: String(limit) });
|
|
150
|
+
if (query)
|
|
151
|
+
params.append("query", query);
|
|
152
|
+
if (env)
|
|
153
|
+
params.append("env", env);
|
|
154
|
+
if (service)
|
|
155
|
+
params.append("service", service);
|
|
156
|
+
const response = await fetch(`${queryBaseUrl}/api/traces/api/v1/search?${params.toString()}`, { method: "GET" });
|
|
157
|
+
if (!response.ok) {
|
|
158
|
+
return {
|
|
159
|
+
content: [
|
|
160
|
+
{
|
|
161
|
+
type: "text",
|
|
162
|
+
text: `Error searching traces: ${response.status} ${response.statusText}`,
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
isError: true,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const data = await response.json();
|
|
169
|
+
return {
|
|
170
|
+
content: [
|
|
171
|
+
{
|
|
172
|
+
type: "text",
|
|
173
|
+
text: JSON.stringify(data, null, 2),
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
server.tool("get_trace", "Fetch a complete trace by its ID from CubeAPM. Returns all spans in the trace with full details.", {
|
|
179
|
+
trace_id: z.string().describe("The hex-encoded trace ID to fetch"),
|
|
180
|
+
start: z.string().describe("Start timestamp in RFC3339 format or Unix seconds"),
|
|
181
|
+
end: z.string().describe("End timestamp in RFC3339 format or Unix seconds"),
|
|
182
|
+
}, async ({ trace_id, start, end }) => {
|
|
183
|
+
const params = new URLSearchParams({ start, end });
|
|
184
|
+
const response = await fetch(`${queryBaseUrl}/api/traces/api/v1/traces/${trace_id}?${params.toString()}`, { method: "GET" });
|
|
185
|
+
if (!response.ok) {
|
|
186
|
+
return {
|
|
187
|
+
content: [
|
|
188
|
+
{
|
|
189
|
+
type: "text",
|
|
190
|
+
text: `Error fetching trace: ${response.status} ${response.statusText}`,
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
isError: true,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const data = await response.json();
|
|
197
|
+
return {
|
|
198
|
+
content: [
|
|
199
|
+
{
|
|
200
|
+
type: "text",
|
|
201
|
+
text: JSON.stringify(data, null, 2),
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
// ============================================
|
|
207
|
+
// INGESTION APIs (for sending data to CubeAPM)
|
|
208
|
+
// ============================================
|
|
209
|
+
server.tool("ingest_metrics_prometheus", "Send metrics to CubeAPM in Prometheus text exposition format.", {
|
|
210
|
+
metrics: z.string().describe("Metrics data in Prometheus text exposition format"),
|
|
211
|
+
}, async ({ metrics }) => {
|
|
212
|
+
const response = await fetch(`${ingestBaseUrl}/api/metrics/v1/save`, {
|
|
213
|
+
method: "POST",
|
|
214
|
+
headers: {
|
|
215
|
+
"Content-Type": "text/plain",
|
|
216
|
+
},
|
|
217
|
+
body: metrics,
|
|
218
|
+
});
|
|
219
|
+
if (!response.ok) {
|
|
220
|
+
return {
|
|
221
|
+
content: [
|
|
222
|
+
{
|
|
223
|
+
type: "text",
|
|
224
|
+
text: `Error ingesting metrics: ${response.status} ${response.statusText}`,
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
isError: true,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
content: [
|
|
232
|
+
{
|
|
233
|
+
type: "text",
|
|
234
|
+
text: "Metrics ingested successfully",
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
// Start the server
|
|
240
|
+
async function main() {
|
|
241
|
+
const transport = new StdioServerTransport();
|
|
242
|
+
await server.connect(transport);
|
|
243
|
+
console.error("CubeAPM MCP server running on stdio");
|
|
244
|
+
}
|
|
245
|
+
main().catch((error) => {
|
|
246
|
+
console.error("Fatal error:", error);
|
|
247
|
+
process.exit(1);
|
|
248
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cubeapm-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP server for CubeAPM - Query traces, metrics, and logs from your observability platform using AI assistants",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"cubeapm-mcp": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"start": "node dist/index.js",
|
|
18
|
+
"dev": "tsx src/index.ts",
|
|
19
|
+
"prepublishOnly": "npm run build"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/TechnicalRhino/cubeapm-mcp.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/TechnicalRhino/cubeapm-mcp/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/TechnicalRhino/cubeapm-mcp#readme",
|
|
29
|
+
"author": "TechnicalRhino",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"keywords": [
|
|
32
|
+
"mcp",
|
|
33
|
+
"model-context-protocol",
|
|
34
|
+
"cubeapm",
|
|
35
|
+
"observability",
|
|
36
|
+
"apm",
|
|
37
|
+
"traces",
|
|
38
|
+
"metrics",
|
|
39
|
+
"logs",
|
|
40
|
+
"claude",
|
|
41
|
+
"ai",
|
|
42
|
+
"monitoring",
|
|
43
|
+
"distributed-tracing",
|
|
44
|
+
"promql",
|
|
45
|
+
"logsql"
|
|
46
|
+
],
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
52
|
+
"zod": "^3.24.1"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^22.10.2",
|
|
56
|
+
"tsx": "^4.19.2",
|
|
57
|
+
"typescript": "^5.7.2"
|
|
58
|
+
}
|
|
59
|
+
}
|