You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If `job_id` is provided, stops and removes that session if it exists; otherwise stops and removes all sessions. When `quiet` is True, informational logging about stopped sessions is suppressed.
101
+
102
+
Parameters:
103
+
job_id (Optional[str]): Identifier of the session to stop. If omitted, all sessions are stopped.
104
+
quiet (bool): If True, do not emit informational logs about stopped sessions.
105
+
106
+
Returns:
107
+
result (Dict[str, Any]): A dictionary with a "stopped" key listing stopped job IDs. If a specific
108
+
`job_id` was requested but not found, the dictionary also includes a "message" explaining that.
Dispatches a JSON-RPC-like request payload to the corresponding KeepGPUServer method and returns a JSON-RPC response object.
165
+
166
+
Parameters:
167
+
server (KeepGPUServer): The server instance whose methods will be invoked.
168
+
payload (dict): The incoming request object; expected keys:
169
+
- "method" (str): RPC method name ("start_keep", "stop_keep", "status", "list_gpus").
170
+
- "params" (dict, optional): Keyword arguments for the method.
171
+
- "id" (any, optional): Caller-provided request identifier preserved in the response.
172
+
173
+
Returns:
174
+
dict: A JSON-RPC-style response containing:
175
+
- "id": the original request id (or None if not provided).
176
+
- "result": the method's return value on success.
177
+
- OR "error": an object with a "message" string describing the failure.
178
+
"""
129
179
method=payload.get("method")
130
180
params=payload.get("params", {}) or {}
131
181
req_id=payload.get("id")
@@ -150,6 +200,11 @@ class _JSONRPCHandler(BaseHTTPRequestHandler):
150
200
server_version="KeepGPU-MCP/0.1"
151
201
152
202
defdo_POST(self): # noqa: N802
203
+
"""
204
+
Handle HTTP POST requests containing a JSON-RPC payload and send a JSON response.
205
+
206
+
Reads the request body using the Content-Length header, parses it as JSON, dispatches the payload to the internal JSON-RPC dispatcher, and writes the dispatcher result as an application/json response. If the request body cannot be decoded or parsed, responds with HTTP 400 and a JSON error object describing the parsing error.
Start a lightweight HTTP JSON-RPC server that exposes the given KeepGPUServer on the specified host and port.
263
+
264
+
Starts a TCP HTTP server serving _JSONRPCHandler in a background thread, logs the listening address, waits for the thread to finish, and on interruption or shutdown performs a clean shutdown of the HTTP server and calls server.shutdown() to release resources.
265
+
266
+
Parameters:
267
+
server (KeepGPUServer): The KeepGPUServer instance whose RPC methods will be exposed over HTTP.
268
+
host (str): Host address to bind the HTTP server to.
Run the HTTP server's request loop until the server is shut down.
280
+
281
+
Blocks the current thread and processes incoming HTTP requests for the
282
+
server instance until the server is stopped.
283
+
"""
195
284
httpd.serve_forever()
196
285
197
286
thread=threading.Thread(target=_serve)
@@ -210,6 +299,11 @@ def _serve():
210
299
211
300
212
301
defmain() ->None:
302
+
"""
303
+
Entry point for the KeepGPU MCP server that parses command-line arguments and starts the chosen transport.
304
+
305
+
Parses --mode (stdio or http), --host and --port (for http mode), instantiates a KeepGPUServer, and runs either the stdio loop or the HTTP server based on the selected mode.
0 commit comments