@dondonudonjp/vertexai-imagen-mcp-server
Version:
[DEPRECATED] MCP Server for Vertex AI Imagen image generation. Imagen endpoints shut down 2026-06-30; migrate to the nanoBanana MCP Server (Gemini image models).
67 lines • 2.52 kB
JavaScript
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
export async function getJobResult(context, args) {
const { job_id } = args;
if (!job_id) {
throw new McpError(ErrorCode.InvalidParams, 'job_id is required');
}
const { jobManager } = context;
try {
const job = jobManager.getJob(job_id);
if (!job) {
throw new McpError(ErrorCode.InvalidRequest, `Job not found: ${job_id}`);
}
if (job.status === 'pending') {
throw new McpError(ErrorCode.InvalidRequest, `Job is still pending. Current status: ${job.status}`);
}
if (job.status === 'running') {
throw new McpError(ErrorCode.InvalidRequest, `Job is still running. Current status: ${job.status}`);
}
if (job.status === 'failed') {
throw new McpError(ErrorCode.InvalidRequest, `Job failed: ${job.error || 'Unknown error'}`);
}
if (!job.result) {
throw new McpError(ErrorCode.InternalError, 'Job completed but no result found');
}
// 結果をフォーマット
const resultInfo = [
`Job completed successfully!`,
`\nJob ID: ${job.id}`,
`Type: ${job.type}`,
`Completed: ${job.completedAt?.toISOString()}`,
`\nResult:`,
];
const result = job.result;
if (result.outputPath) {
resultInfo.push(`Output: ${result.outputPath}`);
resultInfo.push(`URI: ${result.uri}`);
resultInfo.push(`MIME Type: ${result.mimeType}`);
}
else if (result.outputPaths) {
resultInfo.push(`Generated ${result.outputPaths.length} image(s):`);
result.outputPaths.forEach((path, idx) => {
resultInfo.push(` ${idx + 1}. ${path}`);
});
}
else if (result.message) {
resultInfo.push(result.message);
}
else {
resultInfo.push(JSON.stringify(result, null, 2));
}
return {
content: [
{
type: 'text',
text: resultInfo.join('\n'),
},
],
};
}
catch (error) {
if (error instanceof McpError) {
throw error;
}
throw new McpError(ErrorCode.InternalError, `Failed to get job result: ${error instanceof Error ? error.message : String(error)}`);
}
}
//# sourceMappingURL=getJobResult.js.map