oneuptime/MCP
Nawaz Dhandala e93b9f7759
feat: Implement MCP Tool Handler and Server Management
- Added ToolHandler.ts to manage tool execution and response formatting.
- Implemented session management in SessionManager.ts for handling API keys and session data.
- Created MCPServer.ts for initializing and managing the MCP server instance.
- Developed SelectFieldGenerator.ts to generate select field objects for API queries.
- Introduced SchemaConverter.ts for converting Zod schemas to JSON Schema format.
- Built ToolGenerator.ts to generate MCP tools for OneUptime models, including CRUD operations.
- Enhanced logging throughout the code for better traceability and debugging.
2025-12-17 18:01:21 +00:00
..
__mocks__ feat: Improve error handling and logging in OneUptimeApiService and related tests 2025-07-01 21:02:32 +01:00
__tests__ feat: Implement MCP Tool Handler and Server Management 2025-12-17 18:01:21 +00:00
build feat: Implement MCP Hello World Server with basic tools and configuration 2025-06-27 12:56:38 +01:00
Config feat: Implement MCP Tool Handler and Server Management 2025-12-17 18:01:21 +00:00
Handlers feat: Implement MCP Tool Handler and Server Management 2025-12-17 18:01:21 +00:00
Server feat: Implement MCP Tool Handler and Server Management 2025-12-17 18:01:21 +00:00
Services feat: Implement MCP Tool Handler and Server Management 2025-12-17 18:01:21 +00:00
Tools feat: Implement MCP Tool Handler and Server Management 2025-12-17 18:01:21 +00:00
Types refactor: Improve type definitions and enhance JSON schema handling in MCP services 2025-12-16 11:42:56 +00:00
Utils feat: Implement MCP Tool Handler and Server Management 2025-12-17 18:01:21 +00:00
.env.example refactor: Simplify environment configuration by removing hostname, protocol, and base route; update API service to use URL 2025-06-27 14:06:32 +01:00
Dockerfile.tpl refactor: update Dockerfile for Node.js version and improve nodemon configuration 2025-12-17 17:46:40 +00:00
Index.ts feat: Implement MCP Tool Handler and Server Management 2025-12-17 18:01:21 +00:00
jest.config.json refactor: Simplify tsconfig structure in jest.config.json 2025-12-16 11:34:02 +00:00
nodemon.json refactor: update Dockerfile for Node.js version and improve nodemon configuration 2025-12-17 17:46:40 +00:00
package-lock.json feat: Add ejs as a dependency in package.json and package-lock.json 2025-12-16 18:32:00 +00:00
package.json feat: Add ejs as a dependency in package.json and package-lock.json 2025-12-16 18:32:00 +00:00
README.md fix: remove TelemetryAttribute and TelemetryAttributeService references and related code 2025-10-15 16:26:05 +01:00
tsconfig.json refactor: update package dependencies and tsconfig settings 2025-12-16 10:50:09 +00:00

OneUptime MCP Server

A production-ready Model Context Protocol (MCP) server for OneUptime that provides dynamic tools for all OneUptime models and operations.

Features

  • Dynamic Tool Generation: Automatically generates MCP tools for all OneUptime models (Database and Analytics)
  • Full CRUD Operations: Supports Create, Read, Update, Delete, List, and Count operations
  • Production Ready: Built with proper error handling, logging, and configuration
  • Extensible: Automatically supports new models as they are added to OneUptime
  • Type Safe: Fully typed with TypeScript

Available Operations

The MCP server automatically generates tools for each OneUptime model with the following operations:

Database Models

  • oneuptime_create{ModelName} - Create a new record
  • oneuptime_get{ModelName} - Retrieve a record by ID
  • oneuptime_list{ModelName}s - List records with filtering
  • oneuptime_update{ModelName} - Update a record
  • oneuptime_delete{ModelName} - Delete a record
  • oneuptime_count{ModelName}s - Count records

Analytics Models

  • oneuptime_create{ModelName} - Create analytics data
  • oneuptime_list{ModelName}s - Query analytics data
  • oneuptime_count{ModelName}s - Count analytics records

Supported Models

The server automatically generates tools for all OneUptime models including:

Database Models: Incident, Alert, Monitor, Project, User, Team, StatusPage, and 100+ more Analytics Models: Log, Metric, Span, ExceptionInstance, MonitorLog

Configuration

Copy .env.example to .env and configure:

# OneUptime API Key (Required)
ONEUPTIME_API_KEY=your_oneuptime_api_key_here

# OneUptime Instance URL (Optional - defaults to https://oneuptime.com)
ONEUPTIME_URL=https://oneuptime.com

Installation

  1. Install dependencies:
npm install
  1. Configure environment variables:
cp .env.example .env
# Edit .env with your OneUptime configuration
  1. Build the server:
npm run build
  1. (Optional) Link for global CLI usage:
npm run link

Usage

Development

npm run dev

Production

npm start

Example Tool Usage

List Incidents

{
  "name": "oneuptime_listIncidents",
  "arguments": {
    "query": {"projectId": "your-project-id"},
    "limit": 10
  }
}

Create Alert

{
  "name": "oneuptime_createAlert", 
  "arguments": {
    "data": {
      "title": "High CPU Usage",
      "description": "CPU usage above 90%",
      "projectId": "your-project-id"
    }
  }
}

Get Monitor by ID

{
  "name": "oneuptime_getMonitor",
  "arguments": {
    "id": "monitor-id-here"
  }
}

Query Logs

{
  "name": "oneuptime_listLogs",
  "arguments": {
    "query": {
      "serviceId": "service-id",
      "severity": "error"
    },
    "limit": 50,
    "sort": {"time": -1}
  }
}

Troubleshooting

MCP Logging Compatibility

This server uses a custom MCPLogger class that ensures all log messages are directed to stderr instead of stdout. This is critical for MCP protocol compliance, as stdout is reserved for JSON-RPC messages.

Fixed Issues:

  • Failed to parse message warnings caused by log messages going to stdout
  • Dotenv initialization messages interfering with MCP protocol
  • All informational logging now properly directed to stderr

If you encounter parsing warnings, ensure no code is writing to stdout directly - use MCPLogger instead of console methods.

Architecture

  • DynamicToolGenerator: Automatically discovers and generates tools for all OneUptime models
  • OneUptimeApiService: Handles API communication with OneUptime instance
  • Type Definitions: Provides type safety and IntelliSense support
  • Error Handling: Comprehensive error handling and user-friendly messages

Development

Adding New Models

New models are automatically supported! When new models are added to OneUptime:

  1. Database models added to Common/Models/DatabaseModels/Index.ts
  2. Analytics models added to Common/Models/AnalyticsModels/Index.ts

The MCP server will automatically generate tools for them on the next restart.

Testing

npm test

Linting

npm run audit
npm run dep-check

License

Apache-2.0 - See LICENSE file for details.