Skill

Integrate GitHub Copilot into Applications

Build apps that programmatically interact with GitHub Copilot via the Copilot SDK - sessions, custom tools, hooks, MCP servers, and streaming.

Works with github

91
Spark score
out of 100
Updated 5 days ago
Version 15.8.0
Models
gpt 4

Add to Favorites

Why it matters

Build custom applications that programmatically leverage GitHub Copilot's code generation capabilities. Extend Copilot's functionality with custom tools and hooks for enhanced control and automation.

Outcomes

What it gets done

01

Programmatically interact with GitHub Copilot.

02

Manage Copilot sessions and messages.

03

Define and integrate custom tools for Copilot.

04

Implement hooks for session lifecycle events.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/ag-copilot-sdk | bash

Overview

GitHub Copilot SDK

A GitHub Copilot SDK skill covering session management, custom tools, lifecycle hooks, MCP server integration, and streaming across four languages. Use when building applications that programmatically drive GitHub Copilot with custom tools, hooks, MCP integrations, or BYOK providers.

What it does

This skill covers the GitHub Copilot SDK, which wraps the Copilot CLI via JSON-RPC to let applications programmatically interact with GitHub Copilot - session management, custom tools, hooks, MCP server integration, and streaming - across Node.js, Python, Go, and .NET. Prerequisites: GitHub Copilot CLI installed and authenticated, a Copilot subscription (Individual/Business/Enterprise, not required for BYOK), and Node.js 18+/Python 3.8+/Go 1.21+/.NET 8.0+.

Every language follows the same core pattern: create a client, create a session, send messages, then stop the client. Streaming responses are enabled by setting streaming: true on session creation and subscribing to assistant.message_delta events for real-time output, with an on(handler) method to subscribe to all events or a specific event type.

Custom tools let Copilot call application-defined functions - each defined with a name, description, JSON-schema parameters, and a handler - available per-language via defineTool (Node.js/Go) or a @define_tool decorator with Pydantic models (Python) or AIFunctionFactory.Create (.NET), then passed into session creation's tools array.

Hooks intercept session lifecycle points: onPreToolUse (before a tool executes, for permission control or argument modification, returning an allow/deny/ask decision with optional modified arguments or suppressed output), onPostToolUse (after execution, for result transformation or logging), onUserPromptSubmitted (message modification/filtering), onSessionStart/onSessionEnd (context setup/cleanup), and onErrorOccurred (custom error handling/retry).

MCP server integration connects pre-built tool capabilities via remote HTTP servers (type: "http" with a url) or local stdio servers (type: "local" with a command, args, and a tools allowlist or ["*"]), configurable with env, cwd, and timeout. Authentication resolves in priority order: an explicit githubToken in the constructor, environment variables (COPILOT_GITHUB_TOKEN then GH_TOKEN then GITHUB_TOKEN), stored OAuth from copilot auth login, or GitHub CLI credentials. BYOK (Bring Your Own Key) lets you use your own API keys without a Copilot subscription, configuring a provider (openai, azure, anthropic, or ollama) with baseUrl/apiKey/wireApi - using "responses" wire API for the GPT-5 series and "completions" for others.

Sessions persist across restarts via an explicit sessionId, resumable later with client.resumeSession() - though BYOK sessions must re-provide the provider config on resume since keys aren't persisted. infiniteSessions configuration (with backgroundCompactionThreshold and bufferExhaustionThreshold) handles long-running workflows that would otherwise exceed context limits. Additional session configuration covers custom agents (named personas with their own prompt), a systemMessage override, skillDirectories/disabledSkills for loading and disabling Copilot skills, and onPermissionRequest/onUserInputRequest handlers for programmatic tool permission and user-input responses. An external, separately-running CLI (copilot --headless --port 4321) can be connected to via cliUrl instead of letting the SDK auto-manage the process. Debugging is enabled via logLevel: "debug", with common issues covering CLI-not-found, authentication failures, using a session after destroy(), and connection-refused errors (mitigated by autoRestart).

import { CopilotClient } from "@github/copilot-sdk";

const client = new CopilotClient();
const session = await client.createSession({ model: "gpt-4.1" });

const response = await session.sendAndWait({ prompt: "What is 2 + 2?" });
console.log(response?.data.content);

await client.stop();

When to use - and when NOT to

Use this skill when building applications that programmatically interact with GitHub Copilot - managing sessions, defining custom tools, hooking into session lifecycle events, integrating MCP servers, or streaming responses - in Node.js, Python, Go, or .NET.

Inputs and outputs

Inputs: a prompt or task to send to a Copilot session, along with any custom tools, hooks, MCP server configs, or provider (BYOK) settings.

Outputs: a Copilot session response (streamed or awaited), tool-call results from custom or MCP-provided tools, and persisted/resumable session state.

Integrations

@github/copilot-sdk (Node.js), github-copilot-sdk (Python), github.com/github/copilot-sdk/go (Go), GitHub.Copilot.SDK (.NET); GitHub Copilot CLI; Model Context Protocol servers; OpenAI, Azure OpenAI, Azure AI Foundry, Anthropic, and Ollama as BYOK providers.

Who it's for

Developers building applications that programmatically drive GitHub Copilot - custom tools, session hooks, MCP integrations, or BYOK model providers - across Node.js, Python, Go, or .NET.

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.