Skip to main content
Glama

get_submission_content

Retrieve detailed submission content including text and attached files for a specific student and assignment on Moodle.

Instructions

Obtiene el contenido detallado de una entrega específica, incluyendo texto y archivos adjuntos

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
studentIdYesID del estudiante
assignmentIdYesID de la tarea

Implementation Reference

  • The handler function that retrieves detailed submission content from Moodle API, processes online text and file plugins, and returns formatted JSON.
    private async getSubmissionContent(args: any) {
      if (!args.studentId || !args.assignmentId) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Student ID and Assignment ID are required'
        );
      }
    
      console.error(`[API] Requesting submission content for student ${args.studentId} on assignment ${args.assignmentId}`);
      
      try {
        // Utilizamos la función mod_assign_get_submission_status para obtener el contenido detallado
        const response = await this.axiosInstance.get('', {
          params: {
            wsfunction: 'mod_assign_get_submission_status',
            assignid: args.assignmentId,
            userid: args.studentId,
          },
        });
    
        // Procesamos la respuesta para extraer el contenido relevante
        const submissionData = response.data.submission || {};
        const plugins = response.data.lastattempt?.submission?.plugins || [];
        
        // Extraemos el texto de la entrega y los archivos adjuntos
        let submissionText = '';
        const files = [];
        
        for (const plugin of plugins) {
          // Procesamos el plugin de texto en línea
          if (plugin.type === 'onlinetext') {
            const textField = plugin.editorfields?.find((field: any) => field.name === 'onlinetext');
            if (textField) {
              submissionText = textField.text || '';
            }
          }
          
          // Procesamos el plugin de archivos
          if (plugin.type === 'file') {
            const filesList = plugin.fileareas?.find((area: any) => area.area === 'submission_files');
            if (filesList && filesList.files) {
              for (const file of filesList.files) {
                files.push({
                  filename: file.filename,
                  fileurl: file.fileurl,
                  filesize: file.filesize,
                  filetype: file.mimetype,
                });
              }
            }
          }
        }
        
        // Construimos el objeto de respuesta
        const submissionContent = {
          assignment: args.assignmentId,
          userid: args.studentId,
          status: submissionData.status || 'unknown',
          submissiontext: submissionText,
          plugins: [
            {
              type: 'onlinetext',
              content: submissionText,
            },
            {
              type: 'file',
              files: files,
            },
          ],
          timemodified: submissionData.timemodified || 0,
        };
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(submissionContent, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error('[Error]', error);
        if (axios.isAxiosError(error)) {
          return {
            content: [
              {
                type: 'text',
                text: `Error al obtener el contenido de la entrega: ${
                  error.response?.data?.message || error.message
                }`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    }
  • TypeScript interface defining the structure of submission content returned by the handler.
    interface SubmissionContent {
      assignment: number;
      userid: number;
      status: string;
      submissiontext?: string;
      plugins?: Array<{
        type: string;
        content?: string;
        files?: Array<{
          filename: string;
          fileurl: string;
          filesize: number;
          filetype: string;
        }>;
      }>;
      timemodified: number;
    }
  • src/index.ts:199-216 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema for validation.
    {
      name: 'get_submission_content',
      description: 'Obtiene el contenido detallado de una entrega específica, incluyendo texto y archivos adjuntos',
      inputSchema: {
        type: 'object',
        properties: {
          studentId: {
            type: 'number',
            description: 'ID del estudiante',
          },
          assignmentId: {
            type: 'number',
            description: 'ID de la tarea',
          },
        },
        required: ['studentId', 'assignmentId'],
      },
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cfsandoval/Mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server