jenkins_whoami
Retrieve the authenticated Jenkins user identity by querying the whoAmI API endpoint. Returns details about the current session.
Instructions
Return the authenticated Jenkins identity from /whoAmI/api/json.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/jenkins_mcp_server/tools.py:55-59 (registration)The tool 'jenkins_whoami' is registered as an MCP tool via the @mcp.tool() decorator inside register_tools().
def register_tools(mcp: FastMCP) -> None: @mcp.tool() def jenkins_whoami() -> dict[str, Any]: """Return the authenticated Jenkins identity from /whoAmI/api/json.""" return _run(lambda: _get_json("whoAmI")) - src/jenkins_mcp_server/tools.py:57-59 (handler)The handler function for the 'jenkins_whoami' tool. It calls _get_json('whoAmI') which hits the Jenkins /whoAmI/api/json endpoint to return the authenticated identity.
def jenkins_whoami() -> dict[str, Any]: """Return the authenticated Jenkins identity from /whoAmI/api/json.""" return _run(lambda: _get_json("whoAmI")) - Helper function _get_json creates a client via _client() and calls client.get_json(), used by the jenkins_whoami handler.
def _get_json(path: str, params: dict[str, Any] | None = None) -> Any: with _client() as client: return client.get_json(path, params=params) - JenkinsClient.get_json() performs the actual HTTP GET request with /api/json appended, and returns the parsed JSON response.
def get_json(self, path: str, params: Mapping[str, Any] | None = None) -> Json: response = self.request("GET", append_api_json(path), params=params) try: payload = response.json() except json.JSONDecodeError as exc: raise JenkinsHTTPError( response.status_code, "GET", normalize_relative_path(path), "Response was not JSON", _body_snippet(response), ) from exc return payload - append_api_json() ensures the path ends with /api/json (e.g., 'whoAmI' -> 'whoAmI/api/json').
def append_api_json(path: str) -> str: path = normalize_relative_path(path) split = urlsplit(path) clean = split.path.rstrip("/") if not clean.endswith("/api/json") and clean != "api/json": clean = f"{clean}/api/json" return urlunsplit(("", "", clean, split.query, ""))