feat: smeta_mcp self-contained + интеграция в claude_bridge.py (Этап 2 prep)
— smeta_mcp.py больше не зависит от claude_bridge_glm: read_xlsx_sheet, list_files реализованы локально через openpyxl и iterdir; find_in_normative fault-tolerant к отсутствию sentence_transformers/pymorphy2. Проверено в smeta-claude-sandbox image: extract_complaints_pairs внутри Docker отрабатывает корректно (231/145/339 на реальном файле). — claude_bridge.py: mount smeta_mcp.py/complaints.py/mcp_config.json в /app/, передача SMETA_USER/SMETA_TAB/SMETA_WORK_DIR в env, --mcp-config к claude args, mcp__smeta__* в allowedTools, бамп ресурсов до 2g/2cpus. — sandbox/mcp_config.json — конфиг MCP-сервера для claude CLI. — SMETA_WORK_DIR override: в Docker /data смонтирован как work_dir вкладки, и MCP идёт прямо туда без сборки пути из user/tab. Что осталось до полной интеграции (Этап 2/3): — переключить dev backend на claude/hybrid и сделать E2E — per-(user,tab) lock вместо глобального semaphore — rate limit per-user Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+33
-6
@@ -139,14 +139,26 @@ async def stream_claude(
|
||||
instructions = APP_DIR / "claude_project_instructions.md"
|
||||
|
||||
# Build claude args
|
||||
smeta_mcp_path = APP_DIR / "smeta_mcp.py"
|
||||
smeta_complaints_path = APP_DIR / "complaints.py"
|
||||
smeta_mcp_config = APP_DIR / "sandbox" / "mcp_config.json"
|
||||
mcp_available = (smeta_mcp_path.exists() and smeta_complaints_path.exists()
|
||||
and smeta_mcp_config.exists())
|
||||
|
||||
claude_args = [
|
||||
"-p", message,
|
||||
"--output-format", "stream-json",
|
||||
"--verbose",
|
||||
"--allowedTools", "Bash,Read,Write,Edit,Glob,Grep",
|
||||
"--allowedTools",
|
||||
("Bash,Read,Write,Edit,Glob,Grep,"
|
||||
"mcp__smeta__read_xlsx_sheet,"
|
||||
"mcp__smeta__list_files,"
|
||||
"mcp__smeta__extract_complaints_pairs,"
|
||||
"mcp__smeta__apply_pukts_to_registry"),
|
||||
]
|
||||
if mcp_available:
|
||||
claude_args.extend(["--mcp-config", "/app/mcp_config.json"])
|
||||
if instructions.exists():
|
||||
# Mount instructions file into container
|
||||
claude_args.extend([
|
||||
"--append-system-prompt-file", "/instructions.md"
|
||||
])
|
||||
@@ -156,9 +168,9 @@ async def stream_claude(
|
||||
# Docker command
|
||||
cmd = [
|
||||
"docker", "run", "--rm",
|
||||
# Resource limits
|
||||
"--memory=512m",
|
||||
"--cpus=1",
|
||||
# Resource limits — bumped for xlsm parsing
|
||||
"--memory=2g",
|
||||
"--cpus=2",
|
||||
"--network=host", # access xray on host
|
||||
# Mount work directory as /data
|
||||
"-v", f"{work_dir.resolve()}:/data",
|
||||
@@ -167,8 +179,13 @@ async def stream_claude(
|
||||
"-v", f"{os.path.expanduser('~')}/.claude.json:/home/worker/.claude.json",
|
||||
# Mount smeta-railway project (read-only)
|
||||
"-v", f"{SMETA_PROJECT_DIR}:/smeta:ro",
|
||||
# Mount instructions
|
||||
]
|
||||
if mcp_available:
|
||||
cmd.extend([
|
||||
"-v", f"{smeta_mcp_path.resolve()}:/app/smeta_mcp.py:ro",
|
||||
"-v", f"{smeta_complaints_path.resolve()}:/app/complaints.py:ro",
|
||||
"-v", f"{smeta_mcp_config.resolve()}:/app/mcp_config.json:ro",
|
||||
])
|
||||
if instructions.exists():
|
||||
cmd.extend(["-v", f"{instructions.resolve()}:/instructions.md:ro"])
|
||||
|
||||
@@ -177,6 +194,16 @@ async def stream_claude(
|
||||
"-e", f"HTTPS_PROXY=http://{DOCKER_HOST_GW}:{XRAY_PORT}",
|
||||
"-e", f"HTTP_PROXY=http://{DOCKER_HOST_GW}:{XRAY_PORT}",
|
||||
"-e", "HOME=/home/worker",
|
||||
])
|
||||
if mcp_available:
|
||||
# MCP видит файлы текущей вкладки прямо по /data — этот
|
||||
# путь смонтирован выше как work_dir пользователя
|
||||
cmd.extend([
|
||||
"-e", f"SMETA_USER={username}",
|
||||
"-e", f"SMETA_TAB={tab_id}",
|
||||
"-e", "SMETA_WORK_DIR=/data",
|
||||
])
|
||||
cmd.extend([
|
||||
# Working directory
|
||||
"-w", "/data",
|
||||
# Image + claude args
|
||||
|
||||
Reference in New Issue
Block a user