Skip to main content
Glama

nrf_search

Search code and documentation in the nRF Connect SDK repository using GitHub's search qualifiers to find specific files, samples, or configuration examples.

Instructions

Search for code or documentation across the nRF Connect SDK repo using GitHub code search.

Supports GitHub search qualifiers to narrow results:

  • Plain keyword: "DFU_TARGET_IMAGE_TYPE_ANY"

  • Docs only: "FOTA path:doc/nrf"

  • Samples only: "peripheral_hr path:samples"

  • Specific extension: "CONFIG_BT_PERIPHERAL extension:conf"

  • Source files only: "bt_le_adv_start extension:c"

  • Headers only: "struct bt_conn extension:h"

Returns matching file paths (up to 20). Use nrf_read to fetch the content. Note: Requires GITHUB_TOKEN for reliable results (unauthenticated search is heavily rate-limited).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch terms with optional GitHub qualifiers (path:, extension:, filename:)

Implementation Reference

  • Handler function for nrf_search tool - executes GitHub code search API call, constructs query with repo qualifier, and returns up to 20 matching file paths
    if (name === "nrf_search") {
      const query = (args as { query: string }).query;
      const fullQuery = `${query} repo:${REPO}`;
      const url = `${BASE_URL}/search/code?q=${encodeURIComponent(fullQuery)}&per_page=20`;
      const data = await githubGet(url) as {
        total_count: number;
        items: Array<{ path: string; name: string }>;
      };
    
      if (!data.items || data.items.length === 0) {
        return {
          content: [{ type: "text", text: `No results found for: ${query}` }],
        };
      }
    
      const results = data.items.map((item) => item.path).join("\n");
      const text = `Found ${data.total_count} result(s) (showing up to 20):\n\n${results}`;
      return {
        content: [{ type: "text", text }],
      };
    }
  • src/index.ts:106-130 (registration)
    Tool registration in TOOLS array defining nrf_search with name, description, and input schema requiring a query parameter
      {
        name: "nrf_search",
        description: `Search for code or documentation across the nRF Connect SDK repo using GitHub code search.
    
    Supports GitHub search qualifiers to narrow results:
    - Plain keyword:        "DFU_TARGET_IMAGE_TYPE_ANY"
    - Docs only:           "FOTA path:doc/nrf"
    - Samples only:        "peripheral_hr path:samples"
    - Specific extension:  "CONFIG_BT_PERIPHERAL extension:conf"
    - Source files only:   "bt_le_adv_start extension:c"
    - Headers only:        "struct bt_conn extension:h"
    
    Returns matching file paths (up to 20). Use nrf_read to fetch the content.
    Note: Requires GITHUB_TOKEN for reliable results (unauthenticated search is heavily rate-limited).`,
        inputSchema: {
          type: "object",
          properties: {
            query: {
              type: "string",
              description: "Search terms with optional GitHub qualifiers (path:, extension:, filename:)",
            },
          },
          required: ["query"],
        },
      },
  • Helper function for making authenticated GitHub API requests with error handling and rate limit detection
    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();
    }
  • Input schema for nrf_search tool defining the required query parameter with support for GitHub search qualifiers
    inputSchema: {
      type: "object",
      properties: {
        query: {
          type: "string",
          description: "Search terms with optional GitHub qualifiers (path:, extension:, filename:)",
        },
      },
      required: ["query"],
    },
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