Skip to content

Add env vars to resource MCP#12665

Merged
JamesNK merged 2 commits intomainfrom
jamesnk/mcp-env-vars
Nov 6, 2025
Merged

Add env vars to resource MCP#12665
JamesNK merged 2 commits intomainfrom
jamesnk/mcp-env-vars

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Nov 4, 2025

Description

Make resource env vars available in list_resources.

Example of env var values:
image

Alternative ideas:

  • Only include env var names and not values
  • Only include env var names and not values, and add a get_resource_env_var tool call that takes a resource name and env var name, and returns the value.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Copilot AI review requested due to automatic review settings November 4, 2025 09:00
@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12665

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12665"

Copy link
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

This PR adds the ability to include environment variables in the resource graph JSON output for AI/MCP tools. This allows AI assistants to access configured environment variables when analyzing application resources.

Key changes:

  • Added an optional includeEnvironmentVariables parameter to GetResponseGraphJson method
  • Updated the MCP list_resources tool to include environment variables in its output
  • Updated the tool description to reflect the new capability

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Aspire.Dashboard/Model/Assistant/AIHelpers.cs Added includeEnvironmentVariables parameter and logic to conditionally include environment variables in resource graph JSON
src/Aspire.Dashboard/Mcp/AspireResourceMcpTools.cs Updated list_resources tool to request environment variables and updated its description

@sebastienros
Copy link
Member

My recommendation would be to start with names only, this will handle the majority of the needs. At least until there is a way to opt-in for also sending values.

And without it what about using regexes to categorize the values and return patterns instead of the actual values, either name of the format or format with placeholders (redacted segments that are not special chars / separators).

  • true|false => [BOOLEAN]
  • proto://[user:pass@]host:port (and/or _URI name) -> [URI] or redact secret and query
  • http://domain/path?query -> http://[DOMAIN]/[PATH]?[QUERY]
  • key=value;... or ConnectionString in the name -> [ConnectionString] or redact values key1=[VALUE];key2=[VALUE] if there are multiple values (prevent false positive)
  • number -> [NUMBER]
  • random string -> [STRING]

@JamesNK
Copy link
Member Author

JamesNK commented Nov 5, 2025

Updated to names only. And added a sentence to results to explain that environment_variables are names only for security reasons.

@JamesNK
Copy link
Member Author

JamesNK commented Nov 6, 2025

Waiting on approve...

Copy link
Member

@sebastienros sebastienros left a comment

Choose a reason for hiding this comment

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

Have you tried the same kind of demo as @maddymontaquila but without the screenshot?

@davidfowl
Copy link
Member

I did!

@JamesNK JamesNK merged commit dc21640 into main Nov 6, 2025
296 checks passed
@JamesNK JamesNK deleted the jamesnk/mcp-env-vars branch November 6, 2025 01:05
@JamesNK
Copy link
Member Author

JamesNK commented Nov 6, 2025

/backport to release/13.0

@dotnet-policy-service dotnet-policy-service bot added this to the 13.1 milestone Nov 6, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/19121393650

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants