Python: Introducing Local MCP Servers (#389)

* mcp parts

* mcp parts 2

* removed structured output in favor of handling in chatresponse, mcp as AITool and running samples

* updated naming

* fixed test
This commit is contained in:
Eduard van Valkenburg
2025-08-13 11:48:22 +02:00
committed by GitHub
Unverified
parent 80b0920e58
commit ad3d8171bf
20 changed files with 1970 additions and 298 deletions
@@ -4,9 +4,10 @@ import asyncio
from random import randint
from typing import Annotated
from agent_framework import ChatResponse
from agent_framework.azure import AzureResponsesClient
from azure.identity import DefaultAzureCredential
from pydantic import Field
from pydantic import BaseModel, Field
def get_weather(
@@ -17,20 +18,28 @@ def get_weather(
return f"The weather in {location} is {conditions[randint(0, 3)]} with a high of {randint(10, 30)}°C."
class OutputStruct(BaseModel):
"""Structured output for weather information."""
location: str
weather: str
async def main() -> None:
client = AzureResponsesClient(ad_credential=DefaultAzureCredential())
message = "What's the weather in Amsterdam and in Paris?"
stream = False
stream = True
print(f"User: {message}")
if stream:
print("Assistant: ", end="")
async for chunk in client.get_streaming_response(message, tools=get_weather):
if str(chunk):
print(str(chunk), end="")
print("")
response = await ChatResponse.from_chat_response_generator(
client.get_streaming_response(message, tools=get_weather, response_format=OutputStruct),
output_format_type=OutputStruct,
)
print(f"Assistant: {response.value}")
else:
response = await client.get_response(message, tools=get_weather)
print(f"Assistant: {response}")
response = await client.get_response(message, tools=get_weather, response_format=OutputStruct)
print(f"Assistant: {response.value}")
if __name__ == "__main__":