Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

Refactor MCP settings handling and update embodiment types (#267)

Muhammad Hamza Khane59c37b84f90
diff --git a/packages/app/src/builder-ui/Agent.class.ts b/packages/app/src/builder-ui/Agent.class.ts
index 33401c98..cb2206aa 100644
--- a/packages/app/src/builder-ui/Agent.class.ts
+++ b/packages/app/src/builder-ui/Agent.class.ts
@@ -496,8 +496,9 @@ export class Agent extends EventEmitter {
[EMBODIMENT_TYPE.CHAT_GPT]: 'true',
[EMBODIMENT_TYPE.LLM]: 'true',
[EMBODIMENT_TYPE.API.toUpperCase()]: 'true',
- [EMBODIMENT_TYPE.MCP]: '{"isEnabled":true}',
+ [EMBODIMENT_TYPE.MCP]: 'true',
[EMBODIMENT_TYPE.ALEXA]: 'true',
+ [EMBODIMENT_TYPE.FORM]: 'true',
};
const currentSettings = await getAgentSettings(agentId);
diff --git a/packages/app/src/react/features/agent-settings/clients/index.ts b/packages/app/src/react/features/agent-settings/clients/index.ts
index 71971679..6340cc11 100644
--- a/packages/app/src/react/features/agent-settings/clients/index.ts
+++ b/packages/app/src/react/features/agent-settings/clients/index.ts
@@ -16,10 +16,6 @@ export const updateEmbodiment = async (agentId, embodimentType, status): Promise
key: embodimentType,
value: status.toString(),
};
- // Added exemption for MCP as it may contain other settings
- if (embodimentType === 'mcp') {
- updatePayload.value = JSON.stringify({ isEnabled: status });
- }
const result = await fetch(`/api/page/agents/agent/${agentId}/settings`, {
method: 'PUT',
diff --git a/packages/app/src/react/features/embodiments/embodiment-helper.ts b/packages/app/src/react/features/embodiments/embodiment-helper.ts
index a0482fa9..bfd53040 100644
--- a/packages/app/src/react/features/embodiments/embodiment-helper.ts
+++ b/packages/app/src/react/features/embodiments/embodiment-helper.ts
@@ -1,4 +1,4 @@
-import { useQuery, useQueryClient } from '@tanstack/react-query';
+import { useQuery } from '@tanstack/react-query';
import { Agent as AgentInstance } from '../../../builder-ui/Agent.class';
import { EMBODIMENT_TYPE } from '../../shared/enums';
import { Agent } from '../../shared/types/agent-data.types';
@@ -68,27 +68,19 @@ export function structureAgentSetting(
if (key === 'mcp') {
try {
- // Handle case where value might already be an object or a valid JSON string
- if (typeof value === 'string') {
- // Handle empty string or whitespace-only strings
- if (!value.trim()) {
- valueEmb = { isEnabled: false };
- } else {
- valueEmb = JSON.parse(value);
- }
+ if (!value?.trim()) {
+ embEnabled = false;
} else {
- valueEmb = value;
+ const parsedSettings = JSON.parse(value);
+ embEnabled =
+ typeof parsedSettings === 'boolean' ? parsedSettings : parsedSettings?.isEnabled;
}
- } catch (error) {
+ } catch {
// If JSON.parse fails, treat as disabled MCP
- console.warn(`Failed to parse MCP value: ${value}`, error);
- valueEmb = { isEnabled: false };
+ embEnabled = false;
+ } finally {
+ valueEmb = JSON.stringify(embEnabled);
}
- // Ensure valueEmb is an object and has isEnabled property
- if (!valueEmb || typeof valueEmb !== 'object') {
- valueEmb = { isEnabled: false };
- }
- embEnabled = Boolean(valueEmb?.isEnabled);
} else {
valueEmb = value;
embEnabled = value === 'true';
@@ -261,8 +253,6 @@ export const useAgentSettings = (
refreshEmbodiments?: () => void;
},
) => {
- const queryClient = useQueryClient();
-
return useQuery({
queryKey: ['agentSettings', agentId],
queryFn: async () => {
@@ -291,8 +281,6 @@ export const useAgentSettings = (
* @returns Query result with embodiments data, loading state, and refetch function
*/
export const useAgentEmbodiments = (agentId: string, callback?: AgentSettingsCallback) => {
- const queryClient = useQueryClient();
-
return useQuery({
queryKey: ['agentEmbodiments', agentId],
queryFn: async () => {
diff --git a/packages/app/src/react/features/embodiments/embodiment-settings.ts b/packages/app/src/react/features/embodiments/embodiment-settings.ts
index 5fd4cd94..ac9a8ea1 100644
--- a/packages/app/src/react/features/embodiments/embodiment-settings.ts
+++ b/packages/app/src/react/features/embodiments/embodiment-settings.ts
@@ -40,7 +40,7 @@ type UseAgentEmbodimentSettingsCallback = (
) => void;
// Global state for modal management to prevent multiple instances
-let globalModalManager = {
+const globalModalManager = {
activeAgentId: null as string | null,
activeInstanceId: null as string | null,
activeModal: null as string | null,
@@ -334,8 +334,7 @@ export const useAgentEmbodimentSettings = (
const updateEmbodimentStatus = async (embodimentType: string, status: boolean) => {
try {
// Format the value correctly for MCP settings to match API behavior
- const formattedValue =
- embodimentType === 'mcp' ? JSON.stringify({ isEnabled: status }) : status.toString();
+ const formattedValue = status.toString();
updateAgentSettingsCache(embodimentType, formattedValue, true);
callCallback();
diff --git a/packages/runtime/src/modules/embodiment/modules/mcp/services/mcp.services.ts b/packages/runtime/src/modules/embodiment/modules/mcp/services/mcp.services.ts
index 33869f26..097040f3 100644
--- a/packages/runtime/src/modules/embodiment/modules/mcp/services/mcp.services.ts
+++ b/packages/runtime/src/modules/embodiment/modules/mcp/services/mcp.services.ts
@@ -11,9 +11,7 @@ export const isMcpEnabled = (agent: Agent) => {
if (mcpSettings) {
try {
const parsedMcpSettings = JSON.parse(mcpSettings);
- if (parsedMcpSettings.isEnabled) {
- isEnabled = true;
- }
+ isEnabled = typeof parsedMcpSettings === 'boolean' ? parsedMcpSettings : parsedMcpSettings?.isEnabled;
} catch (error) {
isEnabled = false;
}