Tools
Beginner5 min read
Overview
A GitHub tool is one GitHub API operation an AI model can call, such as reading an issue or merging a pull request. The SDK has 97 of them: 49 read and 48 write. Each tool describes every input it takes, so the model knows what to pass, and returns only the fields the model needs instead of GitHub's whole response.
You create the tools in one call and hand them to the model like any other AI SDK tools. Most agents only need the tools for one job, which a preset picks for you. Every write tool asks for approval before it runs.
Configure
Create the tools with createGithubTools() and pass them wherever the AI SDK takes tools: generateText, streamText or a ToolLoopAgent.
import { createGithubTools } from '@github-tools/sdk'
import { generateText } from 'ai'
const { text } = await generateText({
model: 'anthropic/claude-opus-5.5',
tools: createGithubTools({ preset: 'issue-triage' }),
prompt: 'Summarize issue 42 on vercel/ai.',
})
The tool catalog lists all 97 tools.
Options
Every option is optional.
| Option | Default | What it does |
|---|---|---|
token | GITHUB_TOKEN | A token string, or an async function that returns one. See Auth |
preset | All 97 tools | One preset or an array of presets. See Presets |
requireApproval | true | Which writes ask first: true, false, 'auto' or per tool. See Approval |
evaluation | Jev, maxRisk: 1, minIntent: 0.6 | The decision model behind 'auto'. See Approval |
context | None | A default owner, repo, pull request, issue or ref. See Context |
overrides | None | A per-tool description, title or needsApproval. See Overrides |
author, committer | The token's owner | Who the commits are from. See Commits |
coAuthors | None | Co-authored-by trailers on every commit. See Commits |
guardrails | Block credentials | The repositories and branches any call may act on, whoever approves it. See Guardrails |
dryRun | false | Shadow mode: reads run, writes report what they would have done. See Shadow mode |
createGithubAgent() takes the same options plus model, instructions and additionalInstructions, and also accepts preset: 'auto'. The AI SDK integration covers it, and the API reference has every signature.
Call a tool from your code
Each tool has an execute function, so a script or a test can call it without a model. The result is the shaped object the model would read:
import { createGithubTools } from '@github-tools/sdk'
const tools = createGithubTools({ preset: 'repo-explorer' })
const issue = await tools.getIssue.execute!(
{ owner: 'vercel', repo: 'ai', issueNumber: 42 },
{ toolCallId: 'example', messages: [] },
)
// { number, title, body, state, url, author, assignees, labels, comments, createdAt, updatedAt, closedAt, rateLimit }
Pick single tools
When you want a hand-picked set instead of a preset, import the tools one by one. Each tool is exported as a factory. Read factories take a token, and write factories also take { needsApproval }, which defaults to true:
import { addPullRequestComment, getPullRequest, listPullRequestFiles } from '@github-tools/sdk'
const token = process.env.GITHUB_TOKEN!
const tools = {
getPullRequest: getPullRequest(token),
listPullRequestFiles: listPullRequestFiles(token),
addPullRequestComment: addPullRequestComment(token, { needsApproval: true }),
}
A factory returns the bare tool, without the extras createGithubTools() adds. The FAQ lists what you give up.
Overrides
Overrides change how one tool is presented to the model or approved, without changing what it does. Use them to reword a description for your domain, or to stop one write from asking. Key them by tool name:
import { createGithubTools } from '@github-tools/sdk'
const tools = createGithubTools({
overrides: {
listIssues: { description: 'List bugs for the current sprint' },
deleteGist: { needsApproval: false },
},
})
| Property | What it changes |
|---|---|
description | What the model reads to decide when to call the tool |
title | The human-readable name |
needsApproval | A boolean or a function of the input. Wins over requireApproval |
strict | Strict input generation, where the provider supports it |
providerOptions | Provider-specific tool settings |
toModelOutput | How the result is turned into what the model reads |
onInputStart, onInputDelta, onInputAvailable | Callbacks while the model streams the input |
The type is exported as ToolOverrides.
Page through long lists
List tools return one page at a time, so a repository with thousands of issues doesn't arrive in one result:
{ items, hasMore, page, perPage, nextPage? }
When hasMore is true, the model calls the tool again with page: nextPage. Passing maxPages (up to 20) fetches that many pages in one call and returns them together.
| Tools | Default page size | Largest perPage |
|---|---|---|
| Most lists | 30 | 100 |
| Search tools | 10 | 30 |
listDiscussions, listNotifications | 20 |
Output size
Results are trimmed by default so one call can't fill the model's context. Most trims have an input that asks for more:
- Long issue, pull request, discussion and release bodies are cut to about 500 characters. Pass
detail: 'full'for the whole text. - Diff patches are left out of
listPullRequestFiles,getCommitandcompareCommits. PassincludePatch: true, andfilenamesonlistPullRequestFiles, for the diffs you need. getFileContenttakesstartLine,endLineormaxLines. The model sees at most 20,000 characters of a file, 4,000 of each patch and 200 entries of a tree.getWorkflowJobLogsreturns the last 200 lines without timestamps. RaisemaxLinesup to 2,000.
Context tools go further by answering a whole question, such as "why did CI fail", in one call.
Check the rate limit
GitHub limits how many requests a token can make. Every result that is an object carries a rateLimit field from the last GitHub response: remaining, limit, reset, and resource and retryAfter when GitHub sends them. resource is core, search or graphql.
createGithubTools() removes rateLimit from what the model reads, and your code still gets it, for example in onStepFinish or a UI tool part:
import type { GithubRateLimit } from '@github-tools/sdk'
const remaining = (result as { rateLimit?: GithubRateLimit }).rateLimit?.remaining
When the limit runs out, calls fail with RATE_LIMITED, and the message includes the reset time.
Send fewer tool definitions
The model reads every tool definition on every request, whether it calls the tool or not. A preset lists only the tools one job needs, and preset: 'auto' lets a decision model pick them per conversation.
FAQ
tools.mergePullRequest is a type error when the preset doesn't include mergePullRequest, because the return type of createGithubTools() follows the preset. issue-triage doesn't include it, so the property doesn't exist on its tool set.context, overrides, requireApproval: 'auto' and the removal of rateLimit from what the model sees. Those only apply through createGithubTools().createOrUpdateFile, editFiles, mergePullRequest, enablePullRequestAutoMerge) take author, committer and coAuthors in the same object as needsApproval. See Commits.execute, inputSchema or outputSchema.listWorkflows, listWorkflowRuns, listWorkflowJobs and listCheckRuns keep their own keys (workflows, runs, jobs, checkRuns) and add the paging fields next to them. listDiscussions and listPullRequestReviewThreads page with a cursor: pass the returned endCursor as after. listDependabotAlerts returns nextCursor for the same purpose.createGithubTools() returns a plain AI SDK ToolSet.