Skip to main content
Glama
lm203688

feishu-mcp-server

by lm203688

send_message

Send messages to Feishu group chats by providing chat ID and text. Requires disabling read-only mode for execution.

Instructions

发送消息到飞书群聊(需要关闭只读模式)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_idYes群聊ID
textYes消息内容

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler for 'send_message'. Decorated with @mcp.tool(), it accepts chat_id and text, checks if messaging is enabled, calls the client's send_message, and returns the result as JSON. Handles PermissionError (read-only mode) and generic exceptions.
    @mcp.tool()
    def send_message(chat_id: str, text: str) -> str:
        """发送消息到飞书群聊(需要关闭只读模式)
    
        Args:
            chat_id: 群聊ID
            text: 消息内容
        """
        if not config.enable_message:
            return json.dumps({"error": "消息功能未启用"}, ensure_ascii=False)
        try:
            result = client.send_message(chat_id, text)
            return json.dumps(result, ensure_ascii=False, indent=2, default=str)
        except PermissionError as e:
            return json.dumps({"error": str(e)}, ensure_ascii=False)
        except Exception as e:
            return json.dumps({"error": str(e)}, ensure_ascii=False)
  • The FeishuClient.send_message() method that actually makes the API call. Checks read_only mode and allowed_chats permissions, then POSTs to /im/v1/messages with receive_id_type=chat_id to send a text message to the specified chat.
    def send_message(
        self, chat_id: str, text: str, msg_type: str = "text"
    ) -> dict[str, Any]:
        """发送消息到群聊"""
        if self.config.read_only:
            raise PermissionError("只读模式下禁止发送消息")
        if self.config.allowed_chats and chat_id not in self.config.allowed_chats:
            raise PermissionError(f"群聊 '{chat_id}' 不在允许发送的列表中")
    
        return self._request(
            "POST", "/im/v1/messages",
            params={"receive_id_type": "chat_id"},
            json_data={
                "receive_id": chat_id,
                "msg_type": msg_type,
                "content": f'{{"text":"{text}"}}' if msg_type == "text" else text,
            },
        )
  • The @mcp.tool() decorator on line 109 registers 'send_message' as an MCP tool with the FastMCP server.
    @mcp.tool()
    def send_message(chat_id: str, text: str) -> str:
  • FeishuConfig schema defines the settings relevant to send_message: enable_message toggle, read_only flag, and allowed_chats whitelist.
    class FeishuConfig(BaseSettings):
        """飞书应用配置"""
    
        app_id: str = Field(default="", description="飞书应用App ID")
        app_secret: str = Field(default="", description="飞书应用App Secret")
    
        # 功能开关
        enable_doc: bool = Field(default=True, description="启用文档读取")
        enable_message: bool = Field(default=True, description="启用消息发送")
        enable_calendar: bool = Field(default=True, description="启用日历查询")
        enable_sheet: bool = Field(default=True, description="启用电子表格")
    
        # 安全配置
        read_only: bool = Field(default=True, description="只读模式(禁止发送消息等写操作)")
        allowed_chats: Optional[list[str]] = Field(
            default=None, description="允许发送消息的群聊ID列表"
        )
    
        # API配置
        base_url: str = Field(default="https://open.feishu.cn/open-apis", description="飞书API基础URL")
        token_cache_seconds: int = Field(default=3600, description="Token缓存时间(秒)")
  • Test class TestMessagePermission verifying that send_message is blocked in read-only mode and for unallowed chats.
    class TestMessagePermission:
        def test_send_blocked_in_readonly(self):
            config = FeishuConfig(app_id="test", app_secret="secret", read_only=True)
            client = FeishuClient(config)
            with pytest.raises(PermissionError, match="只读"):
                client.send_message("chat_id", "hello")
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the burden of disclosing behavior. It mentions the write operation and a prerequisite, but does not detail other behaviors like rate limits, error handling, or return values. The presence of an output schema partially compensates.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence that conveys purpose and a prerequisite. It is concise and front-loaded with the key information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (two primitive parameters, output schema present) and the description's clear statement of purpose and a prerequisite, it is mostly complete. A bit more about the expected response could be included, but the output schema likely covers that.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Both parameters are described in the input schema (100% coverage). The description does not add additional meaning to the parameters beyond what the schema provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (send) and the resource (message to Feishu group chat). It also includes a prerequisite. It is easily distinguishable from sibling tools, which are all about getting or listing data.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description mentions a prerequisite (need to turn off read-only mode), which guides usage. However, it does not compare to alternative tools or explicitly say when not to use it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lm203688/feishu-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server