Skip to main content
Glama

Obsidian MCP Server

Apache 2.0
338
222
  • Apple
  • Linux
obsidianApiUtils.ts1.31 kB
/** * @module ObsidianApiUtils * @description * Internal utilities for the Obsidian REST API service. */ /** * Encodes a vault-relative file path correctly for API URLs. * Ensures path separators '/' are not encoded, but individual components are. * Handles leading slashes correctly. * * @param filePath - The raw vault-relative file path (e.g., "/Notes/My File.md" or "Notes/My File.md"). * @returns The URL-encoded path suitable for appending to `/vault`. */ export function encodeVaultPath(filePath: string): string { // 1. Trim whitespace and remove any leading/trailing slashes for consistent processing. const trimmedPath = filePath.trim().replace(/^\/+|\/+$/g, ""); // 2. If the original path was just '/' or empty, return an empty string (represents root for files). if (trimmedPath === "") { // For file operations, the API expects /vault/filename.md at the root, // so an empty encoded path segment is correct here. // For listFiles, we handle the root case separately. return ""; } // 3. Split into components, encode each component, then rejoin with literal '/'. const encodedComponents = trimmedPath.split("/").map(encodeURIComponent); const encodedPath = encodedComponents.join("/"); // 4. Prepend the leading slash. return `/${encodedPath}`; }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cyanheads/obsidian-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server