kl-mcp-client 2.1.0__py3-none-any.whl → 2.1.2__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.
@@ -146,3 +146,4 @@ class MCPClient:
146
146
  async def aclose(self):
147
147
  """Close the httpx async client"""
148
148
  await self._client.aclose()
149
+
@@ -272,3 +272,50 @@ class MCPTools:
272
272
  },
273
273
  )
274
274
  return res.get("structuredContent", {})
275
+
276
+ # CLEAN TEXT / READ MODE
277
+ # ======================================================
278
+ async def get_clean_text(self, sessionId: str) -> Dict[str, Any]:
279
+ """
280
+ Lấy toàn bộ visible text đã được clean trên trang hiện tại.
281
+ - Bỏ script/style/iframe/svg/canvas
282
+ - Chỉ text nhìn thấy (display/visibility/opacity)
283
+
284
+ Returns:
285
+ {
286
+ "text": "...",
287
+ "length": 12345
288
+ }
289
+ """
290
+ res = await self.client.call_tool(
291
+ "getCleanText",
292
+ {"sessionId": sessionId},
293
+ )
294
+ return res.get("structuredContent", {})
295
+
296
+ # ======================================================
297
+ # KEYBOARD (ASYNC)
298
+ # ======================================================
299
+ async def send_key(
300
+ self,
301
+ sessionId: str,
302
+ key: str,
303
+ ) -> Dict[str, Any]:
304
+ """
305
+ Send a keyboard key to the active page (async).
306
+
307
+ Args:
308
+ sessionId: MCP browser session
309
+ key: Keyboard key (e.g. "Enter", "Tab", "Escape", "ArrowDown",
310
+ "Ctrl+a", "Ctrl+Enter")
311
+
312
+ Returns:
313
+ structuredContent from MCP server
314
+ """
315
+ return await self.call_tool_structured(
316
+ "sendKey",
317
+ {
318
+ "sessionId": sessionId,
319
+ "key": key,
320
+ },
321
+ )
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, sessionId: str, selector: str, filename: str, base64data: str
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
- filename: tên file trên browser side
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
- return self.client.call_tool(
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
- "filename": filename,
147
- "data": base64data,
181
+ "uploadId": upload_id,
148
182
  },
149
- ).get("structuredContent", {})
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
  # ======================================================
@@ -254,65 +300,24 @@ class MCPTools:
254
300
  "prompt": prompt,
255
301
  },
256
302
  ).get("structuredContent", {})
303
+
257
304
  # ======================================================
258
- # MOUSE / PERFORM ACTIONS
305
+ # CLEAN TEXT / READ MODE
259
306
  # ======================================================
260
307
  @_ensure_client
261
- def perform_click_xy(
262
- self,
263
- sessionId: str,
264
- x: float,
265
- y: float,
266
- ) -> Dict[str, Any]:
267
- """
268
- Move mouse smoothly to (x, y) and left click.
308
+ def get_clean_text(self, sessionId: str) -> Dict[str, Any]:
269
309
  """
270
- return self.client.call_tool(
271
- "perform",
272
- {
273
- "sessionId": sessionId,
274
- "action": "click",
275
- "x": float(x),
276
- "y": float(y),
277
- },
278
- ).get("structuredContent", {})
279
- @_ensure_client
280
- def perform_drag(
281
- self,
282
- sessionId: str,
283
- from_x: float,
284
- from_y: float,
285
- to_x: float,
286
- to_y: float,
287
- ) -> Dict[str, Any]:
288
- """
289
- Drag mouse from (from_x, from_y) to (to_x, to_y).
290
- """
291
- return self.client.call_tool(
292
- "perform",
310
+ Lấy toàn bộ visible text đã được clean trên trang hiện tại.
311
+ - Bỏ script/style/iframe/svg/canvas
312
+ - Chỉ text nhìn thấy (display/visibility/opacity)
313
+
314
+ Returns:
293
315
  {
294
- "sessionId": sessionId,
295
- "action": "drag",
296
- "from": {"x": float(from_x), "y": float(from_y)},
297
- "to": {"x": float(to_x), "y": float(to_y)},
298
- },
299
- ).get("structuredContent", {})
300
- @_ensure_client
301
- def perform_hover(
302
- self,
303
- sessionId: str,
304
- x: float,
305
- y: float,
306
- ) -> Dict[str, Any]:
307
- """
308
- Move mouse smoothly to (x, y) without clicking.
316
+ "text": "...",
317
+ "length": 12345
318
+ }
309
319
  """
310
320
  return self.client.call_tool(
311
- "perform",
312
- {
313
- "sessionId": sessionId,
314
- "action": "hover",
315
- "x": float(x),
316
- "y": float(y),
317
- },
321
+ "getCleanText",
322
+ {"sessionId": sessionId},
318
323
  ).get("structuredContent", {})
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kl-mcp-client
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: MCP Client for Python
5
5
  Author-email: Kyle <hngan.it@gmail.com>
6
6
  License: MIT
@@ -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=Jhx4Zs-1GHCgnHTCHjzmN1batgziOo17fJG5FmQf_Nc,11675
5
+ kl_mcp_client/asyncio/__init__.py,sha256=pdJdBcEH5HaRuHSe2B7VUyRgH5ad3u1dDc4euZMDRMY,106
6
+ kl_mcp_client/asyncio/client.py,sha256=5CpPf1YGOTzYfbG1mAK9s-vhKQULjdlSJnhXm3Th-1s,4413
7
+ kl_mcp_client/asyncio/tools.py,sha256=2rXnmVVCgqRyM30ULN-7tCUARwHg9rbuTyrR-p5O4_Y,11055
8
+ kl_mcp_client-2.1.2.dist-info/METADATA,sha256=uiDz9Ql2IzcHfgNbmBPqu0ofjOepdOmDG9-VuxqS6GI,4443
9
+ kl_mcp_client-2.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ kl_mcp_client-2.1.2.dist-info/top_level.txt,sha256=wd_HFFyGjiKavwACuj8Ny0svtVyNsrxCSVU48EkoQ7c,14
11
+ kl_mcp_client-2.1.2.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=ujhRp0zC5GJKnBYziIPMdKZqrhv8K2t6tBAuwYw7q_k,4513
4
- kl_mcp_client/tools.py,sha256=5lI8eoAaZQuB__IfcAzgJh_J7VLw--NMO1rqcc9X6Qw,11083
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=82zwDC_N0spi_DIPbOq6HgG6qxgpBM2PtBkzUZGDxAo,9658
8
- kl_mcp_client-2.1.0.dist-info/METADATA,sha256=L1ezxu5mRFgD10rsX668ebKhe8dFGmVoIyP2wvzqqo8,4443
9
- kl_mcp_client-2.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- kl_mcp_client-2.1.0.dist-info/top_level.txt,sha256=wd_HFFyGjiKavwACuj8Ny0svtVyNsrxCSVU48EkoQ7c,14
11
- kl_mcp_client-2.1.0.dist-info/RECORD,,