added pyright and fixed type errors
This commit is contained in:
@@ -17,5 +17,10 @@ email = "markus@life-electronic.nl"
|
||||
requires = [ "hatchling",]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"pyright>=1.1.389",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
mcp-knowledge-base = "mcp_knowledge_base:main"
|
||||
|
@@ -8,12 +8,10 @@ import os
|
||||
from dotenv import load_dotenv
|
||||
from mcp.server import Server
|
||||
from mcp.types import (
|
||||
Resource,
|
||||
Tool,
|
||||
TextContent,
|
||||
ImageContent,
|
||||
EmbeddedResource,
|
||||
LoggingLevel,
|
||||
)
|
||||
|
||||
load_dotenv()
|
||||
@@ -52,16 +50,6 @@ add_tool_handler(tools.PatchContentToolHandler())
|
||||
add_tool_handler(tools.AppendContentToolHandler())
|
||||
add_tool_handler(tools.ComplexSearchToolHandler())
|
||||
|
||||
#@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]:
|
||||
"""List available tools."""
|
||||
@@ -69,7 +57,7 @@ async def list_tools() -> list[Tool]:
|
||||
return [th.get_tool_description() for th in tool_handlers.values()]
|
||||
|
||||
@app.call_tool()
|
||||
async def call_tool(name: str, arguments: Any) -> Sequence[TextContent]:
|
||||
async def call_tool(name: str, arguments: Any) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
|
||||
"""Handle tool calls for command line run."""
|
||||
|
||||
if not isinstance(arguments, dict):
|
||||
|
@@ -4,14 +4,13 @@ from mcp.types import (
|
||||
TextContent,
|
||||
ImageContent,
|
||||
EmbeddedResource,
|
||||
LoggingLevel,
|
||||
)
|
||||
import json
|
||||
import os
|
||||
from . import obsidian
|
||||
|
||||
api_key = os.getenv("OBSIDIAN_API_KEY")
|
||||
if not api_key:
|
||||
api_key = os.getenv("OBSIDIAN_API_KEY", "")
|
||||
if api_key == "":
|
||||
raise ValueError("OBSIDIAN_API_KEY environment variable required")
|
||||
|
||||
TOOL_LIST_FILES_IN_VAULT = "list_files_in_vault"
|
||||
@@ -219,7 +218,7 @@ class AppendContentToolHandler(ToolHandler):
|
||||
raise RuntimeError("filepath and content arguments required")
|
||||
|
||||
api = obsidian.Obsidian(api_key=api_key)
|
||||
api.append_content(args["filepath"], args["content"])
|
||||
api.append_content(args.get("filepath", ""), args["content"])
|
||||
|
||||
return [
|
||||
TextContent(
|
||||
@@ -274,11 +273,11 @@ class PatchContentToolHandler(ToolHandler):
|
||||
|
||||
api = obsidian.Obsidian(api_key=api_key)
|
||||
api.patch_content(
|
||||
args["filepath"],
|
||||
args["operation"],
|
||||
args["target_type"],
|
||||
args["target"],
|
||||
args["content"]
|
||||
args.get("filepath", ""),
|
||||
args.get("operation", ""),
|
||||
args.get("target_type", ""),
|
||||
args.get("target", ""),
|
||||
args.get("content", "")
|
||||
)
|
||||
|
||||
return [
|
||||
@@ -317,7 +316,7 @@ class ComplexSearchToolHandler(ToolHandler):
|
||||
raise RuntimeError("query argument missing in arguments")
|
||||
|
||||
api = obsidian.Obsidian(api_key=api_key)
|
||||
results = api.search_json(args["query"])
|
||||
results = api.search_json(args.get("query", ""))
|
||||
|
||||
return [
|
||||
TextContent(
|
||||
|
30
uv.lock
generated
30
uv.lock
generated
@@ -160,6 +160,11 @@ dependencies = [
|
||||
{ name = "requests" },
|
||||
]
|
||||
|
||||
[package.dev-dependencies]
|
||||
dev = [
|
||||
{ name = "pyright" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "mcp", specifier = ">=1.0.0" },
|
||||
@@ -167,6 +172,18 @@ requires-dist = [
|
||||
{ name = "requests", specifier = ">=2.32.3" },
|
||||
]
|
||||
|
||||
[package.metadata.requires-dev]
|
||||
dev = [{ name = "pyright", specifier = ">=1.1.389" }]
|
||||
|
||||
[[package]]
|
||||
name = "nodeenv"
|
||||
version = "1.9.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/43/16/fc88b08840de0e0a72a2f9d8c6bae36be573e475a6326ae854bcc549fc45/nodeenv-1.9.1.tar.gz", hash = "sha256:6ec12890a2dab7946721edbfbcd91f3319c6ccc9aec47be7c7e6b7011ee6645f", size = 47437 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/d2/1d/1b658dbd2b9fa9c4c9f32accbfc0205d532c8c6194dc0f2a4c0428e7128a/nodeenv-1.9.1-py2.py3-none-any.whl", hash = "sha256:ba11c9782d29c27c70ffbdda2d7415098754709be8a7056d79a737cd901155c9", size = 22314 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pydantic"
|
||||
version = "2.10.2"
|
||||
@@ -206,6 +223,19 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/df/c3/b15fb833926d91d982fde29c0624c9f225da743c7af801dace0d4e187e71/pydantic_core-2.27.1-cp313-none-win_arm64.whl", hash = "sha256:45cf8588c066860b623cd11c4ba687f8d7175d5f7ef65f7129df8a394c502de5", size = 1882983 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyright"
|
||||
version = "1.1.389"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "nodeenv" },
|
||||
{ name = "typing-extensions" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/72/4e/9a5ab8745e7606b88c2c7ca223449ac9d82a71fd5e31df47b453f2cb39a1/pyright-1.1.389.tar.gz", hash = "sha256:716bf8cc174ab8b4dcf6828c3298cac05c5ed775dda9910106a5dcfe4c7fe220", size = 21940 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/1b/26/c288cabf8cfc5a27e1aa9e5029b7682c0f920b8074f45d22bf844314d66a/pyright-1.1.389-py3-none-any.whl", hash = "sha256:41e9620bba9254406dc1f621a88ceab5a88af4c826feb4f614d95691ed243a60", size = 18581 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "python-dotenv"
|
||||
version = "1.0.1"
|
||||
|
Reference in New Issue
Block a user