kl-mcp-client 2.1.3__py3-none-any.whl → 2.1.7__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/tools.py +32 -0
- kl_mcp_client/tools.py +163 -0
- {kl_mcp_client-2.1.3.dist-info → kl_mcp_client-2.1.7.dist-info}/METADATA +1 -1
- kl_mcp_client-2.1.7.dist-info/RECORD +11 -0
- {kl_mcp_client-2.1.3.dist-info → kl_mcp_client-2.1.7.dist-info}/WHEEL +1 -1
- kl_mcp_client-2.1.3.dist-info/RECORD +0 -11
- {kl_mcp_client-2.1.3.dist-info → kl_mcp_client-2.1.7.dist-info}/top_level.txt +0 -0
kl_mcp_client/asyncio/tools.py
CHANGED
|
@@ -319,3 +319,35 @@ class MCPTools:
|
|
|
319
319
|
"key": key,
|
|
320
320
|
},
|
|
321
321
|
)
|
|
322
|
+
|
|
323
|
+
# ======================================================
|
|
324
|
+
# BROWSER RUNTIME (NO SESSION)
|
|
325
|
+
# ======================================================
|
|
326
|
+
|
|
327
|
+
async def create_browser(
|
|
328
|
+
self,
|
|
329
|
+
payload: Optional[Dict[str, Any]] = None,
|
|
330
|
+
) -> Dict[str, Any]:
|
|
331
|
+
"""
|
|
332
|
+
Start browser runtime (idempotent).
|
|
333
|
+
- KHÔNG tạo session
|
|
334
|
+
- Dùng cho warm-up / admin / scheduler
|
|
335
|
+
|
|
336
|
+
payload: ThirdPartyOpenRequest (optional)
|
|
337
|
+
"""
|
|
338
|
+
res = await self.client.call_tool(
|
|
339
|
+
"create_browser",
|
|
340
|
+
payload or {},
|
|
341
|
+
)
|
|
342
|
+
return res.get("structuredContent", {})
|
|
343
|
+
|
|
344
|
+
async def release_browser(self) -> Dict[str, Any]:
|
|
345
|
+
"""
|
|
346
|
+
Release / stop browser runtime.
|
|
347
|
+
- KHÔNG cần payload
|
|
348
|
+
"""
|
|
349
|
+
res = await self.client.call_tool(
|
|
350
|
+
"release_browser",
|
|
351
|
+
{},
|
|
352
|
+
)
|
|
353
|
+
return res.get("structuredContent", {})
|
kl_mcp_client/tools.py
CHANGED
|
@@ -422,3 +422,166 @@ class MCPTools:
|
|
|
422
422
|
offset += chunkSize
|
|
423
423
|
|
|
424
424
|
return items
|
|
425
|
+
|
|
426
|
+
@_ensure_client
|
|
427
|
+
def wait_for_selector(
|
|
428
|
+
self, sessionId: str, selector: str, timeoutMs: Optional[int] = None
|
|
429
|
+
) -> Dict[str, Any]:
|
|
430
|
+
args = {
|
|
431
|
+
"sessionId": sessionId,
|
|
432
|
+
"selector": selector,
|
|
433
|
+
}
|
|
434
|
+
if timeoutMs is not None:
|
|
435
|
+
args["timeout"] = int(timeoutMs)
|
|
436
|
+
|
|
437
|
+
return self.client.call_tool("waitForSelector", args).get(
|
|
438
|
+
"structuredContent", {}
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
@_ensure_client
|
|
442
|
+
def send_keys(
|
|
443
|
+
self, sessionId: str, key: str, interval: int = 100
|
|
444
|
+
) -> Dict[str, Any]:
|
|
445
|
+
"""
|
|
446
|
+
Gửi phím: enter, tab, esc, ctrl+c, ctrl+shift+tab, ...
|
|
447
|
+
"""
|
|
448
|
+
return self.client.call_tool(
|
|
449
|
+
"sendKeys",
|
|
450
|
+
{"sessionId": sessionId, "text": key, "interval": interval},
|
|
451
|
+
).get("structuredContent", {})
|
|
452
|
+
|
|
453
|
+
@_ensure_client
|
|
454
|
+
def perform(
|
|
455
|
+
self,
|
|
456
|
+
sessionId: str,
|
|
457
|
+
action: str,
|
|
458
|
+
target: Optional[str] = None,
|
|
459
|
+
value: Optional[str] = None,
|
|
460
|
+
x: Optional[float] = None,
|
|
461
|
+
y: Optional[float] = None,
|
|
462
|
+
from_point: Optional[dict] = None,
|
|
463
|
+
to_point: Optional[dict] = None,
|
|
464
|
+
) -> Dict[str, Any]:
|
|
465
|
+
"""
|
|
466
|
+
action:
|
|
467
|
+
- click (x,y)
|
|
468
|
+
- move / hover (x,y)
|
|
469
|
+
- drag (from -> to)
|
|
470
|
+
- type (target, value)
|
|
471
|
+
"""
|
|
472
|
+
args = {
|
|
473
|
+
"sessionId": sessionId,
|
|
474
|
+
"action": action,
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if target is not None:
|
|
478
|
+
args["target"] = target
|
|
479
|
+
if value is not None:
|
|
480
|
+
args["value"] = value
|
|
481
|
+
if x is not None:
|
|
482
|
+
args["x"] = float(x)
|
|
483
|
+
if y is not None:
|
|
484
|
+
args["y"] = float(y)
|
|
485
|
+
if from_point is not None:
|
|
486
|
+
args["from"] = from_point
|
|
487
|
+
if to_point is not None:
|
|
488
|
+
args["to"] = to_point
|
|
489
|
+
|
|
490
|
+
return self.client.call_tool("perform", args).get("structuredContent", {})
|
|
491
|
+
|
|
492
|
+
@_ensure_client
|
|
493
|
+
def drag_and_drop(
|
|
494
|
+
self,
|
|
495
|
+
sessionId: str,
|
|
496
|
+
from_x: float,
|
|
497
|
+
from_y: float,
|
|
498
|
+
to_x: float,
|
|
499
|
+
to_y: float,
|
|
500
|
+
):
|
|
501
|
+
return self.perform(
|
|
502
|
+
sessionId=sessionId,
|
|
503
|
+
action="drag",
|
|
504
|
+
from_point={"x": from_x, "y": from_y},
|
|
505
|
+
to_point={"x": to_x, "y": to_y},
|
|
506
|
+
)
|
|
507
|
+
|
|
508
|
+
def hover(self, sessionId: str, x: float, y: float):
|
|
509
|
+
return self.perform(
|
|
510
|
+
sessionId=sessionId,
|
|
511
|
+
action="hover",
|
|
512
|
+
x=x,
|
|
513
|
+
y=y,
|
|
514
|
+
)
|
|
515
|
+
|
|
516
|
+
@_ensure_client
|
|
517
|
+
def scroll(
|
|
518
|
+
self,
|
|
519
|
+
sessionId: str,
|
|
520
|
+
*,
|
|
521
|
+
x: Optional[float] = None,
|
|
522
|
+
y: Optional[float] = None,
|
|
523
|
+
selector: Optional[str] = None,
|
|
524
|
+
position: Optional[str] = None, # "top" | "bottom"
|
|
525
|
+
) -> Dict[str, Any]:
|
|
526
|
+
"""
|
|
527
|
+
Scroll trang web.
|
|
528
|
+
|
|
529
|
+
Cách dùng:
|
|
530
|
+
- Scroll theo pixel:
|
|
531
|
+
scroll(sessionId, y=500)
|
|
532
|
+
- Scroll tới element:
|
|
533
|
+
scroll(sessionId, selector="#footer")
|
|
534
|
+
- Scroll top / bottom:
|
|
535
|
+
scroll(sessionId, position="top")
|
|
536
|
+
scroll(sessionId, position="bottom")
|
|
537
|
+
"""
|
|
538
|
+
|
|
539
|
+
args: Dict[str, Any] = {
|
|
540
|
+
"sessionId": sessionId,
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if x is not None:
|
|
544
|
+
args["x"] = float(x)
|
|
545
|
+
if y is not None:
|
|
546
|
+
args["y"] = float(y)
|
|
547
|
+
if selector is not None:
|
|
548
|
+
args["selector"] = selector
|
|
549
|
+
if position is not None:
|
|
550
|
+
args["position"] = position
|
|
551
|
+
|
|
552
|
+
if len(args) == 1:
|
|
553
|
+
return {
|
|
554
|
+
"ok": False,
|
|
555
|
+
"error": "scroll requires x/y or selector or position",
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return self.client.call_tool(
|
|
559
|
+
"scroll",
|
|
560
|
+
args,
|
|
561
|
+
).get("structuredContent", {})
|
|
562
|
+
# ======================================================
|
|
563
|
+
# BROWSER RUNTIME (NO SESSION)
|
|
564
|
+
# ======================================================
|
|
565
|
+
@_ensure_client
|
|
566
|
+
def create_browser(self, payload: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
567
|
+
"""
|
|
568
|
+
Start browser runtime (idempotent).
|
|
569
|
+
Không tạo session, chỉ đảm bảo browser đang RUNNING.
|
|
570
|
+
|
|
571
|
+
payload: map cho ThirdPartyOpenRequest
|
|
572
|
+
"""
|
|
573
|
+
return self.client.call_tool(
|
|
574
|
+
"create_browser",
|
|
575
|
+
payload or {},
|
|
576
|
+
).get("structuredContent", {})
|
|
577
|
+
|
|
578
|
+
@_ensure_client
|
|
579
|
+
def release_browser(self) -> Dict[str, Any]:
|
|
580
|
+
"""
|
|
581
|
+
Release / stop browser runtime.
|
|
582
|
+
Không cần payload.
|
|
583
|
+
"""
|
|
584
|
+
return self.client.call_tool(
|
|
585
|
+
"release_browser",
|
|
586
|
+
{},
|
|
587
|
+
).get("structuredContent", {})
|
|
@@ -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=kEkeG75SUUostCR5gRjLIjJzHg6-iWzXakjf3nvgXKk,18733
|
|
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=ayOqGYoiQ0q15xXz_7sKFq9UzUAqaOG0Uscy6uyvErM,11992
|
|
8
|
+
kl_mcp_client-2.1.7.dist-info/METADATA,sha256=llO4qCoOWzHHF-n2opsj-bRUfdoiIDcbl1Nlb9qGkdw,4443
|
|
9
|
+
kl_mcp_client-2.1.7.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
10
|
+
kl_mcp_client-2.1.7.dist-info/top_level.txt,sha256=wd_HFFyGjiKavwACuj8Ny0svtVyNsrxCSVU48EkoQ7c,14
|
|
11
|
+
kl_mcp_client-2.1.7.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=SRt4Ypi6izGOEl2BJiY4l4DW_Yd2GJjbjOXa-vBRKhw,14137
|
|
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.3.dist-info/METADATA,sha256=WzjSU7IGTITVAQ9ri7LnIGPF6sJTLmm3LGJ0CyytD8g,4443
|
|
9
|
-
kl_mcp_client-2.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
-
kl_mcp_client-2.1.3.dist-info/top_level.txt,sha256=wd_HFFyGjiKavwACuj8Ny0svtVyNsrxCSVU48EkoQ7c,14
|
|
11
|
-
kl_mcp_client-2.1.3.dist-info/RECORD,,
|
|
File without changes
|