Skip to content

@W-21105798: Scaffold Custom API MCP Tool#204

Merged
wei-liu-sf merged 12 commits intomainfrom
W-21105798.wei-liu-sf.scaffold
Feb 26, 2026
Merged

@W-21105798: Scaffold Custom API MCP Tool#204
wei-liu-sf merged 12 commits intomainfrom
W-21105798.wei-liu-sf.scaffold

Conversation

@wei-liu-sf
Copy link
Collaborator

@wei-liu-sf wei-liu-sf commented Feb 24, 2026

Summary

Implementation of Scaffold Custom API MCP Tool

Testing

Restart the local B2C-DX-MCP

Dependencies

  • No net-new third-party dependencies were added
  • If net-new third-party dependencies were added, rationale/discussion is included and 3pl-approved is set by a maintainer

  • Tests pass (pnpm test)
  • Code is formatted (pnpm run format)

@wei-liu-sf wei-liu-sf marked this pull request as draft February 24, 2026 19:39
const flagConfig = {
...extractInstanceFlags(this.flags as Record<string, unknown>),
...mrt.config,
workingDirectory: this.flags['working-directory'],
Copy link
Contributor

Choose a reason for hiding this comment

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

working-directory is deprecated. See #199.

also see prior #160 which exposes workingDirectory/projectDirectory in thecontext.services.getWorkingDirectory() passed to each tool. Not sure which approach is better, but we should standardize on a best one.

Copy link
Contributor

Choose a reason for hiding this comment

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

resolved

.min(1)
.nullish()
.describe(
'Cartridge name that will contain the API. Optional; omit to use the first cartridge found under working directory (--working-directory or SFCC_WORKING_DIRECTORY).',
Copy link
Contributor

Choose a reason for hiding this comment

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

deprecated flags and env vars. see #199

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As I have some questions related to workingDirectory deprecation, I will leave this as is for now and follow up with Charles when he comes back.

Copy link
Contributor

Choose a reason for hiding this comment

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

My preference is to follow the pattern used in all the other tools for now. If later after discussing we decide we need to change our pattern, having everything consistent will make that change easier. Insisting on showing a flag that is correctly marked deprecated is going to confuse our users.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since all other places are changed, can we change this to project directory as well to keep them the same?

Copy link
Contributor

Choose a reason for hiding this comment

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

resolved for now. will revisit.

export function createScaffoldCustomApiTool(loadServices: () => Services): McpTool {
return createToolAdapter<ScaffoldCustomApiInput, ScaffoldCustomApiOutput>(
{
name: 'scapi_customapi_scaffold',
Copy link
Contributor

Choose a reason for hiding this comment

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

We have scapi_custom_apis_status tool, can we unify the tool name? Maybe scapi_custom_api_scaffold

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This name "scapi_custom_api_scaffold" is following the LLD. Once LLD is updated, will update here.

Copy link
Contributor

@yhsieh1 yhsieh1 Feb 25, 2026

Choose a reason for hiding this comment

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

@wei-liu-sf I corrected the name in LLD so that it matches the naming with other scapi tools. Please update it to scapi_custom_api_scaffold. Thank you.

const flagConfig = {
...extractInstanceFlags(this.flags as Record<string, unknown>),
...mrt.config,
workingDirectory: this.flags['working-directory'],
Copy link
Contributor

Choose a reason for hiding this comment

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

getBaseConfigOptions() already supplies workingDirectory so we do not need it here again.

/** Short description of the API. Default: "A custom B2C Commerce API" */
apiDescription?: string;
/** Include example GET/POST endpoints in schema and script. Default: true */
includeExampleEndpoints?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Wonder when agent will set this to false? Do we need this input?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's default to true. I can remove it.

/** Output directory override. Default: scaffold default or project root */
outputDir?: string;
/** If true, preview only (no files written). Default: false */
dryRun?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

What will happen when dryRun is true? Do we need this?

name: 'scapi_customapi_scaffold',
description: `Generate a new custom SCAPI endpoint (OAS 3.0 schema, api.json, script.js) in an existing cartridge. \
Uses the same scaffold as CLI: b2c scaffold generate custom-api. \
Required: apiName (kebab-case). Optional: cartridgeName (defaults to first cartridge found in project), apiType (shopper|admin), apiDescription, includeExampleEndpoints, projectRoot, outputDir, dryRun, force. \
Copy link
Contributor

Choose a reason for hiding this comment

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

Description can be improved to avoid duplicated inputs info that is specified in the input schema. Also we probably can skip the mention of CLI since that seems not help agent to use the tool.

dryRun: args.dryRun ?? false,
files: [],
error:
'No cartridges found in project. Add a cartridge (directory with .project file) or pass cartridgeName explicitly.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we give more details so that agent knows how to add a cartridge project?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, will do

* Generates a new custom SCAPI endpoint using the SDK's custom-api scaffold
* (schema.yaml, api.json, script.js). Mirrors CLI: b2c scaffold generate custom-api.
*
* @module tools/scapi/scapi-customapi-scaffold
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we update file name as well?

{
name: 'scapi_custom_api_scaffold',
description: `Generate a new custom SCAPI endpoint (OAS 3.0 schema, api.json, script.js) in an existing cartridge. \
Uses the same scaffold as CLI: b2c scaffold generate custom-api. \
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove LCI from the description? We should try to keep description short and simple. Mention of CLI might confuse agent.

@wei-liu-sf wei-liu-sf marked this pull request as ready for review February 26, 2026 01:28
Copy link
Contributor

@yhsieh1 yhsieh1 left a comment

Choose a reason for hiding this comment

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

LGTM but seems coverage dropped below threshold.

@yhsieh1 yhsieh1 self-requested a review February 26, 2026 01:58
Copy link
Contributor

@patricksullivansf patricksullivansf left a comment

Choose a reason for hiding this comment

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

thank you! after it merges i'll do a fast follow to address the clean up we discussed

@wei-liu-sf wei-liu-sf merged commit 12bd455 into main Feb 26, 2026
4 checks passed
@wei-liu-sf wei-liu-sf deleted the W-21105798.wei-liu-sf.scaffold branch February 26, 2026 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants