Skip to content

feat: add sf agent mcp asset afscript (W-24729191) - #519

Merged
nico-pappagianis merged 10 commits into
salesforcecli:mainfrom
adharsh-salesforce:w24729191-mcp-asset-afscript
Nov 16, 2026
Merged

nico-pappagianis merged 10 commits into
salesforcecli:mainfrom
adharsh-salesforce:w24729191-mcp-asset-afscript

Conversation

@adharsh-salesforce

@adharsh-salesforce adharsh-salesforce commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds the command sf agent mcp asset afscript -i <0Le server id> --tool <name> [--asset-id <1XO id>]. The command resolves the tool names and asset ids on the MCP server, calls McpAgentScript.generateActions, and prints the action blocks and reasoning entries. The text output is indented for the .agent file (8 and 12 spaces). --json returns the blocks without indentation. The help text says that the API also assigns MCP runtime permissions.

Why

The output is the same text that Agentforce Builder writes. A headless .agent file gets the same key, source and target as Builder. On a 264 development org, all non-blank lines matched the Builder output.

How tested

  • yarn build, yarn lint, yarn test: exit 0, including the JSON schema check.
  • test/commands/agent/mcp/mcp.test.ts: 34 passing.
  • Live run against the Core API on a 264 development org.
  • Runtime check: an agent built from the output called the MCP tool in Builder preview. The reasoner logged MCP tool call success.

Dependency

This PR needs forcedotcom/agents#395 (same change as #393) (adds McpAgentScript.generateActions). Before merge, release @salesforce/agents and bump it in package.json (^2.4.0 on main today). This branch does not change package.json yet, so CI is expected to fail until the bump.

Notes

  • The output lists all --tool values first, then all --asset-id values.
  • An org below API 68.0 gets a clear not-found message.
  • Input errors exit with code 1. API errors exit with code 4.

🤖 Generated with Claude Code

Work item: @W-24729191@

Same change as #515. This copy comes from the fork of the internal account adharsh-salesforce, to check the CLA.

Update an authoring bundle (--authoring-bundle, --subagent)

From review feedback: instead of printing the blocks for someone to paste, the command can now add them to a local authoring bundle.

sf agent mcp asset afscript -o myOrg -i <0Le server id> --tool hello_world --authoring-bundle My_Agent --subagent order_status --subagent returns

  • The two flags need each other. Without them the command prints the blocks as before.
  • For each subagent (or the start agent), it adds each action block under actions: (8 spaces) and each reasoning action under reasoning: > actions: (12 spaces), the places Agentforce Builder uses. It creates a missing actions:, reasoning: or reasoning actions: section.
  • It skips an action key that the subagent already has, so a second run changes nothing. The output lists what it added and skipped for each subagent; --json adds a bundle field with the same data.
  • It finds the bundle with findAuthoringBundle from @salesforce/agents and writes the .agent file. It does not compile it: compiling is a separate API, so run sf agent validate authoring-bundle after it. (An earlier version compiled the bundle; that blocked every run where the compile API is not reachable, such as dev workspace orgs, and every agent that already had unrelated compile errors.)
  • The org comes from --target-org, like the other commands that work on a bundle.

Tests: new test/commands/agent/mcp/afscriptBundle.test.ts: 7 tests for the insert (existing sections, missing sections, idempotent second run, other subagents unchanged, unknown subagent, start agent, CRLF) and 2 command tests (writes the file and does not call Agent.init; a second run changes nothing). The 36 existing mcp tests still pass. I also ran the insert on a real .agent file from an end-to-end test (it skipped the action the subagent already had and added only the new one), and live against a dev org on a workspace. command-snapshot.json and schemas/agent-mcp-asset-afscript.json are updated for the new flags and the bundle field.

All commits on this branch are signed now.

End-to-end test (2026-11-16)

On a dev org with the Core API from 264.13, a headless Claude with the agentforce-generate skill (updated in project-codey #4572) got "add the MCP tool calculate_quote from the MCP server ComplexESTypeFinal to the router of the agent P0Mcp_SkillTest, then validate and deploy it".

  • It ran sf agent mcp asset afscript -i <server> --tool calculate_quote --authoring-bundle P0Mcp_SkillTest --subagent agent_router --json and made no hand edit to the .agent file. The command reported added: [<key>], skipped: [].
  • The diff is +59 -0 lines, all inside start_agent agent_router. The action block and the reasoning entry are byte-equal to the --json output, and the key equals the tool's GenAiFunctionDefinition DeveloperName.
  • Deploy: Succeeded. In Builder Simulate the agent answered a quote request; the reasoner logged filtered 0 inaccessible actions and MCP tool call success: <key>.

Merge order: forcedotcom/agents#395 and its release, then this PR with the @salesforce/agents bump, then the skill in project-codey #4572.

@adharsh-salesforce
adharsh-salesforce marked this pull request as ready for review November 13, 2026 03:19
@adharsh-salesforce
adharsh-salesforce requested review from a team as code owners November 13, 2026 03:19
Live 264 org: asset list returns no active field. Only active=false blocks now.
Human output places action blocks at 8 spaces and reasoning entries at 12,
as Agentforce Builder does. Live check: every non-blank line equals the
Builder modal output.
…729191)

The asset list returns 15-char ids, so an exact compare rejected a correct 18-char id
before the API call. An 18-char id with a wrong checksum still counts as missing.
…and --subagent (W-24729191)

With --authoring-bundle <name> and one or more --subagent <name>, the command adds
each action block under the subagent's actions: and each reasoning action under its
reasoning: actions:, the places Agentforce Builder uses. It creates a missing section,
skips an action the subagent already has, then compiles the bundle in the org and
restores the file if the compile fails. Without the flags it prints the blocks as before.
@adharsh-salesforce
adharsh-salesforce force-pushed the w24729191-mcp-asset-afscript branch from 18264f8 to 455c37b Compare November 13, 2026 18:56
…4729191)

A live run on a workspace org showed the compile call can throw (AgentApiNotFound)
instead of returning errors. The command now restores the .agent file in that case
too and fails with AgentScriptCompileUnavailable. Adds command tests for the three
compile outcomes: success, compile errors, and a thrown compile error.
…729191)

Compiling is a separate API (agent validate authoring-bundle). Calling it from
this command blocked every run where that API is not reachable, and blocked
agents that already had unrelated compile errors. The command now only writes
the blocks and reports what it added and skipped; validate the bundle after it.
2.5.0 is the first release with McpAgentScript.generateActions, which
agent mcp asset afscript calls.
@nico-pappagianis
nico-pappagianis merged commit 8910968 into salesforcecli:main Nov 16, 2026
5 checks passed
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.

2 participants