feat(lark_mcp): 更新飞书卡片消息发送工具以支持单接收者
- 将send_card_message工具从接收ID列表改为单个接收者ID - 修复test.py中导入并调用send_card_message的测试逻辑 - 新增机器人充电、终止任务、通知播放功能 - 扩展迎宾和巡逻功能参数,提供默认值和更灵活的配置 - 更新项目版本号至0.1.13和0.1.9
This commit is contained in:
@@ -52,16 +52,13 @@ tools = [
|
||||
),
|
||||
Tool(
|
||||
name="send_card_message",
|
||||
description="发送消息卡片,入参为receiver_ids、person_id和image_key",
|
||||
description="发送消息卡片,入参为receiver_id、person_id和image_key",
|
||||
inputSchema={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"receiver_ids": {
|
||||
"type": "array",
|
||||
"description": "消息接收者ID列表",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
"receiver_id": {
|
||||
"type": "string",
|
||||
"description": "消息接收者ID"
|
||||
},
|
||||
"person_id": {
|
||||
"type": "string",
|
||||
@@ -72,7 +69,7 @@ tools = [
|
||||
"description": "图片image_key"
|
||||
}
|
||||
},
|
||||
"required": ["image_key"]
|
||||
"required": ["receiver_id", "image_key"]
|
||||
}
|
||||
),
|
||||
Tool(
|
||||
@@ -1766,18 +1763,7 @@ def send_card_message(token: str, receiver_id: str, person_id: str, image_key: s
|
||||
return message_id
|
||||
|
||||
|
||||
def send_card_messages(token: str, receiver_ids: List[str], person_id: str, image_key: str) -> str:
|
||||
if not receiver_ids:
|
||||
raise ValueError("missing receiver_ids")
|
||||
message_ids = []
|
||||
for receiver_id in receiver_ids:
|
||||
normalized_receiver_id = str(receiver_id).strip()
|
||||
if not normalized_receiver_id:
|
||||
continue
|
||||
message_ids.append(send_card_message(token, normalized_receiver_id, person_id, image_key))
|
||||
if not message_ids:
|
||||
raise ValueError("missing receiver_ids")
|
||||
return json.dumps(message_ids, ensure_ascii=False)
|
||||
|
||||
|
||||
|
||||
async def handle_call_tool(name: str, arguments: Dict[str, object], token: str) -> List[TextContent]:
|
||||
@@ -1816,16 +1802,13 @@ async def handle_call_tool(name: str, arguments: Dict[str, object], token: str)
|
||||
result = upload_image_by_file(token, image_source, image_type)
|
||||
elif name == "send_card_message":
|
||||
image_key = str(arguments.get("image_key", "")).strip()
|
||||
receiver_ids = arguments.get("receiver_ids")
|
||||
receiver_id = str(arguments.get("receiver_id", "")).strip()
|
||||
person_id = str(arguments.get("person_id", "")).strip()
|
||||
if not receiver_id:
|
||||
raise ValueError("missing receiver_id")
|
||||
if not image_key:
|
||||
raise ValueError("missing image_key")
|
||||
if not person_id:
|
||||
raise ValueError("missing person_id")
|
||||
if receiver_ids is not None:
|
||||
if not isinstance(receiver_ids, list):
|
||||
raise ValueError("receiver_ids must be a list")
|
||||
result = send_card_messages(token, receiver_ids, person_id, image_key)
|
||||
result = send_card_message(token, receiver_id, person_id, image_key)
|
||||
elif name == "send_confirmation_card":
|
||||
user_id = str(arguments.get("user_id", "")).strip()
|
||||
order_number = str(arguments.get("order_number", "")).strip()
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "lzwcai-lark-mcp"
|
||||
version = "0.1.11"
|
||||
version = "0.1.13"
|
||||
description = "Lark MCP server"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
|
||||
@@ -35,7 +35,7 @@ def main() -> None:
|
||||
mcp_module.types = types_module
|
||||
sys.modules["mcp"] = mcp_module
|
||||
sys.modules["mcp.types"] = types_module
|
||||
from lzwcai_lark_mcp.tools import send_stranger_card
|
||||
from lzwcai_lark_mcp.tools import send_card_message, send_stranger_card
|
||||
app_id = os.getenv("app_id", "")
|
||||
app_secret = os.getenv("app_secret", "")
|
||||
auth_url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
|
||||
@@ -53,6 +53,18 @@ def main() -> None:
|
||||
if not token:
|
||||
raise RuntimeError(f"lark auth response missing token: {data}")
|
||||
user_id = "gegg1d78"
|
||||
receiver_id = os.getenv("receiver_id", user_id)
|
||||
person_id = os.getenv("person_id", "")
|
||||
image_key = os.getenv("image_key", "").strip()
|
||||
if not image_key:
|
||||
raise RuntimeError("missing image_key")
|
||||
card_message_id = send_card_message(
|
||||
token,
|
||||
receiver_id,
|
||||
person_id,
|
||||
image_key
|
||||
)
|
||||
print(card_message_id)
|
||||
result = send_stranger_card(
|
||||
token,
|
||||
user_id,
|
||||
|
||||
Reference in New Issue
Block a user