The mge command-line interface
The mge command-line interface is the recommended way to create, inspect, pilot and serve Endpoints.
Although every component of the mercury.graph.evidence module can be used directly from Python, most users will interact with Endpoints
through the mge command. It automates the complete Endpoint lifecycle, from creating a new project to exposing it as a REST service.
Typical workflow
The most common workflow consists of the following steps:
mge new demo
# Edit the Endpoint configuration
mge pilot demo ALL_READY
mge summary demo
mge serve demo ALL_READY 8000
where:
newcreates a new Endpoint project.pilotloads the Endpoint and drives it to the desired operational state.summarydisplays the current Endpoint configuration and state.serveexposes the Endpoint through its REST API.
Command reference
The following output is produced directly by running:
mge --help
This is the authoritative description of the command-line interface. Whenever the CLI changes, this output should be considered the reference.
usage: Mercury-graph Evidence: Endpoint management cli 3.3.1 [-h] [--just_once] [--log_file LOG_FILE] [--version]
{new,summary,pilot,serve,unlock,complete} name [intent] [port]
Creates, displays, serves and pilots persisted Endpoint objects.
positional arguments:
{new,summary,pilot,serve,unlock,complete}
📁 new [name]: Creates the scaffold of a new Endpoint object with all the necessary files.
📊 summary [path]: Displays a summary of the state of an Endpoint.
🌀 pilot [path, intent]: Loads the Endpoint and pilots it to an intended state running the necessary
queries to reach that state.
🌎 serve [path, intent, port]: Loads the Endpoint, verifies the intent and serves it via http on the given
port. It exposes its Agentic .meta property and the .run method.
🔑 unlock [path]: Forces removing the lock of the Endpoint. Use with caution!
✨ complete bash: Prints the Bash tab-completion command.
Use: source <(mge complete bash)
name name of new Endpoint (for new) or path to an existing Endpoint (all other commands).
intent desired final state (for pilot) or required state (for serve)
port port to serve the Endpoint (only for serve)
options:
-h, --help show this help message and exit
--just_once stop at first run instead of until intent is reached (only for pilot)
--log_file LOG_FILE path of the Agentic event log file (only for pilot and serve)
--version show program's version number and exit
Python implementation
cli.mge
MgeCli(args)
The MgeCli class is a command line interface for managing Mercury-graph Evidence Endpoint objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
dict
|
The command line arguments as parsed by argparse. |
required |
Source code in cli/mge.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
__exec(cmd)
Executes a command and captures the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
The command to execute. |
required |
Returns:
| Type | Description |
|---|---|
list
|
The output of the command as a list of strings. |
Source code in cli/mge.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
complete()
Executes the "complete". The argument self.name is ignored. Should be "bash" because it is a mandatory argument.
Source code in cli/mge.py
363 364 365 366 | |
new()
Executes the "new" command after the arguments have been checked to exist.
Source code in cli/mge.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
pilot()
Executes the "pilot" command after the arguments have been checked to exist.
Source code in cli/mge.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
serve()
Executes the "serve" command after the arguments have been checked to exist.
Source code in cli/mge.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
summary()
Executes the "summary" command after the arguments have been checked to exist.
Source code in cli/mge.py
270 271 272 273 274 275 276 277 278 279 280 | |
unlock()
Executes the "unlock" command after the arguments have been checked to exist.
Source code in cli/mge.py
348 349 350 351 352 353 354 355 356 357 358 359 360 | |
MgeFileLogger(path)
A minimal append-only file logger for Agentic events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The path to the log file. |
required |
Source code in cli/mge.py
20 21 22 23 | |
append(event)
Appends an Agentic event dictionary to the log file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
dict
|
The Agentic event to log. |
required |
Source code in cli/mge.py
26 27 28 29 30 31 32 33 34 | |
MgeHttpServe(ep)
The MgeHttpServe class exposes an Endpoint Agentic API over HTTP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ep
|
Endpoint
|
The Endpoint to expose. |
required |
Source code in cli/mge.py
44 45 46 47 48 49 50 51 52 53 | |
__validated_request(request)
Checks that a request body is a JSON object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
dict
|
The JSON request body. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The validated request body. |
Source code in cli/mge.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
dry_run(request=Body(...))
Simulates running a request against the Endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
dict
|
The JSON request body. |
Body(...)
|
Source code in cli/mge.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
favicon()
Returns the Mercury-graph favicon.
Source code in cli/mge.py
62 63 64 65 | |
meta()
Returns the Endpoint metadata.
Source code in cli/mge.py
68 69 70 71 72 73 74 75 76 77 78 | |
root()
Redirects the root URL to the Endpoint metadata.
Source code in cli/mge.py
56 57 58 59 | |
run(request=Body(...))
Runs a request against the Endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
dict
|
The JSON request body. |
Body(...)
|
Source code in cli/mge.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
serve(port)
Starts the HTTP server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int
|
The TCP port to listen on. |
required |
Source code in cli/mge.py
128 129 130 131 132 133 134 135 | |
A minimalistic Remote Endpoint CLI example
mercury.graph.evidence.remote.remote_endpoint
RemoteEndpoint(base_url)
This is a utility class for interacting with an Endpoint that is served using the mge CLI.
It only provides a subset of the functionality and is intended for quick testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The URL of the endpoint as shown by the CLI (E.g., Uvicorn running on http://0.0.0.0:8765 (Press CTRL+C to quit)) |
required |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
15 16 17 18 19 | |
dry_run(fun_name, args)
Perform a dry run of a function on the remote endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fun_name
|
str
|
The name of the function to dry run. |
required |
args
|
dict
|
The arguments to pass to the function. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The result of the dry run. |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
get_capabilities()
Fetch the capabilities of the remote endpoint.
Returns:
| Type | Description |
|---|---|
list
|
A list of capabilities exposed by the remote endpoint. |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
get_functions()
Fetch the functions exposed by the remote endpoint.
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary of functions with their descriptions and arguments. |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
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 65 66 | |
run(fun_name, args, easy=True)
Run a function on the remote endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fun_name
|
str
|
The name of the function to run. |
required |
args
|
dict
|
The arguments to pass to the function. |
required |
easy
|
bool
|
If True, attempts to simplify argument passing and result handling. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
Any
|
The result of the function execution, potentially simplified if |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |