Ver código fonte

update tools getPage in case not found keyword

Khanh Nguyen 5 meses atrás
pai
commit
f891aa389e
1 arquivos alterados com 14 adições e 7 exclusões
  1. 14 7
      src/server_mcp/tools.py

+ 14 - 7
src/server_mcp/tools.py

@@ -127,23 +127,30 @@ CategoryParent = Annotated[int | None, Field(default=None, description="parent i
 # --- getPage ---
 
 PageUrl = Annotated[str, Field(description="url of the page")]
-PageKeyword = Annotated[str | None, Field(default=None, description="keyword to search in the page")]
+PageKeyword = Annotated[
+    str | None, 
+    Field(default=None, description="keyword to search in the page, if not provided, the whole page is returned")]
 PageOffsetTop = Annotated[int, Field(default=0, description="number of characters before the keyword to return in the response")]
 PageStart = Annotated[
     int, 
     Field(default=0, description="start of the number of characters to search from")]
-PageLimit = Annotated[int, Field(default=100, description="limit of the number of characters to return in the response")]
+PageLimit = Annotated[
+    int, 
+    Field(default=1000, description="limit of the number of characters to return in the response, set to 0 if no limit is desired")]
 
 def _omit_none(**kwargs: Any) -> dict[str, Any]:
     return {key: value for key, value in kwargs.items() if value is not None}
 
 def _search_keyword(html: str, keyword: PageKeyword, offsetTop: PageOffsetTop, start: PageStart, limit: PageLimit) -> str:
+    if limit == 0:
+        limit = len(html)
     if keyword is not None:
         index = html.find(keyword, start)
-        if index != -1:
-            start = index - offsetTop
-            end = index + len(keyword) + limit
-            return html[start:end]
+        if index == -1:
+            return "Aucun mot clé trouvé"
+        start = index - offsetTop
+        end = index + len(keyword) + limit
+        return html[start:end]
     end = min(len(html), start + limit)
     return html[start:end]
 
@@ -487,7 +494,7 @@ def register_tools(mcp_server: Any, client_rest: ClientRest) -> None:
         keyword: PageKeyword = None,
         offsetTop: PageOffsetTop = 0,
         start: PageStart = 0,
-        limit: PageLimit = 100,
+        limit: PageLimit = 1000,
     ) -> str:
         try:
             html = client_rest.execute(