Skip to main content
Glama
regenrek
by regenrek

deepwiki_fetch

Fetch and convert Deepwiki documentation repositories into Markdown format for easy access and integration.

Instructions

Fetch a deepwiki.com repo and return Markdown

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesshould be a URL, owner/repo name (e.g. "vercel/ai"), a two-word "owner repo" form (e.g. "vercel ai"), or a single library keyword
maxDepthNoCan fetch a single site => maxDepth 0 or multiple/all sites => maxDepth 1
modeNoaggregate
verboseNo

Implementation Reference

  • The handler function that normalizes the input URL, performs validation, crawls the deepwiki.com repository using the crawl utility, converts HTML pages to Markdown, and returns the content as an array of text blocks.
    async (input) => {
      // Normalize the URL to support short forms
      const normalizedInput = { ...input }
      if (typeof normalizedInput.url === 'string') {
        let url = normalizedInput.url.trim()
    
        // Only transform when it is not already an explicit HTTP(S) URL
        if (!/^https?:\/\//.test(url)) {
          // Check if the URL is already in the owner/repo format
          if (/^[^/]+\/[^/]+$/.test(url)) {
            // Already in owner/repo format, keep it as is
            // Just prefix with deepwiki.com
          }
          // Single word/term with no slash - process differently
          else if (/^[^/]+$/.test(url)) {
            // For single words, first try to extract a meaningful keyword if the input has spaces
            if (url.includes(' ')) {
              const extracted = extractKeyword(url)
              if (extracted) {
                url = extracted
              }
            }
    
            // Try to resolve the single term against GitHub
            try {
              const repo = await resolveRepo(url) // "owner/repo"
              url = repo
            }
            catch {
              // Fallback to previous behaviour for backward compatibility
              url = `defaultuser/${url}` // TODO: replace defaultuser logic
            }
          }
          // Other formats (phrases with slashes that don't match owner/repo)
          else {
            // Try to extract a library keyword from a free form phrase
            const extracted = extractKeyword(url)
            if (extracted) {
              // Resolve the extracted keyword
              try {
                const repo = await resolveRepo(extracted)
                url = repo
              } catch {
                url = `defaultuser/${extracted}`
              }
            }
          }
    
          // At this point url should be "owner/repo"
          url = `https://deepwiki.com/${url}`
        }
    
        normalizedInput.url = url
      }
      const parse = FetchRequest.safeParse(normalizedInput)
      if (!parse.success) {
        const err: z.infer<typeof ErrorEnvelope> = {
          status: 'error',
          code: 'VALIDATION',
          message: 'Request failed schema validation',
          details: parse.error.flatten(),
        }
        return err
      }
    
      const req = parse.data
      const root = new URL(req.url)
    
      if (req.maxDepth > 1) {
        const err: z.infer<typeof ErrorEnvelope> = {
          status: 'error',
          code: 'VALIDATION',
          message: 'maxDepth > 1 is not allowed',
        }
        return err
      }
    
      if (root.hostname !== 'deepwiki.com') {
        const err: z.infer<typeof ErrorEnvelope> = {
          status: 'error',
          code: 'DOMAIN_NOT_ALLOWED',
          message: 'Only deepwiki.com domains are allowed',
        }
        return err
      }
    
      // Progress emitter
      function emitProgress(e: any) {
        // Progress reporting is not supported in this context because McpServer does not have a sendEvent method.
      }
    
      const crawlResult = await crawl({
        root,
        maxDepth: req.maxDepth,
        emit: emitProgress,
        verbose: req.verbose,
      })
    
      // Convert each page
      const pages = await Promise.all(
        Object.entries(crawlResult.html).map(async ([path, html]) => ({
          path,
          markdown: await htmlToMarkdown(html, req.mode),
        })),
      )
    
      return {
        content: pages.map(page => ({
          type: 'text',
          text: `# ${page.path}\n\n${page.markdown}`,
        })),
      }
    },
  • Zod schema defining the input parameters for the deepwiki_fetch tool: url, maxDepth, mode, and verbose.
    export const FetchRequest = z.object({
      /** Deepwiki repo URL, eg https://deepwiki.com/user/repo */
      url: z.string().describe('should be a URL, owner/repo name (e.g. "vercel/ai"), a two-word "owner repo" form (e.g. "vercel ai"), or a single library keyword'),
      /** Crawl depth limit: 0 means only the root page */
      maxDepth: z.number().int().min(0).max(1).default(1).describe('Can fetch a single site => maxDepth 0 or multiple/all sites => maxDepth 1'),
      /** Conversion mode */
      mode: ModeEnum.default('aggregate'),
      /** Verbose logging flag */
      verbose: z.boolean().default(false),
    })
  • The deepwikiTool function that registers the 'deepwiki_fetch' tool with the MCP context using mcp.tool, providing name, description, input schema, and handler.
    export function deepwikiTool({ mcp }: McpToolContext) {
      mcp.tool(
        'deepwiki_fetch',
        'Fetch a deepwiki.com repo and return Markdown',
        FetchRequest.shape,
        async (input) => {
          // Normalize the URL to support short forms
          const normalizedInput = { ...input }
          if (typeof normalizedInput.url === 'string') {
            let url = normalizedInput.url.trim()
    
            // Only transform when it is not already an explicit HTTP(S) URL
            if (!/^https?:\/\//.test(url)) {
              // Check if the URL is already in the owner/repo format
              if (/^[^/]+\/[^/]+$/.test(url)) {
                // Already in owner/repo format, keep it as is
                // Just prefix with deepwiki.com
              }
              // Single word/term with no slash - process differently
              else if (/^[^/]+$/.test(url)) {
                // For single words, first try to extract a meaningful keyword if the input has spaces
                if (url.includes(' ')) {
                  const extracted = extractKeyword(url)
                  if (extracted) {
                    url = extracted
                  }
                }
    
                // Try to resolve the single term against GitHub
                try {
                  const repo = await resolveRepo(url) // "owner/repo"
                  url = repo
                }
                catch {
                  // Fallback to previous behaviour for backward compatibility
                  url = `defaultuser/${url}` // TODO: replace defaultuser logic
                }
              }
              // Other formats (phrases with slashes that don't match owner/repo)
              else {
                // Try to extract a library keyword from a free form phrase
                const extracted = extractKeyword(url)
                if (extracted) {
                  // Resolve the extracted keyword
                  try {
                    const repo = await resolveRepo(extracted)
                    url = repo
                  } catch {
                    url = `defaultuser/${extracted}`
                  }
                }
              }
    
              // At this point url should be "owner/repo"
              url = `https://deepwiki.com/${url}`
            }
    
            normalizedInput.url = url
          }
          const parse = FetchRequest.safeParse(normalizedInput)
          if (!parse.success) {
            const err: z.infer<typeof ErrorEnvelope> = {
              status: 'error',
              code: 'VALIDATION',
              message: 'Request failed schema validation',
              details: parse.error.flatten(),
            }
            return err
          }
    
          const req = parse.data
          const root = new URL(req.url)
    
          if (req.maxDepth > 1) {
            const err: z.infer<typeof ErrorEnvelope> = {
              status: 'error',
              code: 'VALIDATION',
              message: 'maxDepth > 1 is not allowed',
            }
            return err
          }
    
          if (root.hostname !== 'deepwiki.com') {
            const err: z.infer<typeof ErrorEnvelope> = {
              status: 'error',
              code: 'DOMAIN_NOT_ALLOWED',
              message: 'Only deepwiki.com domains are allowed',
            }
            return err
          }
    
          // Progress emitter
          function emitProgress(e: any) {
            // Progress reporting is not supported in this context because McpServer does not have a sendEvent method.
          }
    
          const crawlResult = await crawl({
            root,
            maxDepth: req.maxDepth,
            emit: emitProgress,
            verbose: req.verbose,
          })
    
          // Convert each page
          const pages = await Promise.all(
            Object.entries(crawlResult.html).map(async ([path, html]) => ({
              path,
              markdown: await htmlToMarkdown(html, req.mode),
            })),
          )
    
          return {
            content: pages.map(page => ({
              type: 'text',
              text: `# ${page.path}\n\n${page.markdown}`,
            })),
          }
        },
      )
    }
  • src/index.ts:30-30 (registration)
    Top-level invocation of deepwikiTool in the main server setup to register the tool with the MCP server instance.
    deepwikiTool({ mcp } as McpToolContext)
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 fetching and returning Markdown but omits critical details like authentication requirements, rate limits, error handling, or whether this is a read-only operation. For a tool with no annotation coverage, this is insufficient.

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 extremely concise—a single sentence that directly states the tool's purpose. Every word earns its place, with no unnecessary elaboration. It's front-loaded and efficiently communicates the core functionality.

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 tool's complexity (4 parameters, 50% schema coverage, no output schema, no annotations), the description is inadequate. It doesn't explain what 'fetching' entails, how the Markdown is structured, error conditions, or usage constraints. For a tool with significant undocumented aspects, more context is needed.

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?

Schema description coverage is 50%, with only the 'url' parameter well-documented in the schema. The description adds no parameter-specific information beyond what the schema provides. It doesn't explain the meaning of 'maxDepth', 'mode', or 'verbose' parameters, leaving gaps in 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 ('deepwiki.com repo'), and specifies the output format ('return Markdown'). It distinguishes the tool by mentioning the specific domain (deepwiki.com) and output type. However, without sibling tools, there's no explicit differentiation from alternatives.

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 other methods or tools. It lacks context about prerequisites, typical use cases, or limitations. With no sibling tools mentioned, it doesn't address alternatives within the server.

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/regenrek/deepwiki-mcp'

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