@davidfuchs/mcp-uptime-kuma 0.2.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 +210 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +138 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +14 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +214 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +197 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +56 -0
- package/dist/types.js.map +1 -0
- package/dist/uptime-kuma-client.d.ts +81 -0
- package/dist/uptime-kuma-client.d.ts.map +1 -0
- package/dist/uptime-kuma-client.js +232 -0
- package/dist/uptime-kuma-client.js.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 David Fuchs
|
|
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,210 @@
|
|
|
1
|
+
# mcp-uptime-kuma
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server for [Uptime Kuma](https://github.com/louislam/uptime-kuma) *version 2*, built with TypeScript and supporting both stdio and streamable HTTP transports.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Multiple Transports**: Supports both stdio (for local integration) and streamable HTTP (for remote access)
|
|
8
|
+
- **Built with TypeScript**: Full type safety and modern tooling
|
|
9
|
+
- **MCP SDK**: Uses the official `@modelcontextprotocol/sdk` package
|
|
10
|
+
- **Uptime Kuma Integration**: Real-time access to monitors and heartbeats via WebSocket connection
|
|
11
|
+
- **Comprehensive Tools**: Retrieve monitor configurations and status data (heartbeats)
|
|
12
|
+
|
|
13
|
+
## Available Tools
|
|
14
|
+
|
|
15
|
+
### getMonitor
|
|
16
|
+
Retrieves detailed information about a specific monitor by its ID.
|
|
17
|
+
|
|
18
|
+
- **Input**:
|
|
19
|
+
- `monitorID` (number): The ID of the monitor to retrieve
|
|
20
|
+
- `includeAdditionalFields` (boolean, optional): Include all additional fields from Uptime Kuma (default: false)
|
|
21
|
+
- **Output**: Monitor configuration object with details like URL, type, check interval, notification settings, etc.
|
|
22
|
+
|
|
23
|
+
### listMonitors
|
|
24
|
+
Retrieves the full list of all monitors the user has access to.
|
|
25
|
+
|
|
26
|
+
- **Input**:
|
|
27
|
+
- `includeAdditionalFields` (boolean, optional): Include all additional fields from Uptime Kuma (default: false)
|
|
28
|
+
- **Output**: Array of monitor objects with count
|
|
29
|
+
|
|
30
|
+
### getHeartbeats
|
|
31
|
+
Retrieves heartbeats (status checks) for a specific monitor.
|
|
32
|
+
|
|
33
|
+
- **Input**:
|
|
34
|
+
- `monitorID` (number): The ID of the monitor to get heartbeats for
|
|
35
|
+
- `includeAll` (boolean, optional): If true, returns all heartbeats (up to 100). If false, returns only the most recent heartbeat (default: false)
|
|
36
|
+
- **Output**: Array of heartbeat objects containing status, response time, timestamps, etc.
|
|
37
|
+
|
|
38
|
+
### listAllHeartbeats
|
|
39
|
+
Retrieves the complete heartbeat list for all monitors.
|
|
40
|
+
|
|
41
|
+
- **Input**:
|
|
42
|
+
- `includeAll` (boolean, optional): If true, returns all heartbeats (up to 100 per monitor). If false, returns only the most recent heartbeat per monitor (default: false)
|
|
43
|
+
- **Output**: Map of monitor IDs to their heartbeat arrays, with monitor and heartbeat counts
|
|
44
|
+
|
|
45
|
+
## Usage Notes
|
|
46
|
+
|
|
47
|
+
- **Monitors** contain configuration information (URLs, check intervals, notification settings, etc.)
|
|
48
|
+
- **Heartbeats** contain actual status data (up/down status, response times, timestamps, etc.)
|
|
49
|
+
- To check if something is **up or down**, use the heartbeat tools, not the monitor tools
|
|
50
|
+
- By default, tools return only essential fields. Set `includeAdditionalFields=true` to get all available data
|
|
51
|
+
|
|
52
|
+
## Prerequisites
|
|
53
|
+
|
|
54
|
+
- Node.js (v18 or higher)
|
|
55
|
+
- An Uptime Kuma instance with credentials
|
|
56
|
+
- Environment variables for configuration (see Configuration section)
|
|
57
|
+
|
|
58
|
+
## Production Usage
|
|
59
|
+
|
|
60
|
+
This MCP server supports both stdio and streamable HTTP transports.
|
|
61
|
+
|
|
62
|
+
### For the stdio Transport
|
|
63
|
+
|
|
64
|
+
For Claude Code, VS Code, or other MCP clients, you can configure the server as follows:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"mcpServers": {
|
|
69
|
+
"uptime-kuma": {
|
|
70
|
+
"command": "npx",
|
|
71
|
+
"args": ["mcp-uptime-kuma"],
|
|
72
|
+
"env": {
|
|
73
|
+
"UPTIME_KUMA_URL": "http://your-uptime-kuma-instance:3001",
|
|
74
|
+
"UPTIME_KUMA_USERNAME": "your_username",
|
|
75
|
+
"UPTIME_KUMA_PASSWORD": "your_password"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### For the Streamable HTTP Transport
|
|
83
|
+
|
|
84
|
+
The recommended way to run the MCP server using streamable HTTP is to run it as a Docker container.
|
|
85
|
+
|
|
86
|
+
A docker-compose file is provided - update the included environment variables as needed and run:
|
|
87
|
+
|
|
88
|
+
`docker compose up -d`
|
|
89
|
+
|
|
90
|
+
The MCP endpoint will be available on your Docker host at port 300 (configurable via `PORT` environment variable).
|
|
91
|
+
|
|
92
|
+
If you'd prefer to run it directly on your host machine, see the Development Usage section below.
|
|
93
|
+
|
|
94
|
+
## Development Usage
|
|
95
|
+
|
|
96
|
+
To run locally, clone the repository and follow these steps:
|
|
97
|
+
|
|
98
|
+
### Install dependencies
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npm install
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Create the environment configuration
|
|
105
|
+
|
|
106
|
+
Configure the required environment variables either directly in your environment, or by creating a `.env` file in the project root.
|
|
107
|
+
|
|
108
|
+
These are the required variables:
|
|
109
|
+
|
|
110
|
+
```env
|
|
111
|
+
UPTIME_KUMA_URL=http://your-uptime-kuma-instance:3001
|
|
112
|
+
UPTIME_KUMA_USERNAME=your_username
|
|
113
|
+
UPTIME_KUMA_PASSWORD=your_password
|
|
114
|
+
PORT=3000 # Optional, only for HTTP transport
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Building
|
|
118
|
+
|
|
119
|
+
Build the TypeScript code to JavaScript:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm run build
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
For development with auto-rebuild:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npm run watch
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Running
|
|
132
|
+
|
|
133
|
+
### Default (stdio Transport)
|
|
134
|
+
|
|
135
|
+
Run in production mode (requires build first):
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
npm start
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
or
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
npm run start:stdio
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
This mode is designed to be spawned by MCP clients (like Claude Desktop, VS Code, etc.) that communicate via standard input/output.
|
|
148
|
+
|
|
149
|
+
### Streamable HTTP Transport (for remote access)
|
|
150
|
+
|
|
151
|
+
Run in production mode (requires build first):
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
npm run start:http
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
By default, the HTTP server runs on port 3000. You can change this with the `PORT` environment variable:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
PORT=8080 npm run start:http
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The MCP endpoint will be available at `http://localhost:3000/mcp`
|
|
164
|
+
|
|
165
|
+
## Testing
|
|
166
|
+
|
|
167
|
+
You can test the server using the MCP Inspector:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
npm run inspector
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### For HTTP transport:
|
|
174
|
+
Start the HTTP server:
|
|
175
|
+
```bash
|
|
176
|
+
npm run dev:http
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Then use the MCP Inspector:
|
|
180
|
+
```bash
|
|
181
|
+
npx @modelcontextprotocol/inspector
|
|
182
|
+
```
|
|
183
|
+
Connect to: `http://localhost:3000/mcp`
|
|
184
|
+
|
|
185
|
+
## Project Structure
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
mcp-uptime-kuma/
|
|
189
|
+
├── src/
|
|
190
|
+
│ ├── index.ts # Main entry point with transport selection
|
|
191
|
+
│ ├── server.ts # Core MCP server configuration with tools
|
|
192
|
+
│ ├── uptime-kuma-client.ts # WebSocket client for Uptime Kuma API
|
|
193
|
+
│ └── types.ts # TypeScript type definitions
|
|
194
|
+
├── dist/ # Compiled JavaScript (generated)
|
|
195
|
+
├── package.json # Project dependencies and scripts
|
|
196
|
+
├── tsconfig.json # TypeScript configuration
|
|
197
|
+
├── .env # Environment configuration (create this)
|
|
198
|
+
└── README.md # This file
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Development
|
|
202
|
+
|
|
203
|
+
To add new tools or modify existing ones, edit `src/server.ts`. The Uptime Kuma client in `src/uptime-kuma-client.ts` handles the WebSocket connection and caches monitor and heartbeat data.
|
|
204
|
+
|
|
205
|
+
## Learn More
|
|
206
|
+
|
|
207
|
+
- [Uptime Kuma](https://github.com/louislam/uptime-kuma)
|
|
208
|
+
- [Model Context Protocol Documentation](https://modelcontextprotocol.io/)
|
|
209
|
+
- [MCP TypeScript SDK](https://www.npmjs.com/package/@modelcontextprotocol/sdk)
|
|
210
|
+
- [MCP Specification](https://spec.modelcontextprotocol.io/)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,eAAe,CAAC;AA0JvB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import 'dotenv/config';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
5
|
+
import express from 'express';
|
|
6
|
+
import { createServer } from './server.js';
|
|
7
|
+
/**
|
|
8
|
+
* Main entry point for @davidfuchs/mcp-uptime-kuma
|
|
9
|
+
* Supports both stdio (default) and streamable-http transports via CLI flags
|
|
10
|
+
*/
|
|
11
|
+
// Validate required environment variables
|
|
12
|
+
function validateEnvironment() {
|
|
13
|
+
const url = process.env.UPTIME_KUMA_URL;
|
|
14
|
+
const username = process.env.UPTIME_KUMA_USERNAME;
|
|
15
|
+
const password = process.env.UPTIME_KUMA_PASSWORD;
|
|
16
|
+
if (!url) {
|
|
17
|
+
console.error('Error: UPTIME_KUMA_URL environment variable is required');
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
if (!username) {
|
|
21
|
+
console.error('Error: UPTIME_KUMA_USERNAME environment variable is required');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
if (!password) {
|
|
25
|
+
console.error('Error: UPTIME_KUMA_PASSWORD environment variable is required');
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
return { url, username, password };
|
|
29
|
+
}
|
|
30
|
+
// Parse command-line arguments
|
|
31
|
+
function parseArgs() {
|
|
32
|
+
const args = process.argv.slice(2);
|
|
33
|
+
let transport = 'stdio';
|
|
34
|
+
for (let i = 0; i < args.length; i++) {
|
|
35
|
+
if (args[i] === '-t' || args[i] === '--transport') {
|
|
36
|
+
const value = args[i + 1];
|
|
37
|
+
if (value === 'stdio' || value === 'streamable-http') {
|
|
38
|
+
transport = value;
|
|
39
|
+
i++; // Skip next arg since we consumed it
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.error(`Invalid transport: ${value}. Must be 'stdio' or 'streamable-http'`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (args[i] === '-h' || args[i] === '--help') {
|
|
47
|
+
console.log(`Usage: mcp-uptime-kuma [options]
|
|
48
|
+
|
|
49
|
+
Options:
|
|
50
|
+
-t, --transport <type> Transport type: 'stdio' (default) or 'streamable-http'
|
|
51
|
+
-h, --help Show this help message
|
|
52
|
+
|
|
53
|
+
Examples:
|
|
54
|
+
mcp-uptime-kuma # Run with stdio transport (default)
|
|
55
|
+
mcp-uptime-kuma -t stdio # Run with stdio transport
|
|
56
|
+
mcp-uptime-kuma -t streamable-http # Run with streamable HTTP transport (port 3000)
|
|
57
|
+
PORT=8080 mcp-uptime-kuma -t streamable-http # Run HTTP on custom port
|
|
58
|
+
`);
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return { transport };
|
|
63
|
+
}
|
|
64
|
+
// Run with the stdio transport
|
|
65
|
+
async function runStdio(config) {
|
|
66
|
+
try {
|
|
67
|
+
const server = await createServer(config);
|
|
68
|
+
const transport = new StdioServerTransport();
|
|
69
|
+
await server.connect(transport);
|
|
70
|
+
console.error('mcp-uptime-kuma server running on stdio transport');
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error('Fatal error in stdio transport:', error);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Run with the streamable HTTP transport
|
|
78
|
+
async function runHttp(config) {
|
|
79
|
+
const app = express();
|
|
80
|
+
app.use(express.json());
|
|
81
|
+
// Create the MCP server once (reused across requests)
|
|
82
|
+
const server = await createServer(config);
|
|
83
|
+
// Handle MCP requests
|
|
84
|
+
app.post('/mcp', async (req, res) => {
|
|
85
|
+
try {
|
|
86
|
+
// Create a new transport for each request to prevent request ID collisions
|
|
87
|
+
const transport = new StreamableHTTPServerTransport({
|
|
88
|
+
sessionIdGenerator: undefined,
|
|
89
|
+
enableJsonResponse: true,
|
|
90
|
+
});
|
|
91
|
+
res.on('close', () => {
|
|
92
|
+
transport.close();
|
|
93
|
+
});
|
|
94
|
+
await server.connect(transport);
|
|
95
|
+
await transport.handleRequest(req, res, req.body);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error('Error handling MCP request:', error);
|
|
99
|
+
if (!res.headersSent) {
|
|
100
|
+
res.status(500).json({
|
|
101
|
+
jsonrpc: '2.0',
|
|
102
|
+
error: {
|
|
103
|
+
code: -32603,
|
|
104
|
+
message: 'Internal server error',
|
|
105
|
+
},
|
|
106
|
+
id: null,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
// Health check endpoint
|
|
112
|
+
app.get('/health', (req, res) => {
|
|
113
|
+
res.json({ status: 'ok', server: 'mcp-uptime-kuma' });
|
|
114
|
+
});
|
|
115
|
+
const port = parseInt(process.env.PORT || '3000');
|
|
116
|
+
app.listen(port, () => {
|
|
117
|
+
console.log(`mcp-uptime-kuma server running on http://localhost:${port}/mcp`);
|
|
118
|
+
console.log(`Health check available at http://localhost:${port}/health`);
|
|
119
|
+
}).on('error', (error) => {
|
|
120
|
+
console.error('Server error:', error);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// Main entry point
|
|
125
|
+
async function main() {
|
|
126
|
+
const config = validateEnvironment();
|
|
127
|
+
const { transport } = parseArgs();
|
|
128
|
+
if (transport === 'stdio') {
|
|
129
|
+
await runStdio(config);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
await runHttp(config);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
main();
|
|
136
|
+
// Also export the server creation function for programmatic use
|
|
137
|
+
export { createServer } from './server.js';
|
|
138
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;GAGG;AAEH,0CAA0C;AAC1C,S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;QACpB,OAAO,CAAC,GAAG,CAAC,sDAAsD,IAAI,MAAM,CAAC,CAAC;QAC9E,OAAO,CAAC,GAAG,CAAC,8CAA8C,IAAI,SAAS,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QACvB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;QACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,mBAAmB;AACnB,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,mBAAmB,EAAE,CAAC;IACrC,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAAC;IAElC,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;QAC1B,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC;AAEP,gEAAgE;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration interface for Uptime Kuma
|
|
4
|
+
*/
|
|
5
|
+
export interface UptimeKumaConfig {
|
|
6
|
+
url: string;
|
|
7
|
+
username: string;
|
|
8
|
+
password: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates and configures the MCP server with tools, resources, and prompts
|
|
12
|
+
*/
|
|
13
|
+
export declare function createServer(config: UptimeKumaConfig): Promise<McpServer>;
|
|
14
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAMpE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CA+Q/E"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { UptimeKumaClient, filterMonitorFields } from './uptime-kuma-client.js';
|
|
5
|
+
import { HeartbeatSchema, MonitorBaseSchema } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates and configures the MCP server with tools, resources, and prompts
|
|
8
|
+
*/
|
|
9
|
+
export async function createServer(config) {
|
|
10
|
+
const server = new McpServer({
|
|
11
|
+
name: 'mcp-uptime-kuma',
|
|
12
|
+
version: '0.1.0',
|
|
13
|
+
}, {
|
|
14
|
+
instructions: `
|
|
15
|
+
This MCP server provides access to Uptime Kuma monitoring data.
|
|
16
|
+
|
|
17
|
+
Available tools:
|
|
18
|
+
- getMonitor: Retrieve configuration and details for a specific monitor by ID
|
|
19
|
+
- listMonitors: Get all monitors with their configurations
|
|
20
|
+
- getHeartbeats: Retrieve status checks and uptime data for a specific monitor
|
|
21
|
+
- listAllHeartbeats: Get status checks and uptime data for all monitors
|
|
22
|
+
|
|
23
|
+
Monitors contain configuration information (URLs, check intervals, notification settings, etc.).
|
|
24
|
+
Heartbeats contain actual status data (up/down status, response times, timestamps, etc.).
|
|
25
|
+
To check if something is up or down, use heartbeat tools, not monitor tools.
|
|
26
|
+
|
|
27
|
+
By default, tools return only essential fields. Set includeAdditionalFields=true to get all available data.
|
|
28
|
+
`
|
|
29
|
+
});
|
|
30
|
+
// Initialize Uptime Kuma client and login
|
|
31
|
+
const client = new UptimeKumaClient(config.url);
|
|
32
|
+
let isAuthenticated = false;
|
|
33
|
+
try {
|
|
34
|
+
await client.connect();
|
|
35
|
+
await client.login(config.username, config.password);
|
|
36
|
+
isAuthenticated = true;
|
|
37
|
+
console.error('Successfully authenticated with Uptime Kuma');
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
41
|
+
console.error('Failed to authenticate with Uptime Kuma:', error);
|
|
42
|
+
throw new McpError(ErrorCode.InternalError, `Failed to authenticate with Uptime Kuma: ${errorMessage}`);
|
|
43
|
+
}
|
|
44
|
+
// Register getMonitor tool
|
|
45
|
+
server.registerTool('getMonitor', {
|
|
46
|
+
title: 'Get Monitor',
|
|
47
|
+
description: 'Retrieves detailed information about a specific monitor by its ID',
|
|
48
|
+
inputSchema: {
|
|
49
|
+
monitorID: z.number().int().positive().describe('The ID of the monitor to retrieve'),
|
|
50
|
+
includeAdditionalFields: z.boolean().optional().describe('Include all additional fields from Uptime Kuma (default: false)')
|
|
51
|
+
},
|
|
52
|
+
outputSchema: {
|
|
53
|
+
monitor: MonitorBaseSchema.passthrough().describe('Monitor object (may include additional fields beyond base schema when includeAdditionalFields is true)')
|
|
54
|
+
},
|
|
55
|
+
}, async ({ monitorID, includeAdditionalFields }) => {
|
|
56
|
+
if (!isAuthenticated) {
|
|
57
|
+
throw new McpError(ErrorCode.InternalError, 'Not authenticated with Uptime Kuma');
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const monitor = client.getMonitor(monitorID);
|
|
61
|
+
if (!monitor) {
|
|
62
|
+
throw new Error(`Monitor with ID ${monitorID} not found`);
|
|
63
|
+
}
|
|
64
|
+
const result = (includeAdditionalFields ?? false) ? monitor : filterMonitorFields(monitor);
|
|
65
|
+
return {
|
|
66
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
67
|
+
structuredContent: { monitor: result },
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
72
|
+
throw new McpError(ErrorCode.InternalError, `Failed to get monitor: ${errorMessage}`);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
// Register listMonitors tool
|
|
76
|
+
server.registerTool('listMonitors', {
|
|
77
|
+
title: 'List Monitors',
|
|
78
|
+
description: 'Retrieves the full list of all monitors the user has access to from the cache. By default returns all fields; set includeAdditionalFields to false to return only defined fields.',
|
|
79
|
+
inputSchema: {
|
|
80
|
+
includeAdditionalFields: z.boolean().optional().describe('Include all additional fields from Uptime Kuma (default: false)')
|
|
81
|
+
},
|
|
82
|
+
outputSchema: {
|
|
83
|
+
monitors: z.array(MonitorBaseSchema.passthrough()).describe('Array of monitor objects (may include additional fields beyond base schema when includeAdditionalFields is true)'),
|
|
84
|
+
count: z.number()
|
|
85
|
+
},
|
|
86
|
+
}, async ({ includeAdditionalFields }) => {
|
|
87
|
+
if (!isAuthenticated) {
|
|
88
|
+
throw new McpError(ErrorCode.InternalError, 'Not authenticated with Uptime Kuma');
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const monitorList = client.getMonitorList();
|
|
92
|
+
const monitors = Object.values(monitorList).map(monitor => (includeAdditionalFields ?? false) ? monitor : filterMonitorFields(monitor));
|
|
93
|
+
return {
|
|
94
|
+
content: [{
|
|
95
|
+
type: 'text',
|
|
96
|
+
text: JSON.stringify(monitors, null, 2)
|
|
97
|
+
}],
|
|
98
|
+
structuredContent: {
|
|
99
|
+
monitors,
|
|
100
|
+
count: monitors.length
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
106
|
+
throw new McpError(ErrorCode.InternalError, `Failed to list monitors: ${errorMessage}`);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
// Register getHeartbeats tool
|
|
110
|
+
server.registerTool('getHeartbeats', {
|
|
111
|
+
title: 'Get Heartbeats',
|
|
112
|
+
description: 'Retrieves heartbeats for a specific monitor from the cache. By default returns up to 100 most recent heartbeats; set includeAll to false to return only the most recent heartbeat.',
|
|
113
|
+
inputSchema: {
|
|
114
|
+
monitorID: z.number().int().positive().describe('The ID of the monitor to get heartbeats for'),
|
|
115
|
+
includeAll: z.boolean().optional().describe('If true, returns all heartbeats (up to 100). If false, returns only the most recent heartbeat (default: false)')
|
|
116
|
+
},
|
|
117
|
+
outputSchema: {
|
|
118
|
+
monitorID: z.number(),
|
|
119
|
+
heartbeats: z.array(HeartbeatSchema),
|
|
120
|
+
count: z.number()
|
|
121
|
+
},
|
|
122
|
+
}, async ({ monitorID, includeAll }) => {
|
|
123
|
+
if (!isAuthenticated) {
|
|
124
|
+
throw new McpError(ErrorCode.InternalError, 'Not authenticated with Uptime Kuma');
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const includeAllFlag = includeAll ?? false;
|
|
128
|
+
let heartbeatsArray;
|
|
129
|
+
if (includeAllFlag) {
|
|
130
|
+
heartbeatsArray = client.getHeartbeatsForMonitor(monitorID, true);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const singleHeartbeat = client.getHeartbeatsForMonitor(monitorID, false);
|
|
134
|
+
heartbeatsArray = singleHeartbeat ? [singleHeartbeat] : [];
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
content: [{
|
|
138
|
+
type: 'text',
|
|
139
|
+
text: JSON.stringify(heartbeatsArray, null, 2)
|
|
140
|
+
}],
|
|
141
|
+
structuredContent: {
|
|
142
|
+
monitorID,
|
|
143
|
+
heartbeats: heartbeatsArray,
|
|
144
|
+
count: heartbeatsArray.length
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
150
|
+
throw new McpError(ErrorCode.InternalError, `Failed to get heartbeats: ${errorMessage}`);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
// Register listAllHeartbeats tool
|
|
154
|
+
server.registerTool('listAllHeartbeats', {
|
|
155
|
+
title: 'List All Heartbeats',
|
|
156
|
+
description: 'Retrieves the complete heartbeat list for all monitors from the cache. By default, each monitor ID maps to an array of up to 100 recent heartbeats; set includeAll to false to return only the most recent heartbeat per monitor.',
|
|
157
|
+
inputSchema: {
|
|
158
|
+
includeAll: z.boolean().optional().describe('If true, returns all heartbeats (up to 100 per monitor). If false, returns only the most recent heartbeat per monitor (default: false)')
|
|
159
|
+
},
|
|
160
|
+
outputSchema: {
|
|
161
|
+
heartbeats: z.record(z.string(), z.array(HeartbeatSchema)).describe('Map of monitor IDs to their heartbeat arrays'),
|
|
162
|
+
monitorCount: z.number(),
|
|
163
|
+
totalHeartbeatCount: z.number()
|
|
164
|
+
},
|
|
165
|
+
}, async ({ includeAll }) => {
|
|
166
|
+
if (!isAuthenticated) {
|
|
167
|
+
throw new McpError(ErrorCode.InternalError, 'Not authenticated with Uptime Kuma');
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const includeAllFlag = includeAll ?? false;
|
|
171
|
+
const rawHeartbeatList = includeAllFlag
|
|
172
|
+
? client.getHeartbeatList(true)
|
|
173
|
+
: client.getHeartbeatList(false);
|
|
174
|
+
// Normalize to always return arrays for consistent schema
|
|
175
|
+
const heartbeatList = {};
|
|
176
|
+
for (const [monitorID, heartbeats] of Object.entries(rawHeartbeatList)) {
|
|
177
|
+
if (includeAllFlag) {
|
|
178
|
+
heartbeatList[monitorID] = heartbeats;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
heartbeatList[monitorID] = heartbeats ? [heartbeats] : [];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Calculate total heartbeat count
|
|
185
|
+
const totalCount = Object.values(heartbeatList).reduce((sum, heartbeats) => sum + heartbeats.length, 0);
|
|
186
|
+
return {
|
|
187
|
+
content: [{
|
|
188
|
+
type: 'text',
|
|
189
|
+
text: JSON.stringify(heartbeatList, null, 2)
|
|
190
|
+
}],
|
|
191
|
+
structuredContent: {
|
|
192
|
+
heartbeats: heartbeatList,
|
|
193
|
+
monitorCount: Object.keys(heartbeatList).length,
|
|
194
|
+
totalHeartbeatCount: totalCount
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
200
|
+
throw new McpError(ErrorCode.InternalError, `Failed to list heartbeats: ${errorMessage}`);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
// Clean up on server shutdown
|
|
204
|
+
process.on('SIGINT', () => {
|
|
205
|
+
client.disconnect();
|
|
206
|
+
process.exit(0);
|
|
207
|
+
});
|
|
208
|
+
process.on('SIGTERM', () => {
|
|
209
|
+
client.disconnect();
|
|
210
|
+
process.exit(0);
|
|
211
|
+
});
|
|
212
|
+
return server;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAWhE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CA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C9B,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACxB,MAAM,CAAC,UAAU,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;QACzB,MAAM,CAAC,UAAU,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for Base Monitor Object structure from Uptime Kuma (defined fields only)
|
|
4
|
+
*/
|
|
5
|
+
export declare const MonitorBaseSchema: z.ZodObject<{
|
|
6
|
+
id: z.ZodNumber;
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
type: z.ZodString;
|
|
9
|
+
url: z.ZodOptional<z.ZodString>;
|
|
10
|
+
method: z.ZodOptional<z.ZodString>;
|
|
11
|
+
interval: z.ZodNumber;
|
|
12
|
+
retryInterval: z.ZodNumber;
|
|
13
|
+
resendInterval: z.ZodNumber;
|
|
14
|
+
maxretries: z.ZodNumber;
|
|
15
|
+
hostname: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
16
|
+
port: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
17
|
+
active: z.ZodBoolean;
|
|
18
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
19
|
+
tag_id: z.ZodNumber;
|
|
20
|
+
monitor_id: z.ZodNumber;
|
|
21
|
+
value: z.ZodNullable<z.ZodString>;
|
|
22
|
+
name: z.ZodString;
|
|
23
|
+
color: z.ZodString;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
tag_id: number;
|
|
26
|
+
monitor_id: number;
|
|
27
|
+
value: string | null;
|
|
28
|
+
name: string;
|
|
29
|
+
color: string;
|
|
30
|
+
}, {
|
|
31
|
+
tag_id: number;
|
|
32
|
+
monitor_id: number;
|
|
33
|
+
value: string | null;
|
|
34
|
+
name: string;
|
|
35
|
+
color: string;
|
|
36
|
+
}>, "many">>;
|
|
37
|
+
notificationIDList: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
38
|
+
accepted_statuscodes_json: z.ZodOptional<z.ZodString>;
|
|
39
|
+
conditions: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
40
|
+
pathName: z.ZodString;
|
|
41
|
+
maintenance: z.ZodBoolean;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
name: string;
|
|
44
|
+
type: string;
|
|
45
|
+
id: number;
|
|
46
|
+
interval: number;
|
|
47
|
+
retryInterval: number;
|
|
48
|
+
resendInterval: number;
|
|
49
|
+
maxretries: number;
|
|
50
|
+
active: boolean;
|
|
51
|
+
pathName: string;
|
|
52
|
+
maintenance: boolean;
|
|
53
|
+
url?: string | undefined;
|
|
54
|
+
method?: string | undefined;
|
|
55
|
+
hostname?: string | null | undefined;
|
|
56
|
+
port?: number | null | undefined;
|
|
57
|
+
tags?: {
|
|
58
|
+
tag_id: number;
|
|
59
|
+
monitor_id: number;
|
|
60
|
+
value: string | null;
|
|
61
|
+
name: string;
|
|
62
|
+
color: string;
|
|
63
|
+
}[] | undefined;
|
|
64
|
+
notificationIDList?: Record<string, boolean> | undefined;
|
|
65
|
+
accepted_statuscodes_json?: string | undefined;
|
|
66
|
+
conditions?: any[] | undefined;
|
|
67
|
+
}, {
|
|
68
|
+
name: string;
|
|
69
|
+
type: string;
|
|
70
|
+
id: number;
|
|
71
|
+
interval: number;
|
|
72
|
+
retryInterval: number;
|
|
73
|
+
resendInterval: number;
|
|
74
|
+
maxretries: number;
|
|
75
|
+
active: boolean;
|
|
76
|
+
pathName: string;
|
|
77
|
+
maintenance: boolean;
|
|
78
|
+
url?: string | undefined;
|
|
79
|
+
method?: string | undefined;
|
|
80
|
+
hostname?: string | null | undefined;
|
|
81
|
+
port?: number | null | undefined;
|
|
82
|
+
tags?: {
|
|
83
|
+
tag_id: number;
|
|
84
|
+
monitor_id: number;
|
|
85
|
+
value: string | null;
|
|
86
|
+
name: string;
|
|
87
|
+
color: string;
|
|
88
|
+
}[] | undefined;
|
|
89
|
+
notificationIDList?: Record<string, boolean> | undefined;
|
|
90
|
+
accepted_statuscodes_json?: string | undefined;
|
|
91
|
+
conditions?: any[] | undefined;
|
|
92
|
+
}>;
|
|
93
|
+
/**
|
|
94
|
+
* Base Monitor type inferred from the Zod schema
|
|
95
|
+
*/
|
|
96
|
+
export type MonitorBase = z.infer<typeof MonitorBaseSchema>;
|
|
97
|
+
/**
|
|
98
|
+
* Monitor with additional fields (includes all Uptime Kuma fields)
|
|
99
|
+
*/
|
|
100
|
+
export interface MonitorWithAdditionalFields extends MonitorBase {
|
|
101
|
+
[key: string]: any;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Monitor type - can include or exclude additional fields based on includeAdditionalFields option
|
|
105
|
+
*/
|
|
106
|
+
export type Monitor<T extends boolean = true> = T extends true ? MonitorWithAdditionalFields : MonitorBase;
|
|
107
|
+
/**
|
|
108
|
+
* Response structure for API callbacks
|
|
109
|
+
*/
|
|
110
|
+
export interface ApiResponse {
|
|
111
|
+
ok: boolean;
|
|
112
|
+
msg?: string;
|
|
113
|
+
msgi18n?: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Login response
|
|
117
|
+
*/
|
|
118
|
+
export interface LoginResponse extends ApiResponse {
|
|
119
|
+
token?: string;
|
|
120
|
+
tokenRequired?: boolean;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get monitor response
|
|
124
|
+
*/
|
|
125
|
+
export interface GetMonitorResponse<T extends boolean = true> extends ApiResponse {
|
|
126
|
+
monitor?: Monitor<T>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Monitor list structure
|
|
130
|
+
*/
|
|
131
|
+
export interface MonitorList<T extends boolean = true> {
|
|
132
|
+
[monitorID: string]: Monitor<T>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Zod schema for Heartbeat object structure from Uptime Kuma
|
|
136
|
+
*/
|
|
137
|
+
export declare const HeartbeatSchema: z.ZodObject<{
|
|
138
|
+
status: z.ZodNumber;
|
|
139
|
+
time: z.ZodString;
|
|
140
|
+
msg: z.ZodString;
|
|
141
|
+
important: z.ZodEffects<z.ZodUnion<[z.ZodBoolean, z.ZodNumber]>, boolean, number | boolean>;
|
|
142
|
+
id: z.ZodOptional<z.ZodNumber>;
|
|
143
|
+
monitor_id: z.ZodOptional<z.ZodNumber>;
|
|
144
|
+
ping: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
145
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
146
|
+
down_count: z.ZodOptional<z.ZodNumber>;
|
|
147
|
+
retries: z.ZodOptional<z.ZodNumber>;
|
|
148
|
+
end_time: z.ZodOptional<z.ZodString>;
|
|
149
|
+
monitorID: z.ZodOptional<z.ZodNumber>;
|
|
150
|
+
localDateTime: z.ZodOptional<z.ZodString>;
|
|
151
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
152
|
+
}, "strip", z.ZodTypeAny, {
|
|
153
|
+
status: number;
|
|
154
|
+
time: string;
|
|
155
|
+
msg: string;
|
|
156
|
+
important: boolean;
|
|
157
|
+
monitor_id?: number | undefined;
|
|
158
|
+
id?: number | undefined;
|
|
159
|
+
ping?: number | null | undefined;
|
|
160
|
+
duration?: number | undefined;
|
|
161
|
+
down_count?: number | undefined;
|
|
162
|
+
retries?: number | undefined;
|
|
163
|
+
end_time?: string | undefined;
|
|
164
|
+
monitorID?: number | undefined;
|
|
165
|
+
localDateTime?: string | undefined;
|
|
166
|
+
timezone?: string | undefined;
|
|
167
|
+
}, {
|
|
168
|
+
status: number;
|
|
169
|
+
time: string;
|
|
170
|
+
msg: string;
|
|
171
|
+
important: number | boolean;
|
|
172
|
+
monitor_id?: number | undefined;
|
|
173
|
+
id?: number | undefined;
|
|
174
|
+
ping?: number | null | undefined;
|
|
175
|
+
duration?: number | undefined;
|
|
176
|
+
down_count?: number | undefined;
|
|
177
|
+
retries?: number | undefined;
|
|
178
|
+
end_time?: string | undefined;
|
|
179
|
+
monitorID?: number | undefined;
|
|
180
|
+
localDateTime?: string | undefined;
|
|
181
|
+
timezone?: string | undefined;
|
|
182
|
+
}>;
|
|
183
|
+
/**
|
|
184
|
+
* Heartbeat type inferred from the Zod schema
|
|
185
|
+
*/
|
|
186
|
+
export type Heartbeat = z.infer<typeof HeartbeatSchema>;
|
|
187
|
+
/**
|
|
188
|
+
* Heartbeat list structure - maps monitor IDs to heartbeats
|
|
189
|
+
* When includeAll is true, returns arrays of heartbeats
|
|
190
|
+
* When includeAll is false, returns only the most recent heartbeat
|
|
191
|
+
*/
|
|
192
|
+
export type HeartbeatList<T extends boolean = true> = T extends true ? {
|
|
193
|
+
[monitorID: string]: Heartbeat[];
|
|
194
|
+
} : {
|
|
195
|
+
[monitorID: string]: Heartbeat | undefined;
|
|
196
|
+
};
|
|
197
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmB5B,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for Monitor tag object
|
|
4
|
+
*/
|
|
5
|
+
const MonitorTagSchema = z.object({
|
|
6
|
+
tag_id: z.number(),
|
|
7
|
+
monitor_id: z.number(),
|
|
8
|
+
value: z.string().nullable(),
|
|
9
|
+
name: z.string(),
|
|
10
|
+
color: z.string(),
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Zod schema for Base Monitor Object structure from Uptime Kuma (defined fields only)
|
|
14
|
+
*/
|
|
15
|
+
export const MonitorBaseSchema = z.object({
|
|
16
|
+
id: z.number(),
|
|
17
|
+
name: z.string(),
|
|
18
|
+
type: z.string(),
|
|
19
|
+
url: z.string().optional(),
|
|
20
|
+
method: z.string().optional(),
|
|
21
|
+
interval: z.number(),
|
|
22
|
+
retryInterval: z.number(),
|
|
23
|
+
resendInterval: z.number(),
|
|
24
|
+
maxretries: z.number(),
|
|
25
|
+
hostname: z.string().nullable().optional(),
|
|
26
|
+
port: z.number().nullable().optional(),
|
|
27
|
+
active: z.boolean(),
|
|
28
|
+
tags: z.array(MonitorTagSchema).optional(),
|
|
29
|
+
notificationIDList: z.record(z.string(), z.boolean()).optional(),
|
|
30
|
+
accepted_statuscodes_json: z.string().optional(),
|
|
31
|
+
conditions: z.array(z.any()).optional(),
|
|
32
|
+
pathName: z.string(),
|
|
33
|
+
maintenance: z.boolean(),
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Zod schema for Heartbeat object structure from Uptime Kuma
|
|
37
|
+
*/
|
|
38
|
+
export const HeartbeatSchema = z.object({
|
|
39
|
+
// Required fields
|
|
40
|
+
status: z.number().describe('0=DOWN, 1=UP, 2=PENDING, 3=MAINTENANCE'),
|
|
41
|
+
time: z.string().describe('Timestamp string'),
|
|
42
|
+
msg: z.string().describe('Status message or error'),
|
|
43
|
+
important: z.union([z.boolean(), z.number()]).transform(val => Boolean(val)).describe('Was this heartbeat a status change?'),
|
|
44
|
+
// Optional fields
|
|
45
|
+
id: z.number().optional().describe('Unique heartbeat ID'),
|
|
46
|
+
monitor_id: z.number().optional().describe('The monitor this heartbeat belongs to'),
|
|
47
|
+
ping: z.number().nullable().optional().describe('Response time in ms, null if not applicable'),
|
|
48
|
+
duration: z.number().optional().describe('Seconds since the last heartbeat for this monitor'),
|
|
49
|
+
down_count: z.number().optional().describe('Consecutive down count for resend logic'),
|
|
50
|
+
retries: z.number().optional().describe('Number of retries attempted for this state'),
|
|
51
|
+
end_time: z.string().optional().describe('End time of the heartbeat check'),
|
|
52
|
+
monitorID: z.number().optional().describe('camelCase alias (used in some events)'),
|
|
53
|
+
localDateTime: z.string().optional().describe('Formatted time in server\'s timezone'),
|
|
54
|
+
timezone: z.string().optional().describe('Server\'s timezone name'),
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;CAClB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,GAAG,EAAE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yB,CAAC;CACpE,CAAC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Socket } from 'socket.io-client';
|
|
2
|
+
import type { MonitorBase, MonitorWithAdditionalFields, LoginResponse, MonitorList, Heartbeat, HeartbeatList } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Uptime Kuma Socket.io API Client
|
|
5
|
+
*/
|
|
6
|
+
export declare class UptimeKumaClient {
|
|
7
|
+
private socket;
|
|
8
|
+
private url;
|
|
9
|
+
private monitorListCache;
|
|
10
|
+
private heartbeatListCache;
|
|
11
|
+
constructor(url: string);
|
|
12
|
+
/**
|
|
13
|
+
* Connect to the Uptime Kuma server
|
|
14
|
+
*/
|
|
15
|
+
connect(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Disconnect from the Uptime Kuma server
|
|
18
|
+
*/
|
|
19
|
+
disconnect(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Login using username and password
|
|
22
|
+
*
|
|
23
|
+
* @param username - Username (can be empty string)
|
|
24
|
+
* @param password - Password/API key
|
|
25
|
+
* @param token - Optional 2FA token if required
|
|
26
|
+
* @returns Promise resolving to the login response
|
|
27
|
+
*/
|
|
28
|
+
login(username: string, password: string, token?: string): Promise<LoginResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* Set up event listeners for monitor list updates
|
|
31
|
+
* These listeners keep the cached monitor list in sync with the server
|
|
32
|
+
*/
|
|
33
|
+
private setupMonitorListListeners;
|
|
34
|
+
/**
|
|
35
|
+
* Set up event listeners for heartbeat updates
|
|
36
|
+
* These listeners keep the cached heartbeat list in sync with the server
|
|
37
|
+
*/
|
|
38
|
+
private setupHeartbeatListeners;
|
|
39
|
+
/**
|
|
40
|
+
* Get a specific monitor by ID from the cache
|
|
41
|
+
*
|
|
42
|
+
* @param monitorID - The ID of the monitor to retrieve
|
|
43
|
+
* @returns The monitor data with all fields, or undefined if not found
|
|
44
|
+
*/
|
|
45
|
+
getMonitor(monitorID: number): MonitorWithAdditionalFields | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Get the cached full list of monitors the user has access to
|
|
48
|
+
* The list is populated after login and kept up-to-date via server events
|
|
49
|
+
*
|
|
50
|
+
* @returns The cached monitor list with all fields
|
|
51
|
+
*/
|
|
52
|
+
getMonitorList(): MonitorList<true>;
|
|
53
|
+
/**
|
|
54
|
+
* Get the cached heartbeat list
|
|
55
|
+
* The list is populated after login and kept up-to-date via server events
|
|
56
|
+
*
|
|
57
|
+
* @param includeAll - If true, returns arrays of all heartbeats (up to 100). If false, returns only the most recent heartbeat for each monitor
|
|
58
|
+
* @returns The cached heartbeat list
|
|
59
|
+
*/
|
|
60
|
+
getHeartbeatList<T extends boolean = true>(includeAll?: T): HeartbeatList<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Get heartbeats for a specific monitor from the cache
|
|
63
|
+
*
|
|
64
|
+
* @param monitorID - The ID of the monitor
|
|
65
|
+
* @param includeAll - If true, returns all heartbeats (up to 100). If false, returns only the most recent heartbeat
|
|
66
|
+
* @returns Heartbeat(s) for the monitor, or empty array/undefined if none exist
|
|
67
|
+
*/
|
|
68
|
+
getHeartbeatsForMonitor<T extends boolean = true>(monitorID: number, includeAll?: T): T extends true ? Heartbeat[] : Heartbeat | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Get the socket instance (for advanced usage)
|
|
71
|
+
*/
|
|
72
|
+
getSocket(): Socket | null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Utility function to filter a monitor object to only include defined fields
|
|
76
|
+
*
|
|
77
|
+
* @param monitor - The monitor object with all fields
|
|
78
|
+
* @returns The monitor object with only defined fields
|
|
79
|
+
*/
|
|
80
|
+
export declare function filterMonitorFields(monitor: MonitorWithAdditionalFields): MonitorBase;
|
|
81
|
+
//# sourceMappingURL=uptime-kuma-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uptime-kuma-client.d.ts","sourceRoot":"","sources":["../src/uptime-kuma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B,CAAC,OAAO,EAAE,2BAA2B,GAAG,WAAW,CAyBrF"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { io, Socket } from 'socket.io-client';
|
|
2
|
+
/**
|
|
3
|
+
* Uptime Kuma Socket.io API Client
|
|
4
|
+
*/
|
|
5
|
+
export class UptimeKumaClient {
|
|
6
|
+
socket = null;
|
|
7
|
+
url;
|
|
8
|
+
monitorListCache = {};
|
|
9
|
+
heartbeatListCache = {};
|
|
10
|
+
constructor(url) {
|
|
11
|
+
this.url = url;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Connect to the Uptime Kuma server
|
|
15
|
+
*/
|
|
16
|
+
connect() {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
this.socket = io(this.url, {
|
|
19
|
+
reconnection: true,
|
|
20
|
+
reconnectionDelay: 1000,
|
|
21
|
+
reconnectionAttempts: 5,
|
|
22
|
+
});
|
|
23
|
+
this.socket.on('connect', () => {
|
|
24
|
+
resolve();
|
|
25
|
+
});
|
|
26
|
+
this.socket.on('connect_error', (error) => {
|
|
27
|
+
reject(new Error(`Connection failed: ${error.message}`));
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Disconnect from the Uptime Kuma server
|
|
33
|
+
*/
|
|
34
|
+
disconnect() {
|
|
35
|
+
if (this.socket) {
|
|
36
|
+
// Remove event listeners
|
|
37
|
+
this.socket.off('monitorList');
|
|
38
|
+
this.socket.off('updateMonitorIntoList');
|
|
39
|
+
this.socket.off('deleteMonitorFromList');
|
|
40
|
+
this.socket.off('heartbeatList');
|
|
41
|
+
this.socket.off('heartbeat');
|
|
42
|
+
this.socket.disconnect();
|
|
43
|
+
this.socket = null;
|
|
44
|
+
}
|
|
45
|
+
// Clear the caches
|
|
46
|
+
this.monitorListCache = {};
|
|
47
|
+
this.heartbeatListCache = {};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Login using username and password
|
|
51
|
+
*
|
|
52
|
+
* @param username - Username (can be empty string)
|
|
53
|
+
* @param password - Password/API key
|
|
54
|
+
* @param token - Optional 2FA token if required
|
|
55
|
+
* @returns Promise resolving to the login response
|
|
56
|
+
*/
|
|
57
|
+
login(username, password, token) {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
if (!this.socket || !this.socket.connected) {
|
|
60
|
+
reject(new Error('Not connected to server'));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const loginData = {
|
|
64
|
+
username,
|
|
65
|
+
password
|
|
66
|
+
};
|
|
67
|
+
if (token) {
|
|
68
|
+
loginData.token = token;
|
|
69
|
+
}
|
|
70
|
+
// Set up listeners for monitor list and heartbeat updates before login
|
|
71
|
+
this.setupMonitorListListeners();
|
|
72
|
+
this.setupHeartbeatListeners();
|
|
73
|
+
this.socket.emit('login', loginData, (response) => {
|
|
74
|
+
if (response.ok) {
|
|
75
|
+
resolve(response);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
reject(new Error(response.msg || 'Login failed'));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Set up event listeners for monitor list updates
|
|
85
|
+
* These listeners keep the cached monitor list in sync with the server
|
|
86
|
+
*/
|
|
87
|
+
setupMonitorListListeners() {
|
|
88
|
+
if (!this.socket)
|
|
89
|
+
return;
|
|
90
|
+
// Listen for the full monitor list (sent after login or on major changes)
|
|
91
|
+
this.socket.on('monitorList', (monitorList) => {
|
|
92
|
+
this.monitorListCache = monitorList;
|
|
93
|
+
});
|
|
94
|
+
// Listen for updates to specific monitors
|
|
95
|
+
this.socket.on('updateMonitorIntoList', (updates) => {
|
|
96
|
+
Object.assign(this.monitorListCache, updates);
|
|
97
|
+
});
|
|
98
|
+
// Listen for monitor deletions
|
|
99
|
+
this.socket.on('deleteMonitorFromList', (monitorID) => {
|
|
100
|
+
delete this.monitorListCache[monitorID.toString()];
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Set up event listeners for heartbeat updates
|
|
105
|
+
* These listeners keep the cached heartbeat list in sync with the server
|
|
106
|
+
*/
|
|
107
|
+
setupHeartbeatListeners() {
|
|
108
|
+
if (!this.socket)
|
|
109
|
+
return;
|
|
110
|
+
// Listen for the full heartbeat list (sent after login)
|
|
111
|
+
this.socket.on('heartbeatList', (monitorID, heartbeatList, important) => {
|
|
112
|
+
// The heartbeatList event sends data per monitor, not all at once
|
|
113
|
+
// Format: (monitorID, array of heartbeats, important flag)
|
|
114
|
+
console.error(`Received heartbeatList for monitor ${monitorID}:`, heartbeatList.length, 'heartbeats');
|
|
115
|
+
this.heartbeatListCache[monitorID.toString()] = heartbeatList;
|
|
116
|
+
});
|
|
117
|
+
// Listen for individual heartbeat updates (real-time)
|
|
118
|
+
this.socket.on('heartbeat', (heartbeat) => {
|
|
119
|
+
// The heartbeat event should always include monitorID
|
|
120
|
+
if (!heartbeat.monitorID) {
|
|
121
|
+
console.error('Received heartbeat without monitorID:', heartbeat);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const monitorID = heartbeat.monitorID.toString();
|
|
125
|
+
// Initialize array for this monitor if it doesn't exist
|
|
126
|
+
if (!this.heartbeatListCache[monitorID]) {
|
|
127
|
+
this.heartbeatListCache[monitorID] = [];
|
|
128
|
+
}
|
|
129
|
+
// Add the new heartbeat to the beginning of the array
|
|
130
|
+
this.heartbeatListCache[monitorID].unshift(heartbeat);
|
|
131
|
+
// Keep only the most recent heartbeats (limit to 100 like the API does)
|
|
132
|
+
if (this.heartbeatListCache[monitorID].length > 100) {
|
|
133
|
+
this.heartbeatListCache[monitorID] = this.heartbeatListCache[monitorID].slice(0, 100);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get a specific monitor by ID from the cache
|
|
139
|
+
*
|
|
140
|
+
* @param monitorID - The ID of the monitor to retrieve
|
|
141
|
+
* @returns The monitor data with all fields, or undefined if not found
|
|
142
|
+
*/
|
|
143
|
+
getMonitor(monitorID) {
|
|
144
|
+
return this.monitorListCache[monitorID.toString()];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get the cached full list of monitors the user has access to
|
|
148
|
+
* The list is populated after login and kept up-to-date via server events
|
|
149
|
+
*
|
|
150
|
+
* @returns The cached monitor list with all fields
|
|
151
|
+
*/
|
|
152
|
+
getMonitorList() {
|
|
153
|
+
return this.monitorListCache;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get the cached heartbeat list
|
|
157
|
+
* The list is populated after login and kept up-to-date via server events
|
|
158
|
+
*
|
|
159
|
+
* @param includeAll - If true, returns arrays of all heartbeats (up to 100). If false, returns only the most recent heartbeat for each monitor
|
|
160
|
+
* @returns The cached heartbeat list
|
|
161
|
+
*/
|
|
162
|
+
getHeartbeatList(includeAll = true) {
|
|
163
|
+
if (includeAll) {
|
|
164
|
+
return this.heartbeatListCache;
|
|
165
|
+
}
|
|
166
|
+
// Return only the most recent heartbeat for each monitor
|
|
167
|
+
const recentHeartbeats = {};
|
|
168
|
+
for (const [monitorID, heartbeats] of Object.entries(this.heartbeatListCache)) {
|
|
169
|
+
recentHeartbeats[monitorID] = heartbeats[0];
|
|
170
|
+
}
|
|
171
|
+
return recentHeartbeats;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get heartbeats for a specific monitor from the cache
|
|
175
|
+
*
|
|
176
|
+
* @param monitorID - The ID of the monitor
|
|
177
|
+
* @param includeAll - If true, returns all heartbeats (up to 100). If false, returns only the most recent heartbeat
|
|
178
|
+
* @returns Heartbeat(s) for the monitor, or empty array/undefined if none exist
|
|
179
|
+
*/
|
|
180
|
+
getHeartbeatsForMonitor(monitorID, includeAll = true) {
|
|
181
|
+
const heartbeats = this.heartbeatListCache[monitorID.toString()];
|
|
182
|
+
if (includeAll) {
|
|
183
|
+
return (heartbeats || []);
|
|
184
|
+
}
|
|
185
|
+
return (heartbeats?.[0]);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get the socket instance (for advanced usage)
|
|
189
|
+
*/
|
|
190
|
+
getSocket() {
|
|
191
|
+
return this.socket;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Utility function to filter a monitor object to only include defined fields
|
|
196
|
+
*
|
|
197
|
+
* @param monitor - The monitor object with all fields
|
|
198
|
+
* @returns The monitor object with only defined fields
|
|
199
|
+
*/
|
|
200
|
+
export function filterMonitorFields(monitor) {
|
|
201
|
+
const filtered = {
|
|
202
|
+
id: monitor.id,
|
|
203
|
+
name: monitor.name,
|
|
204
|
+
type: monitor.type,
|
|
205
|
+
interval: monitor.interval,
|
|
206
|
+
retryInterval: monitor.retryInterval,
|
|
207
|
+
resendInterval: monitor.resendInterval,
|
|
208
|
+
maxretries: monitor.maxretries,
|
|
209
|
+
active: monitor.active,
|
|
210
|
+
pathName: monitor.pathName,
|
|
211
|
+
maintenance: monitor.maintenance,
|
|
212
|
+
};
|
|
213
|
+
// Add optional fields if they exist
|
|
214
|
+
if (monitor.url !== undefined)
|
|
215
|
+
filtered.url = monitor.url;
|
|
216
|
+
if (monitor.method !== undefined)
|
|
217
|
+
filtered.method = monitor.method;
|
|
218
|
+
if (monitor.hostname !== undefined)
|
|
219
|
+
filtered.hostname = monitor.hostname;
|
|
220
|
+
if (monitor.port !== undefined)
|
|
221
|
+
filtered.port = monitor.port;
|
|
222
|
+
if (monitor.tags !== undefined)
|
|
223
|
+
filtered.tags = monitor.tags;
|
|
224
|
+
if (monitor.notificationIDList !== undefined)
|
|
225
|
+
filtered.notificationIDList = monitor.notificationIDList;
|
|
226
|
+
if (monitor.accepted_statuscodes_json !== undefined)
|
|
227
|
+
filtered.accepted_statuscodes_json = monitor.accepted_statuscodes_json;
|
|
228
|
+
if (monitor.conditions !== undefined)
|
|
229
|
+
filtered.conditions = monitor.conditions;
|
|
230
|
+
return filtered;
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=uptime-kuma-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uptime-kuma-client.js","sourceRoot":"","sources":["../src/uptime-kuma-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAa9C;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACnB,MAAM,GAAkB,IAAI,CAAC;IAC7B,GAAG,CAAS;IACZ,gBAAgB,GAAsB,EAAE,CAAC;IACzC,kBAAkB,GAAwB,EAAE,CAAC;IAErD,YAAY,GAAW;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;gBACzB,YAAY,EAAE,IAAI;gBAClB,iBAAiB,EAAE,IAAI;gBACvB,oBAAoB,EAAE,CAAC;aACxB,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;gBAC7B,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,KAAY,EAAE,EAAE;gBAC/C,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC3D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,yBAAyB;YACzB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YAC/B,I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AAK,SAAS;QAAE,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IACnE,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS;QAAE,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IACzE,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;QAAE,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC7D,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;QAAE,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC7D,IAAI,OAAO,CAAC,kBAAkB,KAAK,SAAS;QAAE,QAAQ,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IACvG,IAAI,OAAO,CAAC,yBAAyB,KAAK,SAAS;QAAE,QAAQ,CAAC,yBAAyB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAC5H,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;QAAE,QAAQ,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAE/E,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@davidfuchs/mcp-uptime-kuma",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A Model Context Protocol server with TypeScript supporting stdio and streamable HTTP transports",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mcp-uptime-kuma": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"start": "node dist/index.js",
|
|
18
|
+
"start:stdio": "node dist/index.js -t stdio",
|
|
19
|
+
"start:http": "node dist/index.js -t streamable-http",
|
|
20
|
+
"dev": "tsx src/index.ts",
|
|
21
|
+
"dev:stdio": "tsx src/index.ts -t stdio",
|
|
22
|
+
"dev:http": "tsx src/index.ts -t streamable-http",
|
|
23
|
+
"watch": "tsc --watch",
|
|
24
|
+
"inspector": "npx @modelcontextprotocol/inspector tsx src/index.ts"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"mcp",
|
|
28
|
+
"model-context-protocol",
|
|
29
|
+
"typescript",
|
|
30
|
+
"server",
|
|
31
|
+
"stdio",
|
|
32
|
+
"http",
|
|
33
|
+
"uptime",
|
|
34
|
+
"kuma",
|
|
35
|
+
"uptime kuma"
|
|
36
|
+
],
|
|
37
|
+
"author": "David Fuchs <david@davidfuchs.ca>",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/DavidFuchs/mcp-uptime-kuma.git"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@modelcontextprotocol/sdk": "^1.22.0",
|
|
48
|
+
"dotenv": "^17.2.3",
|
|
49
|
+
"express": "^4.21.2",
|
|
50
|
+
"socket.io-client": "^4.8.1",
|
|
51
|
+
"zod": "^3.24.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/express": "^5.0.0",
|
|
55
|
+
"@types/node": "^22.10.2",
|
|
56
|
+
"tsx": "^4.19.2",
|
|
57
|
+
"typescript": "^5.7.2"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=18.0.0"
|
|
61
|
+
}
|
|
62
|
+
}
|