Typed GitHub API tools for fetching context in LLM-based workflows
Project description
github-context-tools
Typed GitHub API tools that give LLMs structured access to pull requests, code, history, and issues.
Installation
pip install github-context-tools
Quickstart
from github_context_tools import make_tools
tools = make_tools(token="ghp_...") # or set GH_TOKEN / GITHUB_TOKEN env var
# Pass the list to your agent framework's tool registry
agent.run(tools=tools)
How it works
make_tools() returns a list of plain Python functions. You pass that list directly to your agent framework's tool registry — no adapters or glue code needed.
Each tool is fully typed using Annotated[type, "description"] on every parameter and return value. Agent frameworks (Anthropic SDK, LangChain, OpenAI, etc.) read these annotations to automatically generate tool schemas, so the LLM always knows what each tool does, what to pass in, and what to expect back.
Available tools
Pull requests
| Tool | Description | Returns |
|---|---|---|
get_pr_metadata |
Title, author, branch names, SHAs, state, and change stats for a PR | PRMetadata |
get_parsed_pr_diff |
Structured diff of every file changed in a PR, broken into hunks and individual lines | PRDiff |
get_pr_description |
Title, body, and labels of a PR | PRDescription |
get_pr_comments |
All inline review comments and conversation comments on a PR | list[PRComment] |
Code
| Tool | Description | Returns |
|---|---|---|
get_file_at_ref |
Contents of a file at any branch, tag, or commit SHA | FileContent |
get_directory_tree |
Recursive file tree for a repo or subdirectory at a given ref | dict |
search_codebase |
Search a repo by content, file path, filename, or symbol name | list[SearchResult] |
get_sibling_files |
All other files in the same directory as a given file | list[str] |
History
| Tool | Description | Returns |
|---|---|---|
get_file_commit_history |
Recent commits that touched a file, newest-first. Supports filtering by author, date range, and branch | list[CommitSummary] |
get_commit_diff |
Structured diff introduced by a single commit | CommitDiff |
get_blame |
Blame ranges for an entire file, each annotated with the commit, author, and a recency score | list[BlameEntry] |
Issues
| Tool | Description | Returns |
|---|---|---|
get_linked_issue |
Title, body, author, labels, state, and comments for a GitHub issue | Issue |
Conventions
| Tool | Description | Returns |
|---|---|---|
get_repo_conventions |
Contents of well-known convention and context files from the default branch (CONTRIBUTING.md, CLAUDE.md, AGENTS.md, .cursor/rules, .cursorrules, .github/copilot-instructions.md, docs/architecture.md, docs/ARCHITECTURE.md, docs/development.md, DEVELOPMENT.md) |
RepoConventions |
Selecting tools
By default make_tools() returns all 13 tools. Use include or exclude to control which tools are registered with your agent.
Include only the tools you need:
tools = make_tools(
token="ghp_...",
include={"get_pr_metadata", "get_parsed_pr_diff", "get_pr_comments"},
)
Exclude tools you don't want:
tools = make_tools(
token="ghp_...",
exclude={"get_blame", "search_codebase"},
)
Both parameters accept a set[str] of tool names (the function names listed in the Available tools table). Unrecognised names raise a ValueError immediately.
Authentication
Pass a token directly or set an environment variable:
export GH_TOKEN=ghp_...
# or
export GITHUB_TOKEN=ghp_...
tools = make_tools(token="ghp_...")
Required token scopes
Use a classic personal access token (PAT) with the following scopes:
| Scope | Required for |
|---|---|
repo |
All tools on private repositories |
public_repo |
All tools on public repositories only |
Fine-grained PATs work too. Grant read-only access to the following permissions on the target repositories:
| Permission | Required for |
|---|---|
| Contents | get_file_at_ref, get_directory_tree, get_sibling_files, get_repo_conventions |
| Pull requests | get_pr_metadata, get_parsed_pr_diff, get_pr_description, get_pr_comments |
| Issues | get_linked_issue |
| Metadata | Required by GitHub for all repository access (granted automatically) |
get_file_commit_history, get_commit_diff, and get_blame use the Commits and GraphQL APIs, which are covered by the Contents and Metadata permissions above.
The token is captured in a closure and never appears in any tool signature, so it is never exposed to the LLM or included in generated schemas.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file github_context_tools-0.1.0.tar.gz.
File metadata
- Download URL: github_context_tools-0.1.0.tar.gz
- Upload date:
- Size: 36.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
033658f1484993691277e788d68fdc52ad6f1538eadf652838d2d316b457cb24
|
|
| MD5 |
a96b0869cfe684982ee40b8909890546
|
|
| BLAKE2b-256 |
a405eebed10279412b6351d72ee84716b425dccb430df81d374e9c0903c9467b
|
Provenance
The following attestation bundles were made for github_context_tools-0.1.0.tar.gz:
Publisher:
publish.yml on kruthis123/github-context-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
github_context_tools-0.1.0.tar.gz -
Subject digest:
033658f1484993691277e788d68fdc52ad6f1538eadf652838d2d316b457cb24 - Sigstore transparency entry: 1620338850
- Sigstore integration time:
-
Permalink:
kruthis123/github-context-tools@586a250a4c63ef33918d22a6e32b008a78de4125 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kruthis123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@586a250a4c63ef33918d22a6e32b008a78de4125 -
Trigger Event:
push
-
Statement type:
File details
Details for the file github_context_tools-0.1.0-py3-none-any.whl.
File metadata
- Download URL: github_context_tools-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edc873045cd71be10c5ac2af969ff3568421b7fe477e3377293a6fa50cf37f45
|
|
| MD5 |
fe07dd4a50126f48c5640ac1d71ceacc
|
|
| BLAKE2b-256 |
15110a17e5897283476d7a213aee35b55e884d3669c745679d352e1a56938987
|
Provenance
The following attestation bundles were made for github_context_tools-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on kruthis123/github-context-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
github_context_tools-0.1.0-py3-none-any.whl -
Subject digest:
edc873045cd71be10c5ac2af969ff3568421b7fe477e3377293a6fa50cf37f45 - Sigstore transparency entry: 1620339006
- Sigstore integration time:
-
Permalink:
kruthis123/github-context-tools@586a250a4c63ef33918d22a6e32b008a78de4125 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kruthis123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@586a250a4c63ef33918d22a6e32b008a78de4125 -
Trigger Event:
push
-
Statement type: