package_search
Search for government datasets on Data.gov using customizable queries, filters, and sorting options to find relevant packages efficiently.
Instructions
Search for packages (datasets) on Data.gov
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | No | Search query | |
| rows | No | Number of results per page | |
| sort | No | Sort order (e.g., "score desc, name asc") | |
| start | No | Starting offset for results |
Implementation Reference
- src/index.ts:309-322 (handler)The core handler function that executes the package_search tool. It makes an HTTP GET request to the Data.gov API endpoint '/action/package_search' with the provided arguments and returns the response as formatted JSON text.private async packageSearch(args: PackageSearchArgs) { try { const response = await this.axiosInstance.get('/action/package_search', { params: args, }); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2) }, ], }; } catch (error) { return this.handleAxiosError(error); } }
- src/index.ts:201-217 (schema)The JSON schema defining the input parameters for the package_search tool, used in tool listing and validation.inputSchema: { type: 'object', properties: { q: { type: 'string', description: 'Search query' }, sort: { type: 'string', description: 'Sort order (e.g., "score desc, name asc")', }, rows: { type: 'number', description: 'Number of results per page', }, start: { type: 'number', description: 'Starting offset for results', }, },
- src/index.ts:198-219 (registration)The tool registration metadata in the ListToolsRequestSchema handler, including name, description, and input schema.{ name: 'package_search', description: 'Search for packages (datasets) on Data.gov', inputSchema: { type: 'object', properties: { q: { type: 'string', description: 'Search query' }, sort: { type: 'string', description: 'Sort order (e.g., "score desc, name asc")', }, rows: { type: 'number', description: 'Number of results per page', }, start: { type: 'number', description: 'Starting offset for results', }, }, }, },
- src/index.ts:263-270 (registration)The dispatch case in the CallToolRequestSchema handler that validates arguments and invokes the packageSearch handler.case 'package_search': if (!isValidPackageSearchArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid package_search arguments' ); } return this.packageSearch(request.params.arguments);
- src/index.ts:20-25 (schema)TypeScript interface defining the expected arguments for the package_search tool.interface PackageSearchArgs { q?: string; sort?: string; rows?: number; start?: number; }
- src/index.ts:32-38 (helper)Helper function to validate if arguments match the PackageSearchArgs type before calling the handler.const isValidPackageSearchArgs = (args: any): args is PackageSearchArgs => typeof args === 'object' && args !== null && (args.q === undefined || typeof args.q === 'string') && (args.sort === undefined || typeof args.sort === 'string') && (args.rows === undefined || typeof args.rows === 'number') && (args.start === undefined || typeof args.start === 'number');