add_new
Add new media content to your library by specifying service, title, and foreign ID, enabling organized media management and automated workflows.
Instructions
Add new media to library
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| foreignId | Yes | ||
| monitored | No | ||
| qualityProfileId | No | ||
| rootFolderPath | No | ||
| service | Yes | ||
| title | Yes |
Implementation Reference
- src/services/shared.ts:396-466 (handler)The core handler function implementing the add_new tool. It auto-selects quality profile if not provided, constructs the API payload specific to Sonarr/Radarr, performs the POST request to add new media, and returns the result.async addNew(request: AddRequest): Promise<OperationResult<AddData>> { const operation = withMetrics(this.serviceName, "addNew", async () => { debugOperation(this.serviceName, "addNew", { title: request.title, foreignId: request.foreignId, }); // Get quality profile if not provided let qualityProfileId = request.qualityProfileId; if (!qualityProfileId) { const profiles: QualityProfile[] = await fetchJson( this.buildApiUrl("/qualityprofile"), ); if (!profiles || profiles.length === 0) { throw new Error("No quality profiles available"); } // Smart quality profile detection based on service name and available profiles const selectedProfileId = this.selectBestQualityProfile(profiles); qualityProfileId = selectedProfileId ?? undefined; if (!qualityProfileId) { throw new Error( `Unable to auto-select quality profile for ${this.serviceName}. Available profiles: ${profiles.map((p: QualityProfile) => `${p.name} (id: ${p.id})`).join(", ")}. Please specify qualityProfileId explicitly.`, ); } } const addPayload = { title: request.title, [this.id === "sonarr" ? "tvdbId" : "tmdbId"]: request.foreignId, rootFolderPath: request.rootFolderPath, qualityProfileId, monitored: request.monitored ?? true, ...(this.id === "sonarr" ? { seasonFolder: true, addOptions: { searchForMissingEpisodes: false }, } : { addOptions: { searchForMovie: false } }), }; const response: AddResponse = await fetchJson( this.buildApiUrl(this.endpoints.add), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(addPayload), }, ); return { ok: true, data: { service: this.serviceName, mediaKind: this.mediaKind, added: true, id: response.id, title: response.title, existing: false, }, }; }); try { return await operation(); } catch (error) { return handleError(error, this.serviceName); } }
- src/index.ts:100-115 (schema)MCP tool schema definition for 'add_new', including input schema with required parameters service, title, foreignId.{ name: "add_new", description: "Add new media to library", inputSchema: { type: "object", properties: { service: { type: "string" }, title: { type: "string" }, foreignId: { type: "number" }, rootFolderPath: { type: "string" }, qualityProfileId: { type: "number" }, monitored: { type: "boolean" }, }, required: ["service", "title", "foreignId"], }, },
- src/index.ts:308-321 (registration)Tool dispatch/registration in the main switch statement: validates inputs and calls service.addNew() for 'add_new' tool invocations.case "add_new": if (!input.title || !input.foreignId) { throw new McpError( ErrorCode.InvalidParams, "Missing required parameters: title and foreignId", ); } return await service.addNew({ title: input.title, foreignId: input.foreignId, rootFolderPath: input.rootFolderPath, qualityProfileId: input.qualityProfileId, monitored: input.monitored, });
- src/services/base.ts:126-141 (schema)TypeScript interfaces defining the AddRequest input and AddData output types used by the addNew handler.export interface AddRequest { title: string; foreignId: number; rootFolderPath?: string; qualityProfileId?: number; monitored?: boolean; } export interface AddData { service: string; mediaKind: "series" | "movie"; added: boolean; id?: number; title: string; existing: boolean; }
- src/services/base.ts:253-253 (registration)Method signature in ServiceImplementation interface declaring the addNew method that all services must implement.addNew(payload: AddRequest): Promise<OperationResult<AddData>>;