Mcp v1 v2 changes python #71
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright (c) Microsoft Corporation. | |
| # Licensed under the MIT License. | |
| name: E2E - Python OpenAI | |
| on: | |
| workflow_call: # Allow orchestrator to call this workflow | |
| workflow_dispatch: # Allow manual triggering | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'python/openai/**' | |
| - 'scripts/e2e/**' | |
| - '.github/workflows/e2e-python-openai.yml' | |
| pull_request: | |
| branches: [main] | |
| paths: | |
| - 'python/openai/**' | |
| - 'scripts/e2e/**' | |
| permissions: | |
| contents: read | |
| env: | |
| SAMPLE_PATH: python/openai/sample-agent | |
| AGENT_PORT: 3979 | |
| SCRIPTS_PATH: scripts/e2e | |
| E2E_TESTS_PATH: tests/e2e | |
| jobs: | |
| python-openai: | |
| name: Python OpenAI Agent | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET SDK | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '8.0.x' | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install uv package manager | |
| run: pip install uv | |
| - name: Install dependencies | |
| working-directory: ${{ env.SAMPLE_PATH }} | |
| run: uv sync | |
| - name: Log SDK Versions | |
| shell: pwsh | |
| run: | | |
| & "${{ env.SCRIPTS_PATH }}/Get-SDKVersions.ps1" ` | |
| -Runtime "python" ` | |
| -WorkingDirectory "${{ env.SAMPLE_PATH }}" | |
| - name: Acquire Bearer Token (ROPC) | |
| id: token | |
| shell: pwsh | |
| run: | | |
| $token = & "${{ env.SCRIPTS_PATH }}/Acquire-BearerToken.ps1" ` | |
| -ClientId "${{ secrets.MCP_CLIENT_ID }}" ` | |
| -TenantId "${{ secrets.MCP_TENANT_ID }}" ` | |
| -Username "${{ secrets.MCP_TEST_USERNAME }}" ` | |
| -Password "${{ secrets.MCP_TEST_PASSWORD }}" | |
| echo "BEARER_TOKEN=$token" >> $env:GITHUB_OUTPUT | |
| echo "::add-mask::$token" | |
| - name: Copy ToolingManifest.json | |
| shell: pwsh | |
| run: | | |
| & "${{ env.SCRIPTS_PATH }}/Copy-ToolingManifest.ps1" -TargetPath "${{ env.SAMPLE_PATH }}" | |
| - name: Generate .env configuration | |
| shell: pwsh | |
| run: | | |
| $configMappings = @{ | |
| "AZURE_OPENAI_API_KEY" = "${{ secrets.PYTHON_OPENAI_AZURE_OPENAI_API_KEY }}" | |
| "AZURE_OPENAI_ENDPOINT" = "${{ secrets.PYTHON_OPENAI_AZURE_OPENAI_ENDPOINT }}" | |
| "AZURE_OPENAI_DEPLOYMENT" = "${{ secrets.PYTHON_OPENAI_AZURE_OPENAI_DEPLOYMENT }}" | |
| "AZURE_OPENAI_API_VERSION" = "2024-12-01-preview" | |
| "USE_AGENTIC_AUTH" = "false" | |
| "MCP_PLATFORM_ENDPOINT" = "https://agent365.svc.cloud.microsoft" | |
| "AGENT_ID" = "${{ secrets.PYTHON_OPENAI_AGENT_ID }}" | |
| "CONNECTIONS__SERVICE_CONNECTION__SETTINGS__AUTHTYPE" = "ClientSecret" | |
| "CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID" = "${{ secrets.PYTHON_OPENAI_AGENT_ID }}" | |
| "CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET" = "${{ secrets.PYTHON_OPENAI_CLIENT_SECRET }}" | |
| "CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID" = "${{ secrets.TENANT_ID }}" | |
| "CONNECTIONSMAP__0__SERVICEURL" = "*" | |
| "CONNECTIONSMAP__0__CONNECTION" = "SERVICE_CONNECTION" | |
| "ENABLE_OBSERVABILITY" = "true" | |
| } | |
| & "${{ env.SCRIPTS_PATH }}/Generate-EnvConfig.ps1" ` | |
| -OutputPath "${{ env.SAMPLE_PATH }}/.env" ` | |
| -BearerToken "${{ steps.token.outputs.BEARER_TOKEN }}" ` | |
| -Port ${{ env.AGENT_PORT }} ` | |
| -ConfigMappings $configMappings | |
| - name: Start Agent | |
| id: start-agent | |
| shell: pwsh | |
| run: | | |
| $agentPid = & "${{ env.SCRIPTS_PATH }}/Start-Agent.ps1" ` | |
| -AgentPath "${{ env.SAMPLE_PATH }}" ` | |
| -StartCommand "uv run python start_with_generic_host.py" ` | |
| -Port ${{ env.AGENT_PORT }} ` | |
| -BearerToken "${{ steps.token.outputs.BEARER_TOKEN }}" ` | |
| -Environment "Development" ` | |
| -Runtime "python" | |
| echo "AGENT_PID=$agentPid" >> $env:GITHUB_OUTPUT | |
| - name: Verify Agent Running | |
| shell: pwsh | |
| run: | | |
| Write-Host "=== Verifying Agent ===" -ForegroundColor Cyan | |
| $agentPid = "${{ steps.start-agent.outputs.AGENT_PID }}" | |
| Write-Host "Checking agent process (PID: $agentPid)..." -ForegroundColor Gray | |
| if ($agentPid) { | |
| try { | |
| $proc = Get-Process -Id $agentPid -ErrorAction Stop | |
| Write-Host "Agent process (PID: $agentPid) is running: $($proc.ProcessName)" -ForegroundColor Green | |
| } catch { | |
| Write-Host "ERROR: Agent process (PID: $agentPid) is NOT running!" -ForegroundColor Red | |
| $logFile = "${{ env.SAMPLE_PATH }}/agent.log" | |
| if (Test-Path $logFile) { | |
| Write-Host "Agent logs:" -ForegroundColor Yellow | |
| Get-Content $logFile | |
| } | |
| throw "Agent process has stopped" | |
| } | |
| } | |
| $agentUrl = "http://localhost:${{ env.AGENT_PORT }}" | |
| Write-Host "Verifying agent at $agentUrl..." -ForegroundColor Gray | |
| $healthResponse = Invoke-WebRequest -Uri "$agentUrl/api/health" -Method GET -UseBasicParsing -ErrorAction SilentlyContinue | |
| Write-Host "Health check: $($healthResponse.StatusCode)" -ForegroundColor Green | |
| - name: Restore E2E Test Dependencies | |
| shell: pwsh | |
| run: | | |
| dotnet restore "${{ env.E2E_TESTS_PATH }}/Agent365.E2E.Tests.csproj" | |
| - name: Run .NET E2E Tests | |
| shell: pwsh | |
| run: | | |
| dotnet test "${{ env.E2E_TESTS_PATH }}/Agent365.E2E.Tests.csproj" ` | |
| --no-restore ` | |
| --filter "Category=HTTP" ` | |
| --logger "trx;LogFileName=test-results.trx" ` | |
| --results-directory "${{ runner.temp }}/TestResults" | |
| env: | |
| AGENT_PORT: ${{ env.AGENT_PORT }} | |
| AGENT_URL: http://localhost:${{ env.AGENT_PORT }} | |
| TEST_RESULTS_DIR: ${{ runner.temp }}/TestConversations | |
| - name: Upload Test Results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results-python-openai | |
| path: ${{ runner.temp }}/TestResults/ | |
| retention-days: 30 | |
| - name: Emit Test Conversations | |
| if: always() | |
| shell: pwsh | |
| run: | | |
| & "${{ env.SCRIPTS_PATH }}/Emit-TestConversations.ps1" ` | |
| -TestResultsDir "${{ runner.temp }}/TestConversations" | |
| - name: Capture Agent Logs | |
| if: always() | |
| shell: pwsh | |
| run: | | |
| & "${{ env.SCRIPTS_PATH }}/Capture-AgentLogs.ps1" -AgentPath "${{ env.SAMPLE_PATH }}" | |
| - name: Cleanup Agent Process | |
| if: always() | |
| shell: pwsh | |
| run: | | |
| & "${{ env.SCRIPTS_PATH }}/Stop-AgentProcess.ps1" ` | |
| -AgentPID "${{ steps.start-agent.outputs.AGENT_PID }}" ` | |
| -Port ${{ env.AGENT_PORT }} |