get_bills
Retrieve US congressional bills by congress, type, number, or date range to access legislative information directly from Congress.gov.
Instructions
Retrieve a list of bills. Full documentation for this endpoint -> https://github.com/LibraryOfCongress/api.congress.gov/blob/main/Documentation/BillEndpoint.md
Args: congress: Congress number (e.g., 118 for 118th Congress) bill_type: Type of bill - hr: House of Representatives Bill - s: Senate Bill - hjres: House Joint Resolution - sjres: Senate Joint Resolution - hconres: House Concurrent Resolution - sconres: Senate Concurrent Resolution - hres: House Simple Resolution - sres: Senate Simple Resolution bill_number: Specific bill number (requires congress and bill_type) offset: Starting record (default 0) limit: Maximum records to return (max 250, default 20) from_datetime: Start timestamp (YYYY-MM-DDTHH:MM:SSZ format) to_datetime: End timestamp (YYYY-MM-DDTHH:MM:SSZ format) sort: Sort order ('updateDate+asc' or 'updateDate+desc')
Returns: dict: Bill data from Congress.gov API
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bill_number | No | ||
| bill_type | No | ||
| congress | No | ||
| from_datetime | No | ||
| limit | No | ||
| offset | No | ||
| sort | No | updateDate+desc | |
| to_datetime | No |
Implementation Reference
- server.py:28-97 (handler)The handler function for the 'get_bills' MCP tool. Decorated with @mcp.tool(), it constructs API requests to Congress.gov's bill endpoint based on input parameters (congress, bill_type, bill_number, pagination, dates, sort), fetches JSON data, and handles errors.@mcp.tool() async def get_bills( congress: int | None = None, bill_type: str | None = None, bill_number: int | None = None, offset: int = 0, limit: int = 20, from_datetime: str | None = None, to_datetime: str | None = None, sort: str = "updateDate+desc" ) -> dict: """ Retrieve a list of bills. Full documentation for this endpoint -> https://github.com/LibraryOfCongress/api.congress.gov/blob/main/Documentation/BillEndpoint.md Args: congress: Congress number (e.g., 118 for 118th Congress) bill_type: Type of bill - hr: House of Representatives Bill - s: Senate Bill - hjres: House Joint Resolution - sjres: Senate Joint Resolution - hconres: House Concurrent Resolution - sconres: Senate Concurrent Resolution - hres: House Simple Resolution - sres: Senate Simple Resolution bill_number: Specific bill number (requires congress and bill_type) offset: Starting record (default 0) limit: Maximum records to return (max 250, default 20) from_datetime: Start timestamp (YYYY-MM-DDTHH:MM:SSZ format) to_datetime: End timestamp (YYYY-MM-DDTHH:MM:SSZ format) sort: Sort order ('updateDate+asc' or 'updateDate+desc') Returns: dict: Bill data from Congress.gov API """ base_url = "https://api.congress.gov/v3/bill" url = base_url if congress: url += f"/{congress}" if bill_type: url += f"/{bill_type}" if bill_number: url += f"/{bill_number}" params = { "api_key": congress_gov_api_key, "format": "json", "offset": offset, "limit": min(limit, 100) # Enforce API max limit } if from_datetime: params["fromDateTime"] = from_datetime if to_datetime: params["toDateTime"] = to_datetime if not bill_number: params["sort"] = sort try: response = requests.get(url, params=params) response.raise_for_status() return response.json() except requests.exceptions.RequestException as e: return { "error": f"Failed to retrieve bills: {str(e)}", "status_code": getattr(e.response, "status_code", None) }
- server.py:39-62 (schema)The docstring provides detailed input schema (parameters with descriptions, types, defaults) and output description for the get_bills tool, serving as the tool's schema documentation.""" Retrieve a list of bills. Full documentation for this endpoint -> https://github.com/LibraryOfCongress/api.congress.gov/blob/main/Documentation/BillEndpoint.md Args: congress: Congress number (e.g., 118 for 118th Congress) bill_type: Type of bill - hr: House of Representatives Bill - s: Senate Bill - hjres: House Joint Resolution - sjres: Senate Joint Resolution - hconres: House Concurrent Resolution - sconres: Senate Concurrent Resolution - hres: House Simple Resolution - sres: Senate Simple Resolution bill_number: Specific bill number (requires congress and bill_type) offset: Starting record (default 0) limit: Maximum records to return (max 250, default 20) from_datetime: Start timestamp (YYYY-MM-DDTHH:MM:SSZ format) to_datetime: End timestamp (YYYY-MM-DDTHH:MM:SSZ format) sort: Sort order ('updateDate+asc' or 'updateDate+desc') Returns: dict: Bill data from Congress.gov API """
- server.py:28-28 (registration)The @mcp.tool() decorator registers the get_bills function as an MCP tool named 'get_bills' in the FastMCP server.@mcp.tool()