add_resource
Add resources like files or URLs to tasks to provide context and reference materials for AI agents working on complex problem decomposition.
Instructions
Adds a resource to the task.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the resource | |
| url | Yes | URL or file path of the resource | |
| description | No | Description of the resource |
Implementation Reference
- src/index.ts:1000-1043 (handler)The main handler function for the 'add_resource' tool. It validates input, reads current task data, appends the new resource to the resources array, persists the updated data to the config file, and returns success 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: name (required string), url (required string), description (optional 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 ListTools response, including 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)Dispatch/registration in the CallToolRequest handler switch statement that routes 'add_resource' calls to the addResource method.
case 'add_resource': return await this.addResource(request.params.arguments); - src/index.ts:26-29 (schema)TypeScript interface defining the structure of a TaskResource, used for resources in task data.
name: string; url: string; description?: string; }