Session

petrophys.mcp.Session

class Session(
roots=<factory>,
wells=<factory>,
sources=<factory>,
interpretations=<factory>,
results=<factory>,
)[source]

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_ROOTS or, 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 by add_interpretation().

  • results (dict, optional) – Result id to (target id, value, function name): what call_function returned; empty by default and filled by add_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

roots

wells

sources

interpretations

Interpretation id -> (well id, result).

results

Result id (fn-1, fn-2, ...) -> (target id or None, value, function name), from petrophys.mcp.functions.

root_labels

Short labels of roots (their folder names), used in messages.

Methods

add_interpretation

Store an interpretation or workflow run of well_id and return its id.

add_result

Store what a library function returned and return its id (fn-<n>).

add_well

Store well under a new (or the requested) id and return the id.

describe_roots

The allowed folders, by label (never their absolute paths).

display_path

Show path relative to its allowed folder, without the server's absolute path.

interpretation

Return the interpretation or workflow run stored under interpretation_id.

is_allowed

Whether path lies inside an allowed folder (or, when reading, the samples).

redact

Replace the server's absolute folder paths in text with their labels.

resolve_path

Return path as an absolute path inside an allowed root.

result

Return the value stored under result_id.

target_well

Return the interpreted well for an interpretation id, else the loaded well.

well

Return the loaded well stored under well_id.

roots: List[Path]
wells: Dict[str, 'Well']
sources: Dict[str, str]
interpretations: Dict[str, Tuple[str, Any]]

Interpretation id -> (well id, result). The result is a DynamicWorkflowResult (interpret_well) or a WorkflowRunResult (run_workflow).

results: Dict[str, Tuple[str | None, Any, str]]

Result id (fn-1, fn-2, …) -> (target id or None, value, function name), from petrophys.mcp.functions.

root_labels: List[str]

Short labels of roots (their folder names), used in messages.

resolve_path(path, *, must_exist=True)[source]

Return path as 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.

Parameters:
Return type:

Path

is_allowed(path, *, reading=True)[source]

Whether path lies inside an allowed folder (or, when reading, the samples).

Parameters:
Return type:

bool

describe_roots()[source]

The allowed folders, by label (never their absolute paths).

Return type:

str

display_path(path)[source]

Show path relative to its allowed folder, without the server’s absolute path.

Parameters:

path (Any)

Return type:

str

redact(text)[source]

Replace the server’s absolute folder paths in text with their labels.

Parameters:

text (str)

Return type:

str

add_well(well, source, well_id=None)[source]

Store well under a new (or the requested) id and return the id.

Parameters:
  • well (Well)

  • source (str)

  • well_id (Optional[str])

Return type:

str

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:

Well

add_interpretation(well_id, result)[source]

Store an interpretation or workflow run of well_id and return its id.

Parameters:
Return type:

str

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:

Any

add_result(target_id, value, function)[source]

Store what a library function returned and return its id (fn-<n>).

Parameters:
  • target_id (str | None)

  • value (Any)

  • function (str)

Return type:

str

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:

Any

target_well(target_id)[source]

Return the interpreted well for an interpretation id, else the loaded well.

Parameters:

target_id (str)

Return type:

Well