Skip to main content
Glama
SunZhi-Will

Website to Markdown MCP Server

by SunZhi-Will

fetch_website

Convert website content to Markdown format for AI processing, with automatic cleanup and ad removal.

Instructions

Fetch specified website and convert to markdown format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesWebsite URL to fetch

Implementation Reference

  • Core handler function that fetches website content, detects if it's an OpenAPI spec, processes HTML to markdown using enhancedFetcher, and returns structured data including title, markdown, summary, etc.
    async function fetchWebsiteContent(url: string): Promise<{ 
      title: string; 
      content: string; 
      markdown: string;
      wordCount?: number;
      readingTime?: number;
      summary?: string;
      language?: string;
      isOpenAPI?: boolean;
      openAPIData?: {
        spec: OpenAPISpec;
        formatted: string;
        summary: string;
        isValid: boolean;
        errors?: string[];
      };
    }> {
      try {
        console.error(`正在獲取網站: ${url}`);
        
        // 首先檢查是否是 OpenAPI 內容
        const response = await axios.get(url, {
          timeout: 30000,
          headers: {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8,application/json,application/yaml',
            'Accept-Language': 'zh-TW,zh;q=0.9,en;q=0.8',
            'Accept-Encoding': 'gzip, deflate, br',
            'Cache-Control': 'no-cache',
            'Pragma': 'no-cache'
          }
        });
        
        // Check if it's a direct OpenAPI/JSON/YAML file
        const contentType = response.headers['content-type'] || '';
        const rawContent = response.data;
        
        if (contentType.includes('application/json') || 
            contentType.includes('application/yaml') || 
            contentType.includes('text/yaml') ||
            url.endsWith('.json') || 
            url.endsWith('.yaml') || 
            url.endsWith('.yml') ||
            (typeof rawContent === 'string' && isOpenAPIContent(rawContent))) {
          
          console.error(`檢測到 OpenAPI 規範文件: ${url}`);
          
          const content = typeof rawContent === 'string' ? rawContent : JSON.stringify(rawContent, null, 2);
          const openAPIData = await parseOpenAPISpec(content);
          
          return {
            title: openAPIData.spec.info?.title || 'Unknown API',
            content: openAPIData.summary,
            markdown: openAPIData.formatted,
            isOpenAPI: true,
            openAPIData
          };
        }
        
        // 使用增強的獲取器處理一般網頁內容
        const processedContent = await enhancedFetcher.fetchAndProcess(url, {
          removeAds: true,
          removeNavigation: true,
          extractMainContent: true,
          timeout: 30000
        });
        
        console.error(`成功獲取網站: ${processedContent.title} (${processedContent.wordCount} 字, ${processedContent.readingTime} 分鐘閱讀)`);
        
        return {
          title: processedContent.title,
          content: processedContent.content.slice(0, 1000), // 限制純文本內容長度
          markdown: processedContent.markdown,
          wordCount: processedContent.wordCount,
          readingTime: processedContent.readingTime,
          summary: processedContent.summary,
          language: processedContent.language
        };
        
      } catch (error) {
        console.error(`獲取網站 ${url} 失敗:`, error);
        throw new McpError(ErrorCode.InternalError, `無法獲取網站 ${url}: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • src/index.ts:546-559 (registration)
    Tool registration in the ListTools response: defines name 'fetch_website', description, and input schema requiring 'url'.
    {
      name: 'fetch_website',
      description: 'Fetch specified website and convert to markdown format',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'Website URL to fetch'
          }
        },
        required: ['url']
      }
    },
  • Execution handler within CallToolRequestSchema: checks for 'fetch_website', validates URL argument, invokes fetchWebsiteContent, formats the response as markdown with metadata, and returns as text content.
    if (name === 'fetch_website') {
      const url = args?.url as string;
      if (!url) {
        throw new McpError(ErrorCode.InvalidParams, 'Missing required parameter: url');
      }
    
      const result = await fetchWebsiteContent(url);
      
      let output = `# ${result.title}\n\n**來源**: ${url}\n`;
      
      if (result.summary) {
        output += `**摘要**: ${result.summary}\n`;
      }
      
      if (result.readingTime) {
        output += `**預估閱讀時間**: ${result.readingTime} 分鐘\n`;
      }
      
      if (result.wordCount) {
        output += `**字數統計**: ${result.wordCount}\n`;
      }
      
      if (result.language) {
        output += `**語言**: ${result.language === 'zh' ? '中文' : '英文'}\n`;
      }
      
      if (result.isOpenAPI) {
        output += `**類型**: OpenAPI/Swagger 規範\n`;
        if (result.openAPIData?.isValid === false) {
          output += `**驗證警告**: 規範可能有問題\n`;
        }
      }
      
      output += '\n---\n\n';
      output += result.markdown;
    
      return {
        content: [
          {
            type: 'text',
            text: output
          }
        ]
      };
    }
  • Input schema definition for the fetch_website tool: object with required 'url' string property.
    inputSchema: {
      type: 'object',
      properties: {
        url: {
          type: 'string',
          description: 'Website URL to fetch'
        }
      },
      required: ['url']
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions fetching and converting to markdown but lacks details on error handling (e.g., invalid URLs, network failures), rate limits, authentication needs, or what the output looks like beyond 'markdown format'. This leaves significant gaps for a tool that interacts with external resources.

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 directly states the tool's function without unnecessary words. It is front-loaded with the core action and outcome, making it easy to parse quickly.

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

Completeness2/5

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

Given the complexity of fetching external websites (which involves network calls and potential errors) and the lack of annotations and output schema, the description is insufficient. It doesn't address behavioral aspects like error conditions, output structure, or limitations, leaving the agent with incomplete information for reliable use.

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?

The input schema has 100% description coverage, with the 'url' parameter clearly documented. The description adds no additional semantic details beyond implying the URL is for a website, which is already covered by the schema. This meets the baseline for high schema coverage, but doesn't enhance parameter understanding.

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 action ('fetch') and resource ('specified website') with the specific transformation ('convert to markdown format'), making the purpose evident. However, it doesn't explicitly differentiate from sibling tools like 'fetch_example_site' or 'fetch_test_site', which likely perform similar functions on different targets.

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 such as 'fetch_example_site' or 'fetch_test_site', nor does it mention prerequisites like internet connectivity or permissions. It only states what the tool does without contextual usage information.

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/SunZhi-Will/website-to-markdown-mcp'

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