Skip to content

Commit 4aae0ca

Browse files
committed
fix: call tasks/result when task status is input_required
Per the MCP spec (2025-11-25), when a client observes input_required status during task polling it must call tasks/result to give the server a chance to deliver queued elicitation/sampling requests. Previously the polling loop only called tasks/result after completed status, leaving the server unable to trigger elicitation. After elicitation is handled the task transitions back to working so taskCompleted is not set — polling continues until a terminal status is reached.
1 parent dd53302 commit 4aae0ca

File tree

2 files changed

+378
-13
lines changed

2 files changed

+378
-13
lines changed

client/src/App.tsx

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,21 +1148,50 @@ const App = () => {
11481148
? ((response as { _meta?: Record<string, unknown> })._meta ??
11491149
{})
11501150
: undefined;
1151-
latestToolResult = {
1152-
content: [
1151+
1152+
if (taskStatus.status === "input_required") {
1153+
// Per MCP spec: when input_required, call tasks/result to give
1154+
// the server a chance to deliver queued elicitation/sampling
1155+
// requests. After elicitation is handled, the task transitions
1156+
// back to "working" — do NOT set taskCompleted here.
1157+
latestToolResult = {
1158+
content: [
1159+
{
1160+
type: "text",
1161+
text: `Task status: input_required${taskStatus.statusMessage ? ` - ${taskStatus.statusMessage}` : ""}. Awaiting input...`,
1162+
},
1163+
],
1164+
_meta: {
1165+
...(pollingResponseMeta || {}),
1166+
"io.modelcontextprotocol/related-task": { taskId },
1167+
},
1168+
};
1169+
setToolResult(latestToolResult);
1170+
await sendMCPRequest(
11531171
{
1154-
type: "text",
1155-
text: `Task status: ${taskStatus.status}${taskStatus.statusMessage ? ` - ${taskStatus.statusMessage}` : ""}. Polling...`,
1172+
method: "tasks/result",
1173+
params: { taskId },
11561174
},
1157-
],
1158-
_meta: {
1159-
...(pollingResponseMeta || {}),
1160-
"io.modelcontextprotocol/related-task": { taskId },
1161-
},
1162-
};
1163-
setToolResult(latestToolResult);
1164-
// Refresh tasks list to show progress
1165-
void listTasks();
1175+
CompatibilityCallToolResultSchema,
1176+
);
1177+
void listTasks();
1178+
} else {
1179+
latestToolResult = {
1180+
content: [
1181+
{
1182+
type: "text",
1183+
text: `Task status: ${taskStatus.status}${taskStatus.statusMessage ? ` - ${taskStatus.statusMessage}` : ""}. Polling...`,
1184+
},
1185+
],
1186+
_meta: {
1187+
...(pollingResponseMeta || {}),
1188+
"io.modelcontextprotocol/related-task": { taskId },
1189+
},
1190+
};
1191+
setToolResult(latestToolResult);
1192+
// Refresh tasks list to show progress
1193+
void listTasks();
1194+
}
11661195
}
11671196
} catch (pollingError) {
11681197
console.error("Error polling task status:", pollingError);

0 commit comments

Comments
 (0)