Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,43 @@ 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 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).

## Authentication

The application uses `DefaultAzureCredential` for authentication. Make sure you're logged in to Azure CLI:
Expand Down
41 changes: 28 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -35,23 +35,38 @@
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
# Example 1 - Microsoft Learn MCP server:
# mcp_tool = MCPStreamableHTTPTool(
# name="learn-mcp",
# url="https://learn.microsoft.com/mcp",
# description="Microsoft Learn MCP server"
# )

# 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)
# Example 2 - GitHub MCP server with OAuth:
# mcp_tool = MCPStreamableHTTPTool(
# 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
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:

# Create the agent
agent = ChatAgent(
chat_client=chat_client,
instructions=instructions
# Uncomment to add MCP tools:
# , tools=mcp_tool
)

while True:
user_message = input("Enter your message: ")

Expand Down