-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbridging_mail_mcp.py
More file actions
64 lines (51 loc) · 1.57 KB
/
bridging_mail_mcp.py
File metadata and controls
64 lines (51 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sys
import os
import subprocess
import signal
import platform
CREATE_NO_WINDOW = 0x08000000
proc = None
def handle_termination(signum, frame):
if proc and proc.poll() is None:
try:
proc.terminate()
proc.wait(timeout=1)
except:
try:
proc.kill()
except:
pass
sys.exit(0)
def main():
global proc
signal.signal(signal.SIGINT, handle_termination)
signal.signal(signal.SIGTERM, handle_termination)
try:
# Get the directory where the script is located
script_dir = os.path.dirname(os.path.abspath(__file__))
# Construct path to index.js relative to script location
index_js_path = os.path.join(script_dir, 'dist', 'index.js')
# Prepare arguments for Popen, excluding creationflags initially
popen_kwargs = {
"stdin": sys.stdin,
"stdout": sys.stdout,
"stderr": sys.stderr,
"shell": True,
"env": os.environ,
}
# Conditionally add creationflags only on Windows
if platform.system() == "Windows":
popen_kwargs["creationflags"] = CREATE_NO_WINDOW
proc = subprocess.Popen(
f"node {index_js_path}",
**popen_kwargs
)
proc.wait()
except Exception as e:
sys.stderr.write(f"Error: {str(e)}\n")
finally:
if proc and proc.poll() is None:
handle_termination(None, None)
sys.exit(proc.returncode if proc else 1)
if __name__ == "__main__":
main()