Skip to main content
Glama
Ryan7t
by Ryan7t

parse_generic_link

Extract video, image, and text content from any social media share link by parsing platform-independent URLs to retrieve titles, captions, and direct media URLs.

Instructions

解析任意短视频/图文链接,直接启用 generic 兜底逻辑。

参数:
- share_link: 任意平台的分享链接或包含链接的文本(抖音/小红书亦可传入)

返回:
- 包含资源链接和信息的JSON字符串
- 输出字段与其它工具一致:platform/title/caption/url
- 调用完成后,请将结果整理为以下纯文本格式并反馈给用户(禁止使用Markdown):
  标题(如无则留空):
  文案:
  视频/图片链接:
- 请完整保留标题与文案的全部内容,不要省略或截断
- 若未能解析,将返回错误说明(可能原因:页面无直链、需要登录等)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
share_linkYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'parse_generic_link' tool, registered via @mcp.tool(). It invokes the generic media extractor and returns formatted JSON or error.
    @mcp.tool()
    def parse_generic_link(share_link: str) -> str:
        """解析任意短视频/图文链接,直接启用 generic 兜底逻辑。
    
        参数:
        - share_link: 任意平台的分享链接或包含链接的文本(抖音/小红书亦可传入)
    
        返回:
        - 包含资源链接和信息的JSON字符串
        - 输出字段与其它工具一致:platform/title/caption/url
        - 调用完成后,请将结果整理为以下纯文本格式并反馈给用户(禁止使用Markdown):
          标题(如无则留空):
          文案:
          视频/图片链接:
        - 请完整保留标题与文案的全部内容,不要省略或截断
        - 若未能解析,将返回错误说明(可能原因:页面无直链、需要登录等)
        """
        try:
            result = extract_generic_media(share_link)
            result.setdefault("fallback_reason", "generic_tool_invocation")
            return json.dumps(result, ensure_ascii=False, indent=2)
        except Exception as e:
            return json.dumps({
                "status": "error",
                "error": f"通用解析失败: {e}"
            }, ensure_ascii=False, indent=2)
  • Core helper function that performs the actual generic media extraction by fetching the page, parsing HTML with regex patterns for video URLs (og:video, etc.), and extracting title/caption.
    def extract_generic_media(share_text: str) -> Dict[str, str]:
        """尝试从任意链接中提取无水印视频信息。
    
        返回:
            dict: 包含 platform/type/url/title/caption 的基础信息。
    
        失败时抛出 ValueError,便于调用方根据需要返回原始错误。
        """
    
        share_url = _extract_first_url(share_text)
        logger.debug("[GenericExtractor] 开始解析链接: %s", share_url)
    
        response = requests.get(share_url, headers=GENERIC_HEADERS, timeout=10, allow_redirects=True)
        response.raise_for_status()
    
        final_url = response.url
        html_text = response.text
        logger.debug("[GenericExtractor] 最终地址: %s", final_url)
    
        media_url = _find_media_url(html_text)
        if not media_url:
            raise ValueError("未从页面中发现可用的视频直链")
    
        title = (
            _extract_meta(html_text, "og:title")
            or _extract_meta(html_text, "twitter:title")
            or final_url
        )
    
        caption = _extract_meta(html_text, "og:description") or _extract_meta(html_text, "description")
    
        return {
            "status": "success",
            "type": "video",
            "platform": "generic",
            "title": title.strip() if title else None,
            "caption": caption.strip() if caption else None,
            "url": media_url,
            "source_url": final_url,
        }
  • The @mcp.tool() decorator registers the parse_generic_link function as an MCP tool.
    @mcp.tool()
  • Function signature defines the input schema (share_link: str) and output (str JSON).
    def parse_generic_link(share_link: str) -> str:
Behavior4/5

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

With no annotations provided, the description carries full burden and does well. It discloses: 1) output format requirements ('整理为以下纯文本格式并反馈给用户'), 2) content preservation rules ('完整保留标题与文案的全部内容'), 3) error conditions ('若未能解析,将返回错误说明'), and 4) formatting restrictions ('禁止使用Markdown'). It doesn't mention rate limits or authentication needs, but covers key behavioral aspects.

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 well-structured with clear sections (purpose, parameters, returns, formatting instructions). Every sentence adds value: the opening states purpose, parameter section explains input, return section details output format and formatting rules. It could be slightly more concise in the formatting instructions but remains efficient.

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

Completeness5/5

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

Given 1 parameter with 0% schema coverage and no annotations, the description provides complete context. It explains what the tool does, when to use it, parameter semantics, output format, formatting requirements, content handling rules, and error conditions. The existence of an output schema means it doesn't need to detail return structure, and it appropriately focuses on usage context.

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

Parameters5/5

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

With 0% schema description coverage (schema only has title 'Share Link'), the description fully compensates. It explains the parameter accepts '任意平台的分享链接或包含链接的文本' (any platform's share link or text containing links) and specifically mentions '抖音/小红书亦可传入' (Douyin/Xiaohongshu can also be passed). This adds crucial semantic context beyond the bare schema.

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 tool's purpose: '解析任意短视频/图文链接' (parse any short video/image-text link) with 'generic 兜底逻辑' (generic fallback logic). It specifically distinguishes from siblings by handling '任意平台' (any platform) including Douyin/Xiaohongshu, unlike the sibling tools which are platform-specific (extract_douyin_text, parse_douyin_link, parse_xhs_link).

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

Usage Guidelines5/5

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

The description provides explicit usage guidance: '直接启用 generic 兜底逻辑' (directly enable generic fallback logic), implying this should be used as a fallback when platform-specific tools aren't appropriate. It mentions specific platforms (抖音/小红书) that can be handled, and the sibling tool names clearly show this is the generic alternative to platform-specific parsers.

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/Ryan7t/wanyi-watermark'

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