Skip to content

feat(agent): template referencing for mcp integrations - #3125

Open
jordan-umusu wants to merge 1 commit into
fix/mcp-action-environmentfrom
feat/mcp-cred-setup
Open

feat(agent): template referencing for mcp integrations#3125
jordan-umusu wants to merge 1 commit into
fix/mcp-action-environmentfrom
feat/mcp-cred-setup

Conversation

@jordan-umusu

@jordan-umusu jordan-umusu commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary by cubic

Adds environment-aware templating for MCP integrations. Remote header values and stdio env vars now resolve ${{ SECRETS.* }} and ${{ VARS.* }} at runtime with strict, fail‑closed behavior; OAuth Authorization stays authoritative.

  • New Features
    • Resolve template expressions in remote MCP custom headers and OAuth extra headers; header names stay literal, user-supplied authorization is dropped when OAuth is used, and unresolved/malformed templates raise MCPConfigurationError instead of being sent.
    • Resolve template expressions in stdio MCP env values using a shared, strict resolver; missing or invalid references fail closed and literals are preserved.
    • New resolve_templated_mapping adds environment‑scoped resolution, value‑only mode for headers, reference counting, and sanitized errors; used by the MCP HTTP resolver and preset stdio env resolution. Extra guard rejects any header that still contains ${{ ... }}.
    • Pass the effective environment through MCP HTTP server config so secrets/variables resolve for the correct action environment.
    • MCP dialog editors add workspace‑aware @SECRETS/@VARS autocomplete with template pills; CodeEditor supports additionalExtensions and disables default completion when provided. Docs updated to reflect header value templating.

Written for commit 07b9fc8. Summary will update on new commits.

Review in cubic

@jordan-umusu
jordan-umusu marked this pull request as ready for review July 24, 2026 16:40
@jordan-umusu jordan-umusu added the agents LLM agents label Jul 24, 2026
@zeropath-ai

zeropath-ai Bot commented Jul 24, 2026

Copy link
Copy Markdown

No security or compliance issues detected. Reviewed everything up to 07b9fc8.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► frontend/src/components/editor/codemirror/code-editor.tsx
    Add additionalExtensions prop and integrate into extensions and autocompletion behavior
► frontend/src/components/editor/codemirror/common.tsx
    Introduce workspace mapping autocomplete and adjust template suggestions handling
► frontend/src/components/integrations/mcp-integration-dialog.tsx
    Integrate new template editor extensions for MCP editor, enable @SECRETS/@vars insertions, and enhance header description text
Enhancement ► tracecat/agent/mcp/secret_resolution.py
    Add templated mapping resolution logic and new exception type for resolution errors
► tracecat/agent/preset/service.py
    Use resolve_templated_mapping for MCP secret resolution integration
► tracecat/expressions/common.py
    Improve error logging context when jsonpath no matches and avoid exposing operands
Enhancement ► tracecat/expressions/core.py
    Pass strict mode through Expression and TemplateExpression to enable strict resolution behavior
► tracecat/expressions/eval.py
    Thread strict flag through evaluation paths for templated values
Enhancement ► tracecat/integrations/service.py
    Import mcp_secret_resolution module for secret handling in MCP integrations

@mintlify

mintlify Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
tracecat 🟢 Ready View Preview Jul 24, 2026, 4:45 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 90a3516437

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tracecat/agent/mcp/secret_resolution.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba9fb57720

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +104 to +106
vars_map = await get_workspace_variables(
variable_exprs=collected.variables,
role=role,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Thread action environment into MCP variable resolution

HTTP MCP header templates now resolve VARS.*, but this helper fetches variables without the effective workflow/action environment. build_agent_args_activity computes that environment for normal agent args (tracecat/dsl/action.py:694-705), then resolves MCP integrations with only the role (tracecat/dsl/action.py:715-717), and get_workspace_variables(..., environment=None) searches all environments. If a workspace has the same variable name in default and an overridden environment, the new remote header expression can pick the wrong value or depend on DB row order, sending credentials or tenant headers for another environment; thread the resolved environment through this MCP resolution path.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a48d133173

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +107 to +110
secrets = await secrets_manager.get_action_secrets(
secret_exprs=collected.secrets,
action_secrets=set(),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Resolve MCP secrets from the effective environment

When an MCP header or stdio env value references SECRETS.* and the action/workflow runs outside the default environment, this lookup still uses secrets_manager.get_action_secrets() without applying effective_environment; that helper fetches via AuthSandbox(environment=get_runtime_env()), and these MCP trusted-edge/activity paths do not set ctx_run to the action override. The adjacent VARS lookup is environment-scoped, so a mixed header like Authorization: ${{ SECRETS.api.TOKEN }} and X-Tenant: ${{ VARS.tenant.id }} can send a staging tenant with a default-environment credential.

Useful? React with 👍 / 👎.

Comment on lines +1047 to +1048
if environment is not None:
http_ref["environment"] = environment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Carry preset-agent environments into MCP refs

The new ref field is only populated when environment is passed, but preset-backed agents never pass their effective action environment when resolving the preset's saved mcp_integrations (_version_to_agent_config() still calls resolve_mcp_integration_refs(version.mcp_integrations) with no environment). In an ai.preset_agent step that overrides environment and uses a preset MCP server with VARS.* or environment-scoped SECRETS.* in headers/env, the trusted edge will re-resolve from the default environment instead of the action environment, selecting the wrong tenant or credentials.

Useful? React with 👍 / 👎.

@jordan-umusu
jordan-umusu changed the base branch from main to graphite-base/3125 July 27, 2026 15:44
@jordan-umusu
jordan-umusu force-pushed the feat/mcp-cred-setup branch from a48d133 to 07b9fc8 Compare July 27, 2026 15:44
@jordan-umusu
jordan-umusu changed the base branch from graphite-base/3125 to fix/mcp-action-environment July 27, 2026 15:44

Copy link
Copy Markdown
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

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

Labels

agents LLM agents feature mcp Tracecat MCP Connector priority:medium Medium priority ticket

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant