@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).
65 lines • 2.71 kB
JavaScript
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
import { saveTemplate, extractVariables, loadTemplate } from '../utils/templateManager.js';
/**
* プロンプトテンプレートを保存
*/
export async function savePromptTemplate(context, args) {
const { name, description, template, variables, default_params, tags } = args;
if (!name || typeof name !== 'string') {
throw new McpError(ErrorCode.InvalidParams, 'name is required and must be a string');
}
if (!description || typeof description !== 'string') {
throw new McpError(ErrorCode.InvalidParams, 'description is required and must be a string');
}
if (!template || typeof template !== 'string') {
throw new McpError(ErrorCode.InvalidParams, 'template is required and must be a string');
}
try {
// 既存のテンプレートをチェック
const existing = await loadTemplate(name);
// 変数を抽出(省略時は自動抽出)
const extractedVariables = variables || extractVariables(template);
// テンプレートオブジェクトを作成
const promptTemplate = {
name,
description,
template,
variables: extractedVariables,
default_params,
tags,
created_at: existing?.created_at || new Date().toISOString(),
updated_at: new Date().toISOString(),
};
// 保存
await saveTemplate(promptTemplate);
let responseText = '';
if (existing) {
responseText += `✓ Template "${name}" updated successfully\n\n`;
}
else {
responseText += `✓ Template "${name}" created successfully\n\n`;
}
responseText += `Description: ${description}\n`;
responseText += `Template: ${template}\n`;
responseText += `Variables: ${extractedVariables.length > 0 ? extractedVariables.join(', ') : 'none'}\n`;
if (default_params && Object.keys(default_params).length > 0) {
responseText += `Default Parameters:\n${JSON.stringify(default_params, null, 2)}\n`;
}
if (tags && tags.length > 0) {
responseText += `Tags: ${tags.join(', ')}\n`;
}
return {
content: [
{
type: 'text',
text: responseText,
},
],
};
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new McpError(ErrorCode.InternalError, `Failed to save template: ${errorMessage}`);
}
}
//# sourceMappingURL=savePromptTemplate.js.map