diff --git a/README.md b/README.md index e10de1d..a0fc2ba 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ The server implements two tools: - List all files in my vault - List all files in the XYZ directory +- Get the contents of the last architecture call note ## Configuration diff --git a/src/mcp_knowledge_base/server.py b/src/mcp_knowledge_base/server.py index 48247a7..4d980f0 100644 --- a/src/mcp_knowledge_base/server.py +++ b/src/mcp_knowledge_base/server.py @@ -46,16 +46,17 @@ def get_tool_handler(name: str) -> tools.ToolHandler | None: add_tool_handler(tools.ListFilesInDirToolHandler()) add_tool_handler(tools.ListFilesInVaultToolHandler()) +add_tool_handler(tools.GetFileContentsToolHandler()) -@app.list_resources() -async def list_resources() -> list[Resource]: - return [ - Resource( - uri="obisidian:///note/app.log", - name="Application Logs", - mimeType="text/plain" - ) - ] +#@app.list_resources() +#async def list_resources() -> list[Resource]: +# return [ +# Resource( +# uri="obisidian:///note/app.log", +# name="Application Logs", +# mimeType="text/plain" +# ) +# ] @app.list_tools() async def list_tools() -> list[Tool]: diff --git a/src/mcp_knowledge_base/tools.py b/src/mcp_knowledge_base/tools.py index 68f032d..989a67a 100644 --- a/src/mcp_knowledge_base/tools.py +++ b/src/mcp_knowledge_base/tools.py @@ -89,4 +89,40 @@ class ListFilesInDirToolHandler(ToolHandler): type="text", text=json.dumps(files, indent=2) ) + ] + +class GetFileContentsToolHandler(ToolHandler): + def __init__(self): + super().__init__("get_file_contents") + + def get_tool_description(self): + return Tool( + name=self.name, + description="Return the content of a single file in your vault.", + inputSchema={ + "type": "object", + "properties": { + "filepath": { + "type": "string", + "description": "Path to the relevant file (relative to your vault root).", + "format": "path" + }, + }, + "required": ["filepath"] + } + ) + + def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: + if "filepath" not in args: + raise RuntimeError("filepath argument missing in arguments") + + api = obsidian.Obsidian(api_key=api_key) + + content = api.get_file_contents(args["filepath"]) + + return [ + TextContent( + type="text", + text=json.dumps(content, indent=2) + ) ] \ No newline at end of file