Skip to content

cli: allow resolving MCP URL containing ${ENV_VAR}#342

Merged
peterj merged 1 commit intoagentregistry-dev:mainfrom
shashankram:url-env
Mar 13, 2026
Merged

cli: allow resolving MCP URL containing ${ENV_VAR}#342
peterj merged 1 commit intoagentregistry-dev:mainfrom
shashankram:url-env

Conversation

@shashankram
Copy link
Copy Markdown
Collaborator

Description

Allows resolving MCP URLs containing ${ENV_VAR} using dynamic URL resolution from environment variables at runtime. This is extremely useful to not hardcode the MCP URL in the agent code and instead specify them during deployment using environment variables, decoupling code from runtime values that are dynamic.

E.g. arctl agent add-mcp --remote http://\${ADDRESS}/mcp

Change Type

/kind new_feature

Changelog

Allows MCP URLs containing environment variables to be resolved
at runtime.

\# Description
Allows resolving MCP URLs containing ${ENV_VAR} using
dynamic URL resolution from environment variables at runtime.
This is extremely useful to not hardcode the MCP URL in
the agent code and instead specify them during deployment
using environment variables, decoupling code from runtime
values that are dynamic.

\# Change Type

```
/kind new_feature
```

\# Changelog

```release-note
Allows MCP URLs containing environment variables to be resolved
at runtime.
```

Signed-off-by: Shashank Ram <[email protected]>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Enables MCP remote URLs in agent manifests to include ${ENV_VAR} placeholders by relaxing CLI validation (sanitizing placeholders before parsing) and resolving placeholders at runtime in the generated Python agent code.

Changes:

  • Update CLI manifest validation for remote MCP URLs to tolerate ${VAR} placeholders.
  • Add unit tests covering remote MCP URL validation with ${VAR} in host/port/path.
  • Resolve ${VAR} placeholders in MCP URLs at runtime in the ADK Python agent template.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
internal/cli/agent/frameworks/common/manifest_manager.go Sanitizes ${VAR} placeholders prior to url.Parse for remote MCP URL validation.
internal/cli/agent/frameworks/common/manifest_manager_test.go Adds test cases ensuring placeholder-containing remote URLs pass validation.
internal/cli/agent/frameworks/adk/python/templates/agent/mcp_tools.py.tmpl Resolves ${VAR} placeholders in MCP URL (and already in headers) at runtime.
Comments suppressed due to low confidence (1)

internal/cli/agent/frameworks/common/manifest_manager.go:105

  • Current placeholder-sanitization makes URLs that are entirely an env var placeholder (e.g. "${FULL_URL}") fail scheme validation. This conflicts with the PR description’s goal of avoiding hardcoded MCP URLs; consider either allowing a full-placeholder URL (and deferring scheme validation to runtime) or explicitly documenting that scheme/host must be literal and only parts of the URL may be env-substituted (and adjust the validation error message accordingly).
	// Replace ${VAR} placeholders with dummy values so url.Parse can
	// validate the structure. The actual env vars are resolved at runtime.
	// Port placeholders (e.g. :${PORT}) need a numeric replacement.
	sanitized := envVarPortPattern.ReplaceAllString(srv.URL, ":8080")
	sanitized = envVarPattern.ReplaceAllString(sanitized, "placeholder")
	parsed, err := url.Parse(sanitized)
	if err != nil {
		return fmt.Errorf("mcpServers[%d]: url is not a valid URL: %v", i, err)
	}
	if parsed.Scheme != "http" && parsed.Scheme != "https" {
		return fmt.Errorf("mcpServers[%d]: url scheme must be http or https", i)
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@shashankram shashankram added this pull request to the merge queue Mar 13, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 13, 2026
@peterj peterj added this pull request to the merge queue Mar 13, 2026
Merged via the queue into agentregistry-dev:main with commit aa99fcf Mar 13, 2026
11 checks passed
@shashankram shashankram deleted the url-env branch March 13, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants