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
12 changes: 6 additions & 6 deletions src/mcp_obsidian/obsidian.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def append_content(self, filepath: str, content: str) -> Any:
def call_fn():
response = requests.post(
url,
headers=self._get_headers() | {'Content-Type': 'text/markdown'},
data=content,
headers=self._get_headers() | {'Content-Type': 'text/markdown; charset=utf-8'},
data=content.encode('utf-8'),
verify=self.verify_ssl,
timeout=self.timeout
)
Expand All @@ -133,14 +133,14 @@ def patch_content(self, filepath: str, operation: str, target_type: str, target:
url = f"{self.get_base_url()}/vault/{filepath}"

headers = self._get_headers() | {
'Content-Type': 'text/markdown',
'Content-Type': 'text/markdown; charset=utf-8',
'Operation': operation,
'Target-Type': target_type,
'Target': urllib.parse.quote(target)
}

def call_fn():
response = requests.patch(url, headers=headers, data=content, verify=self.verify_ssl, timeout=self.timeout)
response = requests.patch(url, headers=headers, data=content.encode('utf-8'), verify=self.verify_ssl, timeout=self.timeout)
response.raise_for_status()
return None

Expand All @@ -152,8 +152,8 @@ def put_content(self, filepath: str, content: str) -> Any:
def call_fn():
response = requests.put(
url,
headers=self._get_headers() | {'Content-Type': 'text/markdown'},
data=content,
headers=self._get_headers() | {'Content-Type': 'text/markdown; charset=utf-8'},
data=content.encode('utf-8'),
verify=self.verify_ssl,
timeout=self.timeout
)
Expand Down
7 changes: 7 additions & 0 deletions src/mcp_obsidian/server.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import json
import logging
import sys
import io
from collections.abc import Sequence
from functools import lru_cache
from typing import Any
import os
from dotenv import load_dotenv

# Force UTF-8 encoding for stdout/stderr on Windows
if sys.platform == 'win32':
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
from mcp.server import Server
from mcp.types import (
Tool,
Expand Down
14 changes: 7 additions & 7 deletions src/mcp_obsidian/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | Embedded
return [
TextContent(
type="text",
text=json.dumps(files, indent=2)
text=json.dumps(files, indent=2, ensure_ascii=False)
)
]

Expand Down Expand Up @@ -87,7 +87,7 @@ def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | Embedded
return [
TextContent(
type="text",
text=json.dumps(files, indent=2)
text=json.dumps(files, indent=2, ensure_ascii=False)
)
]

Expand Down Expand Up @@ -123,7 +123,7 @@ def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | Embedded
return [
TextContent(
type="text",
text=json.dumps(content, indent=2)
text=json.dumps(content, indent=2, ensure_ascii=False)
)
]

Expand Down Expand Up @@ -185,7 +185,7 @@ def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | Embedded
return [
TextContent(
type="text",
text=json.dumps(formatted_results, indent=2)
text=json.dumps(formatted_results, indent=2, ensure_ascii=False)
)
]

Expand Down Expand Up @@ -430,7 +430,7 @@ def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | Embedded
return [
TextContent(
type="text",
text=json.dumps(results, indent=2)
text=json.dumps(results, indent=2, ensure_ascii=False)
)
]

Expand Down Expand Up @@ -580,7 +580,7 @@ def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | Embedded
return [
TextContent(
type="text",
text=json.dumps(results, indent=2)
text=json.dumps(results, indent=2, ensure_ascii=False)
)
]

Expand Down Expand Up @@ -627,6 +627,6 @@ def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | Embedded
return [
TextContent(
type="text",
text=json.dumps(results, indent=2)
text=json.dumps(results, indent=2, ensure_ascii=False)
)
]