Skip to content

Commit 07c09e6

Browse files
Python: sample using GitHub MCP Server and Azure AI Agent (microsoft#11465)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> This adds a sample using Azure AI Agents and the local Github MCP server as a plugin. Partial for: microsoft#11463 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
1 parent 78dd3d5 commit 07c09e6

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Copyright (c) Microsoft. All rights reserved.
2+
3+
import asyncio
4+
5+
from azure.identity.aio import DefaultAzureCredential
6+
7+
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings, AzureAIAgentThread
8+
from semantic_kernel.connectors.mcp import MCPStdioPlugin
9+
10+
"""
11+
The following sample demonstrates how to create a AzureAIAgent that
12+
answers questions about Github using a Semantic Kernel Plugin from a MCP server.
13+
"""
14+
15+
16+
async def main():
17+
async with (
18+
# 1. Login to Azure and create a Azure AI Project Client
19+
DefaultAzureCredential() as creds,
20+
AzureAIAgent.create_client(credential=creds) as client,
21+
# 2. Create the MCP plugin
22+
MCPStdioPlugin(
23+
name="github",
24+
description="Github Plugin",
25+
command="npx",
26+
args=["-y", "@modelcontextprotocol/server-github"],
27+
) as github_plugin,
28+
):
29+
# 3. Create the agent, with the MCP plugin and the thread
30+
agent = AzureAIAgent(
31+
client=client,
32+
definition=await client.agents.create_agent(
33+
model=AzureAIAgentSettings.create().model_deployment_name,
34+
name="GithubAgent",
35+
instructions="You are a microsoft/semantic-kernel Issue Triage Agent. "
36+
"You look at all issues that have the tag: 'triage' and 'python'."
37+
"When you find one that is untriaged, you will suggest a new assignee "
38+
"based on the issue description, look at recent closed PR's for issues in the same area. "
39+
"You will also suggest additional context if needed, like related issues or a bug fix. ",
40+
),
41+
plugins=[github_plugin], # add the sample plugin to the agent
42+
)
43+
thread: AzureAIAgentThread | None = None
44+
# 4. Print instructions and set the initial user input
45+
print("Starting Azure AI Agent with MCP Plugin sample...")
46+
print("Once the first prompt is answered, you can further ask questions, use `exit` to exit.")
47+
user_input = "Find the latest untriaged, unassigned issues and suggest new assignees."
48+
print(f"# User: {user_input}")
49+
try:
50+
while user_input.lower() != "exit":
51+
# 5. Invoke the agent for a response
52+
response = await agent.get_response(messages=user_input, thread=thread)
53+
print(f"# {response.name}: {response} ")
54+
thread = response.thread
55+
# 6. Get a new user input
56+
user_input = input("# User: ")
57+
finally:
58+
# 7. Cleanup: Clear the thread
59+
await thread.delete() if thread else None
60+
await client.agents.delete_agent(agent.definition.id)
61+
62+
"""
63+
Sample output:
64+
GitHub MCP Server running on stdio
65+
Starting Azure AI Agent with MCP Plugin sample...
66+
Once the first prompt is answered, you can further ask questions, use `exit` to exit.
67+
# User: Find the latest untriaged, unassigned issues and suggest new assignees.
68+
# GithubAgent: Here are the latest untriaged and unassigned issues that are tagged with Python:
69+
70+
1. **[Issue #11459](https://github.com/microsoft/semantic-kernel/issues/11459)**
71+
- **Title:** Python: Bug: The provided example is incorrect
72+
- **Description:** There are apparent mistakes in the provided Python examples concerning shared and
73+
non-shared stateful configurations.
74+
- **Assignee Suggestion:** Assign to **eavanvalkenburg** based on prior involvement with Python-related code and
75+
recent PRs focusing on bug fixes.
76+
77+
2. **[Issue #11465](https://github.com/microsoft/semantic-kernel/issues/11465)**
78+
- **Title:** Python: sample using GitHub MCP Server and Azure AI Agent
79+
- **Description:** This adds a sample demonstrating how to use MCP tools with the Azure AI Agent.
80+
- **Assignee Suggestion:** Assign to **eavanvalkenburg** who is associated with the issue.
81+
82+
### Summary of Suggested Assignees:
83+
- **Issue #11459**: **eavanvalkenburg**
84+
- **Issue #11465**: **eavanvalkenburg**
85+
86+
It seems that I cannot update the assignees directly due to authentication issues. You can use this information
87+
as you see fit to assign these issues. If you need further assistance or specific context for each issue,
88+
please let me know!
89+
"""
90+
91+
92+
if __name__ == "__main__":
93+
asyncio.run(main())

0 commit comments

Comments
 (0)