# Debughandbuch

In diesem Handbuch werden allgemeine Probleme und Debuggingtechniken für das Copilot SDK in allen unterstützten Sprachen behandelt.

<!-- markdownlint-disable GHD046 GHD005 -->

<!-- Suppressed: GHD046 (outdated release terminology), GHD005 (hardcoded data variable) -->

## Inhaltsverzeichnis

* [Debugprotokollierung aktivieren](#enable-debug-logging)
* [Häufige Probleme](#common-issues)
* [Debuggen von MCP-Servern](#mcp-server-debugging)
* [Verbindungsprobleme](#connection-issues)
* [Probleme bei der Toolausführung](#tool-execution-issues)
* [Plattformspezifische Probleme](#platform-specific-issues)

## Debugprotokollierung aktivieren

Der erste Schritt beim Debuggen ermöglicht ausführliche Protokollierung, um zu sehen, was unter der Haube passiert.

<div class="ghd-codetabs">
<div class="ghd-codetab" data-lang="typescript" data-label="TypeScript"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">TypeScript</div>

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

const client = new CopilotClient({
  logLevel: "debug",  // Options: "none", "error", "warning", "info", "debug", "all"
});
```

</div>

<div class="ghd-codetab" data-lang="python" data-label="Python"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Python</div>

```python
from copilot import CopilotClient

client = CopilotClient(log_level="debug")
```

</div>

<div class="ghd-codetab" data-lang="go" data-label="Go"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Go</div>

```golang
import copilot "github.com/github/copilot-sdk/go"

client := copilot.NewClient(&copilot.ClientOptions{
    LogLevel: "debug",
})
```

</div>

<div class="ghd-codetab" data-lang="dotnet" data-label=".NET"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">.NET</div>

<!-- docs-validate: skip -->

```csharp
using GitHub.Copilot;
using Microsoft.Extensions.Logging;

// Using ILogger
var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.SetMinimumLevel(LogLevel.Debug);
    builder.AddConsole();
});

var client = new CopilotClient(new CopilotClientOptions
{
    LogLevel = "debug",
    Logger = loggerFactory.CreateLogger<CopilotClient>()
});
```

</div>

<div class="ghd-codetab" data-lang="java" data-label="Java"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Java</div>

```java
import com.github.copilot.CopilotClient;
import com.github.copilot.rpc.*;

var client = new CopilotClient(new CopilotClientOptions()
    .setLogLevel("debug")
);
```

</div>

</div>

### Protokollverzeichnis

Die CLI schreibt Protokolle in ein Verzeichnis. Sie können einen benutzerdefinierten Speicherort angeben:

<div class="ghd-codetabs">
<div class="ghd-codetab" data-lang="typescript" data-label="TypeScript"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">TypeScript</div>

```typescript
const client = new CopilotClient({
  cliArgs: ["--log-dir", "/path/to/logs"],
});
```

</div>

<div class="ghd-codetab" data-lang="python" data-label="Python"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Python</div>

```python
# The Python SDK does not currently support passing extra CLI arguments.
# Logs are written to the default location or can be configured via
# the CLI when running in server mode.
```

> \[!NOTE]
> Python SDK-Protokollierungskonfiguration ist eingeschränkt. Führen Sie zur erweiterten Protokollierung die CLI manuell mit `--log-dir` aus und stellen Sie die Verbindung über `RuntimeConnection.for_uri(...)` her.

</div>

<div class="ghd-codetab" data-lang="go" data-label="Go"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Go</div>

```golang
client := copilot.NewClient(&copilot.ClientOptions{
    Connection: copilot.StdioConnection{
        Args: []string{"--log-dir", "/path/to/logs"},
    },
})
```

</div>

<div class="ghd-codetab" data-lang="dotnet" data-label=".NET"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">.NET</div>

```csharp
var client = new CopilotClient(new CopilotClientOptions
{
    Connection = RuntimeConnection.ForStdio(args: new[] { "--log-dir", "/path/to/logs" })
});
```

</div>

<div class="ghd-codetab" data-lang="java" data-label="Java"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Java</div>

<!-- docs-validate: skip -->

```java
// The Java SDK does not currently support passing extra CLI arguments.
// For custom log directories, run the CLI manually with --log-dir
// and connect via cliUrl.
```

</div>

</div>

## Häufig auftretende Probleme

### "CLI nicht gefunden" / "Copilot: Befehl nicht gefunden"

**Ursache:** Die Copilot CLI ist nicht installiert oder nicht im PATH.

**Solution:**

1. Installieren der CLI: [Installationshandbuch](/de/copilot/how-tos/copilot-cli/set-up-copilot-cli/install-copilot-cli)

2. Installation überprüfen:

   ```bash
   copilot --version
   ```

3. Oder geben Sie den vollständigen Pfad an:

<div class="ghd-codetabs">
<div class="ghd-codetab" data-lang="javascript" data-label="JavaScript"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">JavaScript</div>

```typescript
const client = new CopilotClient({
  cliPath: "/usr/local/bin/copilot",
});
```

</div>

<div class="ghd-codetab" data-lang="python" data-label="Python"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Python</div>

```python
client = CopilotClient({"cli_path": "/usr/local/bin/copilot"})
```

</div>

<div class="ghd-codetab" data-lang="go" data-label="Go"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Go</div>

```golang
client := copilot.NewClient(&copilot.ClientOptions{
    Connection: copilot.StdioConnection{Path: "/usr/local/bin/copilot"},
})
```

</div>

<div class="ghd-codetab" data-lang="dotnet" data-label=".NET"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">.NET</div>

```csharp
var client = new CopilotClient(new CopilotClientOptions
{
    CliPath = "/usr/local/bin/copilot"
});
```

</div>

<div class="ghd-codetab" data-lang="java" data-label="Java"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Java</div>

```java
var client = new CopilotClient(new CopilotClientOptions()
    .setCliPath("/usr/local/bin/copilot")
);
```

</div>

</div>

### "Nicht authentifiziert"

**Cause:** Die CLI ist nicht mit GitHub authentifiziert.

**Solution:**

1. Authentifizieren der CLI:

   ```bash
   copilot auth login
   ```

2. Oder stellen Sie programmgesteuert ein Token bereit:

<div class="ghd-codetabs">
<div class="ghd-codetab" data-lang="javascript" data-label="JavaScript"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">JavaScript</div>

```typescript
const client = new CopilotClient({
  gitHubToken: process.env.GITHUB_TOKEN,
});
```

</div>

<div class="ghd-codetab" data-lang="python" data-label="Python"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Python</div>

```python
import os
client = CopilotClient({"github_token": os.environ.get("GITHUB_TOKEN")})
```

</div>

<div class="ghd-codetab" data-lang="go" data-label="Go"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Go</div>

```golang
client := copilot.NewClient(&copilot.ClientOptions{
    GitHubToken: os.Getenv("GITHUB_TOKEN"),
})
```

</div>

<div class="ghd-codetab" data-lang="dotnet" data-label=".NET"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">.NET</div>

```csharp
var client = new CopilotClient(new CopilotClientOptions
{
    GitHubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN")
});
```

</div>

<div class="ghd-codetab" data-lang="java" data-label="Java"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Java</div>

```java
var client = new CopilotClient(new CopilotClientOptions()
    .setGitHubToken(System.getenv("GITHUB_TOKEN"))
);
```

</div>

</div>

### "Sitzung nicht gefunden"

**Ursache:** Es wird versucht, eine Sitzung zu verwenden, die zerstört wurde oder nicht vorhanden ist.

**Solution:**

1. Stellen Sie sicher, dass Sie keine Methoden nach diesem `disconnect()`-Aufruf aufrufen:

   ```typescript
   await session.disconnect();
   // Don't use session after this!
   ```

2. Überprüfen Sie bei der Fortsetzung von Sitzungen, ob die Sitzungs-ID vorhanden ist:

   ```typescript
   const sessions = await client.listSessions();
   console.log("Available sessions:", sessions);
   ```

### „Verbindung abgelehnt“ / „ECONNREFUSED“

**Ursache:** Der CLI-Serverprozess ist abgestürzt oder konnte nicht gestartet werden.

**Solution:**

1. Überprüfen Sie, ob die CLI ordnungsgemäß eigenständig ausgeführt wird:

   ```bash
   copilot --server --stdio
   ```

2. Überprüfen Sie bei Verwendung des TCP-Modus nach Portkonflikten:

   ```typescript
   const client = new CopilotClient({
     useStdio: false,
     port: 0,  // Use random available port
   });
   ```

## Debugging auf dem MCP-Server

MCP-Server (Model Context Protocol) können schwierig zu debuggen sein. Umfassende MCP-Debugginganleitungen finden Sie in der dedizierten **[MCP-Serverdebugginghandbuch](/de/copilot/how-tos/copilot-sdk/troubleshooting/mcp-debugging)**.

### Kurze MCP-Checkliste

* [ ] Die ausführbare Datei des MCP-Servers ist vorhanden und läuft unabhängig.
* [ ] Befehlspfad ist richtig (absolute Pfade verwenden)
* [ ] Tools sind aktiviert: `tools: ["*"]`
* [ ] Server antwortet ordnungsgemäß auf `initialize` Anforderung
* [ ] Das Arbeitsverzeichnis (`cwd`) wird bei Bedarf automatisch festgelegt.

### Testen des MCP-Servers

Überprüfen Sie vor der Integration mit dem SDK, ob Ihr MCP-Server funktioniert:

```bash
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' | /path/to/your/mcp-server
```

Eine detaillierte Fehlerbehebung finden Sie unter [MCP-Serverdebugginghandbuch](/de/copilot/how-tos/copilot-sdk/troubleshooting/mcp-debugging).

## Verbindungsprobleme

### Stdio vs TCP-Modus

Das SDK unterstützt zwei Transportmodi:

| Modus                | Description                                               | Anwendungsfall                        |
| -------------------- | --------------------------------------------------------- | ------------------------------------- |
| **Stdio** (Standard) | CLI läuft als Unterprozess, kommuniziert über Rohre       | Lokale Entwicklung, einzelner Prozess |
| **TCP**              | CLI wird separat ausgeführt, kommuniziert über TCP-Socket | Mehrere Clients, Remote CLI           |

**Stdiomodus (Standard):**

```typescript
const client = new CopilotClient({
  useStdio: true,  // This is the default
});
```

**TCP-Modus:**

```typescript
const client = new CopilotClient({
  useStdio: false,
  port: 8080,  // Or 0 for random port
});
```

**Herstellen einer Verbindung mit vorhandenem Server:**

```typescript
const client = new CopilotClient({
  cliUrl: "localhost:8080",  // Connect to running server
});
```

### Diagnose von Verbindungsfehlern

1. **Clientstatus überprüfen:**

   ```typescript
   console.log("Connection state:", client.getState());
   // Should be "connected" after start()
   ```

2. **Auf Zustandsänderungen warten:**

   ```typescript
   client.on("stateChange", (state) => {
     console.log("State changed to:", state);
   });
   ```

3. **Überprüfen Sie, ob der CLI-Prozess ausgeführt wird:**

   ```bash
   # Check for copilot processes
   ps aux | grep copilot
   ```

## Probleme bei der Toolausführung

### Benutzerdefiniertes Tool wird nicht aufgerufen

1. **Überprüfen sie die Toolregistrierung:**

   ```typescript
   const session = await client.createSession({
     tools: [myTool],
   });

   // Check registered tools
   console.log("Registered tools:", session.getTools?.());
   ```

2. **Das Überprüfungstoolschema ist ein gültiges JSON-Schema:**

   ```typescript
   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 };
     },
   };
   ```

3. **Stellen Sie sicher, dass der Handler gültiges Ergebnis zurückgibt:**

   ```typescript
   handler: async (args) => {
     // Must return something JSON-serializable
     return { success: true, data: "result" };
     
     // Don't return undefined or non-serializable objects
   }
   ```

### Nicht sichtbare Toolfehler

Fehlerereignisse abonnieren:

```typescript
session.on("tool.execution_error", (event) => {
  console.error("Tool error:", event.data);
});

session.on("error", (event) => {
  console.error("Session error:", event.data);
});
```

## Plattformspezifische Probleme

### Windows

1. **Pfadtrennzeichen:** Verwenden Sie unformatierte Zeichenfolgen oder Schrägstriche:

   ```csharp
   CliPath = @"C:\Program Files\GitHub\copilot.exe"
   // or
   CliPath = "C:/Program Files/GitHub/copilot.exe"
   ```

2. **PATHEXT-Auflösung:** Das SDK behandelt dies automatisch, aber wenn Probleme weiterhin bestehen:

   ```csharp
   // Explicitly specify .exe
   Command = "myserver.exe"  // Not just "myserver"
   ```

3. **Konsolencodierung:** Stellen Sie UTF-8 für die ordnungsgemäße JSON-Behandlung sicher:

   ```csharp
   Console.OutputEncoding = System.Text.Encoding.UTF8;
   ```

### macOS

1. **Gatekeeper-Probleme:** Wenn CLI blockiert ist:

   ```bash
   xattr -d com.apple.quarantine /path/to/copilot
   ```

2. **PATH-Probleme in GUI-Apps:** GUI-Anwendungen erben vielleicht nicht den Shell-PATH:

   ```typescript
   const client = new CopilotClient({
     cliPath: "/opt/homebrew/bin/copilot",  // Full path
   });
   ```

### Linux

1. **Berechtigungsprobleme:**

   ```bash
   chmod +x /path/to/copilot
   ```

2. **Fehlende Bibliotheken:** Prüfen Sie auf erforderliche geteilte Bibliotheken:

   ```bash
   ldd /path/to/copilot
   ```

## Hilfe erhalten

Wenn Sie noch hängen bleiben:

1. **Sammeln von Debuginformationen:**
   * SDK-Version
   * CLI-Version (`copilot --version`)
   * Betriebssystem
   * Debugprotokolle
   * Minimaler Reproduktionscode

2. **Vorhandene Probleme durchsuchen:**[GitHub Probleme](https://github.com/github/copilot-sdk/issues)

3. **Öffnen Sie ein neues Issue** mit den erfassten Informationen

## Siehe auch

* [Erstellen Sie Ihre erste Copilot-gestützte App](/de/copilot/how-tos/copilot-sdk/getting-started)
* [AUTOTITLE –](/de/copilot/how-tos/copilot-sdk/features/mcp) MCP-Konfiguration und -Einrichtung
* [MCP-Serverdebugginghandbuch](/de/copilot/how-tos/copilot-sdk/troubleshooting/mcp-debugging) – Detaillierte MCP-Problembehandlung
* [API-Referenz](https://github.com/github/copilot-sdk)