From 04ee339d58a96a57752e2f677a6cdbe2a2c99edc Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Fri, 27 Jun 2025 14:06:32 +0100 Subject: [PATCH] refactor: Simplify environment configuration by removing hostname, protocol, and base route; update API service to use URL --- MCP/.env.example | 15 +++------------ MCP/Index.ts | 7 +------ MCP/README.md | 15 ++++----------- MCP/Services/OneUptimeApiService.ts | 19 +++++++------------ 4 files changed, 15 insertions(+), 41 deletions(-) diff --git a/MCP/.env.example b/MCP/.env.example index 5efd59359b..b221effefb 100644 --- a/MCP/.env.example +++ b/MCP/.env.example @@ -1,16 +1,7 @@ # OneUptime MCP Server Configuration -# OneUptime Instance Configuration -ONEUPTIME_HOSTNAME=localhost:3002 -ONEUPTIME_PROTOCOL=http -ONEUPTIME_BASE_ROUTE=/api/v1 - -# Authentication (Required for production) +# OneUptime API Key (Required) ONEUPTIME_API_KEY=your_oneuptime_api_key_here -ONEUPTIME_PROJECT_ID=your_project_id_here -# Server Configuration -NODE_ENV=development -LOG_LEVEL=info -APP_NAME=oneuptime-mcp-server -APP_VERSION=1.0.0 +# OneUptime Instance URL (Optional - defaults to https://oneuptime.com) +ONEUPTIME_URL=https://oneuptime.com diff --git a/MCP/Index.ts b/MCP/Index.ts index 37fb88658b..260f3efaa2 100644 --- a/MCP/Index.ts +++ b/MCP/Index.ts @@ -13,8 +13,6 @@ import OneUptimeApiService, { OneUptimeApiConfig } from "./Services/OneUptimeApi import { McpToolInfo, OneUptimeToolCallArgs } from "./Types/McpTypes"; import OneUptimeOperation from "./Types/OneUptimeOperation"; import ModelType from "./Types/ModelType"; -import Protocol from "Common/Types/API/Protocol"; -import Route from "Common/Types/API/Route"; // Load environment variables dotenv.config(); @@ -48,11 +46,8 @@ class OneUptimeMCPServer { private initializeServices(): void { // Initialize OneUptime API Service const config: OneUptimeApiConfig = { - hostname: process.env.ONEUPTIME_HOSTNAME || "localhost:3002", - protocol: process.env.ONEUPTIME_PROTOCOL === "http" ? Protocol.HTTP : Protocol.HTTPS, + url: process.env.ONEUPTIME_URL || "https://oneuptime.com", apiKey: process.env.ONEUPTIME_API_KEY, - projectId: process.env.ONEUPTIME_PROJECT_ID, - baseRoute: new Route(process.env.ONEUPTIME_BASE_ROUTE || "/api/v1"), }; OneUptimeApiService.initialize(config); diff --git a/MCP/README.md b/MCP/README.md index b076d7a284..5e068f6084 100644 --- a/MCP/README.md +++ b/MCP/README.md @@ -39,18 +39,11 @@ The server automatically generates tools for all OneUptime models including: Copy `.env.example` to `.env` and configure: ```bash -# OneUptime Instance Configuration -ONEUPTIME_HOSTNAME=localhost:3002 -ONEUPTIME_PROTOCOL=http -ONEUPTIME_BASE_ROUTE=/api/v1 +# OneUptime API Key (Required) +ONEUPTIME_API_KEY=your_oneuptime_api_key_here -# Authentication (Required for production) -ONEUPTIME_API_KEY=your_oneuptime_api_key_here -ONEUPTIME_PROJECT_ID=your_project_id_here - -# Server Configuration -NODE_ENV=development -LOG_LEVEL=info +# OneUptime Instance URL (Optional - defaults to https://oneuptime.com) +ONEUPTIME_URL=https://oneuptime.com ``` ## Installation diff --git a/MCP/Services/OneUptimeApiService.ts b/MCP/Services/OneUptimeApiService.ts index db5b4d69f8..56610499b7 100644 --- a/MCP/Services/OneUptimeApiService.ts +++ b/MCP/Services/OneUptimeApiService.ts @@ -13,11 +13,8 @@ import HTTPErrorResponse from "Common/Types/API/HTTPErrorResponse"; import { JSONObject } from "Common/Types/JSON"; export interface OneUptimeApiConfig { - hostname: string; - protocol?: Protocol; + url: string; apiKey?: string; - projectId?: string; - baseRoute?: Route; } export default class OneUptimeApiService { @@ -27,13 +24,15 @@ export default class OneUptimeApiService { public static initialize(config: OneUptimeApiConfig): void { this.config = config; - const protocol = config.protocol || Protocol.HTTPS; - const hostname = new Hostname(config.hostname); - const baseRoute = config.baseRoute || new Route("/api/v1"); + // Parse the URL to extract protocol, hostname, and path + const url = URL.fromString(config.url); + const protocol = url.protocol; + const hostname = url.hostname; + const baseRoute = url.route.toString() === '/' ? new Route('/api/v1') : url.route; this.api = new API(protocol, hostname, baseRoute); - Logger.info(`OneUptime API Service initialized with: ${protocol}://${hostname}${baseRoute}`); + Logger.info(`OneUptime API Service initialized with: ${config.url}`); } /** @@ -148,10 +147,6 @@ export default class OneUptimeApiService { headers['Authorization'] = `Bearer ${this.config.apiKey}`; } - if (this.config.projectId) { - headers['X-Project-ID'] = this.config.projectId; - } - return headers; }