goalstory_read_goals
Retrieve and view user goal journeys with pagination to manage large goal sets effectively.
Instructions
Get an overview of the user's goal journey, with optional pagination to manage larger sets of goals.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Page number for viewing subsets of goals (starts at 1). | |
| limit | No | Maximum number of goals to return per page. |
Implementation Reference
- src/index.ts:372-392 (handler)The handler function for the 'goalstory_read_goals' tool, registered via server.tool(). It constructs a paginated GET request to the /goals endpoint using the doRequest helper and returns the formatted JSON response.server.tool( READ_GOALS_TOOL.name, READ_GOALS_TOOL.description, READ_GOALS_TOOL.inputSchema.shape, async (args) => { const params = new URLSearchParams(); if (args.page) params.set("page", `${args.page}`); if (args.limit) params.set("limit", `${args.limit}`); const url = `${GOALSTORY_API_BASE_URL}/goals?${params.toString()}`; const result = await doRequest(url, "GET"); return { content: [ { type: "text", text: `Goals retrieved:\n${JSON.stringify(result, null, 2)}`, }, ], isError: false, }; }, );
- src/tools.ts:170-184 (schema)Zod input schema and tool metadata (name, description) for 'goalstory_read_goals', used in server.tool() registration.export const READ_GOALS_TOOL = { name: "goalstory_read_goals", description: "Get an overview of the user's goal journey, with optional pagination to manage larger sets of goals.", inputSchema: z.object({ page: z .number() .optional() .describe("Page number for viewing subsets of goals (starts at 1)."), limit: z .number() .optional() .describe("Maximum number of goals to return per page."), }), };
- src/index.ts:372-392 (registration)MCP server.tool() call that registers the 'goalstory_read_goals' tool, providing schema and handler.server.tool( READ_GOALS_TOOL.name, READ_GOALS_TOOL.description, READ_GOALS_TOOL.inputSchema.shape, async (args) => { const params = new URLSearchParams(); if (args.page) params.set("page", `${args.page}`); if (args.limit) params.set("limit", `${args.limit}`); const url = `${GOALSTORY_API_BASE_URL}/goals?${params.toString()}`; const result = await doRequest(url, "GET"); return { content: [ { type: "text", text: `Goals retrieved:\n${JSON.stringify(result, null, 2)}`, }, ], isError: false, }; }, );
- src/types.ts:46-49 (schema)TypeScript interface defining the input shape for 'goalstory_read_goals', matching the Zod schema.export interface GoalstoryReadGoalsInput { page?: number; limit?: number; }
- src/index.ts:62-122 (helper)Generic HTTP request helper (doRequest) used by the tool handler to make authenticated API calls to the GoalStory backend.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)}`, ); } } }