Skip to main content
Glama

nrf_read

Read text files from the nRF Connect SDK repository to access documentation, source code, and configuration examples for development.

Instructions

Read the contents of a file from the nRF Connect SDK repo (nrfconnect/sdk-nrf @ main).

Works for any text file: .rst documentation, .c/.h source, CMakeLists.txt, Kconfig, prj.conf, .yaml, README.rst, etc.

Use nrf_list to discover paths first. Examples:

  • "samples/bluetooth/central_bas/README.rst"

  • "samples/bluetooth/central_bas/src/main.c"

  • "samples/bluetooth/central_bas/CMakeLists.txt"

  • "samples/bluetooth/central_bas/prj.conf"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesFile path within the repo (e.g. 'samples/bluetooth/peripheral_hr/src/main.c')

Implementation Reference

  • The handler function for nrf_read tool that fetches file contents from GitHub API. It validates the path, checks if it's a file vs directory, enforces size limits (500KB max), decodes base64 content, and returns the file text.
    if (name === "nrf_read") {
      const path = (args as { path: string }).path.replace(/^\/+|\/+$/g, "");
      const url = `${BASE_URL}/repos/${REPO}/contents/${encodePath(path)}?ref=${REF}`;
      const data = await githubGet(url) as {
        type?: string;
        size?: number;
        content?: string;
        encoding?: string;
      };
    
      if (Array.isArray(data)) {
        return {
          content: [{ type: "text", text: `'${path}' is a directory. Use nrf_list to browse it.` }],
        };
      }
    
      const size = data.size ?? 0;
      if (size > 500_000) {
        return {
          content: [{
            type: "text",
            text: `File is too large to read directly (${(size / 1024).toFixed(0)} KB). Consider browsing the directory and reading specific source files.`,
          }],
        };
      }
    
      if (!data.content) {
        return {
          content: [{ type: "text", text: `No text content available for '${path}' (may be a binary file).` }],
        };
      }
    
      const content = Buffer.from(data.content, "base64").toString("utf-8");
      return {
        content: [{ type: "text", text: content }],
      };
    }
  • Input schema definition for nrf_read tool specifying the required 'path' parameter (string) for the file path within the nRF Connect SDK repo.
    inputSchema: {
      type: "object",
      properties: {
        path: {
          type: "string",
          description: "File path within the repo (e.g. 'samples/bluetooth/peripheral_hr/src/main.c')",
        },
      },
      required: ["path"],
    },
  • src/index.ts:84-105 (registration)
    Registration of nrf_read tool in the TOOLS array with name, description (including usage examples and supported file types), and inputSchema.
      {
        name: "nrf_read",
        description: `Read the contents of a file from the nRF Connect SDK repo (nrfconnect/sdk-nrf @ ${REF}).
    
    Works for any text file: .rst documentation, .c/.h source, CMakeLists.txt, Kconfig, prj.conf, .yaml, README.rst, etc.
    
    Use nrf_list to discover paths first. Examples:
    - "samples/bluetooth/central_bas/README.rst"
    - "samples/bluetooth/central_bas/src/main.c"
    - "samples/bluetooth/central_bas/CMakeLists.txt"
    - "samples/bluetooth/central_bas/prj.conf"`,
        inputSchema: {
          type: "object",
          properties: {
            path: {
              type: "string",
              description: "File path within the repo (e.g. 'samples/bluetooth/peripheral_hr/src/main.c')",
            },
          },
          required: ["path"],
        },
      },
  • Helper function githubGet() that makes authenticated HTTP GET requests to GitHub API with proper headers and error handling for rate limits.
    async function githubGet(url: string): Promise<unknown> {
      const response = await fetch(url, { headers: githubHeaders() });
      if (!response.ok) {
        const body = await response.text();
        // Surface rate limit info if that's the issue
        const remaining = response.headers.get("x-ratelimit-remaining");
        const reset = response.headers.get("x-ratelimit-reset");
        if (response.status === 403 && remaining === "0" && reset) {
          const resetTime = new Date(parseInt(reset) * 1000).toISOString();
          throw new Error(`GitHub rate limit exceeded. Resets at ${resetTime}. Set GITHUB_TOKEN for higher limits.`);
        }
        throw new Error(`GitHub API ${response.status}: ${body}`);
      }
      return response.json();
    }
  • Helper function encodePath() that encodes each path segment individually while preserving slashes for GitHub API URLs.
    function encodePath(path: string): string {
      // Encode each path segment individually, preserving slashes
      return path.split("/").map(encodeURIComponent).join("/");
    }
Behavior3/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. It discloses that the tool reads text files from a specific repo, but lacks details on permissions, rate limits, error handling, or output format. While it adds context about supported file types, it doesn't fully cover behavioral traits needed for a read operation without annotations.

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 front-loaded with the core purpose, followed by supported file types and usage guidelines with examples. Every sentence adds value without redundancy, making it efficient and well-structured for quick understanding.

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 1 parameter with full schema coverage and no output schema, the description is adequate but has gaps. It explains what the tool does and when to use it, but lacks details on return values, error cases, or behavioral constraints, which are important for a read tool without annotations or output schema.

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 100%, with the parameter 'path' well-documented in the schema. The description adds minimal value beyond the schema by providing examples of paths, but doesn't explain semantics like path format constraints or edge cases. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Read') and resource ('contents of a file from the nRF Connect SDK repo'), specifying it works for various text file types. It explicitly distinguishes from sibling nrf_list by stating 'Use nrf_list to discover paths first,' making the purpose specific and differentiated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool ('Use nrf_list to discover paths first') and implies alternatives by mentioning sibling tools (nrf_list for discovery, nrf_search likely for searching). It sets clear context for file reading versus path discovery.

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/pshanesmith/nrf-mcp'

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