WORLDBOOK

Worldbooks | WebMCP | Search | Submit WebMCP

toutiao WebMCP

Browser tool configuration for toutiao

URL Pattern: ^https?://mp\.toutiao\.com/.*$
Allowed Extra Domains: so.toutiao.com, toutiao.com

Tools (3)

insert_article()

Insert content into Toutiao (头条号) article editor

Parameters

title string - Article title
content string required - Article content (HTML)

JavaScript Handler

(params) => {
  // Set title
  if (params.title) {
    const titleInput = document.querySelector('input[placeholder*="标题"]') || document.querySelector('.title-input input');
    if (titleInput) {
      titleInput.value = params.title;
      titleInput.dispatchEvent(new Event('input', { bubbles: true }));
    }
  }
  // Find editor
  const editor = document.querySelector('.ql-editor') || document.querySelector('[contenteditable="true"]');
  if (!editor) {
    return { success: false, message: 'Editor not found. Open mp.toutiao.com article editor first' };
  }
  editor.innerHTML = params.content;
  editor.dispatchEvent(new Event('input', { bubbles: true }));
  return { success: true, message: 'Content inserted into Toutiao editor' };
}

toutiao_hot()

今日头条热榜

Parameters

count string - 返回条数 (默认 20, 最多 50)

JavaScript Handler

(params) => {
  const run = async function(args) {

      const count = Math.min(parseInt(args.count) || 20, 50);

      const resp = await fetch('https://www.toutiao.com/hot-event/hot-board/?origin=toutiao_pc', {credentials: 'include'});
      if (!resp.ok) {
        // Fallback: parse hot search from homepage
        return await fallbackFromHomepage(count);
      }

      let data;
      try {
        data = await resp.json();
      } catch (e) {
        return await fallbackFromHomepage(count);
      }

      if (!data || !data.data) {
        return await fallbackFromHomepage(count);
      }

      const items = (data.data || data.fixed_top_data || []).slice(0, count).map((item, i) => ({
        rank: i + 1,
        title: item.Title || item.title || '',
        hot_value: item.HotValue || item.hot_value || 0,
        label: item.Label || item.label || '',
        url: item.Url || item.url || '',
        cluster_id: item.ClusterId || item.cluster_id || ''
      }));

      return {count: items.length, items};

      async function fallbackFromHomepage(limit) {
        const homeResp = await fetch('https://www.toutiao.com/', {credentials: 'include'});
        if (!homeResp.ok) return {error: 'HTTP ' + homeResp.status, hint: 'Open www.toutiao.com in bb-browser first'};

        const html = await homeResp.text();
        const parser = new DOMParser();
        const doc = parser.parseFromString(html, 'text/html');

        // Try to extract hot search data from SSR HTML
        const items = [];

        // Method 1: Look for hot search region text
        const allText = doc.body?.textContent || '';

        // Method 2: Parse script tags for embedded data
        const scripts = doc.querySelectorAll('script:not([src])');
        for (const script of scripts) {
          const text = script.textContent || '';
          if (text.includes('hotBoard') || text.includes('hot_board') || text.includes('HotValue')) {
            try {
              const match = text.match(/\[.*"Title".*\]/s) || text.match(/\[.*"title".*"hot_value".*\]/s);
              if (match) {
                const hotData = JSON.parse(match[0]);
                hotData.slice(0, limit).forEach((item, i) => {
                  items.push({
                    rank: i + 1,
                    title: item.Title || item.title || '',
                    hot_value: item.HotValue || item.hot_value || 0,
                    label: item.Label || item.label || '',
                    url: item.Url || item.url || '',
                    cluster_id: item.ClusterId || item.cluster_id || ''
                  });
                });
                if (items.length > 0) return {count: items.length, source: 'homepage_script', items};
              }
            } catch (e) {}
          }
        }

        // Method 3: Parse hot search links from DOM
        const hotLinks = doc.querySelectorAll('a[href*="search"], [class*="hot"] a, [class*="Hot"] a');
        for (const link of hotLinks) {
          const title = (link.textContent || '').trim();
          if (!title || title.length < 2 || title.length > 100) continue;
          if (items.some(it => it.title === title)) continue;
          items.push({
            rank: items.length + 1,
            title,
            hot_value: 0,
            label: '',
            url: link.getAttribute('href') || '',
            cluster_id: ''
          });
          if (items.length >= limit) break;
        }

        if (items.length === 0) {
          return {error: 'Could not extract hot topics', hint: 'Open www.toutiao.com in bb-browser first and make sure you are logged in'};
        }

        return {count: items.length, source: 'homepage_dom', items};
      }
  };
  return run(params || {});
}

toutiao_search()

今日头条搜索

Parameters

query string required - 搜索关键词
count string - 返回结果数量 (默认 10, 最多 20)

JavaScript Handler

🔌 Chrome MCP Server Extension

Use these tools with Claude, ChatGPT, and other AI assistants.

Get Extension →

How to Use WebMCP

WebMCP tools are designed for browser extensions or automation frameworks. The browser extension matches the current URL against the pattern and executes the JavaScript handler when the tool is invoked.

API Endpoint:

GET /api/webmcp/match?url=https://www.toutiao.com/...