Excessibility.MCP.ClientContext (Excessibility v0.14.0)

View Source

Helpers for getting the MCP client's context (working directory, etc).

The MCP server runs from the excessibility project directory, but tools often need to operate in the client's project directory. This module provides helpers to determine the correct working directory.

The client's working directory is determined in this order:

  1. MCP_CLIENT_CWD environment variable (set by the mcp-server wrapper script)
  2. Explicit cwd parameter passed to the tool (for backward compatibility)
  3. Current working directory (fallback)

Summary

Functions

Builds a path relative to the client's working directory.

Returns command options for System.cmd with the correct working directory.

Gets the client's working directory.

Functions

client_path(relative_path, opts \\ [])

Builds a path relative to the client's working directory.

Examples

iex> ClientContext.client_path("test/excessibility/timeline.json")
"/home/user/projects/my_app/test/excessibility/timeline.json"

cmd_opts(extra_opts \\ [])

Returns command options for System.cmd with the correct working directory.

Examples

iex> ClientContext.cmd_opts()
[cd: "/home/user/projects/my_app"]

iex> ClientContext.cmd_opts(stderr_to_stdout: true)
[cd: "/home/user/projects/my_app", stderr_to_stdout: true]

get_cwd(opts \\ [])

Gets the client's working directory.

Options

  • :cwd - Explicit working directory override (for backward compatibility)

Examples

iex> ClientContext.get_cwd()
"/home/user/projects/my_app"

iex> ClientContext.get_cwd(cwd: "/custom/path")
"/custom/path"