MCPcopy Create free account
hub / github.com/agentrpc/agentrpc / HTTPClient

Class HTTPClient

sdk-python/src/agentrpc/http_client.py:8–225  ·  view source on GitHub ↗

HTTP client for making requests to the AgentRPC API.

Source from the content-addressed store, hash-verified

6
7
8class HTTPClient:
9 """HTTP client for making requests to the AgentRPC API."""
10
11 def __init__(self, endpoint: str, api_secret: str):
12 """Initialize the HTTP client.
13
14 Args:
15 endpoint: The API endpoint.
16 api_secret: The API secret key.
17 """
18 self.endpoint = endpoint.rstrip("/")
19 self.api_secret = api_secret
20 self.cluster_id = None
21 self.machine_id = None
22
23 # Get SDK version from package metadata
24 try:
25 sdk_version = version("agentrpc")
26 except PackageNotFoundError:
27 sdk_version = "unknown"
28
29 # Set standard headers
30 self.headers = {
31 "Content-Type": "application/json",
32 "Authorization": f"Bearer {api_secret}",
33 "x-machine-sdk-version": sdk_version,
34 "x-machine-sdk-language": "python",
35 "x-machine-id": "python",
36 }
37
38 def list_tools(self, params: Dict[str, Any]) -> Dict[str, Any]:
39 """List tools from the AgentRPC API.
40
41 Args:
42 params: Parameters including clusterId.
43
44 Returns:
45 The API response.
46
47 Raises:
48 AgentRPCError: If the request fails.
49 """
50 cluster_id = params.get("params", {}).get("clusterId")
51 if not cluster_id:
52 raise AgentRPCError("clusterId is required")
53
54 try:
55 response = self.get(f"/clusters/{cluster_id}/tools")
56 return {"status": 200, "body": response}
57 except Exception as e:
58 raise AgentRPCError(f"Failed to list tools: {str(e)}")
59
60 def create_job(
61 self,
62 cluster_id: str,
63 function_name: Optional[str] = None,
64 tool_name: Optional[str] = None,
65 input_data: Dict[str, Any] = None,

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected