From 62f2a16e958533087d9a2ae7bd97a38c841c60d7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 09:10:38 +0000 Subject: [PATCH 1/3] Initial plan From 44a0bf620ea6e1a101140812a66ada68633a6582 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 09:16:38 +0000 Subject: [PATCH 2/3] Update MCP server support with correct implementation Co-authored-by: paulyuk <1968137+paulyuk@users.noreply.github.com> --- README.md | 30 ++++++++++++++++++++++++++++ main.py | 59 +++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 39a7bd3..60e5ef8 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,36 @@ Enter a message like `what are the laws?` The application will start an interactive conversation loop where you can ask questions. Type 'exit' or 'quit' to end the session. +### Using MCP Servers + +The application supports Model Context Protocol (MCP) servers for extending agent capabilities with remote tools. To use an MCP server: + +1. Uncomment the MCP tool configuration in `main.py`: + +```python +# Create MCP tool from remote URL +mcp_tool = MCPStreamableHTTPTool( + name="example-mcp", + url="https://example.com/mcp", + description="Example MCP server tool" +) +``` + +2. For MCP servers requiring authentication, include headers: + +```python +mcp_tool = MCPStreamableHTTPTool( + name="example-mcp", + url="https://example.com/mcp", + headers={"Authorization": "Bearer YOUR_TOKEN_HERE"}, + description="Example MCP server tool with auth" +) +``` + +3. Uncomment the async context manager usage in the `main()` function to enable the MCP tool with your agent. + +For more information about MCP tools, see the [Agent Framework MCP documentation](https://learn.microsoft.com/en-us/agent-framework/user-guide/model-context-protocol/using-mcp-tools?pivots=programming-language-python). + ## Authentication The application uses `DefaultAzureCredential` for authentication. Make sure you're logged in to Azure CLI: diff --git a/main.py b/main.py index 6c352d2..fbc30e0 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ import asyncio import os -from agent_framework import ChatAgent +from agent_framework import ChatAgent, MCPStreamableHTTPTool from agent_framework.azure import AzureOpenAIChatClient from azure.identity import DefaultAzureCredential, get_bearer_token_provider @@ -35,23 +35,56 @@ ad_token_provider=token_provider ) -# Create the agent -agent = ChatAgent( - chat_client=chat_client, - instructions=instructions -) - -# Optional: Add MCP tool from remote URL -# agent.add_mcp_server("https://example.com/mcp-server") +# Optional: Create MCP tool from remote URL +# Uncomment and configure the following to use an MCP server: +# mcp_tool = MCPStreamableHTTPTool( +# name="example-mcp", +# url="https://example.com/mcp", +# description="Example MCP server tool" +# ) -# Optional: Add MCP tool with authentication -# import httpx -# headers = {"Authorization": "Bearer YOUR_TOKEN_HERE"} -# agent.add_mcp_server("https://example.com/mcp-server", headers=headers) +# Optional: Create MCP tool with authentication headers +# mcp_tool = MCPStreamableHTTPTool( +# name="example-mcp", +# url="https://example.com/mcp", +# headers={"Authorization": "Bearer YOUR_TOKEN_HERE"}, +# description="Example MCP server tool with auth" +# ) # Stay in a loop for continuous conversation async def main(): """Run interactive conversation loop with the agent.""" + + # Optional: Use MCP tool in async context manager + # Uncomment to use MCP tools with the agent: + # async with mcp_tool: + # agent = ChatAgent( + # chat_client=chat_client, + # instructions=instructions, + # tools=mcp_tool + # ) + # + # while True: + # user_message = input("Enter your message: ") + # + # # Check for exit commands + # if not user_message or user_message.lower() in ["exit", "quit"]: + # print("Goodbye!") + # break + # + # try: + # # Invoke the agent and output the text result + # result = await agent.run(user_message) + # print(f"\n{result.text}\n") + # except Exception as ex: + # print(f"Error: {ex}\n") + + # Create the agent without MCP tools + agent = ChatAgent( + chat_client=chat_client, + instructions=instructions + ) + while True: user_message = input("Enter your message: ") From 782e7555735e71a712f2610a12d8fa24bc491ce4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 09:30:19 +0000 Subject: [PATCH 3/3] Simplify MCP examples and use real server URLs Co-authored-by: paulyuk <1968137+paulyuk@users.noreply.github.com> --- README.md | 53 ++++++++++++++++++++++++++++++----------------------- main.py | 42 ++++++++++++------------------------------ 2 files changed, 42 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 60e5ef8..360bb8b 100644 --- a/README.md +++ b/README.md @@ -77,29 +77,36 @@ The application will start an interactive conversation loop where you can ask qu The application supports Model Context Protocol (MCP) servers for extending agent capabilities with remote tools. To use an MCP server: -1. Uncomment the MCP tool configuration in `main.py`: - -```python -# Create MCP tool from remote URL -mcp_tool = MCPStreamableHTTPTool( - name="example-mcp", - url="https://example.com/mcp", - description="Example MCP server tool" -) -``` - -2. For MCP servers requiring authentication, include headers: - -```python -mcp_tool = MCPStreamableHTTPTool( - name="example-mcp", - url="https://example.com/mcp", - headers={"Authorization": "Bearer YOUR_TOKEN_HERE"}, - description="Example MCP server tool with auth" -) -``` - -3. Uncomment the async context manager usage in the `main()` function to enable the MCP tool with your agent. +1. Uncomment one of the MCP tool examples in `main.py`: + + **Example 1 - Microsoft Learn MCP server:** + ```python + mcp_tool = MCPStreamableHTTPTool( + name="learn-mcp", + url="https://learn.microsoft.com/mcp", + description="Microsoft Learn MCP server" + ) + ``` + + **Example 2 - GitHub MCP server with OAuth:** + ```python + mcp_tool = MCPStreamableHTTPTool( + name="github-mcp", + url="https://api.github.com/mcp", + headers={"Authorization": f"Bearer {os.getenv('GITHUB_TOKEN')}"}, + description="GitHub MCP server" + ) + ``` + +2. Uncomment the async context manager line: + ```python + # async with mcp_tool: + ``` + +3. Uncomment the tools parameter in the ChatAgent: + ```python + # , tools=mcp_tool + ``` For more information about MCP tools, see the [Agent Framework MCP documentation](https://learn.microsoft.com/en-us/agent-framework/user-guide/model-context-protocol/using-mcp-tools?pivots=programming-language-python). diff --git a/main.py b/main.py index fbc30e0..de361bb 100644 --- a/main.py +++ b/main.py @@ -36,19 +36,19 @@ ) # Optional: Create MCP tool from remote URL -# Uncomment and configure the following to use an MCP server: +# Example 1 - Microsoft Learn MCP server: # mcp_tool = MCPStreamableHTTPTool( -# name="example-mcp", -# url="https://example.com/mcp", -# description="Example MCP server tool" +# name="learn-mcp", +# url="https://learn.microsoft.com/mcp", +# description="Microsoft Learn MCP server" # ) -# Optional: Create MCP tool with authentication headers +# Example 2 - GitHub MCP server with OAuth: # mcp_tool = MCPStreamableHTTPTool( -# name="example-mcp", -# url="https://example.com/mcp", -# headers={"Authorization": "Bearer YOUR_TOKEN_HERE"}, -# description="Example MCP server tool with auth" +# name="github-mcp", +# url="https://api.github.com/mcp", +# headers={"Authorization": f"Bearer {os.getenv('GITHUB_TOKEN')}"}, +# description="GitHub MCP server" # ) # Stay in a loop for continuous conversation @@ -58,31 +58,13 @@ async def main(): # Optional: Use MCP tool in async context manager # Uncomment to use MCP tools with the agent: # async with mcp_tool: - # agent = ChatAgent( - # chat_client=chat_client, - # instructions=instructions, - # tools=mcp_tool - # ) - # - # while True: - # user_message = input("Enter your message: ") - # - # # Check for exit commands - # if not user_message or user_message.lower() in ["exit", "quit"]: - # print("Goodbye!") - # break - # - # try: - # # Invoke the agent and output the text result - # result = await agent.run(user_message) - # print(f"\n{result.text}\n") - # except Exception as ex: - # print(f"Error: {ex}\n") - # Create the agent without MCP tools + # Create the agent agent = ChatAgent( chat_client=chat_client, instructions=instructions + # Uncomment to add MCP tools: + # , tools=mcp_tool ) while True: