get_bills
Retrieve U.S. 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 |
|---|---|---|---|
| congress | No | ||
| bill_type | No | ||
| bill_number | No | ||
| offset | No | ||
| limit | No | ||
| from_datetime | No | ||
| to_datetime | No | ||
| sort | No | updateDate+desc |
Implementation Reference
- server.py:28-97 (handler)The primary handler for the 'get_bills' tool. Decorated with @mcp.tool() for registration in FastMCP. Implements logic to query Congress.gov API for bills using provided parameters, handles URL construction, request parameters, and error handling.@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:28-28 (registration)The @mcp.tool() decorator registers the get_bills function as an MCP tool.@mcp.tool()
- server.py:29-62 (schema)Function signature with type annotations and comprehensive docstring defining input parameters and output for the get_bills tool schema.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 """