| title | Debugging Copilot SDK | ||
|---|---|---|---|
| shortTitle | Debug Copilot SDK | ||
| intro | Enable debug logging and resolve common connection, authentication, and tool execution issues in {% data variables.copilot.copilot_sdk_short %}. | ||
| product | {% data reusables.gated-features.copilot-sdk %} | ||
| versions |
|
||
| contentType | how-tos |
{% data reusables.copilot.copilot-sdk.technical-preview-note %}
To begin troubleshooting, enable verbose logging to gain visibility into the underlying processes.
import { CopilotClient } from "@github/copilot-sdk";
const client = new CopilotClient({
logLevel: "debug", // Options: "none", "error", "warning", "info", "debug", "all"
});For examples in Python, Go, and .NET, see Debugging Guide in the github/copilot-sdk repository. {% data reusables.copilot.copilot-sdk.java-sdk-link %}
The CLI writes logs to the ABC directory by default. You can specify a different location using the --log-dir argument:
const client = new CopilotClient({
cliArgs: ["--log-dir", "/path/to/logs"],
});For Python and Go, which do not currently support passing extra CLI arguments, run the CLI manually with --log-dir and connect via the cliUrl option. For more information, see Debugging Guide in the github/copilot-sdk repository.
Cause: {% data variables.copilot.copilot_cli %} is not installed or not in PATH.
Solution:
-
Install the CLI. For more information, see AUTOTITLE.
-
Verify installation:
copilot --version
-
Or specify the full path:
const client = new CopilotClient({ cliPath: "/usr/local/bin/copilot", });
For examples in Python, Go, and .NET, see Debugging Guide in the
github/copilot-sdkrepository. {% data reusables.copilot.copilot-sdk.java-sdk-link %}
Cause: The CLI is not authenticated with {% data variables.product.github %}.
Solution:
-
Authenticate the CLI:
copilot auth login
-
Or provide a token programmatically:
const client = new CopilotClient({ githubToken: process.env.GITHUB_TOKEN, });
For examples in Python, Go, and .NET, see Debugging Guide in the
github/copilot-sdkrepository. {% data reusables.copilot.copilot-sdk.java-sdk-link %}
Cause: Attempting to use a session that was destroyed or doesn't exist.
Solution:
-
Ensure you're not calling methods after
disconnect():await session.disconnect(); // Don't use session after this!
-
For resuming sessions, verify the session ID exists:
const sessions = await client.listSessions(); console.log("Available sessions:", sessions);
Cause: The CLI server process crashed or failed to start.
Solution:
-
Check if the CLI runs correctly standalone:
copilot --server --stdio
-
Check for port conflicts if using TCP mode:
const client = new CopilotClient({ useStdio: false, port: 0, // Use random available port });
MCP (Model Context Protocol) servers can be tricky to debug. For comprehensive MCP debugging guidance, see AUTOTITLE.
- MCP server executable exists and runs independently
- Command path is correct (use absolute paths)
- Tools are enabled:
tools: ["*"] - Server responds to
initializerequest correctly - Working directory (
cwd) is set if needed
Before integrating with the SDK, verify your MCP server works:
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' | /path/to/your/mcp-serverFor detailed troubleshooting, see AUTOTITLE.
The SDK supports two transport modes:
| Mode | Description | Use case |
|---|---|---|
| Stdio (default) | CLI runs as subprocess, communicates via pipes | Local development, single process |
| TCP | CLI runs separately, communicates via TCP socket | Multiple clients, remote CLI |
Stdio mode (default):
const client = new CopilotClient({
useStdio: true, // This is the default
});TCP mode:
const client = new CopilotClient({
useStdio: false,
port: 8080, // Or 0 for random port
});Connect to existing server:
const client = new CopilotClient({
cliUrl: "localhost:8080", // Connect to running server
});-
Check client state:
console.log("Connection state:", client.getState()); // Should be "connected" after start()
-
Listen for state changes:
client.on("stateChange", (state) => { console.log("State changed to:", state); });
-
Verify the CLI process is running:
# Check for copilot processes ps aux | grep copilot
-
Verify tool registration:
const session = await client.createSession({ tools: [myTool], }); // Check registered tools console.log("Registered tools:", session.getTools?.());
-
Check the tool schema is valid JSON Schema:
const myTool = { name: "get_weather", description: "Get weather for a location", parameters: { type: "object", properties: { location: { type: "string", description: "City name" }, }, required: ["location"], }, handler: async (args) => { return { temperature: 72 }; }, };
-
Ensure the handler returns a valid result:
handler: async (args) => { // Must return something JSON-serializable return { success: true, data: "result" }; // Don't return undefined or non-serializable objects }
Subscribe to error events:
session.on("tool.execution_error", (event) => {
console.error("Tool error:", event.data);
});
session.on("error", (event) => {
console.error("Session error:", event.data);
});-
Path separators: Use raw strings or forward slashes. For .NET-specific examples, see Debugging Guide in the
github/copilot-sdkrepository. -
Console encoding: Ensure UTF-8 for proper JSON handling. For .NET-specific examples, see Debugging Guide in the
github/copilot-sdkrepository.
-
Gatekeeper issues: If CLI is blocked:
xattr -d com.apple.quarantine /path/to/copilot
-
PATH issues in GUI apps: GUI applications may not inherit shell PATH:
const client = new CopilotClient({ cliPath: "/opt/homebrew/bin/copilot", // Full path });
-
Permission issues:
chmod +x /path/to/copilot
-
Missing libraries: Check for required shared libraries:
ldd /path/to/copilot
If you're still stuck, collect the following debug information before opening an issue:
- SDK version
- CLI version (
copilot --version) - Operating system
- Debug logs
- Minimal reproduction code
Search for existing issues or open a new issue in the github/copilot-sdk repository.