create_course_variant
Create a new course variant by specifying its name to extend course offerings.
Instructions
Create a course variant
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The name of the course variant. |
Implementation Reference
- src/tools/course_variants.ts:58-66 (handler)The async handler function for the create_course_variant tool. It receives body params, POSTs to /course_variants via apiPost, logs the response, and returns formatCreate result on success or formatError on failure.
async (body) => { try { const record = await apiPost<EduframeRecord>("/course_variants", body); void logResponse("create_course_variant", body, record); return formatCreate(record, "course variant"); } catch (error) { return formatError(error); } }, - src/tools/course_variants.ts:53-57 (schema)Tool metadata and input schema for create_course_variant. Defines description, annotations (non-readonly, non-destructive, non-idempotent), and inputSchema requiring a 'name' string field.
{ description: "Create a course variant", annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false }, inputSchema: { name: z.string().describe("The name of the course variant.") }, }, - src/tools/course_variants.ts:51-67 (registration)Registration of create_course_variant via server.registerTool within registerCourseVariantTools(). This binds the tool name, schema, and handler together.
server.registerTool( "create_course_variant", { description: "Create a course variant", annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false }, inputSchema: { name: z.string().describe("The name of the course variant.") }, }, async (body) => { try { const record = await apiPost<EduframeRecord>("/course_variants", body); void logResponse("create_course_variant", body, record); return formatCreate(record, "course variant"); } catch (error) { return formatError(error); } }, ); - src/api.ts:163-174 (helper)The apiPost helper function that the handler calls internally. Performs a POST request to the specified API path with a JSON body.
export async function apiPost<T>(path: string, body: unknown): Promise<T> { const { token } = getConfig(); const url = buildUrl(path); const response = await fetch(url.toString(), { method: "POST", headers: buildHeaders(token), body: JSON.stringify(body), }); return handleResponse<T>(response); } - src/formatters.ts:85-94 (helper)The formatCreate helper used by the handler to format the created resource into a human-readable CallToolResult.
export function formatCreate(record: EduframeRecord, resourceName: string): CallToolResult { return { content: [ { type: "text", text: `Successfully created ${resourceName}:\n\n${formatJSON(record)}${RESPONSE_LOG_HINT}`, }, ], }; }