Explorar o código

feat: 新增 get_command_log 工具并移除 set_multi_values

yangkaixiang hai 2 semanas
pai
achega
9f963db272
Modificáronse 4 ficheiros con 72 adicións e 24 borrados
  1. 1 1
      README.md
  2. 24 1
      m2_mcp/config_api.py
  3. 23 22
      m2_mcp/server.py
  4. 24 0
      scripts/smoke_test.py

+ 1 - 1
README.md

@@ -123,7 +123,7 @@ uv run python -m m2_mcp
 - `search_ai_systems`
 - `search_ai_rcmd_operations`
 - `get_ai_online_v2`
-- `set_multi_values`
+- `get_command_log`
 
 除 `project.list` 外,其他工具都必须传 `project_key`。
 

+ 24 - 1
m2_mcp/config_api.py

@@ -86,7 +86,7 @@ def search_ai_rcmd_operations(
     project_key: str,
     codes: list[str],
     end: str,
-    page_size: int = 20,
+    page_size: int = 10,
     page_num: int = 1,
     order: str = "-create_time",
 ) -> Any:
@@ -113,6 +113,29 @@ def get_ai_online_v2(project_key: str, codes: list[str]) -> Any:
     )
 
 
+def get_command_log(
+    project_key: str,
+    point_id: str,
+    begin: int,
+    end: int,
+    page_size: int = 20,
+    page_num: int = 1,
+    export: bool = False,
+) -> Any:
+    return _post_config(
+        project_key,
+        "/api/configapi/public/get_command_log",
+        {
+            "page_num": page_num,
+            "page_size": page_size,
+            "point_id": point_id,
+            "begin": begin,
+            "end": end,
+            "export": export,
+        },
+    )
+
+
 def set_multi_values(project_key: str, points: list[SetPointValueItem], from_: str = "M2_BACKEND") -> Any:
     return _post_config(
         project_key,

+ 23 - 22
m2_mcp/server.py

@@ -1,6 +1,5 @@
 from __future__ import annotations
 
-import json
 import os
 from typing import Any
 
@@ -8,11 +7,10 @@ from fastmcp import FastMCP
 
 from .auth import load_projects_config
 from .config_api import (
-    SetPointValueItem,
+    get_command_log as api_get_command_log,
     get_ai_online_v2 as api_get_ai_online_v2,
     search_ai_rcmd_operations as api_search_ai_rcmd_operations,
     search_ai_systems as api_search_ai_systems,
-    set_multi_values as api_set_multi_values,
 )
 
 
@@ -67,19 +65,6 @@ def _append_next_page_hint(payload: Any, page_num: int) -> Any:
     return payload
 
 
-def _print_set_multi_values_request(project_key: str, points: list[SetPointValueItem], from_: str) -> None:
-    print(
-        json.dumps(
-            {
-                "event": "set_multi_values",
-                "project_key": project_key,
-                "from": from_,
-                "points": points,
-            },
-            ensure_ascii=False,
-        )
-    )
-
 @mcp.tool()
 def search_ai_systems(
     project_key: str,
@@ -104,11 +89,11 @@ def search_ai_rcmd_operations(
     project_key: str,
     codes: list[str],
     end: str,
-    page_size: int = 20,
+    page_size: int = 10,
     page_num: int = 1,
     order: str = "-create_time",
 ) -> Any:
-    """Search AI strategy records by AI system code. Default page_size is 20 unless explicitly overridden. auto_exec=true means auto control, otherwise recommendation only."""
+    """Search AI strategy records by AI system code. Default page_size is 10 unless explicitly overridden. auto_exec=true means auto control, otherwise recommendation only."""
     payload = api_search_ai_rcmd_operations(
         project_key,
         codes=codes,
@@ -127,10 +112,26 @@ def get_ai_online_v2(project_key: str, codes: list[str]) -> Any:
 
 
 @mcp.tool()
-def set_multi_values(project_key: str, points: list[SetPointValueItem], from_: str = "M2_BACKEND") -> Any:
-    """Write multiple point values to upstream basedataportal."""
-    _print_set_multi_values_request(project_key, points, from_)
-    return api_set_multi_values(project_key, points=points, from_=from_)
+def get_command_log(
+    project_key: str,
+    point_id: str,
+    begin: int,
+    end: int,
+    page_size: int = 20,
+    page_num: int = 1,
+    export: bool = False,
+) -> Any:
+    """Query command delivery logs by point_id and time range. In returned data, status=1 means the point was delivered successfully."""
+    payload = api_get_command_log(
+        project_key,
+        point_id=point_id,
+        begin=begin,
+        end=end,
+        page_size=page_size,
+        page_num=page_num,
+        export=export,
+    )
+    return _append_next_page_hint(payload, page_num)
 
 
 def main() -> None:

+ 24 - 0
scripts/smoke_test.py

@@ -5,6 +5,7 @@ import json
 from typing import Any
 
 from m2_mcp.config_api import (
+    get_command_log,
     get_ai_online_v2,
     search_ai_rcmd_operations,
     search_ai_systems,
@@ -48,6 +49,15 @@ def build_parser() -> argparse.ArgumentParser:
     p.add_argument("--project-key", required=True)
     p.add_argument("--codes", nargs="+", required=True)
 
+    p = subparsers.add_parser("get-command-log")
+    p.add_argument("--project-key", required=True)
+    p.add_argument("--point-id", required=True)
+    p.add_argument("--begin", type=int, required=True)
+    p.add_argument("--end", type=int, required=True)
+    p.add_argument("--page-size", type=int, default=20)
+    p.add_argument("--page-num", type=int, default=1)
+    p.add_argument("--export", type=_parse_bool, default=False)
+
     p = subparsers.add_parser("set-multi-values")
     p.add_argument("--project-key", required=True)
     p.add_argument("--points-json", required=True)
@@ -89,6 +99,20 @@ def main() -> None:
         _print(get_ai_online_v2(args.project_key, codes=args.codes))
         return
 
+    if args.command == "get-command-log":
+        _print(
+            get_command_log(
+                args.project_key,
+                point_id=args.point_id,
+                begin=args.begin,
+                end=args.end,
+                page_size=args.page_size,
+                page_num=args.page_num,
+                export=args.export,
+            )
+        )
+        return
+
     if args.command == "set-multi-values":
         _print(set_multi_values(args.project_key, points=json.loads(args.points_json), from_=args.from_))
         return