feat(mcp): improve agent discovery and execution feedback

Add structured results, optional keyword search and pagination, and runtime information with explicit connection checks. Preserve existing text responses and execution permissions.

Support request cancellation and transfer progress. Verify compatibility with the full CI suite and isolated MCP and HTTP integration tests.
This commit is contained in:
DrSmoothl committed 2026-10-23 15:14:18 +08:00
1 parent 9b5ce9b502
commit 34a73084e0
16 files changed
+1552 -155

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
import type { TransferProgress } from './client.js';
/** One reporter per request. No timers or notifications survive the request. */
export function createProgressReporter(
send: (progress: TransferProgress) => Promise<void>,
signal: AbortSignal,
now: () => number = Date.now,
) {
let latest: TransferProgress | undefined;
let sent = -1;
let sentAt = -Infinity;
const flush = async (): Promise<void> => {
if (!latest || latest.progress <= sent || signal.aborted) {
return;
}
await send(latest);
sent = latest.progress;
sentAt = now();
};
return {
async report(progress: TransferProgress): Promise<void> {
if (
!Number.isFinite(progress.progress) ||
progress.progress < (latest?.progress ?? 0) ||
(progress.total !== undefined &&
(!Number.isFinite(progress.total) ||
progress.total <= 0 ||
progress.progress > progress.total))
) {
throw new Error('Invalid transfer progress');
}
latest = progress;
if (now() - sentAt >= 250) {
await flush();
}
},
finish: flush,
};
}