get-list-of-all-subjects
Retrieve a simplified list of all courses from the ZEN University syllabus, including course name, enrollment grade, quarters, and credit details, for quick reference and planning.
Instructions
Retrieve a simplified list of all courses from the ZEN University syllabus, containing only the essential properties (name, enrollmentGrade, quarters, credit).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:212-264 (registration)Registration of the MCP tool 'get-list-of-all-subjects' with description, empty input schema, and inline asynchronous handler function that fetches, simplifies, and formats the list of subjects.server.tool( "get-list-of-all-subjects", "Retrieve a simplified list of all courses from the ZEN University syllabus, containing only the essential properties (name, enrollmentGrade, quarters, credit).", {}, async () => { try { const result = await fetchAllPages(); // Extract only the required properties from each subject const simplifiedSubjects = result.subjects.map(subject => ({ // code: subject.code, name: subject.name, // description: subject.description, // thumbnailUrl: subject.thumbnailUrl, openingYear: subject.openingYear, metadata: { enrollmentGrade: subject.metadata.enrollmentGrade, teachingMethod: subject.metadata.teachingMethod, subjectRequirement: subject.metadata.subjectRequirement, evaluationSystem: subject.metadata.evaluationSystem, credit: subject.metadata.credit, quarters: subject.metadata.quarters, objective: subject.metadata.objective, specialNotes: subject.metadata.specialNotes, coursePlans: subject.metadata.coursePlans || [] }, subjectCategoryIds: subject.subjectCategoryIds || [] })); // テキスト形式に変換 const formattedText = formatSimplifiedSubjectsToText(simplifiedSubjects); return { content: [ { type: "text", text: formattedText, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${error}`, }, ], }; } }, );
- src/index.ts:217-263 (handler)The handler function for the tool. Fetches all subjects from the API using fetchAllPages(), extracts simplified properties, formats them into a text list using formatSimplifiedSubjectsToText(), and returns as MCP text content. Handles errors by returning error text.async () => { try { const result = await fetchAllPages(); // Extract only the required properties from each subject const simplifiedSubjects = result.subjects.map(subject => ({ // code: subject.code, name: subject.name, // description: subject.description, // thumbnailUrl: subject.thumbnailUrl, openingYear: subject.openingYear, metadata: { enrollmentGrade: subject.metadata.enrollmentGrade, teachingMethod: subject.metadata.teachingMethod, subjectRequirement: subject.metadata.subjectRequirement, evaluationSystem: subject.metadata.evaluationSystem, credit: subject.metadata.credit, quarters: subject.metadata.quarters, objective: subject.metadata.objective, specialNotes: subject.metadata.specialNotes, coursePlans: subject.metadata.coursePlans || [] }, subjectCategoryIds: subject.subjectCategoryIds || [] })); // テキスト形式に変換 const formattedText = formatSimplifiedSubjectsToText(simplifiedSubjects); return { content: [ { type: "text", text: formattedText, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${error}`, }, ], }; } },
- src/index.ts:215-215 (schema)Empty Zod schema for tool inputs (no parameters required).{},
- src/index.ts:126-162 (helper)Helper function to fetch all pages of subjects from the Zen University syllabus API endpoint, merging all subjects into a single response object.async function fetchAllPages(options?: FetchOptions) { // まず最初のページを取得 const firstPageUrl = createUrl(0, options); const firstResponse = await fetch(firstPageUrl); if (!firstResponse.ok) { throw new Error(`APIリクエストに失敗しました: ${firstResponse.status} ${firstResponse.statusText}`); } const firstData = (await firstResponse.json()) as ApiResponse; const allSubjects = [...firstData.subjects]; const { totalPages, totalCount, pageSize, relatedTags } = firstData; // 2ページ目以降を順次取得 (page=1 ~ totalPages-1) for (let page = 1; page < totalPages; page++) { const url = createUrl(page, options); const response = await fetch(url); if (!response.ok) { throw new Error(`APIリクエストに失敗しました: ${response.status} ${response.statusText}`); } const data = (await response.json()) as ApiResponse; allSubjects.push(...data.subjects); } // 単一のオブジェクトとしてまとめる const mergedData = { totalCount, pageSize, page: 0, // 全ページのデータを結合した結果なので、page=0 とする totalPages, relatedTags, subjects: allSubjects, }; return mergedData; }
- src/index.ts:199-209 (helper)Helper function to format a list of simplified subjects into a readable text string, used in the tool response.function formatSimplifiedSubjectsToText(subjects: any[]): string { let text = `検索結果: ${subjects.length}件の科目が見つかりました\n\n`; // 科目名と想定年次のリスト const subjectList = subjects.map(subject => formatSimplifiedSubjectToText(subject)); // 1行に1科目ずつ表示 text += subjectList.join('\n'); return text; }