queryData
Retrieve detailed trade data for imports or exports, filtered by country, state, economic block, or product categories, and analyze metrics like FOB, KG, and CIF within specified periods.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| details | Yes | ||
| filters | No | ||
| flow | Yes | ||
| language | No | pt | |
| metrics | Yes | ||
| monthDetail | Yes | ||
| period | Yes |
Implementation Reference
- src/ComexstatClient.ts:270-337 (handler)Core handler implementation of queryData that validates period format and performs POST request to Comexstat API '/general' endpoint with the provided parameters.async queryData( flow: "export" | "import", period: { from: string; to: string }, // Format: YYYY-MM (e.g., "2023-01") monthDetail: boolean, filters: Array<{ filter: | "country" | "state" | "economicBlock" | "section" | "chapter" | "position" | "subposition" | "ncm"; values: number[]; }> = [], details: Array< | "country" | "state" | "economicBlock" | "section" | "chapter" | "position" | "subposition" | "ncm" >, metrics: Array< | "metricFOB" | "metricKG" | "metricStatistic" | "metricFreight" | "metricInsurance" | "metricCIF" >, language: string = "pt" ): Promise<{ data: { list: any[]; }; success: boolean; message: string | null; processo_info: any; language: string; }> { // Validate date format const dateFormatRegex = /^\d{4}-\d{2}$/; if ( !dateFormatRegex.test(period.from) || !dateFormatRegex.test(period.to) ) { throw new Error( 'Period dates must be in YYYY-MM format (e.g., "2023-01")' ); } return this.post( "/general", { flow, monthDetail, period, filters, details, metrics, }, { language } ); }
- src/ComexstatMCP.ts:93-150 (schema)Zod input schema for the queryData MCP tool defining parameters like flow, period, filters, details, metrics with validation.{ flow: z.enum(["export", "import"]), monthDetail: z.boolean(), period: z.object({ from: z .string() .regex( /^\d{4}-\d{2}$/, "Must be in YYYY-MM format (e.g., '2023-01')" ), to: z .string() .regex( /^\d{4}-\d{2}$/, "Must be in YYYY-MM format (e.g., '2023-01')" ), }), filters: z .array( z.object({ filter: z.enum([ "country", "state", "economicBlock", "section", "chapter", "position", "subposition", "ncm", ]), values: z.array(z.number()), }) ) .optional(), details: z.array( z.enum([ "country", "state", "economicBlock", "section", "chapter", "position", "subposition", "ncm", ]) ), metrics: z.array( z.enum([ "metricFOB", "metricKG", "metricStatistic", "metricFreight", "metricInsurance", "metricCIF", ]) ), language: z.string().optional().default("pt"), },
- src/ComexstatMCP.ts:91-177 (registration)MCP tool registration for 'queryData' using server.tool() with schema and wrapper handler that JSON.stringifies the client response.this.server.tool( "queryData", { flow: z.enum(["export", "import"]), monthDetail: z.boolean(), period: z.object({ from: z .string() .regex( /^\d{4}-\d{2}$/, "Must be in YYYY-MM format (e.g., '2023-01')" ), to: z .string() .regex( /^\d{4}-\d{2}$/, "Must be in YYYY-MM format (e.g., '2023-01')" ), }), filters: z .array( z.object({ filter: z.enum([ "country", "state", "economicBlock", "section", "chapter", "position", "subposition", "ncm", ]), values: z.array(z.number()), }) ) .optional(), details: z.array( z.enum([ "country", "state", "economicBlock", "section", "chapter", "position", "subposition", "ncm", ]) ), metrics: z.array( z.enum([ "metricFOB", "metricKG", "metricStatistic", "metricFreight", "metricInsurance", "metricCIF", ]) ), language: z.string().optional().default("pt"), }, async ({ flow, period, monthDetail, filters, details, metrics, language, }) => ({ content: [ { type: "text", text: JSON.stringify( await this.client.queryData( flow, period, monthDetail, filters || [], details, metrics, language ) ), }, ], }) );