@awesomate/hosting-mcp 0.172.61 → 0.172.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,212 @@
1
+ #!/usr/bin/env python3
2
+ # awesomate-muse-client
3
+ """Call one Awesomate tool from Muse (or any shell) and print the answer.
4
+
5
+ Installed by the Awesomate connect as
6
+ ~/workspace/custom-connectors/custom.awesomate/bin/client.py. Python 3,
7
+ standard library only. It starts the Awesomate MCP server over stdio, makes
8
+ one call and stops the server again. The server reads the key from
9
+ ~/.awesomate/credentials.json itself: this helper never reads, prints or
10
+ passes a token.
11
+
12
+ client.py call <tool> ['<json arguments>']
13
+ client.py tools
14
+ client.py --account <slug> call <tool> ['<json arguments>']
15
+
16
+ AWESOMATE_MCP_COMMAND (a JSON array) replaces the server command, for tests.
17
+ """
18
+
19
+ import json
20
+ import os
21
+ import subprocess
22
+ import sys
23
+ import threading
24
+
25
+ SERVER = ["npx", "-y", "--package=@awesomate/hosting-mcp", "awesomate-hosting-mcp"]
26
+ TIMEOUT = float(os.environ.get("AWESOMATE_CLIENT_TIMEOUT", "300"))
27
+ PROTOCOL = "2025-06-18"
28
+
29
+ USAGE = (
30
+ "Usage: client.py [--account <slug>] call <tool> ['<json arguments>']\n"
31
+ " client.py [--account <slug>] tools"
32
+ )
33
+
34
+
35
+ def fail(message, code=1):
36
+ sys.stderr.write(message.rstrip() + "\n")
37
+ sys.exit(code)
38
+
39
+
40
+ class Server:
41
+ def __init__(self, account):
42
+ command = SERVER
43
+ override = os.environ.get("AWESOMATE_MCP_COMMAND")
44
+ if override:
45
+ command = json.loads(override)
46
+ elif os.name == "nt":
47
+ command = ["cmd", "/c"] + SERVER
48
+ env = dict(os.environ)
49
+ if account:
50
+ env["AWESOMATE_ACCOUNT"] = account
51
+ try:
52
+ self.proc = subprocess.Popen(
53
+ command,
54
+ stdin=subprocess.PIPE,
55
+ stdout=subprocess.PIPE,
56
+ stderr=subprocess.PIPE,
57
+ env=env,
58
+ )
59
+ except FileNotFoundError:
60
+ fail("Could not start the Awesomate MCP server: npx was not found. Install Node.js 18 or later.")
61
+ self.stderr = []
62
+ self.timed_out = False
63
+ self.drainer = threading.Thread(target=self._drain, daemon=True)
64
+ self.drainer.start()
65
+ self.next_id = 0
66
+
67
+ def kill(self):
68
+ # On Windows the server runs under cmd /c, and killing cmd.exe leaves node holding the pipe.
69
+ if os.name == "nt":
70
+ subprocess.run(["taskkill", "/T", "/F", "/PID", str(self.proc.pid)],
71
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
72
+ else:
73
+ self.proc.kill()
74
+
75
+ def expire(self):
76
+ self.timed_out = True
77
+ self.kill()
78
+
79
+ def _drain(self):
80
+ for line in self.proc.stderr:
81
+ self.stderr.append(line.decode("utf-8", "replace"))
82
+
83
+ def stopped(self):
84
+ # The server's last words may still be on their way through the drain thread: let it exit
85
+ # and finish reading them (briefly) before saying why it stopped.
86
+ try:
87
+ self.proc.wait(timeout=2)
88
+ except Exception:
89
+ pass
90
+ self.drainer.join(timeout=2)
91
+ tail = "".join(self.stderr[-5:]).strip()
92
+ fail("The Awesomate MCP server stopped before it answered." + (("\n" + tail) if tail else ""))
93
+
94
+ def send(self, message):
95
+ try:
96
+ self.proc.stdin.write((json.dumps(message) + "\n").encode("utf-8"))
97
+ self.proc.stdin.flush()
98
+ except (BrokenPipeError, OSError):
99
+ # The server exited (npx offline, install failed): give its own words, never a traceback.
100
+ try:
101
+ self.proc.wait(timeout=2)
102
+ except subprocess.TimeoutExpired:
103
+ pass
104
+ self.stopped()
105
+
106
+ def request(self, method, params):
107
+ self.next_id += 1
108
+ wanted = self.next_id
109
+ self.send({"jsonrpc": "2.0", "id": wanted, "method": method, "params": params})
110
+ while True:
111
+ line = self.proc.stdout.readline()
112
+ if not line:
113
+ if self.timed_out:
114
+ fail("No answer from the Awesomate MCP server within %d seconds." % TIMEOUT)
115
+ self.stopped()
116
+ try:
117
+ message = json.loads(line)
118
+ except ValueError:
119
+ continue
120
+ if "method" in message and "id" in message:
121
+ # A request from the server. Answer a ping, refuse anything else.
122
+ if message["method"] == "ping":
123
+ self.send({"jsonrpc": "2.0", "id": message["id"], "result": {}})
124
+ else:
125
+ self.send({"jsonrpc": "2.0", "id": message["id"], "error": {"code": -32601, "message": "Not supported"}})
126
+ continue
127
+ if message.get("id") != wanted:
128
+ continue
129
+ if "error" in message:
130
+ fail("The Awesomate MCP server refused the call: " + str(message["error"].get("message", message["error"])))
131
+ return message.get("result", {})
132
+
133
+ def start(self):
134
+ self.request("initialize", {
135
+ "protocolVersion": PROTOCOL,
136
+ "capabilities": {},
137
+ "clientInfo": {"name": "muse", "version": "1"},
138
+ })
139
+ self.send({"jsonrpc": "2.0", "method": "notifications/initialized"})
140
+
141
+ def stop(self):
142
+ try:
143
+ self.proc.stdin.close()
144
+ except OSError:
145
+ pass
146
+ try:
147
+ self.proc.wait(timeout=5)
148
+ except subprocess.TimeoutExpired:
149
+ self.kill()
150
+
151
+
152
+ def text_of(result):
153
+ parts = [c.get("text", "") for c in result.get("content", []) if c.get("type") == "text"]
154
+ if parts:
155
+ return "\n".join(parts)
156
+ if "structuredContent" in result:
157
+ return json.dumps(result["structuredContent"], indent=2)
158
+ return json.dumps(result, indent=2)
159
+
160
+
161
+ def main(argv):
162
+ account = None
163
+ if len(argv) >= 2 and argv[0] == "--account":
164
+ account = argv[1]
165
+ argv = argv[2:]
166
+ if not argv or argv[0] in ("-h", "--help"):
167
+ fail(USAGE, 0 if argv else 2)
168
+ command = argv[0]
169
+ if command == "call":
170
+ if len(argv) < 2:
171
+ fail(USAGE, 2)
172
+ tool = argv[1]
173
+ try:
174
+ arguments = json.loads(argv[2]) if len(argv) > 2 and argv[2].strip() else {}
175
+ except ValueError as err:
176
+ fail("The arguments are not valid JSON: " + str(err), 2)
177
+ if not isinstance(arguments, dict):
178
+ fail("The arguments must be one JSON object, like '{\"domain\": \"example.com\"}'.", 2)
179
+ elif command != "tools":
180
+ fail(USAGE, 2)
181
+
182
+ server = Server(account)
183
+ timer = threading.Timer(TIMEOUT, server.expire)
184
+ timer.daemon = True
185
+ timer.start()
186
+ try:
187
+ server.start()
188
+ if command == "tools":
189
+ cursor = None
190
+ while True:
191
+ result = server.request("tools/list", {"cursor": cursor} if cursor else {})
192
+ for t in result.get("tools", []):
193
+ first = (t.get("description") or "").strip().split("\n")[0]
194
+ print(t.get("name", "") + ": " + first[:160])
195
+ cursor = result.get("nextCursor")
196
+ if not cursor:
197
+ break
198
+ return 0
199
+ result = server.request("tools/call", {"name": tool, "arguments": arguments})
200
+ out = text_of(result)
201
+ if result.get("isError"):
202
+ sys.stderr.write(out.rstrip() + "\n")
203
+ return 1
204
+ print(out)
205
+ return 0
206
+ finally:
207
+ timer.cancel()
208
+ server.stop()
209
+
210
+
211
+ if __name__ == "__main__":
212
+ sys.exit(main(sys.argv[1:]))