|
1 | 1 | from AgentCrew.modules import logger |
2 | | -from typing import Dict, Any, List, Optional, Callable, TextIO, AnyStr |
| 2 | +from typing import Dict, Any, List, Optional, Callable |
3 | 3 | from mcp import ClientSession, StdioServerParameters |
4 | 4 | from mcp.types import Prompt, ContentBlock, TextContent, ImageContent |
5 | 5 | from mcp.client.stdio import stdio_client |
|
8 | 8 | from .config import MCPServerConfig |
9 | 9 | import asyncio |
10 | 10 | import threading |
11 | | -import tempfile |
12 | | -from datetime import datetime |
13 | | - |
14 | | - |
15 | | -class MCPLogIO(TextIO): |
16 | | - """File-like object compatible with sys.stderr for MCP logging.""" |
17 | | - |
18 | | - def __init__(self): |
19 | | - self.log_path = ( |
20 | | - tempfile.gettempdir() + f"/mcp_agentcrew_{datetime.now().timestamp()}.log" |
21 | | - ) |
22 | | - print(f"Routing MCP logs to {self.log_path}") |
23 | | - self.file = open(self.log_path, "w+") |
24 | | - |
25 | | - def write(self, data: AnyStr) -> int: |
26 | | - """Write data to the log file.""" |
27 | | - if isinstance(data, bytes): |
28 | | - # Convert bytes to string for writing |
29 | | - str_data = data.decode("utf-8", errors="replace") |
30 | | - else: |
31 | | - str_data = str(data) |
32 | | - self.file.write(str_data) |
33 | | - self.file.flush() # Ensure data is written immediately |
34 | | - return 0 |
35 | | - |
36 | | - def flush(self): |
37 | | - """Flush the file buffer.""" |
38 | | - self.file.flush() |
39 | | - |
40 | | - def close(self): |
41 | | - """Close the file.""" |
42 | | - self.file.close() |
43 | | - |
44 | | - def fileno(self): |
45 | | - """Return the file descriptor.""" |
46 | | - return self.file.fileno() |
47 | | - |
| 11 | +from AgentCrew.modules import FileLogIO |
48 | 12 |
|
49 | 13 | # Initialize the logger |
50 | | -mcp_log_io = MCPLogIO() |
| 14 | +mcp_log_io = FileLogIO("mcpclient_agentcrew") |
51 | 15 |
|
52 | 16 |
|
53 | 17 | class MCPService: |
|
0 commit comments