MapleStatsMCP

City of Toronto · Notes from the code

How MapleStats works with Toronto's open data

A number from a city dataset is only useful if you know what it measures. This post follows one question through open.toronto.ca: find the dataset, read what the City says its columns mean, then get the figures, with the citation and licence attached.

Finding a dataset

The City's portal runs CKAN, the open-source catalogue many governments use, and its API answers anyone. MapleStats reads it with 13 general CKAN tools, the same ones it uses for the federal portal and the other city and provincial catalogues, and adds 9 tools written for the Toronto datasets people ask about most.

The question this post follows: how well are Toronto's rental apartment buildings kept? The City's RentSafeTO program scores them. A search of the catalogue finds the dataset:

Requestcall_tool
{
  "name": "ckan_search_datasets",
  "arguments": {"portal": "toronto", "query": "apartment building evaluation", "rows": 2}
}
Response, trimmedckan.PackageSearchResult
{
  "packages": [
    {
      "name": "apartment-building-evaluation",
      "title": "Apartment Building Evaluation",
      "notes_excerpt": "This dataset contains building evaluation data for rental buildings that are registered in the City's RentSafeTO: Apartment Building Standards program.",
      "update_frequency": "Daily",
      "owner_unit": "Municipal Licensing & Standards",
      "datastore_resources": 2,
      "landing_page_url": "https://open.toronto.ca/dataset/apartment-building-evaluation/"
      // + 11 more fields
    }
    // 1 more
  ],
  "total_count": 4,
  "provenance": {
    "url": "https://ckan0.cf.opendata.inter.prod-toronto.ca/api/3/action/package_search?q=apartment+building+evaluation&rows=2&start=0"
    // + 13 more fields
  }
}

What a column means

A column called CURRENT BUILDING EVAL SCORE invites a guess. The City does not leave it to one: its DataStore keeps a note on each column, and the dataset's record says how the data were collected and how often they change. ckan_get_dataset_documents returns both, here for the 70 columns of the current evaluations, kept to the ones that match "score":

Requestcall_tool
{
  "name": "ckan_get_dataset_documents",
  "arguments": {"portal": "toronto", "dataset_id": "apartment-building-evaluation", "query": "score"}
}
Response, trimmedckan.DatasetDocuments
{
  "title": "Apartment Building Evaluation",
  "about": {
    "refresh_rate": "Daily",
    "owner_division": "Municipal Licensing & Standards"
  },
  "data_dictionary": [
    {
      "resource_names": [
        "Apartment Building Evaluations 2023 - current"
      ],
      "fields": [
        {
          "name": "CURRENT BUILDING EVAL SCORE",
          "description": "An assessment of a building's compliance with property standards which is calculated by adding the reactive score (applicable Orders or Notices of Violations) to the proactive score (latest building evaluation score)"
          // + 2 more fields
        },
        {
          "name": "PROACTIVE BUILDING SCORE",
          "description": "The score of the most recent, proactive evaluation of the common areas of a building reflecting the weighted score of all, applicable, evaluation categories."
          // + 2 more fields
        },
        {
          "name": "CURRENT REACTIVE SCORE",
          "description": "Total score of all applicable Orders and Notices of Violation issued for a building"
          // + 2 more fields
        }
      ],
      "fields_total": 70
    }
    // 1 more
  ],
  "documents": [
    {
      "title": "Information page",
      "url": "https://www.toronto.ca/community-people/housing-shelter/rental-housing-standards/apartment-building-standards/",
      "kind": "information page"
    },
    {
      "title": "RentSafeTO",
      "url": "https://www.toronto.ca/community-people/housing-shelter/rental-housing-tenant-information/rental-housing-standards/apartment-building-standards/rentsafeto-for-tenants/",
      "kind": "linked in the description"
    }
    // 1 more
  ],
  "notes": [
    "The documents are listed, not opened: some publishers' terms or robots.txt rule out automated copies (the City of Toronto's, for one), so read them in a browser and cite them by their URL."
  ],
  // + 4 more fields
  "provenance": {
    "url": "https://ckan0.cf.opendata.inter.prod-toronto.ca/api/3/action/package_show?id=apartment-building-evaluation"
    // + 13 more fields
  }
}

Two things change how the score should be read. It adds two parts: the latest proactive evaluation, and the orders and notices of violation issued since. And the dataset's description says the officers inspect common areas, mechanical and security systems, parking and exterior grounds. A building's score says nothing about the inside of any one unit. An agent that reads this before answering will say so.

The 3 pages the dataset points to are listed with their address but not opened. The City's website terms bar copying its pages without permission, so the agent gives you the link to read and cite. The idea for this tool comes from the CKAN MCP Server, an honourable mention at the 2025 Toronto Open Data Awards; MapleStats' version reads only what the portal's API serves.

Apartment scores by ward

With the meaning settled, toronto_summarize_apartment_scores reads the evaluations and groups the buildings by ward. On 19 November 2026, Scarborough-Rouge Park had the lowest mean score (85.9) of the 25 wards, and Etobicoke Centre the highest (94.3).

RentSafeTO scores by ward, from 3,611 buildings, recorded 19 November 2026. Mean and median rounded to one decimal.
WardBuildingsUnitsMeanMedianLowest
01 Etobicoke North829,60292.493.077
02 Etobicoke Centre13413,06494.396.072
03 Etobicoke-Lakeshore25013,96892.794.069
04 Parkdale-High Park20717,49290.892.051
05 York South-Weston23818,35487.989.062
06 York Centre23515,93992.194.069
07 Humber River-Black Creek10315,11690.792.070
08 Eglinton-Lawrence24214,42492.494.070
09 Davenport956,85987.889.052
10 Spadina-Fort York6210,61090.493.045
11 University-Rosedale14913,74488.891.053
12 Toronto-St. Paul's34027,47891.093.059
13 Toronto Centre21429,43690.192.073
14 Toronto-Danforth1519,98589.592.067
15 Don Valley West17116,69693.194.076
16 Don Valley East15916,41291.493.069
17 Don Valley North7411,90191.892.076
18 Willowdale477,22290.893.071
19 Beaches-East York20213,11091.493.049
20 Scarborough Southwest16313,18689.891.062
21 Scarborough Centre13611,83588.890.069
22 Scarborough-Agincourt427,59292.794.080
23 Scarborough North91,64994.194.090
24 Scarborough-Guildwood7812,51589.090.069
25 Scarborough-Rouge Park282,10385.986.077

The means and medians are of buildings, not of units: a 300-unit tower counts as much as a 12-unit walk-up. The result says so, so an agent can say so too.

A neighbourhood beside the city

The City's Neighbourhood Profiles give each of its 140 neighbourhoods a column of census figures, with the city as a whole beside them. toronto_get_neighbourhood_profile returns one neighbourhood and the city on the same row, here for housing in Regent Park:

Requestcall_tool
{
  "name": "toronto_get_neighbourhood_profile",
  "arguments": {"neighbourhood": "Regent Park", "topic": "core housing need"}
}
Response, trimmedtoronto.NeighbourhoodProfile
{
  "census_year": 2016,
  "neighbourhood": "Regent Park",
  "rows": [
    {
      "characteristic": "Rate of core housing need",
      "value": null,
      "city_value": "23.3"
    },
    {
      "characteristic": "Number of households in core housing need",
      "value": "1,340",
      "city_value": "240,780"
    },
    {
      "characteristic": "Rate of unaffordable housing",
      "value": "39.4",
      "city_value": "36.6"
    },
    {
      "characteristic": "Rate of inadequate housing",
      "value": "9.6",
      "city_value": "7.1"
    },
    {
      "characteristic": "Rate of unsuitable housing",
      "value": "16",
      "city_value": "12.1"
    }
    // 16 more rows
  ],
  "provenance": {
    "url": "https://ckan0.cf.opendata.inter.prod-toronto.ca/api/3/action/datastore_search?resource_id=7f8eee5e-85fb-415c-aef3-c3bd4998445f&fields=_id%2CCategory%2CTopic%2CCharacteristic%2CData+Source%2CCity+of+Toronto%2CRegent+Park&sort=_id&limit=1000"
    // + 13 more fields
  }
}

In 2016, 39.4% of Regent Park's households spent 30% or more of their income on shelter, against 36.6% for the city. The City published no rate of core housing need for the neighbourhood (the city's was 23.3%), and the response leaves it empty rather than fill it in. These are the 2016 profiles: the 2021 ones come only as a spreadsheet file, which the server does not download (see the portal's rules).

Short-term rentals

Of 8,598 registrations in force with the City's short-term rental program, 2,622 were in Spadina-Fort York. toronto_summarize_short_term_rentals counts them by ward, property type or postal code. The City's table also lists each operator's registration number and street address; the tool returns counts only. A registration is not a booking or a night stayed, and the result says that as well.

The portal's rules

The API, not the files. The portal's robots.txt allows its API and disallows automated downloads of its resource files. MapleStats reads the catalogue and the DataStore tables through the API and downloads none of the files. Some datasets exist only as files, so they are out of reach for now: 311 service requests (yearly ZIP files), the TTC's GTFS schedules, the 2021 Neighbourhood Profiles (a spreadsheet) and DineSafe inspections older than the DataStore table. Asked to read one of these files, the CKAN file tools say why they will not.

The City's pages. The documents a dataset links to are listed, not copied, as above.

The licence. The data are under the Open Government Licence - Toronto, which allows use, copying and publishing, commercially too, with an acknowledgement. Every result from the 9 Toronto tools carries the dataset's citation and the sentence the licence asks for: "Contains information licensed under the Open Government Licence - Toronto."

A named, paced client. Requests carry MapleStats' own User-Agent and go through one rate limit per portal, shared by every tool that reads it.

Where to go next