mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-23 20:23:00 +00:00
Async read/write
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from typing import Any, Optional, Annotated
|
||||
from pathlib import Path
|
||||
|
||||
from hanzo_async import read_lines
|
||||
from pydantic import Field
|
||||
from mcp.server import FastMCP
|
||||
from mcp.server.fastmcp import Context as MCPContext
|
||||
@@ -58,8 +59,7 @@ Returns:
|
||||
return f"Error: Not a file: {file_path}"
|
||||
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8", errors="replace") as f:
|
||||
lines = f.readlines()
|
||||
lines = await read_lines(path, encoding="utf-8", errors="replace")
|
||||
|
||||
# Apply offset and limit
|
||||
total_lines = len(lines)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from typing import Optional, Annotated
|
||||
from pathlib import Path
|
||||
|
||||
from hanzo_async import write_file, mkdir
|
||||
from pydantic import Field
|
||||
from mcp.server import FastMCP
|
||||
from mcp.server.fastmcp import Context as MCPContext
|
||||
@@ -50,11 +51,10 @@ Returns:
|
||||
|
||||
try:
|
||||
# Create parent directories if needed
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
await mkdir(path.parent, parents=True, exist_ok=True)
|
||||
|
||||
# Write content
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
await write_file(path, content, encoding="utf-8")
|
||||
|
||||
return f"Successfully wrote {len(content)} bytes to {file_path}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user