goalstory_read_one_story
Retrieve a specific story to revisit visualizations and mental imagery created for goal achievement, helping users maintain motivation and track progress through personalized narratives.
Instructions
Retrieve a specific story to revisit the visualization and mental imagery created for goal achievement.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Unique identifier of the story to retrieve. |
Implementation Reference
- src/index.ts:705-722 (handler)MCP tool registration and handler implementation. Makes a GET request to /stories/{id} using the doRequest helper and formats the response as text content.server.tool( READ_ONE_STORY_TOOL.name, READ_ONE_STORY_TOOL.description, READ_ONE_STORY_TOOL.inputSchema.shape, async (args) => { const url = `${GOALSTORY_API_BASE_URL}/stories/${args.id}`; const result = await doRequest(url, "GET"); return { content: [ { type: "text", text: `Story data:\n${JSON.stringify(result, null, 2)}`, }, ], isError: false, }; }, );
- src/tools.ts:400-407 (schema)Tool definition including name, description, and Zod input schema requiring a story ID.export const READ_ONE_STORY_TOOL = { name: "goalstory_read_one_story", description: "Retrieve a specific story to revisit the visualization and mental imagery created for goal achievement.", inputSchema: z.object({ id: z.string().describe("Unique identifier of the story to retrieve."), }), };
- src/types.ts:115-117 (schema)TypeScript interface defining the input shape for the tool.export interface GoalstoryReadOneStoryInput { id: string; }
- src/index.ts:62-122 (helper)Shared helper function used by all tool handlers to perform HTTP requests to the backend API with authentication, error handling, and logging.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)}`, ); } } }