Files
agent-framework/python/scripts/local_mcp_streamable_http_server.py
Eduard van Valkenburg 5e056b672e Python: [BREAKING] Python: Provider-leading client design & OpenAI package extraction (#4818)
* Python: Provider-leading client design & OpenAI package extraction

Major refactoring of the Python Agent Framework client architecture:

- Extract OpenAI clients into new `agent-framework-openai` package
- Core package no longer depends on openai, azure-identity, azure-ai-projects
- Rename clients for discoverability: OpenAIResponsesClient → OpenAIChatClient,
  OpenAIChatClient → OpenAIChatCompletionClient
- Unify `model_id`/`deployment_name`/`model_deployment_name` → `model` param
- New FoundryChatClient for Azure AI Foundry Responses API
- New FoundryAgent/FoundryAgentClient for connecting to pre-configured Foundry agents
- Remove OpenAIBase/OpenAIConfigMixin from non-deprecated client MRO
- Deprecate AzureOpenAI* clients, AzureAIClient, OpenAIAssistantsClient
- Reorganize samples: azure_openai+azure_ai+azure_ai_agent → azure/
- ADR-0020: Provider-Leading Client Design

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: missing Agent imports in samples, .model_id → .model in foundry_local sample

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: CI failures — mypy errors, coverage targets, sample imports

- azure-ai mypy: add type ignores for TypedDict total=, model arg, forward ref
- Coverage: replace core.azure/openai targets with openai package target
- project_provider: add type annotation for opts dict

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: populate openai .pyi stub, fix broken README links, coverage targets

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fixes

* updated observabilitty

* reset azure init.pyi

* fix errors

* updated adr number

* fix foundry local

* fixed not renamed docstrings and comments, and added deprecated markers to old classes

* fix tests and pyprojects

* fix test vars

* updated function tests

* update durable

* updated test setup for functions

* Fix Foundry auth in workflow samples

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Stabilize Python integration workflows

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Update hosting samples for Foundry

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Trigger full CI rerun

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Trigger CI rerun again

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* trigger rerun

* trigger rerun

* fix for litellm

* undo durabletask changes

* Move Foundry APIs into foundry namespace

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix Foundry pyproject formatting

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Split provider samples by Foundry surface

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Restore hosting sample requirements

Also fix the Foundry Local sample link after the provider sample move.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* updated tests

* udpated foundry integration tests

* removed dist from azurefunctions tests

* Use separate Foundry clients for concurrent agents

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix client setup in azfunc and durable

* disabled two tests

* updated setup for some function and durable tests

* improved azure openai setup with new clients

* ignore deprecated

* fixes

* skip 11

* remove openai assistants int tests

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-25 09:56:29 +00:00

96 lines
3.1 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
"""Run a deterministic local streamable HTTP MCP server for integration tests."""
from __future__ import annotations
import argparse
import asyncio
from collections.abc import Sequence
from mcp.server.fastmcp import FastMCP
from starlette.requests import Request
from starlette.responses import JSONResponse, Response
DEFAULT_HOST = "127.0.0.1"
DEFAULT_PORT = 8011
DEFAULT_MOUNT_PATH = "/mcp"
SERVER_NAME = "agent-framework-local-ci-mcp"
AGENT_FRAMEWORK_DESCRIPTION = (
"Microsoft Agent Framework is a multi-language framework for building, orchestrating, and deploying AI agents."
)
def _normalize_mount_path(path: str) -> str:
"""Normalize a configured mount path for the streamable HTTP endpoint."""
normalized = path.strip() or DEFAULT_MOUNT_PATH
if not normalized.startswith("/"):
normalized = f"/{normalized}"
return normalized.rstrip("/") or "/"
def create_server(*, host: str, port: int, mount_path: str) -> FastMCP:
"""Create the local MCP integration test server."""
server = FastMCP(
name=SERVER_NAME,
instructions="Deterministic local MCP server used by Agent Framework integration tests.",
host=host,
port=port,
streamable_http_path=mount_path,
log_level="INFO",
)
@server.custom_route("/healthz", methods=["GET"], include_in_schema=False)
async def healthz(_request: Request) -> Response:
"""Return a simple readiness response for CI health checks."""
await asyncio.sleep(0)
return JSONResponse(
{
"status": "ok",
"name": SERVER_NAME,
"mcp_path": mount_path,
}
)
@server.tool(
name="search_agent_framework_docs",
description="Return deterministic Agent Framework documentation text for MCP integration tests.",
)
def search_agent_framework_docs(query: str) -> str:
"""Return a deterministic response for the MCP integration tests."""
return (
f"{AGENT_FRAMEWORK_DESCRIPTION}\n\n"
f"Query: {query}\n"
"This response came from the local streamable HTTP MCP integration test server."
)
return server
def parse_args(argv: Sequence[str] | None = None) -> argparse.Namespace:
"""Parse CLI arguments for the local MCP server."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--host", default=DEFAULT_HOST, help="Host interface to bind.")
parser.add_argument("--port", type=int, default=DEFAULT_PORT, help="Port to bind.")
parser.add_argument(
"--mount-path",
default=DEFAULT_MOUNT_PATH,
help="Mount path for the streamable HTTP MCP endpoint.",
)
return parser.parse_args(list(argv) if argv is not None else None)
def main(argv: Sequence[str] | None = None) -> None:
"""Start the local MCP streamable HTTP server."""
args = parse_args(argv)
server = create_server(
host=args.host,
port=args.port,
mount_path=_normalize_mount_path(args.mount_path),
)
server.run(transport="streamable-http")
if __name__ == "__main__":
main()