kl-mcp-client 2.1.0__tar.gz → 2.1.2__tar.gz
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-2.1.0 → kl_mcp_client-2.1.2}/PKG-INFO +1 -1
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client/asyncio/client.py +1 -0
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client/asyncio/tools.py +47 -0
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client/tools.py +69 -64
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client.egg-info/PKG-INFO +1 -1
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/pyproject.toml +1 -1
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/README.md +0 -0
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client/__init__.py +0 -0
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client/__version__.py +0 -0
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client/asyncio/__init__.py +0 -0
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client/client.py +0 -0
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client.egg-info/SOURCES.txt +0 -0
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client.egg-info/dependency_links.txt +0 -0
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client.egg-info/requires.txt +0 -0
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/kl_mcp_client.egg-info/top_level.txt +0 -0
- {kl_mcp_client-2.1.0 → kl_mcp_client-2.1.2}/setup.cfg +0 -0
|
@@ -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
|
+
)
|
|
@@ -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
|
# ======================================================
|
|
@@ -254,65 +300,24 @@ class MCPTools:
|
|
|
254
300
|
"prompt": prompt,
|
|
255
301
|
},
|
|
256
302
|
).get("structuredContent", {})
|
|
303
|
+
|
|
257
304
|
# ======================================================
|
|
258
|
-
#
|
|
305
|
+
# CLEAN TEXT / READ MODE
|
|
259
306
|
# ======================================================
|
|
260
307
|
@_ensure_client
|
|
261
|
-
def
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
-
"
|
|
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", {})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|