setVariable
Set and modify variables in Spline 3D scenes to control animations, object properties, and interactive behaviors through parameter adjustments.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sceneId | Yes | Scene ID | |
| variableName | Yes | Variable name | |
| value | No | Variable value | |
| variableType | Yes | Variable type |
Implementation Reference
- src/tools/scene-tools.js:199-244 (handler)The handler function that implements the 'setVariable' tool. It takes sceneId, variableName, value, and variableType, converts the value to the appropriate type, and updates the variable via the Spline API.server.tool( 'setVariable', { sceneId: z.string().min(1).describe('Scene ID'), variableName: z.string().min(1).describe('Variable name'), value: z.any().describe('Variable value'), variableType: z.enum(['string', 'number', 'boolean']).describe('Variable type'), }, async ({ sceneId, variableName, value, variableType }) => { try { // Convert value based on specified type let typedValue = value; if (variableType === 'number') { typedValue = Number(value); } else if (variableType === 'boolean') { typedValue = Boolean(value); } else { typedValue = String(value); } await apiClient.request('PUT', `/scenes/${sceneId}/variables/${variableName}`, { value: typedValue, type: variableType }); return { content: [ { type: 'text', text: `Variable "${variableName}" set to ${JSON.stringify(typedValue)}` } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error setting variable: ${error.message}` } ], isError: true }; } } );
- src/tools/scene-tools.js:202-206 (schema)The Zod input schema for the setVariable tool parameters.sceneId: z.string().min(1).describe('Scene ID'), variableName: z.string().min(1).describe('Variable name'), value: z.any().describe('Variable value'), variableType: z.enum(['string', 'number', 'boolean']).describe('Variable type'), },
- src/index.js:92-92 (registration)Registration of the scene tools module, which includes the setVariable tool, on the MCP server.registerSceneTools(server);
- src/index.js:19-19 (registration)Import of the scene-tools module containing the setVariable tool.import { registerSceneTools } from './tools/scene-tools.js';