Skip to content

feat(toolbox): sync TOOLBOX_<NAME>_MCP_ENDPOINT env var on create/delete#8677

Merged
trangevi merged 3 commits into
mainfrom
zhihuan/toolbox-endpoint-env
Jun 19, 2026
Merged

feat(toolbox): sync TOOLBOX_<NAME>_MCP_ENDPOINT env var on create/delete#8677
trangevi merged 3 commits into
mainfrom
zhihuan/toolbox-endpoint-env

Conversation

@hund030

@hund030 hund030 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #8672. After azd ai toolbox create, the toolbox's versioned MCP endpoint is now persisted to the active azd environment instead of only printed, so developers and agents can consume it without re-running a command. azd ai toolbox delete clears it when the whole toolbox is removed.

Changes

  • toolbox_create.go / toolbox_delete.go: write the endpoint under TOOLBOX_<NAME>_MCP_ENDPOINT on create and blank it on whole-toolbox delete (version delete is intentionally untouched).
  • toolbox_env.go: new setToolboxEndpointEnv helper (gRPC GetCurrent + SetValue); best-effort — a missing azd daemon is skipped rather than failing the operation.
  • internal/foundry/envkey: key builder duplicated from azure.ai.agents (separate Go modules) so both extensions agree on the key; test mirrors the agents cases to guard drift.

azd ai toolbox create now writes the new toolbox's versioned MCP endpoint to the active azd environment under the TOOLBOX_<NORMALIZED_NAME>_MCP_ENDPOINT key (the same convention agents consume), and azd ai toolbox delete clears it when the whole toolbox is removed.

The key builder is duplicated from azure.ai.agents into internal/foundry/envkey since the extensions are separate Go modules. Env writes are best-effort: a missing azd daemon is skipped rather than failing the toolbox operation. Closes #8672.
Copilot AI review requested due to automatic review settings June 16, 2026 09:08
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

📋 Prioritization Note

Thanks for the contribution! The linked issue isn't in the current milestone yet.
Review may take a bit longer — reach out to @rajeshkamal5050 or @kristenwomack if you'd like to discuss prioritization.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the azure.ai.toolboxes extension to persist each toolbox’s version-scoped MCP endpoint into the active azd environment on azd ai toolbox create, and to clear that stored endpoint on whole-toolbox azd ai toolbox delete, enabling downstream agents/tools to consume the endpoint without re-running commands.

Changes:

  • Persist the created toolbox version’s MCP endpoint to the active azd environment under TOOLBOX_<NORMALIZED_NAME>_MCP_ENDPOINT.
  • Clear the persisted endpoint value on whole-toolbox delete (leaving version-delete behavior unchanged).
  • Add a shared env-var key normalizer (internal/foundry/envkey) plus unit tests and update extension changelog.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
cli/azd/extensions/azure.ai.toolboxes/internal/foundry/envkey/envkey.go Adds toolbox-name normalization and env-var key builder for TOOLBOX_<NAME>_MCP_ENDPOINT.
cli/azd/extensions/azure.ai.toolboxes/internal/foundry/envkey/envkey_test.go Adds test cases to keep key normalization aligned with the agents extension.
cli/azd/extensions/azure.ai.toolboxes/internal/cmd/toolbox_test_helpers_test.go Adds test seams to stub/record env sync calls from create/delete flows.
cli/azd/extensions/azure.ai.toolboxes/internal/cmd/toolbox_env.go Introduces helper that writes/clears the endpoint in the active azd environment via gRPC.
cli/azd/extensions/azure.ai.toolboxes/internal/cmd/toolbox_env_test.go Adds tests asserting endpoint env sync on create and clearing on whole-toolbox delete.
cli/azd/extensions/azure.ai.toolboxes/internal/cmd/toolbox_delete.go Clears the stored endpoint value after successful whole-toolbox deletion.
cli/azd/extensions/azure.ai.toolboxes/internal/cmd/toolbox_create.go Writes the computed versioned MCP endpoint to the env and updates emitted output accordingly.
cli/azd/extensions/azure.ai.toolboxes/internal/cmd/toolbox_commands_test.go Extends create tests to assert the endpoint env sync is invoked with the versioned URL.
cli/azd/extensions/azure.ai.toolboxes/CHANGELOG.md Documents the new env sync behavior under Unreleased.

Comment thread cli/azd/extensions/azure.ai.toolboxes/internal/cmd/toolbox_env.go
Comment thread cli/azd/extensions/azure.ai.toolboxes/internal/foundry/envkey/envkey.go Outdated
Comment thread cli/azd/extensions/azure.ai.toolboxes/internal/cmd/toolbox_env.go Outdated
…pell

GetCurrent returns codes.Unknown 'default environment not found' (not Unavailable) when no default environment is selected, which previously hard-failed create/delete. Match the message text (as azure.ai.agents does) so the env write is skipped. Add envkey/Alphanum to the extension cspell word list.
@glharper

Copy link
Copy Markdown
Member

Review — Approve ✅

Clean, well-tested, and consistent with the extension conventions. No blocking issues.

What it does

After azd ai toolbox create, the versioned MCP endpoint is persisted to the active azd environment under TOOLBOX_<NORMALIZED_NAME>_MCP_ENDPOINT (the key agents consume), and whole-toolbox delete blanks it. Version-delete is intentionally left untouched.

Strengths

  • Cross-extension key consistency verified. Diffed the new internal/foundry/envkey/envkey.go against azure.ai.agents/internal/pkg/envkey/envkey.go — the normalization ([^A-Z0-9]+_) and format string are logically byte-for-byte equivalent, and the mirrored test cases (incl. run-collapsing, trailing underscore, empty) guard against drift. The duplication is justified per the package-boundary rule (separate Go modules).
  • Error handling matches the AGENTS guidance. setToolboxEndpointEnv classifies once via exterrors.Internal(CodeAzdClientFailed, …) at the user-facing boundary; lower helpers stay plain. The best-effort skip (isNoAzdEnvironment) correctly covers both codes.Unavailable (no daemon) and the status-less "default environment not found" sentinel surfaced as codes.Unknown.
  • Testability seam (setToolboxEndpointEnvFunc var) lets the create/delete cores be unit-tested without a live gRPC server; tests assert the happy path, error propagation, and the version-scoped URL.
  • Docs/CHANGELOG/cspell all updated; log.Printf (not fmt) used for the skip diagnostic — correct per the log-vs-fmt convention.

Minor observations (non-blocking)

  1. Ordering side effect: on create, the toolbox is created before the env write, so an env-write failure returns an error while the toolbox already exists. This is deliberate and covered by TestRunToolboxCreateWith_EnvSyncErrorPropagates. Reasonable, but worth confirming the team is fine surfacing a hard error for what's otherwise a convenience write — an argument could be made to make SetValue best-effort too (log + continue) so a transient daemon hiccup doesn't fail an otherwise-successful create.
  2. isNoAzdEnvironment message match depends on the host's exact string "default environment not found", which is inherently fragile — but it mirrors the existing azure.ai.agents behavior, so acceptable.

Verification performed

  • go build ./...
  • go test ./internal/cmd/... ./internal/foundry/envkey/... ✅ (both pass)
  • Confirmed withAzdClient, buildToolboxMcpURL (version-scoped URL), exterrors.Internal, and CodeAzdClientFailed all resolve correctly.
  • No lines exceed the 125-char lll limit in the new Go files.

…int-env

# Conflicts:
#	cli/azd/extensions/azure.ai.toolboxes/CHANGELOG.md
@github-actions github-actions Bot added the ext-toolboxes azure.ai.toolboxes extension label Jun 18, 2026
@trangevi trangevi merged commit cf1073a into main Jun 19, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext-agents azure.ai.agents extension ext-toolboxes azure.ai.toolboxes extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azd ai toolbox create and delete should also add the toolbox endpoint to env var

5 participants