Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ const DesignerEditorConsumption = () => {
...getSKUDefaultHostOptions(Constants.SKU.CONSUMPTION),
},
showPerformanceDebug,
mcpClientToolEnabled: true,
}}
>
{definition ? (
Expand Down
114 changes: 73 additions & 41 deletions libs/designer-v2/src/lib/core/actions/bjsworkflow/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
LogEntryLevel,
LoggerService,
OperationManifestService,
ConnectionService,
WorkflowService,
getIntl,
create,
Expand Down Expand Up @@ -75,7 +76,7 @@ import type {
import merge from 'lodash.merge';
import { createTokenValueSegment } from '../../utils/parameters/segment';
import { ConnectorManifest } from './agent';
import { isA2AWorkflow } from '../../../core/state/workflow/helper';
import { isA2AWorkflow, isBuiltInMcpOperation } from '../../../core/state/workflow/helper';

export interface SerializeOptions {
skipValidation: boolean;
Expand Down Expand Up @@ -288,9 +289,12 @@ export const serializeOperation = async (

let serializedOperation: LogicAppsV2.OperationDefinition;
const isManagedMcpClient = operation.type?.toLowerCase() === 'mcpclienttool' && operation.kind?.toLowerCase() === 'managed';
const isBuiltInMcpClient = isBuiltInMcpOperation(operation);

if (isManagedMcpClient) {
serializedOperation = await serializeManagedMcpOperation(rootState, operationId);
} else if (isBuiltInMcpClient) {
serializedOperation = await serializeBuiltInMcpOperation(rootState, operationId);
} else if (OperationManifestService().isSupported(operation.type, operation.kind)) {
serializedOperation = await serializeManifestBasedOperation(rootState, operationId);
} else {
Expand Down Expand Up @@ -334,22 +338,6 @@ export const serializeOperation = async (
removeRunAfterTriggerFromOperation(serializedOperation, replacedTriggerId);
}

// If dynamic inputs failed to load and no stashed parameters exist (initial load failure),
// preserve the original definition's inputs so dynamic parameter values are not lost on save.
const nodeInputs = getRecordEntry(rootState.operations.inputParameters, operationId);
const hasDynamicInputsError = !!errors?.[ErrorLevel.DynamicInputs];
const hasStash = !!nodeInputs?.stashedDynamicParameterValues?.length;
const hasDynamicParamsInGroups = getOperationInputParameters(nodeInputs as NodeInputs).some((p) => p.info.isDynamic);
if (hasDynamicInputsError && !hasStash && !hasDynamicParamsInGroups) {
const originalDef = getRecordEntry(rootState.workflow.operations, operationId);
if (originalDef && 'inputs' in originalDef && originalDef.inputs && 'inputs' in serializedOperation) {
serializedOperation = {
...serializedOperation,
inputs: merge({}, originalDef.inputs, serializedOperation.inputs),
};
}
}

return serializedOperation;
};

Expand Down Expand Up @@ -521,6 +509,60 @@ const serializeManagedMcpOperation = async (rootState: RootState, nodeId: string
};
};

const serializeBuiltInMcpOperation = async (rootState: RootState, nodeId: string): Promise<LogicAppsV2.OperationDefinition> => {
const operationInfo = getRecordEntry(rootState.operations.operationInfo, nodeId) as NodeOperation;
if (!operationInfo) {
throw new AssertionException(AssertionErrorCode.OPERATION_NOT_FOUND, `Operation with id ${nodeId} not found`);
}
const { type, kind } = operationInfo;

const inputsToSerialize = getOperationInputsToSerialize(rootState, nodeId);

const nativeMcpOperationInfo = { connectorId: 'connectionProviders/mcpclient', operationId: 'nativemcpclient' };
const manifest = await getOperationManifest(nativeMcpOperationInfo);
const inputParameters = serializeParametersFromManifest(inputsToSerialize, manifest);

const operationFromWorkflow = getRecordEntry(rootState.workflow.operations, nodeId) as LogicAppsV2.OperationDefinition;

// Look up the connection to get MCP server URL and authentication type
const referenceKey = getRecordEntry(rootState.connections.connectionsMapping, nodeId);
const connectionReference = referenceKey ? getRecordEntry(rootState.connections.connectionReferences, referenceKey) : undefined;
const connectionId = connectionReference?.connection?.id;

let mcpServerUrl = '';
let authenticationType = 'None';

if (connectionId) {
try {
const connection = await ConnectionService().getConnection(connectionId);
const parameterValues = (connection?.properties as any)?.parameterValues;
if (parameterValues) {
mcpServerUrl = parameterValues.mcpServerUrl ?? '';
authenticationType = parameterValues.authenticationType ?? 'None';
}
} catch {
// Fall back to empty values if connection lookup fails
}
}

const inputs = {
Connection: {
McpServerUrl: mcpServerUrl,
Authentication: authenticationType,
},
parameters: {
...inputParameters.parameters,
},
};

return {
type: type,
kind: kind,
...optional('description', operationFromWorkflow.description),
...optional('inputs', inputs),
};
};

const serializeSwaggerBasedOperation = async (rootState: RootState, operationId: string): Promise<LogicAppsV2.OperationDefinition> => {
const idReplacements = rootState.workflow.idReplacements;
const operationInfo = getRecordEntry(rootState.operations.operationInfo, operationId) as NodeOperation;
Expand Down Expand Up @@ -606,29 +648,15 @@ export interface SerializedParameter extends ParameterInfo {
export const getOperationInputsToSerialize = (rootState: RootState, operationId: string): SerializedParameter[] => {
const idReplacements = rootState.workflow.idReplacements;
const nodeInputs = getRecordEntry(rootState.operations.inputParameters, operationId) as NodeInputs;
const shouldEncode = shouldEncodeParameterValueForOperationBasedOnMetadata(rootState.operations.operationInfo[operationId] ?? {});

const currentParams = getOperationInputParameters(nodeInputs);
const serialized = currentParams.map((input) => ({
return getOperationInputParameters(nodeInputs).map((input) => ({
...input,
value: parameterValueToString(input, true /* isDefinitionValue */, idReplacements, shouldEncode),
value: parameterValueToString(
input,
true /* isDefinitionValue */,
idReplacements,
shouldEncodeParameterValueForOperationBasedOnMetadata(rootState.operations.operationInfo[operationId] ?? {})
),
}));

// If dynamic parameters were stashed (cleared during loading or after failure),
// include them as fallback so their values are not lost on save.
const stashed = nodeInputs?.stashedDynamicParameterValues;
if (stashed?.length) {
const currentKeys = new Set(currentParams.map((p) => p.parameterKey));
const missingStashed = stashed.filter((p) => !currentKeys.has(p.parameterKey));
for (const param of missingStashed) {
serialized.push({
...param,
value: parameterValueToString(param, true /* isDefinitionValue */, idReplacements, shouldEncode),
});
}
}

return serialized;
};

const serializeParametersFromManifest = (inputs: SerializedParameter[], manifest: OperationManifest): Record<string, any> => {
Expand Down Expand Up @@ -997,11 +1025,15 @@ const serializeHost = (
};

const mergeHostWithInputs = (hostInfo: Record<string, any>, inputs: any): any => {
const result = { ...inputs };
for (const [key, value] of Object.entries(hostInfo)) {
result[key] = result[key] ? { ...result[key], ...value } : value;
if (inputs[key]) {
inputs[key] = { ...inputs[key], ...value };
} else {
inputs[key] = value;
}
}
return result;

return inputs;
};

//#endregion
Expand Down
4 changes: 4 additions & 0 deletions libs/designer-v2/src/lib/core/state/workflow/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ export const isManagedMcpOperation = (operation: { type?: string; kind?: string
return equals(operation?.type, Constants.NODE.TYPE.MCP_CLIENT) && equals(operation?.kind, Constants.NODE.KIND.MANAGED);
};

export const isBuiltInMcpOperation = (operation: { type?: string; kind?: string }) => {
return equals(operation?.type, Constants.NODE.TYPE.MCP_CLIENT) && !equals(operation?.kind, Constants.NODE.KIND.MANAGED);
};

export const isA2AWorkflow = (state: WorkflowState): boolean => {
const workflowKind = state.workflowKind;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import {
ConnectionParameterEditorService,
ConnectionService,
ConsumptionConnectionService,
Capabilities,
ConnectionParameterTypes,
SERVICE_PRINCIPLE_CONSTANTS,
Expand Down Expand Up @@ -405,12 +406,23 @@ export const CreateConnection = (props: CreateConnectionProps) => {
}, [enabledCapabilities, parametersByCapability]);

// Don't show name for simple connections
const showNameInput = useMemo(
() =>
const showNameInput = useMemo(() => {
const isMcpClientConnection = connectorId?.toLowerCase().includes('mcpclient');

if (isMcpClientConnection) {
const connectionService = ConnectionService();
const isConsumptionSku = connectionService instanceof ConsumptionConnectionService;

if (isConsumptionSku) {
return false;
}
}

return (
!(isUsingOAuth && !isMultiAuth) &&
(isMultiAuth || Object.keys(capabilityEnabledParameters ?? {}).length > 0 || legacyManagedIdentitySelected),
[isUsingOAuth, isMultiAuth, capabilityEnabledParameters, legacyManagedIdentitySelected]
);
(isMultiAuth || Object.keys(capabilityEnabledParameters ?? {}).length > 0 || legacyManagedIdentitySelected)
);
}, [connectorId, isUsingOAuth, isMultiAuth, capabilityEnabledParameters, legacyManagedIdentitySelected]);

const validParams = useMemo(() => {
if (showNameInput && !connectionDisplayName) {
Expand Down
63 changes: 59 additions & 4 deletions libs/designer/src/lib/core/actions/bjsworkflow/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
LogEntryLevel,
LoggerService,
OperationManifestService,
ConnectionService,
WorkflowService,
getIntl,
create,
Expand Down Expand Up @@ -75,7 +76,7 @@ import type {
import merge from 'lodash.merge';
import { createTokenValueSegment } from '../../utils/parameters/segment';
import { ConnectorManifest } from './agent';
import { isA2AWorkflow, isManagedMcpOperation } from '../../../core/state/workflow/helper';
import { isA2AWorkflow, isBuiltInMcpOperation, isManagedMcpOperation } from '../../../core/state/workflow/helper';

export interface SerializeOptions {
skipValidation: boolean;
Expand Down Expand Up @@ -284,9 +285,12 @@ export const serializeOperation = async (

let serializedOperation: LogicAppsV2.OperationDefinition;
const isManagedMcpClient = isManagedMcpOperation(operation);
const isBuiltInMcpClient = isBuiltInMcpOperation(operation);

if (isManagedMcpClient) {
serializedOperation = await serializeManagedMcpOperation(rootState, operationId);
} else if (isBuiltInMcpClient) {
serializedOperation = await serializeBuiltInMcpOperation(rootState, operationId);
} else if (OperationManifestService().isSupported(operation.type, operation.kind)) {
serializedOperation = await serializeManifestBasedOperation(rootState, operationId);
} else {
Expand Down Expand Up @@ -501,6 +505,60 @@ const serializeManagedMcpOperation = async (rootState: RootState, nodeId: string
};
};

const serializeBuiltInMcpOperation = async (rootState: RootState, nodeId: string): Promise<LogicAppsV2.OperationDefinition> => {
const operationInfo = getRecordEntry(rootState.operations.operationInfo, nodeId) as NodeOperation;
if (!operationInfo) {
throw new AssertionException(AssertionErrorCode.OPERATION_NOT_FOUND, `Operation with id ${nodeId} not found`);
}
const { type, kind } = operationInfo;

const inputsToSerialize = getOperationInputsToSerialize(rootState, nodeId);

const nativeMcpOperationInfo = { connectorId: 'connectionProviders/mcpclient', operationId: 'nativemcpclient' };
const manifest = await getOperationManifest(nativeMcpOperationInfo);
const inputParameters = serializeParametersFromManifest(inputsToSerialize, manifest);

const operationFromWorkflow = getRecordEntry(rootState.workflow.operations, nodeId) as LogicAppsV2.OperationDefinition;

// Look up the connection to get MCP server URL and authentication type
const referenceKey = getRecordEntry(rootState.connections.connectionsMapping, nodeId);
const connectionReference = referenceKey ? getRecordEntry(rootState.connections.connectionReferences, referenceKey) : undefined;
const connectionId = connectionReference?.connection?.id;

let mcpServerUrl = '';
let authenticationType = 'None';

if (connectionId) {
try {
const connection = await ConnectionService().getConnection(connectionId);
const parameterValues = (connection?.properties as any)?.parameterValues;
if (parameterValues) {
mcpServerUrl = parameterValues.mcpServerUrl ?? '';
authenticationType = parameterValues.authenticationType ?? 'None';
}
} catch {
// Fall back to empty values if connection lookup fails
}
}

const inputs = {
Connection: {
McpServerUrl: mcpServerUrl,
Authentication: authenticationType,
},
parameters: {
...inputParameters.parameters,
},
};

return {
type: type,
kind: kind,
...optional('description', operationFromWorkflow.description),
...optional('inputs', inputs),
};
};

const serializeSwaggerBasedOperation = async (rootState: RootState, operationId: string): Promise<LogicAppsV2.OperationDefinition> => {
const idReplacements = rootState.workflow.idReplacements;
const operationInfo = getRecordEntry(rootState.operations.operationInfo, operationId) as NodeOperation;
Expand Down Expand Up @@ -903,7 +961,6 @@ const serializeHost = (
},
};
case ConnectionReferenceKeyFormat.OpenApiConnection: {
// eslint-disable-next-line no-case-declarations
const connectorSegments = connectorId.split('/');
return {
host: {
Expand Down Expand Up @@ -966,10 +1023,8 @@ const serializeHost = (
const mergeHostWithInputs = (hostInfo: Record<string, any>, inputs: any): any => {
for (const [key, value] of Object.entries(hostInfo)) {
if (inputs[key]) {
// eslint-disable-next-line no-param-reassign
inputs[key] = { ...inputs[key], ...value };
} else {
// eslint-disable-next-line no-param-reassign
inputs[key] = value;
}
}
Expand Down
4 changes: 4 additions & 0 deletions libs/designer/src/lib/core/state/workflow/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ export const isManagedMcpOperation = (operation: { type?: string; kind?: string
return equals(operation?.type, Constants.NODE.TYPE.MCP_CLIENT) && equals(operation?.kind, Constants.NODE.KIND.MANAGED);
};

export const isBuiltInMcpOperation = (operation: { type?: string; kind?: string }) => {
return equals(operation?.type, Constants.NODE.TYPE.MCP_CLIENT) && !equals(operation?.kind, Constants.NODE.KIND.MANAGED);
};

export const isA2AWorkflow = (state: WorkflowState): boolean => {
const workflowKind = state.workflowKind;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import {
ConnectionParameterEditorService,
ConnectionService,
ConsumptionConnectionService,
Capabilities,
ConnectionParameterTypes,
SERVICE_PRINCIPLE_CONSTANTS,
Expand Down Expand Up @@ -407,12 +408,23 @@ export const CreateConnection = (props: CreateConnectionProps) => {
}, [enabledCapabilities, parametersByCapability]);

// Don't show name for simple connections
const showNameInput = useMemo(
() =>
const showNameInput = useMemo(() => {
const isMcpClientConnection = connectorId?.toLowerCase().includes('mcpclient');

if (isMcpClientConnection) {
const connectionService = ConnectionService();
const isConsumptionSku = connectionService instanceof ConsumptionConnectionService;

if (isConsumptionSku) {
return false;
}
}

return (
!(isUsingOAuth && !isMultiAuth) &&
(isMultiAuth || Object.keys(capabilityEnabledParameters ?? {}).length > 0 || legacyManagedIdentitySelected),
[isUsingOAuth, isMultiAuth, capabilityEnabledParameters, legacyManagedIdentitySelected]
);
(isMultiAuth || Object.keys(capabilityEnabledParameters ?? {}).length > 0 || legacyManagedIdentitySelected)
);
}, [connectorId, isUsingOAuth, isMultiAuth, capabilityEnabledParameters, legacyManagedIdentitySelected]);

const validParams = useMemo(() => {
if (showNameInput && !connectionDisplayName) {
Expand Down
Loading
Loading