add_resource
Enables users to attach resources like files or URLs to tasks, providing essential context or supporting materials for task execution within the Divide and Conquer MCP Server framework.
Instructions
Adds a resource to the task.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | Description of the resource | |
| name | Yes | Name of the resource | |
| url | Yes | URL or file path of the resource |
Implementation Reference
- src/index.ts:1000-1043 (handler)The handler function for the 'add_resource' tool. Validates input parameters (name and url required), reads current task data, initializes resources array if needed, appends the new resource, persists changes to the config file via writeTaskData, and returns a success message or error response.private async addResource(args: any): Promise<any> { if (!args?.name || !args?.url) { throw new McpError(ErrorCode.InvalidParams, 'Resource name and URL are required'); } try { const taskData = await this.readTaskData(); // Initialize the resources array if it doesn't exist if (!taskData.resources) { taskData.resources = []; } // Add the resource taskData.resources.push({ name: args.name, url: args.url, description: args.description || '' }); // Write the updated task data to the file await this.writeTaskData(taskData); return { content: [ { type: 'text', text: 'Resource added successfully.', }, ], }; } catch (error) { console.error('Error adding resource:', error); return { content: [ { type: 'text', text: `Error adding resource: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }
- src/index.ts:341-357 (schema)Input schema defining the parameters for the 'add_resource' tool: required 'name' and 'url' strings, optional 'description' string.inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the resource' }, url: { type: 'string', description: 'URL or file path of the resource' }, description: { type: 'string', description: 'Description of the resource' } }, required: ['name', 'url']
- src/index.ts:338-359 (registration)Registration of the 'add_resource' tool in the ListToolsRequestSchema response, providing name, description, and input schema.{ name: 'add_resource', description: 'Adds a resource to the task.', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the resource' }, url: { type: 'string', description: 'URL or file path of the resource' }, description: { type: 'string', description: 'Description of the resource' } }, required: ['name', 'url'] } },
- src/index.ts:444-445 (registration)Route in the CallToolRequestSchema switch statement that dispatches 'add_resource' tool calls to the addResource handler method.case 'add_resource': return await this.addResource(request.params.arguments);
- src/index.ts:25-29 (schema)TypeScript interface defining the structure of a TaskResource, matching the tool's input schema and used in the TaskData.resources array.interface TaskResource { name: string; url: string; description?: string; }