Skip to content

Commit d341db9

Browse files
committed
ok
1 parent e19f08b commit d341db9

2 files changed

Lines changed: 45 additions & 35 deletions

File tree

mcp-studio/server/engine/steps/tool-step.ts

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -185,36 +185,52 @@ export async function executeToolStep(
185185
},
186186
],
187187
});
188-
await client.connect(transport);
189-
190-
// Fetch tool schema for type coercion
191-
let inputSchema: JSONSchema | undefined;
188+
let result: unknown;
192189
try {
193-
const { tools } = await client.listTools();
194-
const tool = tools.find((t) => t.name === toolName);
195-
inputSchema = tool?.inputSchema as JSONSchema | undefined;
196-
} catch {
197-
// If we can't get the schema, proceed without type coercion
198-
}
190+
await client.connect(transport);
191+
192+
// Fetch tool schema for type coercion
193+
let inputSchema: JSONSchema | undefined;
194+
try {
195+
const { tools } = await client.listTools();
196+
const tool = tools.find((t) => t.name === toolName);
197+
inputSchema = tool?.inputSchema as JSONSchema | undefined;
198+
} catch {
199+
// If we can't get the schema, proceed without type coercion
200+
}
199201

200-
// Sanitize input and coerce types based on tool schema
201-
const sanitizedInput = sanitizeInput(input, inputSchema);
202+
// Sanitize input and coerce types based on tool schema
203+
const sanitizedInput = sanitizeInput(input, inputSchema);
202204

203-
const timeoutMs = step.config?.timeoutMs ?? 30000;
205+
const timeoutMs = step.config?.timeoutMs ?? 30000;
204206

205-
const { content, structuredContent, isError } = await client.callTool(
206-
{
207-
name: toolName,
208-
arguments: sanitizedInput,
209-
},
210-
undefined,
211-
{
212-
timeout: timeoutMs,
213-
},
214-
);
215-
await client.close();
207+
const { content, structuredContent, isError } = await client.callTool(
208+
{
209+
name: toolName,
210+
arguments: sanitizedInput,
211+
},
212+
undefined,
213+
{
214+
timeout: timeoutMs,
215+
},
216+
);
216217

217-
const result = structuredContent ?? content;
218+
result = structuredContent ?? content;
219+
220+
if (isError) {
221+
throw new Error(JSON.stringify(result));
222+
}
223+
} catch (error) {
224+
await client.close();
225+
return {
226+
error: error instanceof Error ? error.message : String(error),
227+
startedAt,
228+
completedAt: Date.now(),
229+
stepId: step.name,
230+
};
231+
} finally {
232+
await client.close();
233+
}
218234

219235
// If there's transform code, run it on the raw tool result
220236
if (transformCode) {
@@ -243,7 +259,6 @@ export async function executeToolStep(
243259
return {
244260
output,
245261
startedAt,
246-
error: isError ? JSON.stringify(result) : undefined,
247262
completedAt: Date.now(),
248263
stepId: step.name,
249264
};
@@ -252,7 +267,6 @@ export async function executeToolStep(
252267
return {
253268
output: result,
254269
startedAt,
255-
error: isError ? JSON.stringify(result) : undefined,
256270
completedAt: Date.now(),
257271
stepId: step.name,
258272
};

mcp-studio/server/tools/execution.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,10 @@ export const createCreateTool = (env: Env) =>
132132
workflow_collection_id: context.workflow_collection_id,
133133
});
134134
console.log("publishing event");
135-
const result =
136-
await env.MESH_REQUEST_CONTEXT.state.EVENT_BUS.EVENT_PUBLISH({
137-
type: "workflow.execution.created",
138-
subject: executionId,
139-
});
140-
console.log("🚀 ~ result:", result);
135+
await env.MESH_REQUEST_CONTEXT.state.EVENT_BUS.EVENT_PUBLISH({
136+
type: "workflow.execution.created",
137+
subject: executionId,
138+
});
141139
return {
142140
id: executionId,
143141
workflow_id,
@@ -180,8 +178,6 @@ export const createGetTool = (env: Env) =>
180178
workflow.workflow_collection_id,
181179
);
182180

183-
console.log({ collection });
184-
185181
const stepResults = await getStepResults(env, id);
186182
return {
187183
item: {

0 commit comments

Comments
 (0)