Build Your Own AI Helper Using GitHub Copilot

Simon Bisson
10 Min Read

The GitHub Copilot SDK transforms the Copilot CLI into a versatile agent host with built-in Model Context Protocol (MCP) support.

Agentic AI image
Credit: Shutterstock

GitHub Copilot stands out as a sophisticated AI assistant, having evolved from a tool for code completion to a comprehensive platform for managing and coordinating diverse development agents and services. This evolution includes making Copilot accessible wherever developers work: in the browser, within code editors, and now, via the Copilot CLI in your terminal.

Copilot gains significant power when integrated with Microsoft services like the Work IQ MCP server. This integration allows you to craft prompts that combine code with specifications and, critically, with conversations from outside traditional development environments. A forgotten email might contain a vital feature request or a user story. Leveraging the Copilot CLI and Work IQ to uncover these requirements and translate them into code helps minimize rework and ensures project alignment with business objectives.

While having GitHub Copilot readily available is incredibly beneficial, it often involves switching contexts between applications and the terminal. This isn’t a major hurdle when Copilot is embedded in Visual Studio and Visual Studio Code. However, what if you wanted to integrate this model directly into your custom applications? Constructing an agent command-and-control loop independently can be challenging, even with frameworks like Semantic Kernel.

Introducing the GitHub Copilot SDK

This is precisely where the new GitHub Copilot SDK provides a robust solution. If the Copilot CLI binaries are installed on your system (Windows, macOS, or Linux), you can utilize the SDK (along with the CLI’s JSON APIs) to embed the Copilot CLI into your application code. This grants access to its powerful orchestration capabilities and GitHub’s Model Context Protocol (MCP) registry. An integrated registry simplifies the discovery and installation of MCP servers, accelerating the incorporation of new features into your agent applications.

When your code employs the GitHub Copilot SDK with the CLI, it operates as a server. This enables a headless mode, meaning interactions between your code and the underlying agents occur invisibly. You don’t need to run the CLI directly on devices hosting GitHub Copilot SDK applications; remote access allows installation on a central server. However, users will still require a GitHub Copilot license to utilize SDK applications, even when connecting to a remote instance.

The SDK allows you to leverage the Copilot CLI server as a dedicated tool for executing and managing models and MCP servers, eliminating the need to build these components from scratch and significantly streamlining development. Running the CLI in server mode involves a straightforward launch, specifying a port for prompting. You can then use the server machine’s fully qualified domain name and the chosen port as a connection string.

After the CLI is installed, you can integrate the relevant SDK dialect. Official support is available for JavaScript and TypeScript via Node.js, .NET, Python, and Go. Node.js support is distributed via npm, .NET via NuGet, and Python via pip. The Go SDK is currently hosted in the project’s GitHub repository and can be installed using Go’s get command. As this is a rapidly evolving project, regular updates are recommended.

Utilizing the GitHub Copilot SDK

Invoking the SDK is quite straightforward. For example, in .NET, you instantiate a CopilotClient, establish a session with a supported model, and then dispatch an asynchronous session message containing your prompt to the Copilot CLI. The agent’s response, holding its answer, can then be processed by your code.

This method offers one of the simplest ways to programmatically interact with a large language model (LLM), with analogous approaches used across various languages and platforms. You will need to develop code to render or parse the data returned by the SDK. Therefore, it’s beneficial to construct foundational prompts within your code that encourage the underlying GitHub Copilot LLM to produce easily parseable formats.

By default, the Copilot CLI waits to return a complete response. However, you can enable streaming of response data as it becomes available by adding a streaming directive to the session definition. This feature is particularly useful for crafting interactive user experiences or in scenarios where LLM responses require significant generation time.

Much like Semantic Kernel and other agent development frameworks, the GitHub Copilot SDK is designed to employ “tools” that connect your code to LLMs. These tools can structure data calls that Copilot then translates into natural language. For instance, you might create a tool to query a foreign exchange platform for currency rates on a specific date, which can then be incorporated into a Copilot SDK call by including the tool’s name in the session definition.

Leveraging Tools and MCP Servers

Tools are implemented as handlers linked to either local code or a remote API. Utilizing API calls helps to “ground” the LLM quickly and mitigates risks associated with token exhaustion. Once a tool is set up, you can enable interactive sessions where users construct their own prompts and submit them to the grounded LLM, either as part of a larger application or as a specialized chatbot in platforms like Teams.

You aren’t obligated to develop your own tools; if you’re working with existing platforms and data, your SDK code can interact with an MCP server, such as those provided by Microsoft 365, to gain swift access to extensive data sources. Since the GitHub Copilot SDK builds upon the Copilot CLI’s capabilities, you can begin by configuring links to the appropriate MCP endpoint URLs, allowing the tool to invoke necessary servers as required. An application can support multiple MCP servers simultaneously, for instance, connecting Work IQ to your GitHub repositories to bridge the informational gap between code and its originating email discussions.

MCP servers can be either local or remote, using HTTP for remote connections and stdio for local ones. You might need to include authorization tokens in your MCP server definition and decide whether to accept all its tools or select specific ones for your GitHub Copilot SDK agent to utilize.

Additional SDK agent session options include defining a baseline prompt for all queries to maintain consistency and provide context beyond the user’s direct input. Different agents within the same application can be assigned distinct baseline prompts and unique names for separate functionalities. For example, a local MCP server could grant your application access to a PC’s file system, while a remote GitHub server could provide access to code and repositories.

Beyond official language support, community-driven SDK releases are available for Java, Rust, C++, and Clojure, enabling development with familiar languages and frameworks. However, as these are not official releases, their coordination with GitHub’s own SDKs and level of support may vary.

Integration with the Microsoft Agent Framework

Significantly, the Microsoft Agent Framework now offers support for the GitHub Copilot SDK. This allows seamless integration and orchestration of its agents alongside those built using other tools and frameworks, such as Fabric or Azure OpenAI. This capability empowers you to construct sophisticated AI-powered applications from established components, with the Agent Framework managing workflows across multiple agents. You are not confined to a single LLM; it’s feasible to utilize ChatGPT in one agent and Claude in another.

Tools like the GitHub Copilot SDK serve as an excellent entry point for experimenting with agent development, transforming workflows established within GitHub and Visual Studio Code into standalone MCP-driven applications. Once a collection of distinct, single-purpose agents is developed, they can be interconnected using higher-level orchestration frameworks, thereby automating workflows that draw information from across your business and throughout your application development lifecycle.

Version Control SystemsSoftware DevelopmentDevelopment ToolsArtificial Intelligence
Share This Article
Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *