get_quiz_grade
Retrieve a student's quiz grade on Moodle by specifying the student ID and quiz ID. Simplifies grading management for educators using the Moodle MCP Server.
Instructions
Obtiene la calificación de un estudiante en un quiz específico
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| quizId | Yes | ID del quiz | |
| studentId | Yes | ID del estudiante |
Input Schema (JSON Schema)
{
"properties": {
"quizId": {
"description": "ID del quiz",
"type": "number"
},
"studentId": {
"description": "ID del estudiante",
"type": "number"
}
},
"required": [
"studentId",
"quizId"
],
"type": "object"
}
Implementation Reference
- src/index.ts:584-636 (handler)The main handler function that implements the get_quiz_grade tool. It validates input, calls the Moodle API (mod_quiz_get_user_best_grade), processes the response, and returns the quiz grade information.private async getQuizGrade(args: any) { if (!args.studentId || !args.quizId) { throw new McpError( ErrorCode.InvalidParams, 'Student ID and Quiz ID are required' ); } console.error(`[API] Requesting quiz grade for student ${args.studentId} on quiz ${args.quizId}`); try { const response = await this.axiosInstance.get('', { params: { wsfunction: 'mod_quiz_get_user_best_grade', quizid: args.quizId, userid: args.studentId, }, }); // Procesamos la respuesta const result = { quizId: args.quizId, studentId: args.studentId, hasGrade: response.data.hasgrade, grade: response.data.hasgrade ? response.data.grade : 'No calificado', }; return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { console.error('[Error]', error); if (axios.isAxiosError(error)) { return { content: [ { type: 'text', text: `Error al obtener la calificación del quiz: ${ error.response?.data?.message || error.message }`, }, ], isError: true, }; } throw error; } }
- src/index.ts:220-233 (schema)Input schema defining required parameters studentId and quizId as numbers for the get_quiz_grade tool.inputSchema: { type: 'object', properties: { studentId: { type: 'number', description: 'ID del estudiante', }, quizId: { type: 'number', description: 'ID del quiz', }, }, required: ['studentId', 'quizId'], },
- src/index.ts:217-234 (registration)Tool registration in the ListTools response, specifying name, description, and input schema.{ name: 'get_quiz_grade', description: 'Obtiene la calificación de un estudiante en un quiz específico', inputSchema: { type: 'object', properties: { studentId: { type: 'number', description: 'ID del estudiante', }, quizId: { type: 'number', description: 'ID del quiz', }, }, required: ['studentId', 'quizId'], }, },
- src/index.ts:255-256 (registration)Dispatcher case in CallToolRequest handler that routes get_quiz_grade calls to the specific handler method.case 'get_quiz_grade': return await this.getQuizGrade(request.params.arguments);