kl-mcp-client 2.0.3__tar.gz → 2.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kl-mcp-client
3
- Version: 2.0.3
3
+ Version: 2.0.4
4
4
  Summary: MCP Client for Python
5
5
  Author-email: Kyle <hngan.it@gmail.com>
6
6
  License: MIT
@@ -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
  # ======================================================
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kl-mcp-client
3
- Version: 2.0.3
3
+ Version: 2.0.4
4
4
  Summary: MCP Client for Python
5
5
  Author-email: Kyle <hngan.it@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "kl-mcp-client"
7
- version = "2.0.3"
7
+ version = "2.0.4"
8
8
  description = "MCP Client for Python"
9
9
  dependencies = [ "requests>=2.32.5", "httpx>=0.28.1",]
10
10
  readme = "README.md"
File without changes
File without changes