mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-01-11 19:56:44 +00:00
refactor: Simplify environment configuration by removing hostname, protocol, and base route; update API service to use URL
This commit is contained in:
parent
2a74183de5
commit
04ee339d58
4 changed files with 15 additions and 41 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue