Skip to content

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

Open
adharshvlocity wants to merge 6 commits into
salesforcecli:mainfrom
adharshvlocity:w24729191-mcp-asset-afscript
Open

adharshvlocity wants to merge 6 commits into
salesforcecli:mainfrom
adharshvlocity:w24729191-mcp-asset-afscript

Conversation

@adharshvlocity

@adharshvlocity adharshvlocity commented Nov 10, 2026 •

Copy link
Copy Markdown

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#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

adharsh-salesforce and others added 3 commits November 9, 2026 11:52
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Live 264 org: asset list returns no active field. Only active=false blocks now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@salesforce-cla

Copy link
Copy Markdown

Thanks for the contribution! It looks like @adharsh-salesforce is an internal user so signing the CLA is not required. However, we need to confirm this.

adharsh-salesforce and others added 2 commits November 9, 2026 20:27
…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.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adharshvlocity
adharshvlocity marked this pull request as ready for review November 12, 2026 17:58
@adharshvlocity
adharshvlocity requested review from a team as code owners November 12, 2026 17:58
@adharshvlocity

Copy link
Copy Markdown
Author
Screenshot 2026-11-12 at 9 34 14 AM

@salesforce-cla

Copy link
Copy Markdown

Thanks for the contribution! Before we can merge this, we need @adharshvlocity to sign the Salesforce Inc. Contributor License Agreement.

@adharshvlocity

Copy link
Copy Markdown
Author

CLA signed

nico-pappagianis pushed a commit that referenced this pull request Nov 16, 2026
## 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](https://claude.com/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.
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