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

fetchCsdnArticle

Extract complete article content from CSDN post URLs. Simplify web searches by retrieving full-text data for analysis or integration without requiring API keys.

Instructions

Fetch full article content from a csdn post URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Implementation Reference

  • Core handler function that fetches CSDN article content via HTTP request with custom headers and extracts plain text using Cheerio.
    export async function fetchCsdnArticle(url: string): Promise<{ content: string }> {
    
        const response = await axios.get(url, {
            headers: {
                'Accept': '*/*',
                'Host': 'blog.csdn.net',
                'Connection': 'keep-alive',
                'Cookie': 'https_waf_cookie=771a8075-77ae-4b2cdf3bda08cd28ad372861867be773d8c1; uuid_tt_dd=10_20283045860-1751096847125-425142; dc_session_id=10_1751096847125.891975; waf_captcha_marker=318c5c7f316f665febdb746a58e039a681a94708df7a26376ed47720663cd99d',
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
            }
        });
    
        const $ = cheerio.load(response.data);
        const plainText = $('#content_views').text()
    
        return { content: plainText };
    }
  • MCP tool registration including configurable name, description, Zod input schema for URL validation, and async wrapper handler invoking the core function.
    server.tool(
        fetchCsdnToolName,
        "Fetch full article content from a csdn post URL",
        {
            url: z.string().url().refine(
                (url) => validateArticleUrl(url, 'csdn'),
                "URL must be from blog.csdn.net contains /article/details/ path"
            )
        },
        async ({url}) => {
            try {
                console.error(`Fetching CSDN article: ${url}`);
                const result = await fetchCsdnArticle(url);
    
                return {
                    content: [{
                        type: 'text',
                        text: result.content
                    }]
                };
            } catch (error) {
                console.error('Failed to fetch CSDN article:', error);
                return {
                    content: [{
                        type: 'text',
                        text: `Failed to fetch article: ${error instanceof Error ? error.message : 'Unknown error'}`
                    }],
                    isError: true
                };
            }
        }
  • Zod schema for input validation ensuring the URL is a valid CSDN article URL.
    {
        url: z.string().url().refine(
            (url) => validateArticleUrl(url, 'csdn'),
            "URL must be from blog.csdn.net contains /article/details/ path"
        )
    },
  • Helper function to validate article URLs for different sites including CSDN.
    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;
        }
    };
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