goalstory_create_story
Create and save a personalized story visualizing goal or step achievement. Uses user beliefs, motivations, and context to craft engaging narratives, enhancing motivation and focus.
Instructions
Generate and save a highly personalized story that visualizes achievement of the current goal/step. Uses understanding of the user's beliefs, motivations, and context to create engaging mental imagery. If context is needed, gathers it through user discussion and profile data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| goal_id | Yes | Unique identifier of the goal this story supports. | |
| step_id | Yes | Unique identifier of the specific step this story visualizes. | |
| story_text | Yes | Detailed narrative that vividly illustrates goal/step achievement. | |
| title | Yes | Engaging headline that captures the essence of the story. |
Implementation Reference
- src/index.ts:650-673 (handler)MCP server.tool registration and handler implementation for the 'goalstory_create_story' tool. It constructs a POST request to the /stories API endpoint using the provided goal_id, step_id, title, and story_text, then returns the API response formatted as MCP content.server.tool( CREATE_STORY_TOOL.name, CREATE_STORY_TOOL.description, CREATE_STORY_TOOL.inputSchema.shape, async (args) => { const url = `${GOALSTORY_API_BASE_URL}/stories`; const body = { goal_id: args.goal_id, step_id: args.step_id, title: args.title, story_text: args.story_text, }; const result = await doRequest(url, "POST", body); return { content: [ { type: "text", text: `Story created:\n${JSON.stringify(result, null, 2)}`, }, ], isError: false, }; }, );
- src/tools.ts:349-370 (schema)Zod input schema and tool metadata (name, description) for the 'goalstory_create_story' tool, exported as CREATE_STORY_TOOL and imported for use in server.tool registration.export const CREATE_STORY_TOOL = { name: "goalstory_create_story", description: `Generate and save a highly personalized story that visualizes achievement of the current goal/step. Uses understanding of the user's beliefs, motivations, and context to create engaging mental imagery. If context is needed, gathers it through user discussion and profile data.`, inputSchema: z.object({ goal_id: z .string() .describe("Unique identifier of the goal this story supports."), step_id: z .string() .describe( "Unique identifier of the specific step this story visualizes.", ), title: z .string() .describe("Engaging headline that captures the essence of the story."), story_text: z .string() .describe( "Detailed narrative that vividly illustrates goal/step achievement.", ), }), };
- src/types.ts:101-106 (schema)TypeScript interface defining the expected input shape for the GoalstoryCreateStoryInput, matching the Zod schema.export interface GoalstoryCreateStoryInput { goal_id: string; step_id: string; title?: string; story_text: string; }
- src/index.ts:62-122 (helper)Shared utility function for making authenticated HTTP requests to the GoalStory API, used by the tool handler.async function doRequest<T = any>( url: string, method: string, body?: unknown, ): Promise<T> { console.error("Making request to:", url); console.error("Method:", method); console.error("Body:", body ? JSON.stringify(body) : "none"); try { const response = await axios({ url, method, headers: { "Content-Type": "application/json", Authorization: `Bearer ${GOALSTORY_API_TOKEN}`, }, data: body, timeout: 10000, // 10 second timeout validateStatus: function (status) { return status >= 200 && status < 500; // Accept all status codes less than 500 }, }); console.error("Response received:", response.status); return response.data as T; } catch (err) { console.error("Request failed with error:", err); if (axios.isAxiosError(err)) { if (err.code === "ECONNABORTED") { throw new Error( `Request timed out after 10 seconds. URL: ${url}, Method: ${method}`, ); } if (err.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx throw new Error( `HTTP Error ${ err.response.status }. URL: ${url}, Method: ${method}, Body: ${JSON.stringify( body, )}. Error text: ${JSON.stringify(err.response.data)}`, ); } else if (err.request) { // The request was made but no response was received throw new Error( `No response received from server. URL: ${url}, Method: ${method}`, ); } else { // Something happened in setting up the request that triggered an Error throw new Error(`Request setup failed: ${err.message}`); } } else { // Something else happened throw new Error( `Unexpected error: ${err instanceof Error ? err.message : String(err)}`, ); } } }