UNPKG

@withpica/mcp-server

Version:

MCP Server for withPICA — enables AI assistants to interact with your withPICA music catalog

117 lines • 4.8 kB
/** * Fetching a file a client hands a tool by URL (ChatGPT's * `_meta["openai/fileParams"]`: `{ download_url, file_id, mime_type?, * file_name? }`, developers.openai.com/apps-sdk/reference). * * ⚠️ The URL is caller input. Any MCP client, not only ChatGPT, can put any * address in the field, and the hosted server fetches it from inside PICA's * network. So a fetch here goes only to: * - an https URL on the default port, * - whose parsed hostname is on PICA_FILE_PARAM_HOSTS (exact, or a suffix * entry written with a leading dot; never a substring match), * - connecting only to public addresses. The check runs inside the * connection's own DNS lookup (`lookup` on the request), so the address * checked is the address connected to and a rebinding answer cannot slip * in between a check and the connect, * - following at most MAX_REDIRECTS redirects, each re-checked as above. * PICA_FILE_PARAM_HOSTS empty or unset turns the whole path off. */ import { type LookupAddress } from "node:dns"; import type { IncomingMessage } from "node:http"; /** One file a client passed by reference. */ export interface FileParam { download_url: string; file_id: string; mime_type?: string; file_name?: string; } /** The JSON Schema ChatGPT requires for a file field (all four declared). */ export declare const FILE_PARAM_SCHEMA: { readonly type: "object"; readonly properties: { readonly download_url: { readonly type: "string"; readonly description: "Temporary download URL for the file, set by the client."; }; readonly file_id: { readonly type: "string"; readonly description: "The client's id for the file."; }; readonly mime_type: { readonly type: "string"; readonly description: "The file's MIME type."; }; readonly file_name: { readonly type: "string"; readonly description: "The file's name."; }; }; readonly required: readonly ["download_url", "file_id"]; }; export declare const MAX_REDIRECTS = 3; /** A refusal whose message is safe to show the user and the agent. */ export declare class FileParamRefusal extends Error { constructor(message: string); } /** * The allowed hosts, from a comma-separated list. "files.example.com" is * that host only; ".example.com" is any host under example.com (not * example.com itself). */ export declare function allowedFileHosts(raw?: string | undefined): string[]; export declare function hostAllowed(hostname: string, allowed: string[]): boolean; /** True only for a globally routable unicast address. */ export declare function isPublicAddress(ip: string): boolean; type LookupCallback = (err: NodeJS.ErrnoException | null, address: string | LookupAddress[], family?: number) => void; /** * The connection's DNS lookup: resolves, refuses if ANY answer is not * public, and hands the socket only checked addresses. */ export declare function publicOnlyLookup(hostname: string, options: { all?: boolean; family?: number; } | number, callback: LookupCallback): void; export interface OpenedDownload { body: IncomingMessage; contentLength: number; contentType: string | null; } /** Checks one URL against the rules above, before any connection. */ export declare function checkFileUrl(raw: string, allowed: string[]): URL; /** * Opens a download, following redirects only to allowed hosts. Resolves * once the status is 200 and the size is known and within `maxBytes`; the * caller reads `body`. Sends no credentials of PICA's. */ export declare function openFileDownload(raw: string, opts: { allowed: string[]; maxBytes: number; timeoutMs?: number; redirectsLeft?: number; }): Promise<OpenedDownload>; /** Audio MIME types the upload path accepts, by their leading bytes. */ export declare function sniffAudioType(head: Uint8Array): string | null; /** * Reads the first bytes of a download (at least `min`, unless the file is * shorter) and returns them with an iterator for the rest, so a type check * can run before anything is sent on. */ export declare function readHead(body: AsyncIterable<Buffer>, min?: number): Promise<{ head: Buffer; rest: AsyncIterator<Buffer>; }>; /** * Streams a download to a signed PUT URL (the storage URL * pica_audio_presigned_upload returns), sending exactly `contentLength` * bytes: a body longer or shorter than the size it declared is refused, * not stored. */ export declare function putToSignedUrl(input: { uploadUrl: string; contentType: string; contentLength: number; head: Buffer; rest: AsyncIterator<Buffer>; }): Promise<void>; export {}; //# sourceMappingURL=file-param-fetch.d.ts.map