Pastaba.
Prieigai prie šio puslapio reikalingas įgaliojimas. Galite bandyti prisijungti arba pakeisti katalogus.
Prieigai prie šio puslapio reikalingas įgaliojimas. Galite bandyti pakeisti katalogus.
In this quickstart, you configure the GitHub Copilot SDK to use Azure Model Context Protocol (MCP) tools so that your applications can interact with Azure resources through natural language.
Azure MCP provides tools that let AI assistants interact with Azure resources directly. When you integrate these tools with the Copilot SDK, you can build applications that use natural language to manage Azure subscriptions, resource groups, storage accounts, and more.
Prerequisites
- GitHub Copilot CLI installed.
- Node.js installed (for running the server via
npx). - Azure CLI installed and authenticated (
az login).
Sign in to Azure MCP Server for local development
Azure MCP Server authenticates to Microsoft Entra ID using the Azure Identity library for .NET. The server supports two authentication modes:
- Broker mode: Uses your operating system's native authentication (like Windows Web Account Manager) with
InteractiveBrowserCredential. - Credential chain mode: Tries multiple authentication methods in sequence: environment variables, Visual Studio Code, Visual Studio, Azure CLI, Azure PowerShell, Azure Developer CLI, and interactive browser authentication.
Sign in using any of these methods:
- Open the Command Palette (
Ctrl+Shift+PorCmd+Shift+Pon Mac). - Run Azure: Sign In and follow the prompts.
After signing in, Azure MCP Server can authenticate and run operations on Azure services based on your permissions.
Azure MCP Server configuration example
Regardless of the programming SDK you use, you must configure Azure MCP Server in the app context so that its tools are available. The following example shows the minimal configuration:
{
"mcp_servers": {
"azure-mcp": {
"type": "local",
"command": "npx",
"args": ["-y", "@azure/mcp@latest", "server", "start"],
"tools": ["*"]
}
}
}
The tools: ["*"] parameter enables all tools from the MCP server for the session. In many cases, you should provide a specific list of tool names instead, so the Copilot session can only call the Azure MCP tools that your app needs. The following example restricts the session to a small set of tools:
{
"mcp_servers": {
"azure-mcp": {
"type": "local",
"command": "npx",
"args": ["-y", "@azure/mcp@latest", "server", "start"],
"tools": ["group_list", "storage_account_list", "subscription_list"]
}
}
}
For a full list of available tool names, see Azure MCP Server tools.
Integration examples
The following examples show how to integrate the SDK in different languages.
Note
For faster startup, you can install Azure MCP Server globally using npm install -g @azure/mcp@latest.
Note
The following samples use --allow-all-tools and --allow-all-paths to keep the examples simple. These flags aren't required or recommended for every app. Scope the CLI permissions and the MCP tools configuration to what your app actually needs—broad "allow all" settings can expose more tools and file system access than your Azure MCP integration requires.
Installation
Install the Python SDK package using pip.
pip install github-copilot-sdk
Sample code
The following code demonstrates a complete flow:
import asyncio
from copilot import CopilotClient
from copilot.generated.session_events import SessionEventType
async def main():
# Initialize the Copilot client
client = CopilotClient({
"cli_args": [
"--allow-all-tools",
"--allow-all-paths",
]
})
await client.start()
# Configure Azure MCP server in session config
azure_mcp_config = {
"azure-mcp": {
"type": "local",
"command": "npx",
"args": ["-y", "@azure/mcp@latest", "server", "start"],
"tools": ["*"], # Enable all Azure MCP tools
}
}
# Create session with MCP servers
session = await client.create_session({
"model": "gpt-4.1", # Default model; BYOK can override
"streaming": True,
"mcp_servers": azure_mcp_config,
})
# Handle events
def handle_event(event):
if event.type == SessionEventType.ASSISTANT_MESSAGE_DELTA:
if hasattr(event.data, 'delta_content') and event.data.delta_content:
print(event.data.delta_content, end="", flush=True)
elif event.type == SessionEventType.TOOL_EXECUTION_START:
tool_name = getattr(event.data, 'tool_name', 'unknown')
print(f"\n[TOOL: {tool_name}]")
session.on(handle_event)
# Send prompt
await session.send_and_wait({
"prompt": "List all resource groups in my Azure subscription"
})
await client.stop()
if __name__ == "__main__":
asyncio.run(main())
The preceding code:
- Initializes the Copilot client.
- Configures the Azure MCP server using
npx. - Creates a session with the GPT-4.1 model and streaming enabled.
- Handles events to print assistant responses and tool execution logs.
- Sends a prompt to list Azure resource groups.