refactor: Simplify environment configuration by removing hostname, protocol, and base route; update API service to use URL

This commit is contained in:
Simon Larsen 2025-06-27 14:06:32 +01:00
parent 2a74183de5
commit 04ee339d58
No known key found for this signature in database
GPG key ID: 96C5DCA24769DBCA
4 changed files with 15 additions and 41 deletions

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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;
}