getFileContents
Retrieve the contents of a specific file from an Obsidian vault stored in a private GitHub repository, enabling direct access to your knowledge base content through a provided file path.
Instructions
Retrieve the contents of a specific note, document, or file from your Obsidian vault stored in GitHub (johndoe-org/obsidian-vault). Perfect for accessing your knowledge base content.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to the file within the repository. |
Implementation Reference
- src/github/client.ts:400-438 (registration)Registration of the 'getFileContents' tool using server.tool(), including schema, hints, and the full handler implementation.server.tool( "getFileContents", `Retrieve the contents of a specific note, document, or file from your Obsidian vault stored in GitHub (${this.config.owner}/${this.config.repo}). Perfect for accessing your knowledge base content.`, { filePath: z .string() .describe("Path to the file within the repository."), }, { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true, }, async ({ filePath }) => { const fileContent = await this.handleRequest(async () => { return this.octokit.repos.getContent({ owner: this.config.owner, repo: this.config.repo, path: filePath, // Request raw content to avoid base64 decoding complexities for now mediaType: { format: "raw", }, }); }); // The raw format returns the content directly as a string if (typeof fileContent !== "string") { throw new Error( "Received unexpected content format from GitHub API." ); } return { content: [{ type: "text" as const, text: fileContent }], }; } );
- src/github/client.ts:414-437 (handler)The handler function that retrieves the raw file contents from the GitHub repository using the Octokit API and returns it as text content.async ({ filePath }) => { const fileContent = await this.handleRequest(async () => { return this.octokit.repos.getContent({ owner: this.config.owner, repo: this.config.repo, path: filePath, // Request raw content to avoid base64 decoding complexities for now mediaType: { format: "raw", }, }); }); // The raw format returns the content directly as a string if (typeof fileContent !== "string") { throw new Error( "Received unexpected content format from GitHub API." ); } return { content: [{ type: "text" as const, text: fileContent }], }; }
- src/github/client.ts:403-407 (schema)Zod schema defining the input parameter 'filePath' for the tool.{ filePath: z .string() .describe("Path to the file within the repository."), },