-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Summary
Add a `copy_flow` MCP tool to the now-sdk-ext-mcp server that exposes the `FlowManager.copyFlow()` functionality implemented in now-sdk-ext-core v3.7.0.
This allows AI agents to copy an existing ServiceNow flow into a target scoped application — which is the ServiceNow best practice before modifying any flow. This tool is a critical enabler of the full AI-assisted flow development lifecycle:
copy_flow → pull (now-sdk transform) → modify → push → test_flow → publish_flow
Background
The core library (`@sonisoft/now-sdk-ext-core`) v3.7.0 now has:
- `FlowManager.copyFlow(options)` — Copies a flow via the ProcessFlow REST API (`POST /api/now/processflow/flow/{id}/copy`)
- `CopyFlowOptions` — `{ sourceFlowId, name, targetScope }`
- `FlowCopyResult` — `{ success, newFlowSysId?, errorMessage?, errorCode? }`
The MCP server already has 8 flow tools in `src/tools/flow.ts`. The `copy_flow` tool follows the same pattern.
Why This Matters
In ServiceNow, OOB (out-of-box) flows like "Change - Standard" must not be modified directly — best practice is to copy them into your application scope first, then modify the copy. This tool enables an agent to:
- Copy an OOB or existing flow into the user's application scope
- The copy lands in draft/unpublished state in the target scope
- Pull the flow source locally with `now-sdk transform`
- Make modifications (with agent assistance)
- Push changes back to the instance
- Test with `test_flow`
- Publish with `publish_flow`
Implementation Details
MCP Server: `now-sdk-ext-mcp`
Repo: https://github.com/sonisoft-cnanda/now-sdk-ext-mcp
Tool Definition
Name: `copy_flow`
File: `src/tools/flow.ts` (add as section 9)
Input Schema:
| Parameter | Type | Required | Description |
|---|---|---|---|
| `instance` | string | No | ServiceNow instance alias (uses `SN_AUTH_ALIAS` if omitted) |
| `source_flow_id` | string | Yes | Source flow sys_id or scoped name (e.g. `"global.change__standard"`) |
| `name` | string | Yes | Display name for the new copied flow |
| `target_scope` | string | Yes | Scope sys_id of the target application. Use `list_scoped_apps` to find scope sys_ids. |
Registration:
- Export `registerCopyFlowTool` from `src/tools/flow.ts`
- Register in `src/index.ts` alongside existing flow tools
Prerequisites
- Bump `@sonisoft/now-sdk-ext-core` dependency to `^3.7.0`
Documentation
- `TOOLS.md` — Add a complete `copy_flow` entry
- Inline JSDoc — on the `registerCopyFlowTool` function
Testing
- Unit tests: mock `FlowManager.copyFlow()`, verify registration, schema, output formatting, error handling
- Integration tests: copy a known OOB flow (`e89e3ade731310108ef62d2b04f6a744` — "Change - Standard") into a test scope
Acceptance Criteria
- `copy_flow` tool registered and functional in MCP server
- Follows existing flow tool patterns (no scope in constructor, withConnectionRetry, error handling)
- Tool description prominently explains the copy-before-modify best practice and full lifecycle
- Unit and integration tests passing
- `TOOLS.md` updated with full tool documentation
- `@sonisoft/now-sdk-ext-core` dependency bumped to `^3.7.0`