mcp_server.tools

mcp_server.tools is a deprecated import path for the functions below. Use memdiver.app.tools or the public memdiver.services interface in new code.

Scan datasets, run analysis, and import dumps for a tool session.

scan_dataset(session, root, keylog_filename='keylog.csv', protocols=None)[source]

Scan a dataset directory for protocols, libraries, and lifecycle phases.

The result includes the number of runs with a packet capture and the capture counts by version, scenario, and library. Raise FileNotFoundServiceError if the root is missing.

Parameters:
  • session (ToolSession)

  • root (str)

  • keylog_filename (str)

  • protocols (List[str] | None)

Return type:

dict

list_phases(session, library_dir)[source]

List available lifecycle phases for a library directory.

Parameters:
  • session (ToolSession)

  • library_dir (str)

Return type:

dict

list_protocols(session)[source]

List all registered protocol descriptors.

Parameters:

session (ToolSession)

Return type:

dict

set_region_filter(session, region_filter=None)[source]

Set (or clear) the session’s analysis-time region view filter.

region_filter is a category list ("heap,stack"), a persisted note ("regions=...") or "all"/None/"", which clear it. Tools that take region_filter fall back to this value when the caller omits theirs. Returns the normalised to_note() form. An unknown category name raises an INVALID_INPUT CapabilityError and leaves the filter unchanged.

Parameters:
  • session (ToolSession)

  • region_filter (str | None)

Return type:

dict

get_region_filter(session)[source]

Return the session’s region view filter (None = every region).

Parameters:

session (ToolSession)

Return type:

dict

analyze_library(session, library_dirs, phase, protocol_version, keylog_filename='keylog.csv', template_name='Auto-detect', max_runs=10, normalize=False, expand_keys=True, algorithms=None, *, force=False)[source]

Run the full analysis pipeline on library directories.

force bypasses the consensus memory-budget guard.

Parameters:
  • session (ToolSession)

  • library_dirs (List[str])

  • phase (str)

  • protocol_version (str)

  • keylog_filename (str)

  • template_name (str)

  • max_runs (int)

  • normalize (bool)

  • expand_keys (bool)

  • algorithms (List[str] | None)

  • force (bool)

Return type:

dict

import_dump(session, raw_path, output_path, pid=0, selection=None, materialize=False, exclude=None, key_material=None, decrypt_output=False, key_file=None, passphrase=None, kem_key_file=None, maps_path=None)[source]

Import a dump (raw .dump, ELF core, or minidump) to .msl format.

Delegates to msl.importer.import_dump(), which sniffs the source format and dispatches to the raw, ELF-core, or minidump importer. Plain raw .dump imports remain a byte-for-byte no-op regression.

selection restricts the import to some region categories: a RegionSelection or a spec string such as "heap,stack" / "all"; exclude (e.g. "image") drops categories. None for both imports everything. For .msl input the copy stays verbatim unless materialize is True. Selection outcome fields (selection, excluded_region_count, excluded_bytes, secrets_only_in_excluded, warnings) appear only when relevant.

key_material (core.key_material dict, request-scoped, never cached or logged) opens an encrypted .msl; a materialized copy is re-encrypted under the same key wrapping unless decrypt_output asks for plaintext. key_file / passphrase / kem_key_file (file-path idiom, MCP) are an alternative to key_material. A missing or wrong key on a materialize raises CapabilityError (PRECONDITION) and writes nothing.

maps_path names a /proc/<pid>/maps-style memory map that splits a raw dump into real regions (default: auto-detect a .maps sidecar next to the dump). Formats with their own layout ignore it (warning).

Parameters:
  • session (ToolSession)

  • raw_path (str)

  • output_path (str)

  • pid (int)

  • selection (str | RegionSelection | None)

  • materialize (bool)

  • exclude (str | None)

  • key_material (dict | None)

  • decrypt_output (bool)

  • key_file (str | None)

  • passphrase (str | None)

  • kem_key_file (str | None)

  • maps_path (str | None)

Return type:

dict

preview_import(session, path, selection=None, exclude=None, key_material=None, key_file=None, passphrase=None, kem_key_file=None, maps_path=None)[source]

Metadata-only preview of the regions an import of path would emit.

Returns ImportPreview.to_dict() — format, is_msl, per-region regions (with category), per-category totals and a summary of what selection / exclude would keep and drop. Reads no region payloads and writes nothing. Key material (dict or the file-path params) opens an encrypted .msl so its regions are listed; the result carries encrypted / decrypted. layout says where the regions came from (native / maps / none); maps_path is the memory map of a raw dump, as for import_dump().

Parameters:
  • session (ToolSession)

  • path (str)

  • selection (str | RegionSelection | None)

  • exclude (str | None)

  • key_material (dict | None)

  • key_file (str | None)

  • passphrase (str | None)

  • kem_key_file (str | None)

  • maps_path (str | None)

Return type:

dict

import_raw_dump(session, raw_path, output_path, pid=0, selection=None, materialize=False, exclude=None, key_file=None, passphrase=None, kem_key_file=None, decrypt_output=False, maps_path=None)[source]

Back-compat alias for import_dump().

Retained so existing callers keep working; new code should call import_dump(), which routes through the unified dispatcher.

Parameters:
  • session (ToolSession)

  • raw_path (str)

  • output_path (str)

  • pid (int)

  • selection (str | RegionSelection | None)

  • materialize (bool)

  • exclude (str | None)

  • key_file (str | None)

  • passphrase (str | None)

  • kem_key_file (str | None)

  • decrypt_output (bool)

  • maps_path (str | None)

Return type:

dict