wesktop v0.10.0 /src.wesktop.mcp_tools._http
On this page

Shared stdlib HTTP helper for wesktop's server-delegating MCP tools: attaches a Bearer token and returns parsed JSON or raw text with error handling.

#src.wesktop.mcp_tools._http

#src.wesktop.mcp_tools._http

Shared authenticated-HTTP helper for the HTTP-backed MCP tool modules.

Every server-delegating tool (ask_user, deployment, review, testing) needs the same request scaffolding: join the path onto the server URL, attach a Bearer token, JSON-encode the payload, and translate urllib errors. This module is the single implementation. Pure stdlib, zero internal dependencies.

Two return modes, chosen by the parse_json flag:

  • parse_json=True -- returns the parsed JSON body (a dict) and lets

urllib errors propagate, so the caller can distinguish failure from a valid response (used by ask_user's polling loop).

  • parse_json=False -- returns the raw response body as text, or a formatted

"Error: ..." string on any transport/HTTP failure (used by the tools that surface the server reply verbatim to the agent).

#request

python
def request(server_url: str, auth_token: str, method: str, path: str, payload: dict[str, Any] | None=None, timeout: int=30, *, parse_json: bool) -> Any

Make an authenticated request. See module docstring for return modes.