obsidian-mcp-server
Version:
Obsidian Knowledge-Management MCP (Model Context Protocol) server that enables AI agents and development tools to interact with an Obsidian vault. It provides a comprehensive suite of tools for reading, writing, searching, and managing notes, tags, and fr
72 lines (71 loc) • 3.47 kB
JavaScript
import { z } from "zod";
/**
* Defines a set of standardized error codes for common issues within MCP servers or tools.
* These codes help clients understand the nature of an error programmatically.
*/
export var BaseErrorCode;
(function (BaseErrorCode) {
/** Access denied due to invalid credentials or lack of authentication. */
BaseErrorCode["UNAUTHORIZED"] = "UNAUTHORIZED";
/** Access denied despite valid authentication, due to insufficient permissions. */
BaseErrorCode["FORBIDDEN"] = "FORBIDDEN";
/** The requested resource or entity could not be found. */
BaseErrorCode["NOT_FOUND"] = "NOT_FOUND";
/** The request could not be completed due to a conflict with the current state of the resource. */
BaseErrorCode["CONFLICT"] = "CONFLICT";
/** The request failed due to invalid input parameters or data. */
BaseErrorCode["VALIDATION_ERROR"] = "VALIDATION_ERROR";
/** An error occurred while parsing input data (e.g., date string, JSON). */
BaseErrorCode["PARSING_ERROR"] = "PARSING_ERROR";
/** The request was rejected because the client has exceeded rate limits. */
BaseErrorCode["RATE_LIMITED"] = "RATE_LIMITED";
/** The request timed out before a response could be generated. */
BaseErrorCode["TIMEOUT"] = "TIMEOUT";
/** The service is temporarily unavailable, possibly due to maintenance or overload. */
BaseErrorCode["SERVICE_UNAVAILABLE"] = "SERVICE_UNAVAILABLE";
/** An unexpected error occurred on the server side. */
BaseErrorCode["INTERNAL_ERROR"] = "INTERNAL_ERROR";
/** An error occurred, but the specific cause is unknown or cannot be categorized. */
BaseErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
/** An error occurred during the loading or validation of configuration data. */
BaseErrorCode["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
})(BaseErrorCode || (BaseErrorCode = {}));
/**
* Custom error class for MCP-specific errors.
* Encapsulates a `BaseErrorCode`, a descriptive message, and optional details.
* Provides a method to format the error into a standard MCP tool response.
*/
export class McpError extends Error {
/**
* Creates an instance of McpError.
* @param {BaseErrorCode} code - The standardized error code.
* @param {string} message - A human-readable description of the error.
* @param {Record<string, unknown>} [details] - Optional additional details about the error.
*/
constructor(code, message, details) {
super(message);
this.code = code;
this.details = details;
// Set the error name for identification
this.name = "McpError";
// Ensure the prototype chain is correct
Object.setPrototypeOf(this, McpError.prototype);
}
}
/**
* Zod schema for validating error objects, potentially used for parsing
* error responses or validating error structures internally.
*/
export const ErrorSchema = z
.object({
/** The error code, corresponding to BaseErrorCode enum values. */
code: z.nativeEnum(BaseErrorCode).describe("Standardized error code"),
/** A human-readable description of the error. */
message: z.string().describe("Detailed error message"),
/** Optional additional details or context about the error. */
details: z
.record(z.unknown())
.optional()
.describe("Optional structured error details"),
})
.describe("Schema for validating structured error objects.");