Skip to main content

GitHub Tools

Category: network · 9 tools

GitHub GraphQL/REST tools for PR threads, comments, and contents.

Setup

Authentication

GitHub tools support three authentication methods, resolved in priority order:

  1. Explicit token parameter passed in the tool call
  2. GITHUB_PAT environment variable (Personal Access Token)
  3. GitHub App installation token — minted automatically from GITHUB_APP_ID + GITHUB_APP_PRIVATE_KEY
# Option A: Personal Access Token
export GITHUB_PAT=ghp_your_personal_access_token

# Option B: GitHub App
export GITHUB_APP_ID=123456
export GITHUB_APP_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\n..."

Note: Some mutations (e.g. github.pr.reviewThreads.resolve) require a PAT with repo scope. GitHub App installation tokens receive FORBIDDEN for those operations. See the individual tool reference below.

Import

import { githubToolsProject } from 'toolpack-sdk';

Wire up with Toolpack

import Toolpack from 'toolpack-sdk';
import { githubToolsProject } from 'toolpack-sdk';

const toolpack = await Toolpack.init({
provider: 'openai',
tools: true,
toolProjects: [githubToolsProject],
});

Tools

ToolRequired ParametersOptional ParametersDescription
github.graphql.executequeryvariables, repo, tokenExecute a GitHub GraphQL query or mutation
github.contents.getTextrepo, pathref, token, maxBytesFetch file content as decoded text
github.pr.reviewThreads.listrepo, numbertoken, unresolvedOnly, first, after, commentsFirst, includeMetaList PR review threads
github.pr.reviewThreads.resolvethreadIdrepo, tokenResolve a PR review thread (PAT required)
github.pr.reviewComments.replyrepo, number, inReplyTo, bodytokenReply within an existing PR review thread
github.pr.diff.getrepo, numbertoken, maxBytesFetch the unified diff for a pull request
github.pr.files.listrepo, numbertoken, perPage, pageList files changed in a PR
github.pr.reviews.submitrepo, number, eventbody, comments, tokenSubmit a PR review
github.issues.comments.createrepo, number, bodytokenCreate a comment on an issue or PR

Tool Reference

github.graphql.execute

Execute a GitHub GraphQL query or mutation with standard headers. Note: GitHub App installation tokens (ghs_*) cannot call certain write mutations. The following mutations require a PAT and will return FORBIDDEN with an App token: resolveReviewThread, unresolveReviewThread.

ParameterTypeRequiredDescription
querystringYesGraphQL query string
variablesobjectNoOptional GraphQL variables
repostringNoowner/name — used for token resolution when no explicit token is provided
tokenstringNoGitHub token (App installation or PAT). Omit to auto-resolve from server credentials

github.contents.getText

Fetch file content (decoded text) via the GitHub Contents API.

ParameterTypeRequiredDescription
repostringYesowner/name (e.g. octo/repo)
pathstringYesFile path within the repo
refstringNoBranch, tag, or commit SHA
tokenstringNoGitHub token (App installation or PAT)
maxBytesintegerNoOptional max bytes of decoded text to return; if exceeded, result is truncated with a footer

github.pr.reviewThreads.list

List PR review threads via GraphQL, optionally filtering to unresolved threads only.

ParameterTypeRequiredDescription
repostringYesowner/name
numberintegerYesPR number
tokenstringNoGitHub token (App installation or PAT)
unresolvedOnlybooleanNoIf true, filter to unresolved threads only
firstintegerNoThreads page size (max 100). Default 100
afterstringNoCursor for pagination (GraphQL pageInfo.endCursor)
commentsFirstintegerNoComments per thread (max 100). Default 20
includeMetabooleanNoIf true, return { headRefOid, threads, pageInfo } instead of an array

github.pr.reviewThreads.resolve

Resolve a PR review thread via GraphQL resolveReviewThread mutation. Requires a Personal Access Token (PAT) with repo scope. GitHub App installation tokens receive FORBIDDEN. If using an App token, post a reply acknowledging the fix instead.

ParameterTypeRequiredDescription
threadIdstringYesGraphQL node ID of the review thread
repostringNoowner/name — used for token resolution when no explicit token is provided
tokenstringNoGitHub token — must be a PAT with repo scope

github.pr.reviewComments.reply

Reply within an existing PR review thread to maintain continuity.

ParameterTypeRequiredDescription
repostringYesowner/name
numberintegerYesPR number
inReplyTointegerYesdatabaseId of the review comment to reply to
bodystringYesReply body
tokenstringNoGitHub token (App installation or PAT)

github.pr.diff.get

Fetch the unified diff for a pull request (text/patch).

ParameterTypeRequiredDescription
repostringYesowner/name
numberintegerYesPR number
tokenstringNoGitHub token (App installation or PAT)
maxBytesintegerNoOptional max bytes of diff to return; if exceeded, result is truncated with a footer

github.pr.files.list

List files changed in a PR with positions metadata.

ParameterTypeRequiredDescription
repostringYesowner/name
numberintegerYesPR number
tokenstringNoGitHub token (App installation or PAT)
perPageintegerNoResults per page (max 100)
pageintegerNoPage number

github.pr.reviews.submit

Submit a PR review (APPROVE, REQUEST_CHANGES, or COMMENT), optionally with inline comments.

ParameterTypeRequiredDescription
repostringYesowner/name
numberintegerYesPR number
eventstringYesReview event: APPROVE, REQUEST_CHANGES, or COMMENT
bodystringNoTop-level review body
commentsarrayNoOptional inline comments. Each item requires path (string), position (integer), and body (string)
tokenstringNoGitHub token (App installation or PAT)

github.issues.comments.create

Create a comment on an issue or pull request (conversation tab).

ParameterTypeRequiredDescription
repostringYesowner/name
numberintegerYesIssue or PR number
bodystringYesComment body
tokenstringNoGitHub token (App installation or PAT)

Examples

Reading a File from a Repo

const stream = toolpack.stream({
messages: [{ role: 'user', content: 'Show me the contents of src/index.ts in acme/my-app' }],
model: 'gpt-4o',
});
// AI uses github.contents.getText

Reviewing a Pull Request

const stream = toolpack.stream({
messages: [{ role: 'user', content: 'Review PR #42 in acme/my-app and approve it if the changes look good' }],
model: 'gpt-4o',
});
// AI uses github.pr.diff.get, github.pr.files.list, then github.pr.reviews.submit

Responding to Review Threads

const stream = toolpack.stream({
messages: [{ role: 'user', content: 'List all unresolved review threads on PR #42 in acme/my-app and reply to each one' }],
model: 'gpt-4o',
});
// AI uses github.pr.reviewThreads.list then github.pr.reviewComments.reply

Running a Custom GraphQL Query

const stream = toolpack.stream({
messages: [{ role: 'user', content: 'Get the title and state of the last 5 PRs in acme/my-app using GraphQL' }],
model: 'gpt-4o',
});
// AI uses github.graphql.execute