log executed commands to server stdout
exec, pty_send, and job_run each emit an INFO line so docker compose logs shows what the agent is running.
This commit is contained in:
@@ -5,6 +5,7 @@ Implements MCP Streamable HTTP transport (JSON-RPC 2.0)
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
@@ -14,6 +15,9 @@ import time
|
||||
import uuid
|
||||
from typing import Any
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
|
||||
log = logging.getLogger("mcp")
|
||||
|
||||
import pyte
|
||||
import ptyprocess
|
||||
import uvicorn
|
||||
@@ -247,6 +251,7 @@ async def _dispatch(name: str, args: dict) -> dict:
|
||||
if name == "exec":
|
||||
cmd = args.get("cmd", "")
|
||||
timeout = int(args.get("timeout", 30))
|
||||
log.info("exec: %s", cmd)
|
||||
try:
|
||||
r = subprocess.run(
|
||||
cmd, shell=True, capture_output=True, text=True,
|
||||
@@ -267,6 +272,7 @@ async def _dispatch(name: str, args: dict) -> dict:
|
||||
elif name == "pty_send":
|
||||
sess = _get_pty(args["session_id"])
|
||||
text = _decode_escapes(args.get("text", ""))
|
||||
log.info("pty_send [%s]: %r", sess.id[:8], text)
|
||||
sess.send(text)
|
||||
return {"sent": len(text)}
|
||||
|
||||
@@ -293,6 +299,7 @@ async def _dispatch(name: str, args: dict) -> dict:
|
||||
|
||||
elif name == "job_run":
|
||||
job = BackgroundJob(args.get("cmd", ""))
|
||||
log.info("job_run [%s]: %s", job.id[:8], job.cmd)
|
||||
_jobs[job.id] = job
|
||||
return {"job_id": job.id, "status": job.status}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user