Initial commit: MCP server + web upload interface
Ezer Mishpati - AI legal decision drafting system with: - MCP server (FastMCP) with document processing pipeline - Web upload interface (FastAPI) for file upload and classification - pgvector-based semantic search - Hebrew legal document chunking and embedding
This commit is contained in:
177
mcp-server/src/legal_mcp/tools/cases.py
Normal file
177
mcp-server/src/legal_mcp/tools/cases.py
Normal file
@@ -0,0 +1,177 @@
|
||||
"""MCP tools for case management."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from uuid import UUID
|
||||
|
||||
from legal_mcp import config
|
||||
from legal_mcp.services import db
|
||||
|
||||
|
||||
async def case_create(
|
||||
case_number: str,
|
||||
title: str,
|
||||
appellants: list[str] | None = None,
|
||||
respondents: list[str] | None = None,
|
||||
subject: str = "",
|
||||
property_address: str = "",
|
||||
permit_number: str = "",
|
||||
committee_type: str = "ועדה מקומית",
|
||||
hearing_date: str = "",
|
||||
notes: str = "",
|
||||
) -> str:
|
||||
"""יצירת תיק ערר חדש.
|
||||
|
||||
Args:
|
||||
case_number: מספר תיק הערר (לדוגמה: 123-24)
|
||||
title: כותרת קצרה של הערר
|
||||
appellants: שמות העוררים
|
||||
respondents: שמות המשיבים
|
||||
subject: נושא הערר
|
||||
property_address: כתובת הנכס
|
||||
permit_number: מספר היתר
|
||||
committee_type: סוג הוועדה (ברירת מחדל: ועדה מקומית)
|
||||
hearing_date: תאריך דיון (YYYY-MM-DD)
|
||||
notes: הערות
|
||||
"""
|
||||
from datetime import date as date_type
|
||||
|
||||
h_date = None
|
||||
if hearing_date:
|
||||
h_date = date_type.fromisoformat(hearing_date)
|
||||
|
||||
case = await db.create_case(
|
||||
case_number=case_number,
|
||||
title=title,
|
||||
appellants=appellants,
|
||||
respondents=respondents,
|
||||
subject=subject,
|
||||
property_address=property_address,
|
||||
permit_number=permit_number,
|
||||
committee_type=committee_type,
|
||||
hearing_date=h_date,
|
||||
notes=notes,
|
||||
)
|
||||
|
||||
# Initialize git repo for the case
|
||||
case_dir = config.CASES_DIR / case_number
|
||||
case_dir.mkdir(parents=True, exist_ok=True)
|
||||
(case_dir / "documents").mkdir(exist_ok=True)
|
||||
(case_dir / "drafts").mkdir(exist_ok=True)
|
||||
|
||||
# Save case metadata
|
||||
case_json = case_dir / "case.json"
|
||||
case_json.write_text(json.dumps(case, default=str, ensure_ascii=False, indent=2))
|
||||
|
||||
# Create notes file
|
||||
notes_file = case_dir / "notes.md"
|
||||
notes_file.write_text(f"# הערות - תיק {case_number}\n\n{notes}\n")
|
||||
|
||||
# Initialize git repo
|
||||
subprocess.run(["git", "init"], cwd=case_dir, capture_output=True)
|
||||
subprocess.run(["git", "add", "."], cwd=case_dir, capture_output=True)
|
||||
subprocess.run(
|
||||
["git", "commit", "-m", f"אתחול תיק {case_number}: {title}"],
|
||||
cwd=case_dir,
|
||||
capture_output=True,
|
||||
env={"GIT_AUTHOR_NAME": "Ezer Mishpati", "GIT_AUTHOR_EMAIL": "legal@local",
|
||||
"GIT_COMMITTER_NAME": "Ezer Mishpati", "GIT_COMMITTER_EMAIL": "legal@local",
|
||||
"PATH": "/usr/bin:/bin"},
|
||||
)
|
||||
|
||||
return json.dumps(case, default=str, ensure_ascii=False, indent=2)
|
||||
|
||||
|
||||
async def case_list(status: str = "", limit: int = 50) -> str:
|
||||
"""רשימת תיקי ערר עם אפשרות סינון לפי סטטוס.
|
||||
|
||||
Args:
|
||||
status: סינון לפי סטטוס (new, in_progress, drafted, reviewed, final). ריק = הכל
|
||||
limit: מספר תוצאות מקסימלי
|
||||
"""
|
||||
cases = await db.list_cases(status=status or None, limit=limit)
|
||||
if not cases:
|
||||
return "אין תיקים."
|
||||
return json.dumps(cases, default=str, ensure_ascii=False, indent=2)
|
||||
|
||||
|
||||
async def case_get(case_number: str) -> str:
|
||||
"""קבלת פרטי תיק מלאים כולל רשימת מסמכים.
|
||||
|
||||
Args:
|
||||
case_number: מספר תיק הערר
|
||||
"""
|
||||
case = await db.get_case_by_number(case_number)
|
||||
if not case:
|
||||
return f"תיק {case_number} לא נמצא."
|
||||
|
||||
docs = await db.list_documents(UUID(case["id"]))
|
||||
case["documents"] = docs
|
||||
return json.dumps(case, default=str, ensure_ascii=False, indent=2)
|
||||
|
||||
|
||||
async def case_update(
|
||||
case_number: str,
|
||||
status: str = "",
|
||||
title: str = "",
|
||||
subject: str = "",
|
||||
notes: str = "",
|
||||
hearing_date: str = "",
|
||||
decision_date: str = "",
|
||||
tags: list[str] | None = None,
|
||||
) -> str:
|
||||
"""עדכון פרטי תיק.
|
||||
|
||||
Args:
|
||||
case_number: מספר תיק הערר
|
||||
status: סטטוס חדש (new, in_progress, drafted, reviewed, final)
|
||||
title: כותרת חדשה
|
||||
subject: נושא חדש
|
||||
notes: הערות חדשות
|
||||
hearing_date: תאריך דיון (YYYY-MM-DD)
|
||||
decision_date: תאריך החלטה (YYYY-MM-DD)
|
||||
tags: תגיות
|
||||
"""
|
||||
from datetime import date as date_type
|
||||
|
||||
case = await db.get_case_by_number(case_number)
|
||||
if not case:
|
||||
return f"תיק {case_number} לא נמצא."
|
||||
|
||||
fields = {}
|
||||
if status:
|
||||
fields["status"] = status
|
||||
if title:
|
||||
fields["title"] = title
|
||||
if subject:
|
||||
fields["subject"] = subject
|
||||
if notes:
|
||||
fields["notes"] = notes
|
||||
if hearing_date:
|
||||
fields["hearing_date"] = date_type.fromisoformat(hearing_date)
|
||||
if decision_date:
|
||||
fields["decision_date"] = date_type.fromisoformat(decision_date)
|
||||
if tags is not None:
|
||||
fields["tags"] = tags
|
||||
|
||||
updated = await db.update_case(UUID(case["id"]), **fields)
|
||||
|
||||
# Git commit the update
|
||||
case_dir = config.CASES_DIR / case_number
|
||||
if case_dir.exists():
|
||||
case_json = case_dir / "case.json"
|
||||
case_json.write_text(json.dumps(updated, default=str, ensure_ascii=False, indent=2))
|
||||
subprocess.run(["git", "add", "case.json"], cwd=case_dir, capture_output=True)
|
||||
subprocess.run(
|
||||
["git", "commit", "-m", f"עדכון תיק: {', '.join(fields.keys())}"],
|
||||
cwd=case_dir,
|
||||
capture_output=True,
|
||||
env={"GIT_AUTHOR_NAME": "Ezer Mishpati", "GIT_AUTHOR_EMAIL": "legal@local",
|
||||
"GIT_COMMITTER_NAME": "Ezer Mishpati", "GIT_COMMITTER_EMAIL": "legal@local",
|
||||
"PATH": "/usr/bin:/bin"},
|
||||
)
|
||||
|
||||
return json.dumps(updated, default=str, ensure_ascii=False, indent=2)
|
||||
Reference in New Issue
Block a user