vcluster-yaml-mcp-server 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. package/package.json +3 -2
  2. package/src/http-server.js +49 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vcluster-yaml-mcp-server",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "MCP server for querying vcluster YAML configurations using jq",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -35,7 +35,8 @@
35
35
  "express-rate-limit": "^8.1.0",
36
36
  "js-yaml": "^4.1.0",
37
37
  "node-fetch": "^3.3.2",
38
- "node-jq": "^6.0.1"
38
+ "node-jq": "^6.0.1",
39
+ "prom-client": "^15.1.0"
39
40
  },
40
41
  "engines": {
41
42
  "node": ">=18"
@@ -5,10 +5,29 @@ import { createServer } from './server.js';
5
5
  import express from 'express';
6
6
  import rateLimit from 'express-rate-limit';
7
7
  import { requireApiKey } from './middleware/auth.js';
8
+ import promClient from 'prom-client';
8
9
 
9
10
  const PORT = process.env.PORT || 3000;
10
11
  const REQUIRE_AUTH = process.env.REQUIRE_AUTH === 'true';
11
12
 
13
+ // Prometheus metrics setup
14
+ const register = new promClient.Registry();
15
+ promClient.collectDefaultMetrics({ register });
16
+
17
+ const mcpRequestCounter = new promClient.Counter({
18
+ name: 'mcp_requests_total',
19
+ help: 'Total MCP requests',
20
+ labelNames: ['method', 'status'],
21
+ registers: [register]
22
+ });
23
+
24
+ const mcpRequestDuration = new promClient.Histogram({
25
+ name: 'mcp_request_duration_seconds',
26
+ help: 'MCP request duration in seconds',
27
+ labelNames: ['method'],
28
+ registers: [register]
29
+ });
30
+
12
31
  const app = express();
13
32
 
14
33
  // Security headers
@@ -53,6 +72,12 @@ app.get('/health', apiLimiter, (_req, res) => {
53
72
  });
54
73
  });
55
74
 
75
+ // Prometheus metrics endpoint
76
+ app.get('/metrics', async (_req, res) => {
77
+ res.set('Content-Type', register.contentType);
78
+ res.end(await register.metrics());
79
+ });
80
+
56
81
  // Root endpoint info
57
82
  app.get('/', (_req, res) => {
58
83
  res.json({
@@ -61,7 +86,8 @@ app.get('/', (_req, res) => {
61
86
  description: 'MCP server for querying vCluster YAML configurations',
62
87
  endpoints: {
63
88
  mcp: '/mcp',
64
- health: '/health'
89
+ health: '/health',
90
+ metrics: '/metrics'
65
91
  },
66
92
  documentation: 'https://github.com/Piotr1215/vcluster-yaml-mcp-server'
67
93
  });
@@ -69,22 +95,32 @@ app.get('/', (_req, res) => {
69
95
 
70
96
  // MCP endpoint with Streamable HTTP transport
71
97
  const mcpHandler = async (req, res) => {
98
+ const start = Date.now();
72
99
  console.log(`MCP ${req.method} request received`);
73
100
 
74
- // Create new transport per request to prevent ID collisions
75
- const transport = new StreamableHTTPServerTransport({
76
- sessionIdGenerator: undefined,
77
- enableJsonResponse: true
78
- });
101
+ try {
102
+ // Create new transport per request to prevent ID collisions
103
+ const transport = new StreamableHTTPServerTransport({
104
+ sessionIdGenerator: undefined,
105
+ enableJsonResponse: true
106
+ });
79
107
 
80
- // Cleanup on connection close
81
- res.on('close', () => {
82
- transport.close();
83
- });
108
+ // Cleanup on connection close
109
+ res.on('close', () => {
110
+ transport.close();
111
+ });
112
+
113
+ const server = createServer();
114
+ await server.connect(transport);
115
+ await transport.handleRequest(req, res, req.body);
84
116
 
85
- const server = createServer();
86
- await server.connect(transport);
87
- await transport.handleRequest(req, res, req.body);
117
+ mcpRequestCounter.inc({ method: req.method, status: 'success' });
118
+ } catch (error) {
119
+ mcpRequestCounter.inc({ method: req.method, status: 'error' });
120
+ throw error;
121
+ } finally {
122
+ mcpRequestDuration.observe({ method: req.method }, (Date.now() - start) / 1000);
123
+ }
88
124
  };
89
125
 
90
126
  // Support both GET and POST for MCP endpoint