getFileContents
Retrieve the contents of a specific file from your Obsidian vault stored in GitHub. Input the file path to access and analyze documentation or notes directly.
Instructions
Retrieve the contents of a specific note, document, or file from your Obsidian vault stored in GitHub (my-organization/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:414-437 (handler)The main execution handler for the getFileContents tool. It fetches the raw file content from the GitHub repository using Octokit.repos.getContent with raw media type and returns it as MCP 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:404-406 (schema)Zod input schema for the tool, defining the required 'filePath' parameter.filePath: z .string() .describe("Path to the file within the repository."),
- src/github/client.ts:400-438 (registration)Registration of the getFileContents tool via server.tool() call, including name, description, input schema, execution hints, and handler function.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 }], }; } );