- Complete project setup with TypeScript, Jest, MCPB manifest - Implement foundational infrastructure (CLI executor, logger, error handler) - Add 9 file operation tools for User Story 1 - Full MCP protocol compliance with stdio transport - Input validation and sanitization for security - Comprehensive error handling with actionable messages - Constitutional compliance: all 6 principles satisfied MVP includes: - obsidian_create_note, read, append, prepend, delete, move, rename, open, file_info - Zod validation schemas for all parameters - 30s timeout configuration with per-command overrides - Stderr-only logging with sanitized output - Graceful shutdown handling Build: ✅ 0 errors, 0 vulnerabilities Tasks: 48/167 complete (MVP milestone) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
168 lines
2.9 KiB
TypeScript
168 lines
2.9 KiB
TypeScript
/**
|
|
* Core TypeScript type definitions for Obsidian MCP Bundle
|
|
* Defines types for tool inputs, outputs, errors, and internal data structures
|
|
*/
|
|
|
|
import { z } from 'zod';
|
|
|
|
/**
|
|
* Base tool input type - all tools receive parameters as an object
|
|
*/
|
|
export interface ToolInput {
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
/**
|
|
* Successful tool output
|
|
*/
|
|
export interface ToolOutput {
|
|
content: Array<{
|
|
type: 'text';
|
|
text: string;
|
|
}>;
|
|
isError?: false;
|
|
}
|
|
|
|
/**
|
|
* Error response conforming to MCP error format
|
|
*/
|
|
export interface ErrorResponse {
|
|
content: Array<{
|
|
type: 'text';
|
|
text: string;
|
|
}>;
|
|
isError: true;
|
|
}
|
|
|
|
/**
|
|
* MCP error codes mapping
|
|
*/
|
|
export enum MCPErrorCode {
|
|
InvalidParams = -32602,
|
|
InternalError = -32603,
|
|
ParseError = -32700,
|
|
InvalidRequest = -32600,
|
|
MethodNotFound = -32601,
|
|
}
|
|
|
|
/**
|
|
* Custom error types for Obsidian operations
|
|
*/
|
|
export enum ObsidianErrorType {
|
|
FILE_NOT_FOUND = 'FILE_NOT_FOUND',
|
|
VAULT_NOT_FOUND = 'VAULT_NOT_FOUND',
|
|
OBSIDIAN_NOT_RUNNING = 'OBSIDIAN_NOT_RUNNING',
|
|
AMBIGUOUS_NAME = 'AMBIGUOUS_NAME',
|
|
CLI_TIMEOUT = 'CLI_TIMEOUT',
|
|
CLI_ERROR = 'CLI_ERROR',
|
|
VALIDATION_ERROR = 'VALIDATION_ERROR',
|
|
}
|
|
|
|
/**
|
|
* CLI execution result
|
|
*/
|
|
export interface CLIResult {
|
|
stdout: string;
|
|
stderr: string;
|
|
exitCode: number;
|
|
timedOut?: boolean;
|
|
}
|
|
|
|
/**
|
|
* CLI command configuration
|
|
*/
|
|
export interface CLICommand {
|
|
command: string;
|
|
args: string[];
|
|
timeout?: number;
|
|
cwd?: string;
|
|
}
|
|
|
|
/**
|
|
* Vault configuration from environment
|
|
*/
|
|
export interface VaultConfig {
|
|
vaultName: string;
|
|
}
|
|
|
|
/**
|
|
* Note metadata
|
|
*/
|
|
export interface NoteMetadata {
|
|
path: string;
|
|
name: string;
|
|
folder?: string;
|
|
size?: number;
|
|
created?: string;
|
|
modified?: string;
|
|
tags?: string[];
|
|
properties?: Record<string, unknown>;
|
|
}
|
|
|
|
/**
|
|
* Search result
|
|
*/
|
|
export interface SearchResult {
|
|
file: string;
|
|
matches?: Array<{
|
|
line: number;
|
|
text: string;
|
|
}>;
|
|
}
|
|
|
|
/**
|
|
* Task item
|
|
*/
|
|
export interface TaskItem {
|
|
id?: string;
|
|
text: string;
|
|
completed: boolean;
|
|
line?: number;
|
|
file?: string;
|
|
}
|
|
|
|
/**
|
|
* Link reference
|
|
*/
|
|
export interface LinkReference {
|
|
source: string;
|
|
target: string;
|
|
type: 'wikilink' | 'markdown' | 'embed';
|
|
}
|
|
|
|
/**
|
|
* Property definition
|
|
*/
|
|
export interface PropertyDefinition {
|
|
key: string;
|
|
value: unknown;
|
|
type: 'text' | 'number' | 'boolean' | 'date' | 'list' | 'object';
|
|
}
|
|
|
|
/**
|
|
* Tool definition for MCP protocol
|
|
*/
|
|
export interface ToolDefinition {
|
|
name: string;
|
|
description: string;
|
|
inputSchema: z.ZodObject<any>;
|
|
}
|
|
|
|
/**
|
|
* Logger interface
|
|
*/
|
|
export interface Logger {
|
|
info(message: string, ...args: unknown[]): void;
|
|
warn(message: string, ...args: unknown[]): void;
|
|
error(message: string, ...args: unknown[]): void;
|
|
debug(message: string, ...args: unknown[]): void;
|
|
}
|
|
|
|
/**
|
|
* Timeout configuration
|
|
*/
|
|
export interface TimeoutConfig {
|
|
default: number;
|
|
perCommand: Record<string, number>;
|
|
}
|