Skip to main content
Glama

codewiki_fetch_repo

Retrieve AI-generated wiki documentation for open-source repositories to access structured project information and documentation.

Instructions

Fetch generated wiki content for a repository from codewiki.google

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repoYes
modeNoaggregate

Implementation Reference

  • Main tool handler function that processes the codewiki_fetch_repo request, validates input, resolves the repository, fetches wiki content from CodeWiki, and returns formatted output based on mode (aggregate or pages).
    async (rawInput) => {
      const parsed = FetchRepoInput.safeParse(rawInput)
      if (!parsed.success) {
        return {
          content: [{ type: 'text', text: `Invalid arguments: ${parsed.error.message}` }],
          isError: true,
        }
      }
    
      try {
        const { repo, mode } = parsed.data
        const resolved = await resolveRepoInput(repo, config)
        const { data: result, meta } = await client.fetchRepository(resolved.repoUrl)
    
        if (mode === 'pages') {
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({
                repo: result.repo,
                commit: result.commit,
                canonicalUrl: result.canonicalUrl,
                pages: result.sections.map(section => ({
                  title: section.title,
                  level: section.level,
                  anchor: section.anchor,
                  markdown: section.markdown,
                  diagramCount: section.diagramCount,
                })),
                meta,
              }, null, 2),
            }],
          }
        }
    
        const aggregate = result.sections.map(toSectionMarkdown).join('\n\n')
        const preface = [
          `Repository: ${result.repo}`,
          `Commit: ${result.commit ?? 'unknown'}`,
          result.canonicalUrl ? `Canonical URL: ${result.canonicalUrl}` : null,
          `Response: ${meta.totalBytes} bytes in ${meta.totalElapsedMs}ms`,
        ].filter(Boolean).join('\n')
    
        return {
          content: [{
            type: 'text',
            text: `${preface}\n\n${aggregate}`.trim(),
          }],
        }
      } catch (err) {
        return formatMcpError(err)
      }
    },
  • Tool registration function that registers codewiki_fetch_repo with the MCP server, defining the tool name, description, input schema, and handler.
    export function registerFetchRepoTool(mcp: McpServer, client: CodeWikiClient, config?: CodeWikiConfig): void {
      mcp.tool(
        'codewiki_fetch_repo',
        'Fetch generated wiki content for a repository from codewiki.google',
        FetchRepoInput.shape,
        async (rawInput) => {
          const parsed = FetchRepoInput.safeParse(rawInput)
          if (!parsed.success) {
            return {
              content: [{ type: 'text', text: `Invalid arguments: ${parsed.error.message}` }],
              isError: true,
            }
          }
    
          try {
            const { repo, mode } = parsed.data
            const resolved = await resolveRepoInput(repo, config)
            const { data: result, meta } = await client.fetchRepository(resolved.repoUrl)
    
            if (mode === 'pages') {
              return {
                content: [{
                  type: 'text',
                  text: JSON.stringify({
                    repo: result.repo,
                    commit: result.commit,
                    canonicalUrl: result.canonicalUrl,
                    pages: result.sections.map(section => ({
                      title: section.title,
                      level: section.level,
                      anchor: section.anchor,
                      markdown: section.markdown,
                      diagramCount: section.diagramCount,
                    })),
                    meta,
                  }, null, 2),
                }],
              }
            }
    
            const aggregate = result.sections.map(toSectionMarkdown).join('\n\n')
            const preface = [
              `Repository: ${result.repo}`,
              `Commit: ${result.commit ?? 'unknown'}`,
              result.canonicalUrl ? `Canonical URL: ${result.canonicalUrl}` : null,
              `Response: ${meta.totalBytes} bytes in ${meta.totalElapsedMs}ms`,
            ].filter(Boolean).join('\n')
    
            return {
              content: [{
                type: 'text',
                text: `${preface}\n\n${aggregate}`.trim(),
              }],
            }
          } catch (err) {
            return formatMcpError(err)
          }
        },
      )
    }
  • Input validation schema for codewiki_fetch_repo tool using Zod, defining repo (required string) and mode (enum: 'aggregate' or 'pages', default 'aggregate').
    export const FetchRepoInput = z.object({
      repo: z.string().min(1),
      mode: z.enum(['aggregate', 'pages']).default('aggregate'),
    })
  • Local helper function that converts a WikiSection to markdown format with appropriate heading level.
    function toSectionMarkdown(section: WikiSection): string {
      const depth = Math.max(1, Math.min(6, section.level))
      const heading = '#'.repeat(depth)
      const body = section.markdown || section.summary || ''
      return `${heading} ${section.title}\n\n${body}`.trim()
    }
  • Helper function that resolves repository input (URL, owner/repo, or natural language) to a normalized repository format with proper URL construction.
    export async function resolveRepoInput(
      input: string,
      config?: Pick<CodeWikiConfig, 'githubToken' | 'requestTimeout'>,
    ): Promise<NormalizedRepo> {
      const raw = input.trim()
    
      // URL → sync
      if (/^https?:\/\//i.test(raw)) {
        return normalizeRepoInput(raw)
      }
    
      // owner/repo → sync
      const parts = raw.replace(/^\/+|\/+$/g, '').split('/').filter(Boolean)
      if (parts.length === 2) {
        return normalizeRepoInput(raw)
      }
    
      // Natural language → NLP → GitHub search → normalize
      const keyword = extractKeyword(raw) ?? raw
      const fullName = await resolveRepoFromGitHub(keyword, config ?? { requestTimeout: 30_000 })
      return normalizeRepoInput(fullName)
    }

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/izzzzzi/codewiki-mcp'

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