Skip to main content
Glama
muhenan

Xiaohongshu MCP Server

by muhenan

xiaohongshu_login

Log in to Xiaohongshu accounts using browser automation with optional headless mode and custom Chrome path for account management.

Instructions

登录小红书账号

Args: headless: 是否使用无头模式,默认False(建议使用有界面模式进行扫码) chrome_path: Chrome浏览器可执行文件路径,可选

Returns: 登录结果消息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chrome_pathNo
headlessNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'xiaohongshu_login' MCP tool. It is decorated with @mcp.tool() for registration and uses type hints/docstring for schema. Orchestrates browser management and delegates login to XiaohongshuLogin class.
    @mcp.tool()
    async def xiaohongshu_login(
        headless: bool = False,
        chrome_path: Optional[str] = None
    ) -> str:
        """
        登录小红书账号
    
        Args:
            headless: 是否使用无头模式,默认False(建议使用有界面模式进行扫码)
            chrome_path: Chrome浏览器可执行文件路径,可选
    
        Returns:
            登录结果消息
        """
        try:
            logger.info("开始小红书登录流程...")
    
            # 创建浏览器管理器
            browser_manager = BrowserManager(
                headless=headless,
                chrome_path=chrome_path
            )
    
            async with browser_manager.get_page() as page:
                # 创建登录处理器
                login_handler = XiaohongshuLogin(page)
    
                # 执行登录
                success = await login_handler.login()
    
                if success:
                    logger.success("🎉 登录成功!")
                    return "✅ 小红书登录成功"
                else:
                    logger.error("❌ 登录失败")
                    return "❌ 小红书登录失败"
    
        except Exception as e:
            error_msg = f"登录过程中发生错误: {e}"
            logger.error(error_msg)
            return f"❌ {error_msg}"
  • The core login logic implementation in XiaohongshuLogin class, called by the tool handler. Handles navigation, QR code waiting, and login status detection.
    async def login(self) -> bool:
        """
        执行登录流程
    
        Returns:
            bool: 登录成功返回True,失败返回False
        """
        try:
            logger.info("开始登录流程...")
    
            # 导航到小红书探索页,这会触发登录弹窗
            await self.page.goto(self.base_url)
            await self.page.wait_for_load_state("networkidle")
    
            # 等待2秒让页面完全加载
            await asyncio.sleep(2)
    
            # 检查是否已经登录
            if await self.check_login_status():
                logger.info("已经处于登录状态,无需重新登录")
                return True
    
            logger.info("等待用户扫码登录...")
            logger.info("请在浏览器中扫描二维码完成登录")
    
            # 等待登录成功的元素出现,最多等待5分钟
            try:
                await self.page.wait_for_selector(
                    self.login_indicator,
                    timeout=300000  # 5分钟超时
                )
                logger.success("🎉 检测到登录成功!正在保存登录状态...")
                return True
    
            except PlaywrightTimeoutError:
                logger.error("❌ 登录超时,请检查是否完成扫码")
                return False
    
        except Exception as e:
            logger.error(f"登录过程中出错: {e}")
            return False
  • Helper method to check login status, used within the login process.
    async def check_login_status(self) -> bool:
        """
        检查登录状态
    
        Returns:
            bool: True表示已登录,False表示未登录
        """
        try:
            logger.info("正在检查登录状态...")
    
            # 导航到小红书探索页,使用更短的超时时间
            await self.page.goto(self.base_url, timeout=15000)
    
            # 只等待domcontentloaded,不等待networkidle
            await self.page.wait_for_load_state("domcontentloaded")
    
            # 等待页面基本元素加载
            await asyncio.sleep(2)
    
            # 尝试多种方式检查登录状态
            return await self._check_login_with_multiple_methods()
    
        except Exception as e:
            logger.error(f"检查登录状态时出错: {e}")
            return False
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions logging in and implies browser automation (via headless mode and Chrome path), but lacks critical details: what authentication method is used (e.g., QR code scanning as hinted, password input), whether it requires user interaction, potential side effects (e.g., session creation, cookies), error handling, or rate limits. This is a significant gap for a login tool with zero annotation coverage.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded with the main purpose first, followed by parameter details. It uses minimal sentences that earn their place by explaining the tool and parameters. However, the structure could be slightly improved by integrating the parameter explanations more seamlessly, but it remains efficient with zero waste.

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

Completeness3/5

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

Given the complexity (login operation with browser automation), no annotations, and an output schema exists (implied by 'Returns: 登录结果消息'), the description is partially complete. It covers the basic purpose and parameters but lacks behavioral context (e.g., how login works, session management) and doesn't leverage the output schema to explain return values. For a tool with 2 parameters and no annotations, it should do more to be fully helpful.

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?

Schema description coverage is 0%, so the description must compensate. It adds meaning for both parameters: 'headless' is explained as controlling headless mode with a default and suggestion, and 'chrome_path' as an optional Chrome executable path. However, it doesn't cover parameter interactions (e.g., if headless=true affects chrome_path usage) or provide examples, leaving some ambiguity. With 2 parameters partially documented, this meets the baseline for low coverage.

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

Purpose4/5

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

The description clearly states the tool's purpose as '登录小红书账号' (login to Xiaohongshu account), which is a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'xiaohongshu_check_status' (which likely checks login status) or 'xiaohongshu_publish' (which likely posts content), though the login function is reasonably distinct by nature.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., whether an account is needed), when to use it relative to siblings (e.g., login before publishing), or any exclusions. The only contextual note is a suggestion for headless mode, which is parameter-specific, not usage guidance.

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/muhenan/xiaohongshu-mcp-python'

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