Skip to content

Commit 6b986c1

Browse files
committed
refactor: move Python changes to a separate PR
1 parent a4cfb73 commit 6b986c1

2 files changed

Lines changed: 24 additions & 20 deletions

File tree

‎python/samples/02-agents/providers/foundry/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This folder contains Microsoft Foundry and Foundry Local samples for Agent Frame
2727
| [`foundry_chat_client_with_hosted_mcp.py`](foundry_chat_client_with_hosted_mcp.py) | Foundry Chat Client with hosted MCP |
2828
| [`foundry_chat_client_with_local_mcp.py`](foundry_chat_client_with_local_mcp.py) | Foundry Chat Client with local MCP |
2929
| [`foundry_chat_client_with_session.py`](foundry_chat_client_with_session.py) | Foundry Chat Client with session management |
30-
| [`foundry_chat_client_with_toolbox.py`](foundry_chat_client_with_toolbox.py) | Discover and invoke Foundry toolbox tools on demand with `tool_search` and `call_tool` over MCP |
30+
| [`foundry_chat_client_with_toolbox.py`](foundry_chat_client_with_toolbox.py) | Foundry Chat Client connected to a toolbox via its MCP endpoint using `MCPStreamableHTTPTool` |
3131
| [`foundry_chat_client_with_toolbox_skills.py`](foundry_chat_client_with_toolbox_skills.py) | Foundry Chat Client that discovers MCP-based skills from a Foundry Toolbox endpoint via `MCPSkillsSource` (uses an Azure AD bearer token and the toolbox preview header) |
3232

3333
## FoundryLocalClient Samples

‎python/samples/02-agents/providers/foundry/foundry_chat_client_with_toolbox.py‎

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@
2424
Prerequisites:
2525
- A Microsoft Foundry project with a toolbox configured
2626
- FOUNDRY_PROJECT_ENDPOINT and FOUNDRY_MODEL environment variables set
27+
- FOUNDRY_TOOLBOX_ENDPOINT: the toolbox's MCP endpoint URL, e.g.
28+
``https://<account>.services.ai.azure.com/api/projects/<project>/toolsets/<name>/mcp?api-version=v1``
2729
- Azure CLI authentication (``az login``)
28-
29-
The helper publishes a version with tool search enabled and connects to that exact
30-
version. The model initially sees tool_search and call_tool, then discovers the
31-
underlying MCP tools as needed. Each run creates a version; existing versions are
32-
not deleted. Remove ToolSearchToolboxTool() to compare the full initial tool list.
3330
"""
3431

32+
# Must match the ``<name>`` segment of FOUNDRY_TOOLBOX_ENDPOINT.
3533
TOOLBOX_NAME = "research_toolbox"
3634

3735

3836
def create_sample_toolbox(name: str) -> str:
39-
"""Create a toolbox version with tool search in the Foundry project.
37+
"""Create (or replace) a toolbox version in the Foundry project.
4038
4139
Toolboxes are normally configured in the Foundry portal or a deployment
4240
script, not the application itself. This helper exists so the sample can
43-
be run end-to-end without first setting a toolbox up by hand. Returns the
44-
created version identifier without deleting existing versions.
41+
be run end-to-end without first setting a toolbox up by hand — delete any
42+
existing toolbox under ``name``, then create a fresh version containing a
43+
single MCP tool. Returns the created version identifier.
4544
"""
4645
from azure.ai.projects import AIProjectClient
47-
from azure.ai.projects.models import MCPToolboxTool, ToolboxTool, ToolSearchToolboxTool
46+
from azure.ai.projects.models import MCPTool, Tool
47+
from azure.core.exceptions import ResourceNotFoundError
4848

4949
with (
5050
AzureCliCredential() as credential,
@@ -54,18 +54,23 @@ def create_sample_toolbox(name: str) -> str:
5454
if toolboxes is None:
5555
toolboxes = cast(Any, project_client.beta).toolboxes
5656

57-
tools: list[ToolboxTool] = [
58-
MCPToolboxTool(
57+
try:
58+
toolboxes.delete(name)
59+
print(f"Toolbox `{name}` deleted")
60+
except ResourceNotFoundError:
61+
pass
62+
63+
tools: list[Tool] = [
64+
MCPTool(
5965
server_label="api_specs",
6066
server_url="https://gitmcp.io/Azure/azure-rest-api-specs",
6167
require_approval="never",
62-
),
63-
ToolSearchToolboxTool(),
68+
)
6469
]
6570

6671
created = toolboxes.create_version(
6772
name=name,
68-
description="Toolbox version with MCP tools discovered through tool search.",
73+
description="Toolbox version with MCP require_approval set to 'never'.",
6974
tools=tools,
7075
)
7176
print(f"Created toolbox {created.name}@{created.version} ({len(created.tools)} tool(s))")
@@ -87,14 +92,13 @@ def provide(_kwargs: dict[str, Any]) -> dict[str, str]:
8792
async def main() -> None:
8893
credential = DefaultAzureCredential()
8994

90-
# Connect to the new version so the tool-search configuration is unambiguous.
91-
version = create_sample_toolbox(TOOLBOX_NAME)
92-
project_endpoint = os.environ["FOUNDRY_PROJECT_ENDPOINT"].rstrip("/")
95+
# Comment out if the toolbox already exists in your Foundry project.
96+
create_sample_toolbox(TOOLBOX_NAME)
9397

9498
toolbox_tool = MCPStreamableHTTPTool(
9599
name="foundry_toolbox",
96100
description="Tools exposed by the configured Foundry toolbox",
97-
url=f"{project_endpoint}/toolboxes/{TOOLBOX_NAME}/versions/{version}/mcp?api-version=v1",
101+
url=os.environ["FOUNDRY_TOOLBOX_ENDPOINT"],
98102
header_provider=make_toolbox_header_provider(credential),
99103
load_prompts=False,
100104
)
@@ -108,7 +112,7 @@ async def main() -> None:
108112
instructions="You are a helpful assistant. Use the available toolbox tools to answer the user.",
109113
tools=toolbox_tool,
110114
) as agent:
111-
query = "Find the REST API documentation for Azure Container Apps session pools."
115+
query = "What tools do you have access to?"
112116
print(f"User: {query}")
113117
result = await agent.run(query)
114118
print(f"Assistant: {result}")

0 commit comments

Comments
 (0)