replicate-flux-mcp
Version:
MCP for Replicate Flux Model
31 lines (30 loc) • 1.08 kB
JavaScript
import { replicate } from "../services/replicate.js";
import { handleError } from "../utils/error.js";
export const registerPredictionListTool = async ({ limit, }) => {
try {
const predictions = [];
for await (const page of replicate.paginate(replicate.predictions.list)) {
predictions.push(...page);
if (predictions.length >= limit) {
break;
}
}
const limitedPredictions = predictions.slice(0, limit);
const totalPages = Math.ceil(predictions.length / limit);
return {
content: [
{
type: "text",
text: `Found ${limitedPredictions.length} predictions (showing ${limitedPredictions.length} of ${predictions.length} total, page 1 of ${totalPages})`,
},
{
type: "text",
text: JSON.stringify(limitedPredictions, null, 2),
},
],
};
}
catch (error) {
return handleError(error);
}
};