Skip to main content
Glama
Aas-ee
by Aas-ee

fetchJuejinArticle

Extract full article content from Juejin (掘金) post URLs using this tool. Ideal for retrieving detailed information without requiring API keys, supported by open-webSearch's multi-engine search capabilities.

Instructions

Fetch full article content from a Juejin(掘金) post URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Implementation Reference

  • Core handler function that implements the tool logic: fetches the Juejin article HTML using axios with mobile User-Agent, parses with cheerio, tries multiple CSS selectors to extract content, falls back to body text, cleans up scripts/styles, and returns the text content.
    export async function fetchJuejinArticle(url: string): Promise<{ content: string }> {
        try {
            console.error(`🔍 Fetching Juejin article: ${url}`);
    
            const response = await axios.get(url, {
                headers: {
                    'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1',
                    'Connection': 'keep-alive',
                    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
                    'Accept-Encoding': 'gzip, deflate, br, zstd',
                    'pragma': 'no-cache',
                    'cache-control': 'no-cache',
                    'upgrade-insecure-requests': '1',
                    'sec-fetch-site': 'none',
                    'sec-fetch-mode': 'navigate',
                    'sec-fetch-user': '?1',
                    'sec-fetch-dest': 'document',
                    'accept-language': 'zh-CN,zh;q=0.9',
                    'priority': 'u=0, i'
                },
                timeout: 30000,
                decompress: true
            });
    
            const $ = cheerio.load(response.data);
    
            // 掘金文章内容的可能选择器(按优先级排序)
            const selectors = [
                '.markdown-body',
                '.article-content',
                '.content',
                '[data-v-md-editor-preview]',
                '.bytemd-preview',
                '.article-area .content',
                '.main-area .article-area',
                '.article-wrapper .content'
            ];
    
            let content = '';
    
            // 尝试多个选择器
            for (const selector of selectors) {
                console.error(`🔍 Trying selector: ${selector}`);
                const element = $(selector);
                if (element.length > 0) {
                    console.error(`✅ Found content with selector: ${selector}`);
                    // 移除脚本和样式标签
                    element.find('script, style, .code-block-extension, .hljs-ln-numbers').remove();
                    content = element.text().trim();
    
                    if (content.length > 100) { // 确保内容足够长
                        break;
                    }
                }
            }
    
            // 如果所有选择器都失败,尝试提取页面主要文本内容
            if (!content || content.length < 100) {
                console.error('⚠️ All selectors failed, trying fallback extraction');
                $('script, style, nav, header, footer, .sidebar, .comment').remove();
                content = $('body').text().trim();
            }
    
            console.error(`✅ Successfully extracted ${content.length} characters`);
            return { content };
    
        } catch (error) {
            console.error('❌ 获取掘金文章失败:', error);
            throw new Error(`获取掘金文章失败: ${error instanceof Error ? error.message : '未知错误'}`);
        }
    }
  • Registers the fetchJuejinArticle tool on the MCP server, providing description, input schema with URL validation, and an async wrapper handler that calls the core fetchJuejinArticle function and formats the MCP response.
    server.tool(
        fetchJuejinToolName,
        "Fetch full article content from a Juejin(掘金) post URL",
        {
            url: z.string().url().refine(
                (url) => validateArticleUrl(url, 'juejin'),
                "URL must be from juejin.cn and contain /post/ path"
            )
        },
        async ({url}) => {
            try {
                console.error(`Fetching Juejin article: ${url}`);
                const result = await fetchJuejinArticle(url);
    
                return {
                    content: [{
                        type: 'text',
                        text: result.content
                    }]
                };
            } catch (error) {
                console.error('Failed to fetch Juejin article:', error);
                return {
                    content: [{
                        type: 'text',
                        text: `Failed to fetch article: ${error instanceof Error ? error.message : 'Unknown error'}`
                    }],
                    isError: true
                };
            }
        }
    );
  • Zod input schema for the tool: validates that the URL is from juejin.cn and contains /post/ path using the validateArticleUrl helper.
        url: z.string().url().refine(
            (url) => validateArticleUrl(url, 'juejin'),
            "URL must be from juejin.cn and contain /post/ path"
        )
    },
  • Helper function validateArticleUrl used in schema to check if provided URL is a valid Juejin post (hostname juejin.cn and path includes /post/).
    const validateArticleUrl = (url: string, type: 'linuxdo' | 'csdn' | 'juejin'): boolean => {
        try {
            const urlObj = new URL(url);
    
            switch (type) {
                case 'linuxdo':
                    return urlObj.hostname === 'linux.do' && url.includes('.json');
                case 'csdn':
                    return urlObj.hostname === 'blog.csdn.net' && url.includes('/article/details/');
                case 'juejin':
                    return urlObj.hostname === 'juejin.cn' && url.includes('/post/');
                default:
                    return false;
            }
        } catch {
            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 'fetch full article content,' which implies a read-only operation, but does not disclose other traits such as authentication needs, rate limits, error handling, or what 'full content' entails (e.g., includes images, metadata). This leaves significant gaps for an agent to understand the tool's behavior.

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, efficient sentence that is front-loaded with the core purpose. There is no wasted text, and every word contributes directly to understanding the tool's function, making it highly concise and well-structured.

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 tool's low complexity (one parameter, no output schema, no annotations), the description is minimally complete. It covers the basic purpose and parameter semantics but lacks details on behavioral aspects like output format, error cases, or usage constraints, which could hinder an agent's ability to use it correctly in varied contexts.

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

Parameters4/5

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

The description adds meaning beyond the input schema by specifying that the 'url' parameter must be a 'Juejin post URL,' which clarifies the expected content type. With schema description coverage at 0% and only one parameter, this compensation is effective, though it could further detail URL format or validation rules.

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 specific action ('fetch full article content') and resource ('from a Juejin post URL'), distinguishing it from sibling tools like fetchCsdnArticle or fetchGithubReadme by specifying the Juejin platform. It uses precise verbs and identifies the exact resource type.

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

Usage Guidelines3/5

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

The description implies usage context by specifying 'Juejin post URL,' suggesting it should be used for articles from that platform. However, it does not explicitly state when to use this tool versus alternatives like search or other fetch tools, nor does it provide exclusions or prerequisites for usage.

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

Related 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/Aas-ee/open-webSearch'

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