Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build custom Copilot extensions and AI agents using the Azure-hosted GitHub Copilot SDK
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/existing-project-integration.md
1# Integrating Copilot SDK into Existing Projects23Add Copilot SDK AI features to an existing application.45## Project Analysis67Detect the project type by scanning for indicator files:89| Indicator | Language | Framework hints |10|-----------|----------|-----------------|11| `package.json` | Node.js | Express, Fastify, Next.js |12| `requirements.txt` / `pyproject.toml` | Python | Flask, FastAPI, Django |13| `go.mod` | Go | Gin, Echo, net/http |14| `*.csproj` / `*.sln` | .NET | ASP.NET, Minimal API |1516## Study Template Patterns1718Read the template via MCP for reference implementation:1920`github-mcp-server-get_file_contents` with `owner: "azure-samples"`, `repo: "copilot-sdk-service"`. Read `AGENTS.md` first.2122Use `github-mcp-server-get_file_contents` with `owner: "github"`, `repo: "copilot-sdk"` for current SDK API examples. If context7 is available, you can also use it (`context7-resolve-library-id` then `context7-query-docs`). If context7 is not available, instruct the user to install it: `npx -y @upstash/context7-mcp@latest`.2324## Integration Steps2526### 1. Add SDK dependency2728| Language | Package |29|----------|---------|30| Node.js | `@github/copilot-sdk` |31| Python | `github-copilot-sdk` |32| Go / .NET | See SDK repo |3334### 2. Create Copilot endpoint3536Add a route (e.g., `/api/chat`) that creates a `CopilotClient`, starts a session, and returns the response. Use `sendAndWait` for one-shot or SSE streaming for chat.3738Adapt to the app's existing routing pattern (Express router, FastAPI route, etc.).3940### 3. Configure authentication4142Use `gh auth token` for local dev; for production, use Key Vault.4344### 4. Wire into existing app4546Register the new route with the existing server/app instance. Do NOT create a separate server.4748> ⚠️ **Warning:** Do not duplicate server startup logic.4950## BYOM Support5152If the user wants Azure BYOM, add on top of standard integration:53541. Add `@azure/identity` dependency552. Get fresh token per request: `credential.getToken("https://cognitiveservices.azure.com/.default")`563. Pass `provider` config with `bearerToken` to `createSession`574. Set `model` to Azure deployment name (required)585. Set env vars: `AZURE_OPENAI_ENDPOINT`, `MODEL_NAME`5960See [Azure Model Configuration](azure-model-config.md).6162## Testing6364```bash65curl -s -X POST http://localhost:<port>/api/chat \66-H "Content-Type: application/json" \67-d '{"message":"test"}'68```6970## Errors7172| Error | Fix |73|-------|-----|74| SDK not found | Verify dependency installed and import path |75| Auth fails locally | Run `gh auth login` then `gh auth refresh --scopes copilot` |76| Route conflicts | Ensure endpoint path doesn't collide |77