Session¶
petrophys.mcp.Session
- class Session(
- roots=<factory>,
- wells=<factory>,
- sources=<factory>,
- interpretations=<factory>,
- results=<factory>,
Wells and interpretation results held by one MCP server process.
- Parameters:
roots (iterable of path, optional) – Folders whose files may be read and written. Defaults to the folders in
PETROPHYS_MCP_ROOTSor, when that is unset, the current working directory. Bundled sample data is always readable.wells (dict, optional) – Loaded wells by well id; empty by default and filled by
add_well().sources (dict, optional) – The source each loaded well was read from, by well id; filled by
add_well().interpretations (dict, optional) – Interpretation id to
(well id, result); empty by default and filled byadd_interpretation().results (dict, optional) – Result id to
(target id, value, function name): whatcall_functionreturned; empty by default and filled byadd_result().
Notes
Paths shown to the client are relative to the allowed folders; the server’s absolute paths never appear in responses or error messages. With several folders, a path is shown as
<folder name>/<relative path>, and such paths are accepted back.Attributes
Interpretation id -> (well id, result).
Result id (
fn-1,fn-2, ...) -> (target id or None, value, function name), frompetrophys.mcp.functions.Short labels of
roots(their folder names), used in messages.Methods
Store an interpretation or workflow run of
well_idand return its id.Store what a library function returned and return its id (
fn-<n>).Store
wellunder a new (or the requested) id and return the id.The allowed folders, by label (never their absolute paths).
Show
pathrelative to its allowed folder, without the server's absolute path.Return the interpretation or workflow run stored under
interpretation_id.Whether
pathlies inside an allowed folder (or, when reading, the samples).Replace the server's absolute folder paths in
textwith their labels.Return
pathas an absolute path inside an allowed root.Return the value stored under
result_id.Return the interpreted well for an interpretation id, else the loaded well.
Return the loaded well stored under
well_id.- roots: List[Path]¶
- interpretations: Dict[str, Tuple[str, Any]]¶
Interpretation id -> (well id, result). The result is a
DynamicWorkflowResult(interpret_well) or aWorkflowRunResult(run_workflow).
- results: Dict[str, Tuple[str | None, Any, str]]¶
Result id (
fn-1,fn-2, …) -> (target id or None, value, function name), frompetrophys.mcp.functions.
- resolve_path(path, *, must_exist=True)[source]¶
Return
pathas an absolute path inside an allowed root.Relative paths are taken from the first root (when reading, from the first root that holds the file). With several roots, a relative path may start with a root’s label, as
display_path()writes it.
- is_allowed(path, *, reading=True)[source]¶
Whether
pathlies inside an allowed folder (or, when reading, the samples).
- display_path(path)[source]¶
Show
pathrelative to its allowed folder, without the server’s absolute path.
- add_well(well, source, well_id=None)[source]¶
Store
wellunder a new (or the requested) id and return the id.
- well(well_id)[source]¶
Return the loaded well stored under
well_id.- Raises:
SessionError – If no well has that id; the message lists the loaded wells.
- Parameters:
well_id (str)
- Return type:
- add_interpretation(well_id, result)[source]¶
Store an interpretation or workflow run of
well_idand return its id.
- interpretation(interpretation_id)[source]¶
Return the interpretation or workflow run stored under
interpretation_id.- Raises:
SessionError – If no interpretation has that id; when the id is a well’s, the message says to interpret that well first.
- Parameters:
interpretation_id (str)
- Return type:
- add_result(target_id, value, function)[source]¶
Store what a library function returned and return its id (
fn-<n>).
- result(result_id)[source]¶
Return the value stored under
result_id.- Raises:
SessionError – If no result has that id; the message lists the known ids.
- Parameters:
result_id (str)
- Return type: