create_apprun
Create a new AppRun application on Sakura Cloud by specifying name, Docker image, plan, and optional environment variables and zone.
Instructions
Create a new AppRun application
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the AppRun application | |
| description | No | Description of the AppRun application | |
| dockerImage | Yes | Docker image to use for the AppRun application | |
| planId | Yes | Plan ID for the AppRun application | |
| environment | No | Environment variables for the AppRun application | |
| zone | No | The zone to use (e.g., "tk1v", "is1a", "tk1a"). Defaults to "tk1v" if not specified. |
Implementation Reference
- src/server.ts:1257-1295 (schema)Input schema definition for the create_apprun tool, defining parameters like name, dockerImage, planId, etc.name: 'create_apprun', description: 'Create a new AppRun application', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the AppRun application' }, description: { type: 'string', description: 'Description of the AppRun application' }, dockerImage: { type: 'string', description: 'Docker image to use for the AppRun application' }, planId: { type: 'string', description: 'Plan ID for the AppRun application' }, environment: { type: 'array', description: 'Environment variables for the AppRun application', items: { type: 'object', properties: { key: { type: 'string' }, value: { type: 'string' } } } }, zone: { type: 'string', description: 'The zone to use (e.g., "tk1v", "is1a", "tk1a"). Defaults to "tk1v" if not specified.' } }, required: ['name', 'dockerImage', 'planId'] }
- src/server.ts:2277-2314 (handler)The handler function that implements create_apprun by validating inputs, preparing the request body, and calling the Sakura Cloud AppRun API to create the application.} else if (request.params.name === 'create_apprun') { try { validateCredentials(); const name = request.params.arguments?.name as string; const description = request.params.arguments?.description as string || ''; const dockerImage = request.params.arguments?.dockerImage as string; const planId = request.params.arguments?.planId as string; const environment = request.params.arguments?.environment as Array<{key: string, value: string}> || []; if (!name || !dockerImage || !planId) { throw new Error('Name, Docker image, and plan ID are required'); } const zone = request.params.arguments?.zone as string || DEFAULT_ZONE; const createBody = { name: name, description: description, planId: planId, image: dockerImage, environment: environment.map(env => ({ key: env.key, value: env.value })), }; const createResult = await fetchFromAppRunAPI('/applications', 'POST', createBody); return { content: [ { type: 'text', text: JSON.stringify(createResult, null, 2) } ] }; } catch (error) { console.error('Error calling tool:', error); throw error; }
- src/server.ts:75-122 (helper)Helper function used by create_apprun (and other AppRun tools) to make authenticated HTTPS requests to the Sakura Cloud AppRun API.async function fetchFromAppRunAPI(path: string, method: string = 'GET', bodyData?: any): Promise<any> { return new Promise((resolve, reject) => { validateCredentials(); const options = { hostname: 'secure.sakura.ad.jp', port: 443, path: `/cloud/api/apprun/1.0/apprun/api${path}`, method: method, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': `Basic ${Buffer.from(`${SACLOUD_API_TOKEN}:${SACLOUD_API_SECRET}`).toString('base64')}` } }; const req = https.request(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { try { if (data) { const parsedData = JSON.parse(data); resolve(parsedData); } else { resolve({}); } } catch (err) { reject(new Error(`Failed to parse response: ${err}`)); } }); }); req.on('error', (error) => { reject(error); }); if (bodyData && (method === 'POST' || method === 'PUT')) { req.write(JSON.stringify(bodyData)); } req.end(); }); }
- src/server.ts:1257-1296 (registration)The tool is registered by being included in the list returned by ListToolsRequestSchema handler.name: 'create_apprun', description: 'Create a new AppRun application', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the AppRun application' }, description: { type: 'string', description: 'Description of the AppRun application' }, dockerImage: { type: 'string', description: 'Docker image to use for the AppRun application' }, planId: { type: 'string', description: 'Plan ID for the AppRun application' }, environment: { type: 'array', description: 'Environment variables for the AppRun application', items: { type: 'object', properties: { key: { type: 'string' }, value: { type: 'string' } } } }, zone: { type: 'string', description: 'The zone to use (e.g., "tk1v", "is1a", "tk1a"). Defaults to "tk1v" if not specified.' } }, required: ['name', 'dockerImage', 'planId'] } },