Skip to main content
Glama

MCP Tools for Obsidian

index.ts2.01 kB
import { formatMcpError, makeRequest, parseTemplateParameters, type ToolRegistry, } from "$/shared"; import { type } from "arktype"; import { buildTemplateArgumentsSchema, LocalRestAPI } from "shared"; export function registerTemplaterTools(tools: ToolRegistry) { tools.register( type({ name: '"execute_template"', arguments: LocalRestAPI.ApiTemplateExecutionParams.omit("createFile").and( { // should be boolean but the MCP client returns a string "createFile?": type("'true'|'false'"), }, ), }).describe("Execute a Templater template with the given arguments"), async ({ arguments: args }) => { // Get prompt content const data = await makeRequest( LocalRestAPI.ApiVaultFileResponse, `/vault/${args.name}`, { headers: { Accept: LocalRestAPI.MIME_TYPE_OLRAPI_NOTE_JSON }, }, ); // Validate prompt arguments const templateParameters = parseTemplateParameters(data.content); const validArgs = buildTemplateArgumentsSchema(templateParameters)( args.arguments, ); if (validArgs instanceof type.errors) { throw formatMcpError(validArgs); } const templateExecutionArgs: { name: string; arguments: Record<string, string>; createFile: boolean; targetPath?: string; } = { name: args.name, arguments: validArgs, createFile: args.createFile === "true", targetPath: args.targetPath, }; // Process template through Templater plugin const response = await makeRequest( LocalRestAPI.ApiTemplateExecutionResponse, "/templates/execute", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(templateExecutionArgs), }, ); return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }], }; }, ); }

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/jacksteamdev/obsidian-mcp-tools'

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