update_affiliation
Update an existing affiliation by providing its ID and optional fields such as key contact status, user, or account.
Instructions
Update an affiliation.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ID of the affiliation to update | |
| key_contact | No | Boolean indicating if this user is a key contact of the account. | |
| user_id | No | Unique identifier of the associated user | |
| account_id | No | Unique identifier of the associated account |
Implementation Reference
- src/tools/affiliations.ts:60-84 (handler)The "update_affiliation" tool handler. It is registered via server.registerTool, takes id (path param) and optional key_contact, user_id, account_id (body), calls apiPatch to PATCH /affiliations/{id}, logs the response, and formats the result using formatUpdate.
server.registerTool( "update_affiliation", { description: "Update an affiliation.", annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }, inputSchema: { id: z.number().int().positive().describe("ID of the affiliation to update"), key_contact: z .boolean() .optional() .describe("Boolean indicating if this user is a key contact of the account."), user_id: z.number().int().optional().describe("Unique identifier of the associated user"), account_id: z.number().int().optional().describe("Unique identifier of the associated account"), }, }, async ({ id, ...body }) => { try { const record = await apiPatch<EduframeRecord>(`/affiliations/${id}`, body); void logResponse("update_affiliation", { id, ...body }, record); return formatUpdate(record, "affiliation"); } catch (error) { return formatError(error); } }, ); - src/tools/affiliations.ts:60-84 (registration)The tool is registered inside the `registerAffiliationTools` function on line 7, via `server.registerTool("update_affiliation", ...)`. Registration includes the input schema with id, key_contact, user_id, account_id fields.
server.registerTool( "update_affiliation", { description: "Update an affiliation.", annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }, inputSchema: { id: z.number().int().positive().describe("ID of the affiliation to update"), key_contact: z .boolean() .optional() .describe("Boolean indicating if this user is a key contact of the account."), user_id: z.number().int().optional().describe("Unique identifier of the associated user"), account_id: z.number().int().optional().describe("Unique identifier of the associated account"), }, }, async ({ id, ...body }) => { try { const record = await apiPatch<EduframeRecord>(`/affiliations/${id}`, body); void logResponse("update_affiliation", { id, ...body }, record); return formatUpdate(record, "affiliation"); } catch (error) { return formatError(error); } }, ); - src/tools/affiliations.ts:60-84 (schema)Input schema defined inline in the second argument of registerTool. Uses Zod: id (z.number().int().positive()), key_contact (z.boolean().optional()), user_id (z.number().int().optional()), account_id (z.number().int().optional()).
server.registerTool( "update_affiliation", { description: "Update an affiliation.", annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }, inputSchema: { id: z.number().int().positive().describe("ID of the affiliation to update"), key_contact: z .boolean() .optional() .describe("Boolean indicating if this user is a key contact of the account."), user_id: z.number().int().optional().describe("Unique identifier of the associated user"), account_id: z.number().int().optional().describe("Unique identifier of the associated account"), }, }, async ({ id, ...body }) => { try { const record = await apiPatch<EduframeRecord>(`/affiliations/${id}`, body); void logResponse("update_affiliation", { id, ...body }, record); return formatUpdate(record, "affiliation"); } catch (error) { return formatError(error); } }, ); - src/api.ts:196-212 (helper)The apiPatch function used by the handler to perform a PATCH request to /affiliations/{id}. It sends the token-authenticated request with a JSON body.
* Perform a PATCH request to partially update a resource. * * @param path - API path, e.g. "/leads/1" * @param body - Request body */ export async function apiPatch<T>(path: string, body: unknown): Promise<T> { const { token } = getConfig(); const url = buildUrl(path); const response = await fetch(url.toString(), { method: "PATCH", headers: buildHeaders(token), body: JSON.stringify(body), }); return handleResponse<T>(response); } - src/formatters.ts:96-111 (helper)The formatUpdate function that formats the PATCH response into a human-readable CallToolResult with 'Successfully updated affiliation:' prefix.
/** * Format the response of an UPDATE tool call. * * @param record - The updated resource record returned by the API. * @param resourceName - Human-readable name of the resource type (e.g. "course"). */ export function formatUpdate(record: EduframeRecord, resourceName: string): CallToolResult { return { content: [ { type: "text", text: `Successfully updated ${resourceName}:\n\n${formatJSON(record)}${RESPONSE_LOG_HINT}`, }, ], }; }