ntfy-mcp-server
Version:
An MCP (Model Context Protocol) server designed to interact with the ntfy push notification service. It enables LLMs and AI agents to send notifications to your devices with extensive customization options.
40 lines (39 loc) • 1.14 kB
JavaScript
import { z } from "zod";
// Base error codes that all tools can use
export const BaseErrorCode = {
UNAUTHORIZED: 'UNAUTHORIZED',
FORBIDDEN: 'FORBIDDEN',
NOT_FOUND: 'NOT_FOUND',
CONFLICT: 'CONFLICT',
VALIDATION_ERROR: 'VALIDATION_ERROR',
RATE_LIMITED: 'RATE_LIMITED',
TIMEOUT: 'TIMEOUT',
SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
INTERNAL_ERROR: 'INTERNAL_ERROR',
UNKNOWN_ERROR: 'UNKNOWN_ERROR'
};
// Base MCP error class
export class McpError extends Error {
constructor(code, message, details) {
super(message);
this.code = code;
this.details = details;
this.name = 'McpError';
}
toResponse() {
const content = {
type: "text",
text: `Error [${this.code}]: ${this.message}${this.details ? `\nDetails: ${JSON.stringify(this.details, null, 2)}` : ''}`
};
return {
content: [content],
isError: true
};
}
}
// Error schema for validation
export const ErrorSchema = z.object({
code: z.string(),
message: z.string(),
details: z.record(z.unknown()).optional()
});