File: README.md

package info (click to toggle)
python-azure 20251118%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 783,356 kB
  • sloc: python: 6,474,533; ansic: 804; javascript: 287; sh: 205; makefile: 198; xml: 109
file content (61 lines) | stat: -rw-r--r-- 2,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
pip install -e src/adapter/python
## Agent Framework MCP GitHub Token Sample

This sample mirrors the simpler `mcp_simple` Agent Framework sample but adds an MCP server (GitHub) that requires a Bearer token (`GITHUB_TOKEN`). The token is injected as an HTTP Authorization header when constructing the `MCPStreamableHTTPTool`.

### Script

- `mcp_apikey.py` – Creates a `ChatAgent` configured with an `AzureOpenAIChatClient` and a GitHub MCP tool, then serves it via the agents hosting adapter (`from_agent_framework(...).run_async()`).

## Prerequisites

> **Azure sign-in:** Run `az login` before starting the sample so `DefaultAzureCredential` can acquire a CLI token.

### Environment Variables

Copy `.envtemplate` to `.env` and supply:

```
AZURE_OPENAI_ENDPOINT=https://<endpoint-name>.cognitiveservices.azure.com/
OPENAI_API_VERSION=2025-03-01-preview
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=<deployment-name>
GITHUB_TOKEN=<your-github-token>
```

### GitHub Token Setup

To obtain a GitHub token for the MCP server:

1. Go to [GitHub Settings > Developer settings > Personal access tokens > Tokens (classic)](https://github.com/settings/tokens)
1. Click "Generate new token" → "Generate new token (classic)"
1. Select the minimum required scopes under the "repo" category. For this sample, the following scopes are sufficient:
   - `public_repo` (Access public repositories)
   - `repo:status` (Access commit statuses)
   If you need access to private repositories, also select `repo` (Full control of private repositories).
1. Click "Generate token"
1. Copy the token immediately (you won't be able to see it again)
1. Add it to your `.env` file as `GITHUB_TOKEN=<your-token>`

### Run

From this folder:

```bash
python mcp_apikey.py
```

### Test (non‑streaming example)

```bash
curl -X POST http://localhost:8088/responses \
  -H "Content-Type: application/json" \
  -d '{"input":"summarize the last change in <repo url>","stream":false}'
```

### Test (streaming example)

```bash
curl -X POST http://localhost:8088/responses \
  -H "Content-Type: application/json" \
  -d '{"input":"summarize the last change in <repo url>","stream":true}'
```