Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "MCP server to work with Obsidian via the remote REST plugin"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"mcp>=1.1.0",
"mcp>=1.8.0",
"python-dotenv>=1.0.1",
"requests>=2.32.3",
]
Expand Down
83 changes: 68 additions & 15 deletions src/mcp_obsidian/tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import Sequence
from mcp.types import (
Tool,
ToolAnnotations,
TextContent,
ImageContent,
EmbeddedResource,
Expand Down Expand Up @@ -41,6 +42,10 @@ def get_tool_description(self):
"properties": {},
"required": []
},
annotations=ToolAnnotations(
title="List Files in Vault",
readOnlyHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand Down Expand Up @@ -72,7 +77,11 @@ def get_tool_description(self):
},
},
"required": ["dirpath"]
}
},
annotations=ToolAnnotations(
title="List Files in Directory",
readOnlyHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand Down Expand Up @@ -109,7 +118,11 @@ def get_tool_description(self):
},
},
"required": ["filepath"]
}
},
annotations=ToolAnnotations(
title="Get File Contents",
readOnlyHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand All @@ -134,7 +147,7 @@ def __init__(self):
def get_tool_description(self):
return Tool(
name=self.name,
description="""Simple search for documents matching a specified text query across all files in the vault.
description="""Simple search for documents matching a specified text query across all files in the vault.
Use this tool when you want to do a simple text search""",
inputSchema={
"type": "object",
Expand All @@ -150,7 +163,11 @@ def get_tool_description(self):
}
},
"required": ["query"]
}
},
annotations=ToolAnnotations(
title="Simple Search",
readOnlyHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand Down Expand Up @@ -211,7 +228,11 @@ def get_tool_description(self):
}
},
"required": ["filepath", "content"]
}
},
annotations=ToolAnnotations(
title="Append Content",
destructiveHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand Down Expand Up @@ -255,7 +276,7 @@ def get_tool_description(self):
"enum": ["heading", "block", "frontmatter"]
},
"target": {
"type": "string",
"type": "string",
"description": "Target identifier (heading path, block reference, or frontmatter field)"
},
"content": {
Expand All @@ -264,7 +285,11 @@ def get_tool_description(self):
}
},
"required": ["filepath", "operation", "target_type", "target", "content"]
}
},
annotations=ToolAnnotations(
title="Patch Content",
destructiveHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand Down Expand Up @@ -309,7 +334,11 @@ def get_tool_description(self):
}
},
"required": ["filepath", "content"]
}
},
annotations=ToolAnnotations(
title="Put Content",
destructiveHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand Down Expand Up @@ -350,7 +379,11 @@ def get_tool_description(self):
}
},
"required": ["filepath", "confirm"]
}
},
annotations=ToolAnnotations(
title="Delete File",
destructiveHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand All @@ -377,7 +410,7 @@ def __init__(self):
def get_tool_description(self):
return Tool(
name=self.name,
description="""Complex search for documents using a JsonLogic query.
description="""Complex search for documents using a JsonLogic query.
Supports standard JsonLogic operators plus 'glob' and 'regexp' for pattern matching. Results must be non-falsy.

Use this tool when you want to do a complex search, e.g. for all documents with certain tags etc.
Expand Down Expand Up @@ -417,7 +450,11 @@ def get_tool_description(self):
}
},
"required": ["query"]
}
},
annotations=ToolAnnotations(
title="Complex Search",
readOnlyHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand Down Expand Up @@ -456,7 +493,11 @@ def get_tool_description(self):
},
},
"required": ["filepaths"]
}
},
annotations=ToolAnnotations(
title="Batch Get File Contents",
readOnlyHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand Down Expand Up @@ -497,7 +538,11 @@ def get_tool_description(self):
}
},
"required": ["period"]
}
},
annotations=ToolAnnotations(
title="Get Periodic Note",
readOnlyHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand Down Expand Up @@ -554,7 +599,11 @@ def get_tool_description(self):
}
},
"required": ["period"]
}
},
annotations=ToolAnnotations(
title="Get Recent Periodic Notes",
readOnlyHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand Down Expand Up @@ -609,7 +658,11 @@ def get_tool_description(self):
"default": 90
}
}
}
},
annotations=ToolAnnotations(
title="Get Recent Changes",
readOnlyHint=True,
),
)

def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
Expand Down
Loading