koala73/worldmonitor · error · ValueError

get() needs a host-relative API path starting with '/'

Error message

get() needs a host-relative API path starting with '/'

What it means

The Python SDK `Client.get()` requires a host-relative REST path beginning with `/` (e.g. `/api/health`). Paths without a leading slash are rejected before any network call, because the method concatenates `base_url + path` and a missing slash would silently produce a wrong URL. Use the curated helper `health()` for the common case.

Source

Thrown at sdk/python/src/worldmonitor_sdk/__init__.py:194

        args.update(kwargs)
        return self._rpc("tools/call", {"name": name, "arguments": args})

    def list_tools(self):
        """List every MCP tool (public - no key needed)."""
        return self._rpc("tools/list")

    def list_prompts(self):
        """List MCP prompt templates (public)."""
        return self._rpc("prompts/list")

    def list_resources(self):
        """List MCP resources (public)."""
        return self._rpc("resources/list")

    def get(self, path, params=None, **kwargs):
        """GET a raw REST path (host-relative, e.g. ``/api/health``)."""
        if not path.startswith("/"):
            raise ValueError("get() needs a host-relative API path starting with '/'")
        query = dict(params or {})
        query.update(kwargs)
        url = self.base_url + path
        if query:
            url += "?" + urllib.parse.urlencode({k: _stringify(v) for k, v in query.items()})
        status, content_type, text = self._transport(
            {"url": url, "method": "GET", "headers": self._headers(accept="application/json")},
            self.timeout,
        )
        value = parse_body(text, content_type)
        if status < 200 or status >= 300:
            raise APIError(status, value)
        return value

    def health(self):
        """API status / health check."""
        return self.get("/api/health")

View on GitHub (pinned to ffec79ac33)

Solutions

  1. Prefix the path with `/`: `client.get("/api/health")`
  2. Use `client.health()` for the health endpoint, which supplies the path correctly
  3. Normalize programmatically: `path = '/' + path.lstrip('/')`

Example fix

# before
client.get("api/health")
# after
client.get("/api/health")
# or use the curated helper
client.health()
Defensive patterns

Strategy: validation

Validate before calling

# Normalize the path before calling get().
path = '/' + path.lstrip('/')
if not path.startswith('/'):
    raise ValueError('path must start with /')
client.get(path)

Type guard

def is_host_relative_path(path: str) -> bool:
    return isinstance(path, str) and path.startswith('/')

Prevention

When it happens

Trigger: Calling `client.get("api/health")` or any path lacking a leading `/`; passing a path copied from docs that omitted the slash.

Common situations: Copy/pasting a path from documentation that renders without the leading slash; constructing the path dynamically without ensuring a `/` prefix.

Related errors


AI-assisted analysis of koala73/worldmonitor@ffec79ac33 (2026-08-12). Data as JSON: /api/errors/a53d6a598d5ea18b. Report an issue: GitHub.