ExMCP.SpecSync.Metadata (ex_mcp v0.10.0)

View Source

Manages sync metadata for MCP specification files.

Tracks per-file SHA256 checksums, ETags, and sync timestamps in a .sync_metadata.json file within the specs directory.

Summary

Functions

Checks if a file has changed compared to the stored metadata.

Returns the stored ETag for a file, if any.

Loads sync metadata from the given base directory.

Saves sync metadata to the given base directory.

Computes SHA256 checksum of content.

Updates metadata for a specific file after successful sync.

Types

file_entry()

@type file_entry() :: %{
  sha256: String.t(),
  etag: String.t() | nil,
  synced_at: String.t(),
  source_url: String.t()
}

t()

@type t() :: %{
  version: integer(),
  last_sync: String.t() | nil,
  files: %{required(String.t()) => file_entry()}
}

Functions

file_changed?(metadata, relative_path, content)

@spec file_changed?(t(), String.t(), binary()) :: boolean()

Checks if a file has changed compared to the stored metadata.

Returns true if the file is new or its content differs from the stored checksum.

get_etag(metadata, relative_path)

@spec get_etag(t(), String.t()) :: String.t() | nil

Returns the stored ETag for a file, if any.

load(base_dir)

@spec load(String.t()) :: t()

Loads sync metadata from the given base directory.

Returns a metadata map with file checksums and sync info. If the file doesn't exist, returns an empty metadata structure.

save(base_dir, metadata)

@spec save(String.t(), t()) :: :ok | {:error, term()}

Saves sync metadata to the given base directory.

sha256(content)

@spec sha256(binary()) :: String.t()

Computes SHA256 checksum of content.

update_file(metadata, relative_path, content, opts \\ [])

@spec update_file(t(), String.t(), binary(), keyword()) :: t()

Updates metadata for a specific file after successful sync.