github_search
Find GitHub repositories on specific topics by keyword. Filter by language and creation recency, then sort by stars to identify trending projects.
Instructions
Search GitHub repositories by keyword via the official Search API. USE THIS WHEN: user has a specific topic ('medical imaging 리포', 'mammography GitHub'). days filters by repository created_at (treats it as 'repos created in the last N days') — pair with sort=stars for a stable trending-substitute. USE github_trending INSTEAD WHEN: no specific topic, just browsing.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| language | No | ||
| days | No | ||
| sort | No | stars | |
| max_results | No | ||
| response_format | No | markdown |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- trends_mcp.py:785-792 (schema)Pydantic input schema for the github_search tool, defining fields: query, language, days, sort, max_results, response_format.
class GitHubSearchInput(BaseModel): model_config = ConfigDict(str_strip_whitespace=True, extra="forbid") query: str = Field(..., min_length=1, max_length=300) language: str | None = Field(None, max_length=40) days: int | None = Field(None, ge=1, le=3650) sort: str = Field("stars", pattern=r"^(stars|forks|updated|best-match)$") max_results: int = Field(20, ge=1, le=100) response_format: ResponseFormat = ResponseFormat.MARKDOWN - trends_mcp.py:897-914 (registration)Registration of the github_search tool via the @_maybe_tool decorator which conditionally registers with FastMCP if the 'github' source is enabled.
@_maybe_tool( source="github", name="github_search", description=( "Search GitHub repositories by keyword via the official Search API. " "USE THIS WHEN: user has a specific topic ('medical imaging 리포', " "'mammography GitHub'). `days` filters by repository `created_at` " "(treats it as 'repos created in the last N days') — pair with " "`sort=stars` for a stable trending-substitute. " "USE github_trending INSTEAD WHEN: no specific topic, just browsing." ), annotations={ "readOnlyHint": True, "destructiveHint": False, "openWorldHint": True, "idempotentHint": True, }, ) - trends_mcp.py:915-971 (handler)Main handler function for the github_search tool. Calls the GitHub Search API with query, language, date filters, and sort options; returns formatted markdown or JSON results.
async def github_search( query: str, language: str | None = None, days: int | None = None, sort: str = "stars", max_results: int = 20, response_format: ResponseFormat = ResponseFormat.MARKDOWN, ) -> str: try: args = GitHubSearchInput( query=query, language=language, days=days, sort=sort, max_results=max_results, response_format=response_format, ) q_parts = [args.query] if args.language: q_parts.append(f"language:{args.language}") if args.days: since_date = (_utc_now() - timedelta(days=args.days)).strftime("%Y-%m-%d") q_parts.append(f"created:>{since_date}") params: dict[str, Any] = { "q": " ".join(q_parts), "per_page": args.max_results, } if args.sort != "best-match": params["sort"] = args.sort params["order"] = "desc" headers = { "Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", } token = os.environ.get("GITHUB_TOKEN") if token: headers["Authorization"] = f"Bearer {token}" ttl = TTL_TRENDING if args.days else TTL_DEFAULT data = await _http_get_json(GITHUB_API, params=params, headers=headers, ttl=ttl) items = data.get("items", []) if isinstance(data, dict) else [] repos = [ { "full_name": r.get("full_name", ""), "url": r.get("html_url", ""), "description": r.get("description") or "", "language": r.get("language"), "stars": r.get("stargazers_count", 0), "forks": r.get("forks_count", 0), "created_at": r.get("created_at"), "updated_at": r.get("updated_at"), } for r in items[: args.max_results] ] header = f"GitHub 검색 `{args.query}` ({len(repos)}건)" return _format(repos, args.response_format, render_md=lambda x: _render_github_md(x, header)) except Exception as e: return _handle_error(e, "github_search") - trends_mcp.py:795-815 (helper)Helper function that renders a list of GitHub repo dicts into markdown format, used by both github_search and github_trending.
def _render_github_md(items: list[dict[str, Any]], header: str) -> str: if not items: return f"# {header}\n\n_결과 없음_" lines = [f"# {header}", f"_총 {len(items)}건_", ""] for i, r in enumerate(items, 1): bits: list[str] = [] if r.get("language"): bits.append(str(r["language"])) bits.append(f"⭐{r.get('stars', 0):,}") if "forks" in r and r["forks"] is not None: bits.append(f"🍴{r['forks']:,}") if r.get("stars_period"): bits.append(f"📈+{r['stars_period']:,}") meta = " · ".join(bits) desc = _trim(r.get("description"), 200) lines.append( f"## {i}. [{r['full_name']}]({r['url']})\n" f"- {meta}\n" + (f"- {desc}\n" if desc else "") ) return "\n".join(lines)