modelcontextprotocol/servers · error · ValueError

Invalid start_timestamp: '${start_timestamp}' - cannot start

Error message

Invalid start_timestamp: '${start_timestamp}' - cannot start with '-'

What it means

git_log() defends against git flag injection: a start_timestamp beginning with '-' would be interpreted by the git CLI as an option rather than a date (e.g. '--all' or an exec-like char sequence). The function raises ValueError before ever invoking Git when the value starts with a dash.

Source

Thrown at src/git/src/mcp_server_git/server.py:162

                raise ValueError(f"Invalid path: '{f}'")
            try:
                resolved.relative_to(repo_root)
            except ValueError:
                raise ValueError(
                    f"Path '{f}' is outside the repository '{repo_root}'"
                )
        # Use '--' to prevent files starting with '-' from being interpreted as options
        repo.git.add("--", *files)
    return "Files staged successfully"

def git_reset(repo: git.Repo) -> str:
    repo.index.reset()
    return "All staged changes reset"

def git_log(repo: git.Repo, max_count: int = 10, start_timestamp: Optional[str] = None, end_timestamp: Optional[str] = None) -> list[str]:
    # Defense in depth: reject timestamps starting with '-' to prevent flag injection
    if start_timestamp and start_timestamp.startswith("-"):
        raise ValueError(f"Invalid start_timestamp: '{start_timestamp}' - cannot start with '-'")
    if end_timestamp and end_timestamp.startswith("-"):
        raise ValueError(f"Invalid end_timestamp: '{end_timestamp}' - cannot start with '-'")

    kwargs: dict[str, Any] = {"max_count": max_count}
    if start_timestamp:
        kwargs["since"] = start_timestamp
    if end_timestamp:
        kwargs["until"] = end_timestamp

    commits = list(repo.iter_commits(**kwargs))
    log = []
    for commit in commits:
        log.append(
            f"Commit: {commit.hexsha}\n"
            f"Author: {commit.author}\n"
            f"Date: {commit.authored_datetime}\n"
            f"Message: {commit.message}\n"
        )

View on GitHub (pinned to d73f99efbf)

Solutions

  1. Pass an absolute date/time string that does not begin with '-', e.g. '2024-01-01' or '2 weeks ago'.
  2. Use positive relative expressions ('2 weeks ago') instead of negative ones ('-2 weeks').
  3. Sanitize/strip leading dashes from user-supplied timestamps in your client before calling the tool.
  4. Catch the ValueError in call_tool and return an explanatory message to the model.

Example fix

// before
await call_git_log({ "start_timestamp": "-2 weeks" });
// after
await call_git_log({ "start_timestamp": "2 weeks ago" });
Defensive patterns

Strategy: validation

Validate before calling

def safe_timestamp(ts: str | None) -> str | None:
    if ts and ts.startswith("-"):
        raise ValueError(f"timestamp cannot start with '-': {ts}")
    return ts

start_timestamp = safe_timestamp(start_timestamp)

Type guard

def is_safe_timestamp(ts: str | None) -> bool:
    return ts is None or not ts.startswith("-")

Try / catch

try:
    log = await call_tool("git_log", {"repo_path": path, "start_timestamp": ts})
except ValueError as e:
    if "cannot start with" in str(e):
        return f"Invalid timestamp, use e.g. '2024-01-01' or '2 weeks ago': {e}"
    raise

Prevention

When it happens

Trigger: Calling the git_log tool with arguments like start_timestamp='--since-as-filter' or any LLM-supplied string starting with '-'; passing negative-looking dates such as '-1 day' directly instead of using the supported format.

Common situations: LLM clients hallucinating flag-style arguments; users attempting relative dates like '-2 weeks'; adversarial prompt-injection payloads trying to smuggle extra git options through the timestamp parameters.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of modelcontextprotocol/servers@d73f99efbf (2026-09-07). Data as JSON: /api/errors/9a2cf1bdba3b6bc0. Report an issue: GitHub.