kl-mcp-client 2.0.2__py3-none-any.whl → 2.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kl_mcp_client/asyncio/client.py +2 -2
- kl_mcp_client/client.py +2 -2
- kl_mcp_client/tools.py +56 -10
- {kl_mcp_client-2.0.2.dist-info → kl_mcp_client-2.0.4.dist-info}/METADATA +1 -1
- kl_mcp_client-2.0.4.dist-info/RECORD +11 -0
- kl_mcp_client-2.0.2.dist-info/RECORD +0 -11
- {kl_mcp_client-2.0.2.dist-info → kl_mcp_client-2.0.4.dist-info}/WHEEL +0 -0
- {kl_mcp_client-2.0.2.dist-info → kl_mcp_client-2.0.4.dist-info}/top_level.txt +0 -0
kl_mcp_client/asyncio/client.py
CHANGED
|
@@ -23,7 +23,7 @@ class MCPClient:
|
|
|
23
23
|
headers: Optional[Dict[str, str]] = None,
|
|
24
24
|
timeout: int = 30,
|
|
25
25
|
retries: int = 1,
|
|
26
|
-
proxies
|
|
26
|
+
proxies=None,
|
|
27
27
|
):
|
|
28
28
|
"""
|
|
29
29
|
base_url: full MCP HTTP endpoint e.g. http://localhost:3000/mcp
|
|
@@ -47,7 +47,7 @@ class MCPClient:
|
|
|
47
47
|
self._client = httpx.AsyncClient(
|
|
48
48
|
headers=self.headers,
|
|
49
49
|
timeout=httpx.Timeout(self.timeout),
|
|
50
|
-
|
|
50
|
+
proxy=proxies,
|
|
51
51
|
)
|
|
52
52
|
|
|
53
53
|
# local session cache
|
kl_mcp_client/client.py
CHANGED
|
@@ -22,7 +22,7 @@ class MCPClient:
|
|
|
22
22
|
headers: Optional[Dict[str, str]] = None,
|
|
23
23
|
timeout: int = 30,
|
|
24
24
|
retries: int = 1,
|
|
25
|
-
proxies
|
|
25
|
+
proxies=None,
|
|
26
26
|
):
|
|
27
27
|
"""
|
|
28
28
|
base_url: full MCP HTTP endpoint e.g. http://localhost:3000/mcp
|
|
@@ -49,7 +49,7 @@ class MCPClient:
|
|
|
49
49
|
base_url=self.base_url,
|
|
50
50
|
headers=self.headers,
|
|
51
51
|
timeout=httpx.Timeout(self.timeout),
|
|
52
|
-
|
|
52
|
+
proxy=proxies,
|
|
53
53
|
)
|
|
54
54
|
|
|
55
55
|
def close(self):
|
kl_mcp_client/tools.py
CHANGED
|
@@ -126,27 +126,63 @@ class MCPTools:
|
|
|
126
126
|
|
|
127
127
|
@_ensure_client
|
|
128
128
|
def upload_file(
|
|
129
|
-
self,
|
|
129
|
+
self,
|
|
130
|
+
sessionId: str,
|
|
131
|
+
selector: str,
|
|
132
|
+
file_path: str,
|
|
130
133
|
) -> Dict[str, Any]:
|
|
131
134
|
"""
|
|
132
|
-
Upload file vào input[type=file]
|
|
135
|
+
Upload file (kể cả video lớn) vào input[type=file] theo luồng mới:
|
|
136
|
+
1. Multipart upload file lên MCP server
|
|
137
|
+
2. Nhận uploadId
|
|
138
|
+
3. Gọi MCP tool uploadFile với uploadId
|
|
139
|
+
|
|
133
140
|
Args:
|
|
134
141
|
sessionId: MCP browser session
|
|
135
142
|
selector: CSS selector, ví dụ 'input[type=file]'
|
|
136
|
-
|
|
137
|
-
base64data: dữ liệu base64 (không kèm header)
|
|
138
|
-
Returns:
|
|
139
|
-
structured result từ server
|
|
143
|
+
file_path: đường dẫn file local (video, pdf, doc, ...)
|
|
140
144
|
"""
|
|
141
|
-
|
|
145
|
+
|
|
146
|
+
if not file_path:
|
|
147
|
+
return {"ok": False, "error": "file_path is required"}
|
|
148
|
+
|
|
149
|
+
# --------------------------------------------------
|
|
150
|
+
# 1️⃣ Multipart upload file lên MCP server
|
|
151
|
+
# --------------------------------------------------
|
|
152
|
+
try:
|
|
153
|
+
with open(file_path, "rb") as f:
|
|
154
|
+
resp = self.client.http.post(
|
|
155
|
+
"/upload",
|
|
156
|
+
files={"file": f},
|
|
157
|
+
timeout=300, # upload file lớn
|
|
158
|
+
)
|
|
159
|
+
except Exception as e:
|
|
160
|
+
return {"ok": False, "error": f"upload http failed: {e}"}
|
|
161
|
+
|
|
162
|
+
if resp.status_code != 200:
|
|
163
|
+
return {
|
|
164
|
+
"ok": False,
|
|
165
|
+
"error": f"upload http error {resp.status_code}: {resp.text}",
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
data = resp.json()
|
|
169
|
+
upload_id = data.get("uploadId")
|
|
170
|
+
if not upload_id:
|
|
171
|
+
return {"ok": False, "error": "uploadId not returned from server"}
|
|
172
|
+
|
|
173
|
+
# --------------------------------------------------
|
|
174
|
+
# 2️⃣ Gọi MCP tool uploadFile (PATH MODE)
|
|
175
|
+
# --------------------------------------------------
|
|
176
|
+
result = self.client.call_tool(
|
|
142
177
|
"uploadFile",
|
|
143
178
|
{
|
|
144
179
|
"sessionId": sessionId,
|
|
145
180
|
"selector": selector,
|
|
146
|
-
"
|
|
147
|
-
"data": base64data,
|
|
181
|
+
"uploadId": upload_id,
|
|
148
182
|
},
|
|
149
|
-
)
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
return result.get("structuredContent", {})
|
|
150
186
|
|
|
151
187
|
@_ensure_client
|
|
152
188
|
def wait_for_selector(
|
|
@@ -229,6 +265,16 @@ class MCPTools:
|
|
|
229
265
|
{"sessionId": sessionId, "selector": selector, "args": args or {}},
|
|
230
266
|
)
|
|
231
267
|
|
|
268
|
+
@_ensure_client
|
|
269
|
+
def find_element_by_prompt(self, sessionId: str, prompt: str) -> Dict[str, Any]:
|
|
270
|
+
"""
|
|
271
|
+
Gọi tool findElementByPrompt trên MCP server.
|
|
272
|
+
Trả về structuredContent gồm: html, nodeId.
|
|
273
|
+
"""
|
|
274
|
+
return self.client.call_tool(
|
|
275
|
+
"findElementByPrompt", {"sessionId": sessionId, "prompt": prompt}
|
|
276
|
+
).get("structuredContent", {})
|
|
277
|
+
|
|
232
278
|
# ======================================================
|
|
233
279
|
# AI / CONTENT PARSING
|
|
234
280
|
# ======================================================
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
kl_mcp_client/__init__.py,sha256=pdJdBcEH5HaRuHSe2B7VUyRgH5ad3u1dDc4euZMDRMY,106
|
|
2
|
+
kl_mcp_client/__version__.py,sha256=CCYQUt19bi0kfo0Q8q8snnwgw_c9F3s6FFxTMsX1yDE,22
|
|
3
|
+
kl_mcp_client/client.py,sha256=ujhRp0zC5GJKnBYziIPMdKZqrhv8K2t6tBAuwYw7q_k,4513
|
|
4
|
+
kl_mcp_client/tools.py,sha256=yJ8eTZrIPCyAwLm462e1eZOz6yaPk39J4gd13BzYXbw,10974
|
|
5
|
+
kl_mcp_client/asyncio/__init__.py,sha256=pdJdBcEH5HaRuHSe2B7VUyRgH5ad3u1dDc4euZMDRMY,106
|
|
6
|
+
kl_mcp_client/asyncio/client.py,sha256=bgooGIzdU-BKAo0f2wHZKkuIHlKrj5GJ8vxAuwU6Xn4,4409
|
|
7
|
+
kl_mcp_client/asyncio/tools.py,sha256=tCeHUc4ao99Hu4ck0BmvDo95vmTtG1ChvwHamaIx_zE,7655
|
|
8
|
+
kl_mcp_client-2.0.4.dist-info/METADATA,sha256=95PHfR0WCTh4FcvCc6F9a1HLkGYAaZpdJd9N1lGPGWI,4443
|
|
9
|
+
kl_mcp_client-2.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
+
kl_mcp_client-2.0.4.dist-info/top_level.txt,sha256=wd_HFFyGjiKavwACuj8Ny0svtVyNsrxCSVU48EkoQ7c,14
|
|
11
|
+
kl_mcp_client-2.0.4.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
kl_mcp_client/__init__.py,sha256=pdJdBcEH5HaRuHSe2B7VUyRgH5ad3u1dDc4euZMDRMY,106
|
|
2
|
-
kl_mcp_client/__version__.py,sha256=CCYQUt19bi0kfo0Q8q8snnwgw_c9F3s6FFxTMsX1yDE,22
|
|
3
|
-
kl_mcp_client/client.py,sha256=3NN18vvrxV32hkKFGuWqfeZLZ303jl5m8atpe14U69Q,4543
|
|
4
|
-
kl_mcp_client/tools.py,sha256=kcxg4Cw1sAf8QmPCF6DW7pET55hZs64ztQxBDoe27go,9350
|
|
5
|
-
kl_mcp_client/asyncio/__init__.py,sha256=pdJdBcEH5HaRuHSe2B7VUyRgH5ad3u1dDc4euZMDRMY,106
|
|
6
|
-
kl_mcp_client/asyncio/client.py,sha256=giOz_h8x_RoO5wA1ebiWBy1eU7owU_YOxXAFV2Z_MCk,4439
|
|
7
|
-
kl_mcp_client/asyncio/tools.py,sha256=tCeHUc4ao99Hu4ck0BmvDo95vmTtG1ChvwHamaIx_zE,7655
|
|
8
|
-
kl_mcp_client-2.0.2.dist-info/METADATA,sha256=Kkl2XxG4d2ftuKO1_1BR7C84bJNSZQN6NnMBBvQx8yo,4443
|
|
9
|
-
kl_mcp_client-2.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
-
kl_mcp_client-2.0.2.dist-info/top_level.txt,sha256=wd_HFFyGjiKavwACuj8Ny0svtVyNsrxCSVU48EkoQ7c,14
|
|
11
|
-
kl_mcp_client-2.0.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|