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
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
__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
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
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
377 378 379 380 | |
new()
Executes the "new" command after the arguments have been checked to exist.
Source code in cli/mge.py
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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
pilot()
Executes the "pilot" command after the arguments have been checked to exist.
Source code in cli/mge.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
serve()
Executes the "serve" command after the arguments have been checked to exist.
Source code in cli/mge.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
summary()
Executes the "summary" command after the arguments have been checked to exist.
Source code in cli/mge.py
284 285 286 287 288 289 290 291 292 293 294 | |
unlock()
Executes the "unlock" command after the arguments have been checked to exist.
Source code in cli/mge.py
362 363 364 365 366 367 368 369 370 371 372 373 374 | |
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
34 35 36 37 | |
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
40 41 42 43 44 45 46 47 48 | |
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
58 59 60 61 62 63 64 65 66 67 | |
__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
152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
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
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
favicon()
Returns the Mercury-graph favicon.
Source code in cli/mge.py
76 77 78 79 | |
meta()
Returns the Endpoint metadata.
Source code in cli/mge.py
82 83 84 85 86 87 88 89 90 91 92 | |
root()
Redirects the root URL to the Endpoint metadata.
Source code in cli/mge.py
70 71 72 73 | |
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
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
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
142 143 144 145 146 147 148 149 | |
mge_home()
Returns the path to the mge client home directory to locate its resource files.
Source code in cli/mge.py
13 14 15 16 17 18 19 20 21 22 23 24 | |
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 |
Attributes:
| Name | Type | Description |
|---|---|---|
capabilities |
list
|
The capabilities of the remote endpoint, in the OpenAI tools format, as given by its metadata. |
last_response |
dict
|
The complete response of the last call to |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
29 30 31 32 33 34 | |
_check_arguments(fun_name, fun, args)
Checks that the arguments of a function are a dictionary with all its required arguments and no unknown ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fun_name
|
str
|
The name of the function. |
required |
fun
|
dict
|
The function, as parsed by |
required |
args
|
Any
|
The arguments to check. |
required |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
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 268 | |
_error_detail(error)
Extracts the detail that the Endpoint sends with an HTTP error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
HTTPError
|
The error. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The detail, or a sentence saying that there is none. |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
_function(name)
Returns a function, as parsed by _parse_capabilities(), or raises a RemoteEndpointError if it does not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the function. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The function. |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
_parse_capabilities()
Parse the capabilities of the remote endpoint into a dictionary of functions, used by run() and describe().
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary, keyed by capability name, with the description and the arguments of each capability. |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
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 109 110 | |
_request(path, payload=None, what=None)
Sends a request to the remote endpoint and returns its decoded JSON answer, translating failures into RemoteEndpointError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The path of the request, without the base URL (E.g., 'meta' or 'run'). |
required |
payload
|
dict
|
The JSON body of a POST request. If None, the request is a GET. |
None
|
what
|
str
|
What the request does, to start the error message (E.g., '"chat_with_reader"'). |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The decoded JSON answer. |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
_text_as_arguments(fun_name, fun, text)
Builds the arguments of a function from a single text, as run() does when easy is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fun_name
|
str
|
The name of the function. |
required |
fun
|
dict
|
The function, as parsed by |
required |
text
|
str
|
The text. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The arguments, with the text as the value of the only required argument (or of the only argument, if none is required) when that argument is a string. |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
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 197 | |
describe(name)
Describe a capability of the remote endpoint: what it does and which arguments it takes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the capability, as returned by |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary with the keys 'name', 'description' and 'arguments'. 'arguments' maps each argument name to a dictionary with its 'type', 'description' and whether it is 'required'. |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
dry_run(fun_name, args)
Perform a dry run of a function on the remote endpoint.
The arguments are not checked by the client: validating them is what the Endpoint does in a dry run.
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
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
list_capabilities()
List the names of the capabilities exposed by the remote endpoint.
Each name is unique in the Endpoint and is the first argument of run().
Returns:
| Type | Description |
|---|---|
list
|
The names of the capabilities, in the order given by the Endpoint. |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
54 55 56 57 58 59 60 61 62 63 | |
run(fun_name, args, easy=True)
Run a function on the remote endpoint.
The complete response is always stored in last_response, so the history of an agent's tool calls can be inspected after
an easy call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fun_name
|
str
|
The name of the function to run. |
required |
args
|
dict or str
|
The arguments to pass to the function. When |
required |
easy
|
bool
|
If True, simplifies argument passing and returns the result itself: the |
True
|
Returns:
| Type | Description |
|---|---|
Any
|
The result of the function when |
Raises:
| Type | Description |
|---|---|
RemoteEndpointError
|
if the function does not exist, its arguments are not valid (checked before sending them), the
Endpoint cannot be reached or answers with an HTTP error, or, when |
Source code in mercury/graph/evidence/remote/remote_endpoint.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
RemoteEndpointError
Bases: Exception
Raised when a request to a remote Endpoint cannot be made or the Endpoint answers with an error.