Skip to main content
Glama

Get Package README

get_readme_data

Extract README file content from GitHub repositories for npm packages to understand functionality and usage details.

Instructions

Get README file content from a package's GitHub repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageNameYes
versionNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
readmeYes
packageYes
versionYes
repositoryYes
descriptionYes

Implementation Reference

  • The core handler function for the 'get_readme_data' tool. It fetches package metadata from npm registry, validates with schema, extracts GitHub repository URL, fetches the README.md content, formats the response with text and structured output, and handles errors appropriately.
    async ({ packageName, version }) => {
      try {
        const rawData = await fetchPackageData(packageName, version);
        const parseResult = NpmRegistryResponseSchema.safeParse(rawData);
    
        if (!parseResult.success) {
          throw new Error(
            `Invalid package data structure: ${parseResult.error.message}`
          );
        }
    
        const data = parseResult.data;
        const { url: repositoryUrl } = data.repository;
    
        const readme = await fetchReadmeFromGitHub(repositoryUrl);
    
        const output = {
          package: data.name,
          version: data.version,
          description: data.description || "N/A",
          repository: repositoryUrl,
          readme,
        };
    
        return {
          content: [
            {
              type: "text",
              text: `Package: ${data.name}\nVersion: ${
                data.version
              }\nDescription: ${
                data.description || "N/A"
              }\nRepository: ${repositoryUrl}\n\nREADME:\n${readme}`,
            },
          ],
          structuredContent: output,
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error fetching package ${packageName}: ${
                error instanceof Error ? error.message : "Unknown error"
              }`,
            },
          ],
          isError: true,
        };
      }
    }
  • src/index.ts:196-264 (registration)
    The registration of the 'get_readme_data' tool using server.registerTool, including inline input/output schemas and the handler function.
    server.registerTool(
      "get_readme_data",
      {
        title: "Get Package README",
        description: "Get README file content from a package's GitHub repository",
        inputSchema: {
          packageName: z.string(),
          version: z.string().optional(),
        },
        outputSchema: {
          package: z.string(),
          version: z.string(),
          description: z.string(),
          repository: z.string(),
          readme: z.string(),
        },
      },
      async ({ packageName, version }) => {
        try {
          const rawData = await fetchPackageData(packageName, version);
          const parseResult = NpmRegistryResponseSchema.safeParse(rawData);
    
          if (!parseResult.success) {
            throw new Error(
              `Invalid package data structure: ${parseResult.error.message}`
            );
          }
    
          const data = parseResult.data;
          const { url: repositoryUrl } = data.repository;
    
          const readme = await fetchReadmeFromGitHub(repositoryUrl);
    
          const output = {
            package: data.name,
            version: data.version,
            description: data.description || "N/A",
            repository: repositoryUrl,
            readme,
          };
    
          return {
            content: [
              {
                type: "text",
                text: `Package: ${data.name}\nVersion: ${
                  data.version
                }\nDescription: ${
                  data.description || "N/A"
                }\nRepository: ${repositoryUrl}\n\nREADME:\n${readme}`,
              },
            ],
            structuredContent: output,
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error fetching package ${packageName}: ${
                  error instanceof Error ? error.message : "Unknown error"
                }`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • Zod schema used in the handler to validate the npm registry response data before extracting repository URL.
    const NpmRegistryResponseSchema = z.object({
      name: z.string(),
      version: z.string(),
      description: z.string().optional(),
      repository: z.object({
        type: z.string(),
        url: z.string(),
      }),
    });
  • Helper function called by the handler to fetch package metadata from npm registry for the specified package and version (or latest).
    async function fetchPackageData(
      packageName: string,
      version?: string
    ): Promise<any> {
      const versionPath = version || "latest";
      const encodedPackageName = encodeURIComponent(packageName);
      const response = await fetch(
        `https://registry.npmjs.org/${encodedPackageName}/${versionPath}`
      );
    
      if (!response.ok) {
        throw new Error(
          `Failed to fetch package ${packageName}: ${response.statusText}`
        );
      }
    
      return await response.json();
    }
  • Helper function called by the handler to fetch README.md content from the package's GitHub repository, trying main/master branches first then default.
    async function fetchReadmeFromGitHub(repositoryUrl: string): Promise<string> {
      const githubUrl = new URL(repositoryUrl.replace("git+", ""));
      const repositoryPath = githubUrl.pathname.substring(1).replace(".git", "");
    
      // Try branches in order: main, master, default
      const branches = ["main", "master"];
    
      for (const branch of branches) {
        const readmeUrl = `https://raw.githubusercontent.com/${repositoryPath}/refs/heads/${branch}/README.md`;
        const readmeResponse = await fetch(readmeUrl);
    
        if (readmeResponse.ok) {
          return await readmeResponse.text();
        }
      }
    
      // If both branches fail, try without branch specification (will return default branch)
      const defaultReadmeUrl = `https://raw.githubusercontent.com/${repositoryPath}/README.md`;
      const defaultResponse = await fetch(defaultReadmeUrl);
    
      if (defaultResponse.ok) {
        return await defaultResponse.text();
      }
    
      throw new Error("README not found in main, master, or default branch");
    }
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 retrieving content from GitHub but doesn't specify aspects like rate limits, authentication needs, error handling, or response format (though output schema exists). This leaves significant gaps for a tool interacting with external APIs.

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 any wasted words. It's front-loaded and appropriately sized for its purpose, earning full marks for conciseness.

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 moderate complexity (external GitHub access) and lack of annotations, the description is incomplete—it doesn't cover behavioral traits like API constraints. However, the existence of an output schema reduces the need to explain return values, making it minimally adequate but with clear gaps.

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 0%, so the description must compensate, but it doesn't explain the parameters 'packageName' or 'version' beyond what's implied. It adds minimal value over the schema, as it doesn't clarify parameter meanings, formats, or examples, resulting in a baseline score due to the output schema's presence.

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 ('Get README file content') and resource ('from a package's GitHub repository'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_package_info' or 'get_package_quality', which might also provide README-related data, so it misses full sibling distinction.

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. With siblings like 'get_package_info' that might include README content, there's no indication of when this tool is preferred, such as for raw README text or specific GitHub access, leaving usage context implied at best.

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/JuanSebastianGB/npm-context-agent-mcp'

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