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
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search terms with optional GitHub qualifiers (path:, extension:, filename:) |
Implementation Reference
- src/index.ts:206-226 (handler)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"], }, }, - src/index.ts:33-47 (helper)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(); } - src/index.ts:120-129 (schema)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"], },