Edit

Share via


Quickstart: Integrate Azure MCP Server with GitHub Copilot SDK

This guide explains how to configure the GitHub Copilot SDK to use Azure Model Context Protocol (MCP) tools for interacting with Azure resources.

Azure MCP provides a set of tools that enable AI assistants to interact with Azure resources directly. When integrated with the Copilot SDK, you can build applications that leverage natural language to manage Azure subscriptions, resource groups, storage accounts, and more.

Prerequisites

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:

  1. Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P on Mac).
  2. 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, Azure MCP server must be configured in the app context for tools to be available. The essential configuration resembles the following:

{
  "mcp_servers": {
    "azure-mcp": {
      "type": "local",
      "command": "npx",
      "args": ["-y", "@azure/mcp@latest", "server", "start"],
      "tools": ["*"]
    }
  }
}

The tools: ["*"] parameter is essential - it enables all tools from the MCP server for the session.

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.

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.