added call to get the content of a file
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -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]:
|
||||
|
@@ -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)
|
||||
)
|
||||
]
|
Reference in New Issue
Block a user