nyc-charter-laws-rules
The single place to access, process, and query New York City's three primary legal documents:
- The New York City Charter
- The New York City Administrative Code
- The Rules of the City of New York
This repo includes:
- A MCP (Model Context Protocol) server so AI assistants can query the documents directly
- Scripts to fetch and parse the latest bulk XML from American Legal Publishing
- A committed JSON index (
data/index/json/) for machine use. The MCP server reads it, and it is the only data in the npm package.
- A committed Markdown index (
data/index/markdown/) for human browsing — readable directly on GitHub. The server does not read it, and it is not in the npm package.
- A site structure (
data/structure/) for the law website: each section's subdivisions, cross-reference targets, and chapter and title names, built with the index (see Site structure). It is not in the npm package.
- A website, the BetaNYC Law Reader: the Charter and the Administrative Code, one page per section, with links between sections and search, built from the index by
npm run build-site (see The website). .github/workflows/deploy-site.yml builds it and publishes it to law.beta.nyc on GitHub Pages; the HTML is never committed. It is not in the npm package.
Clone the repo and everything is ready to use. No setup required to browse or query the current index. Run npm run fetch-data && npm run build-index only when you want to refresh from AML.
Vibe coded with Claude by BetaNYC.
What's changed: new tools, corrections and other changes a reader would notice, newest first. Daily law text updates are in CHANGELOG.md.
API key
No API key is required. The Charter, Administrative Code, and Rules are served from an offline corpus bundled with the package, so this server works out of the box — no signup, no token, no environment variables to set.
The bundled text is as of the release. An npm install carries the law text from the day that version was published. When the daily refresh picks up new law text, it also publishes a new patch release automatically (see Releases), so the law text in npx -y @betanyc/nyc-charter-laws-rules is normally at most a day behind main's. Code changes ship with the next release. Automatic releases pause while a hand-bumped version is waiting to be published or a release run has failed. get_version reports the dates you are actually serving. To serve main's index directly, see Getting current law text.
What it does
Exposes 8 tools over MCP:
| Tool |
Description |
search |
Keyword search across all three documents (short keyword queries work best) |
get_section |
Retrieve a specific section by citation (e.g. § 259, Chapter 11); a long text comes in parts |
list_titles |
List the chapters of a document, in order |
get_title |
List the sections in a chapter, or in an Administrative Code or Rules title (citation and heading of each) |
get_version |
Return the currency date for each document — so responses can be grounded in exactly how current the law is |
whats_changed |
What changed in this server, newest first, from WHATS-CHANGED.md: new tools and corrections |
about_betanyc |
Who built this server, where its code is, and where to report a bug in this server or ask for a new feature |
about_data |
Where the law text comes from, from DATA-SOURCES.json: the publisher, whether it is the official text, when this server's index was built, where to check a section and how to report an error |
Tools reference
Every law-text answer (search, get_section, list_titles, get_title) ends, before the disclaimer, with a source line per document it came from. It says that BetaNYC converted the text and how, so it is not the official text; the date of this server's copy; and the official record, with its publisher and a link to the code library. search adds that snippets are cut at 400 characters. Under it is the publisher's own "current through" line from the same copy, exactly as the publisher gives it. An example, from a Charter answer on the November 14, 2026 copy (the date and the "current through" line change with every copy):
BetaNYC modified this data: converted by BetaNYC from the publisher's bulk XML files: line breaks are collapsed, so tables run together; the publisher's editing markers are removed and character codes decoded; math signs and Greek letters set in the old Symbol font are changed to the characters the font shows (³ to ≥) where BetaNYC has checked them; citations are worked out by BetaNYC from headings and can be wrong or cut short. This copy should not be considered the official record. As of 2026-11-14T11:05:40.153Z (the date of the copy this server answers from). Official record: New York City Charter, bulk XML download (American Legal Publishing), https://codelibrary.amlegal.com/codes/newyorkcity/latest/NYCcharter/0-0-0-1
The publisher's own "current through" line for it, as given: "Current through Local Law 2026/164, enacted November 10, 2026,"
get_version reports dates and counts, not law text, so its lines start Source: … (American Legal Publishing). and end with Link:. The wording of both kinds comes from the shared module's provenance().
The copy date is indexedAt in versions.json. It moves only when the text changes, so a copy can be days old and still match the publisher's latest download. The index keeps no date for when the source was last checked, so none is shown. Answers that find nothing ("No results found", "Section not found", "No titles found", "No sections found") say which documents were searched and carry the same lines.
Anything an answer repeats from the request (a query, citation, title, parameter name or value, or tool name) is cut to one line of at most 100 characters, ending …. If an index file is missing or unreadable, the answer names the document and says the server's operator should reinstall the package or rebuild the index; the file path goes to the server's stderr, not to the answer.
Every list says how much of how many it shows when it does not show everything, and how to get the rest.
Every tool only reads, and answers from the index bundled with the package, never a live API. Each says so in its MCP annotations (readOnlyHint: true, openWorldHint: false).
search
Keyword search across the NYC Charter, Administrative Code, and Rules. It is keyword matching, not a question-answering engine, so short keyword queries work best: sidewalk shed rather than "How long can a sidewalk shed stay up?"
An empty query (nothing, only spaces, or only quote marks such as "") is an error that says to send a keyword or a phrase, or to call get_section for a citation. Through 0.7.x an empty query listed all 22,637 sections.
Short terms match whole words only. A query, or in step 2 a term, with 3 or fewer letters and digits matches only where no letter or digit touches it on either side: x is the word x, not the x in "wax", and tax is not the start of "taxes". A longer one matches as below: the phrase anywhere, a term at the start of a word. Only letters and digits count, so s ≥ 4t is short and matches as whole words at its ends. The answer says when a query or term matched whole words only. This is the rule, and the limit, that BetaNYC's nyc-budget-mcp uses for its text filters. Through 0.7.x a matched inside 22,150 sections. It fits this search because the phrase step already ranked whole-word matches first, so a short query's best results were already whole words; the rule drops the rest, which were noise. The step 2 rule for longer terms, start of a word with no check at the end, is unchanged, since a whole-word check there lost an eval question (below). The eval passes the same 15 of 17 questions with this rule.
-
Phrase first. The whole query is matched as typed (case-insensitive). Quotes around the whole query, straight or curly, are removed first, so "open data" and open data search the same phrase. If any section contains it, those results are returned, relevance-ranked: heading matches rank above citation matches, which rank above body-text matches, and whole-word matches rank above substring matches.
-
Terms, if the phrase finds nothing. Question words and common words (how, what, can, a, the, up, about, …) are dropped. The full list is SEARCH_STOPWORDS in src/corpus.ts. Each remaining term matches at the start of a word, with a trailing plural s ignored, so tanks finds "tank" and shed does not find "established". There is no check at the end of a word, so car also finds "carbon"; that is what lets appoints find "appointed" (a whole-word check was tried and lost an eval question). Every section with at least one term gets one score, and results are sorted by it alone (termScore in src/corpus.ts):
- a rare word counts more than a common one (its weight is the log of sections searched divided by sections that contain it);
- a word in the heading or citation counts 3 times;
- a long section is pushed down a little: the score is divided by 1 + log(1 + length / average length);
- the score is multiplied by the share of the words' total weight the section covers, so a section with the rare words beats one with only the common ones;
- sections under 100 characters (empty headings,
[Repealed]) count 0.3 times, and Local Law appendix records (heading like L.L. 2016/002) half.
So a section with every word can rank below one with fewer, rarer words in its heading. Through 0.5.x, a section with more of the words always came first, before any weight applied, so long definitions sections that happen to hold every word won.
-
Said out loud. When step 2 runs, the first line of the response says so and lists the terms:
- every result contains every term:
No section contains the exact query; showing sections containing all of: building, owners, required, drinking, water, tanks.
- some results lack a term, and no section anywhere has every term:
No section matched every term; showing sections matching some of: smoking, banned, nyc.
- some results lack a term, and at least one section has every term:
No section contains the exact query; showing the best matches for some or all of: long, sidewalk, shed, stay.
-
How many. For a phrase match, when more sections matched than limit, a line after the results says Showing 10 of 35 matching sections, best first. and how to see others. When step 2 ran, sections with every term and sections with only some are counted apart, for example 1 section contains every term; it does not rank in this list. To see more of them, raise limit (max 50), … then 1525 other sections contain only some of the terms; the 10 shown are the best-ranked of those. When no section has every term: 619 sections contain some of the terms; the 10 shown are the best-ranked of those. The response never suggests raising limit to see sections that hold only some of the words.
-
Snippets show the match. Each snippet is at most 400 characters of the section's text, around the first match of the phrase, or of any term in step 2: it starts up to 100 characters before the match, at the start of a word, with … where text is left out at either end. A match only in the heading or citation shows the opening. A line after the results says so; get_section returns the full text. Through 0.7.x a snippet was always the first 400 characters, so a hit on s ≥ 4t in Section BC 722 showed 722.1's opening.
This is still keyword matching: a question whose answer uses other words ("warm" and "winter" for a section about minimum temperatures) does not find it. See Evaluation set.
| Parameter |
Type |
Required |
Default |
Description |
query |
string |
yes |
— |
Search term or phrase |
corpus |
string |
no |
all |
charter, admin_code, rules, or all |
limit |
integer |
no |
10 |
Max results (1 to 50) |
search("open data")
search("landlord inspection", corpus="admin_code", limit=20)
search("board of health", corpus="rules")
search("How long can a sidewalk shed stay up?") # term fallback; first line says so
get_section
Retrieve a specific section by citation or heading fragment. Input is normalized (with or without §, any case, extra whitespace, any kind of dash). If the same citation exists in more than one document (e.g. charter Chapter 3 vs a rules chapter, or a rules section number repeated across titles), a disambiguation list is returned. Its first line says what to add to get one: set 'corpus' (charter, admin_code or rules) only when corpus was not given and the matches are in more than one document, and the title when the citations name one (To get one, name its title in the citation, as each line below does: '1 RCNY § 2-01'.). The list comes in pages of 25: Showing 1 to 25 of 39. Call again with offset 25 for the next ones., and past the end, Nothing at offset 50: there are 39 in all., as the other lists say it.
Long text comes in parts. A section's text is at most max_chars characters per answer (default 20,000; 1,000 to 100,000). About 2% of records are longer, such as Section BC 722 and RS 18-1 (each about 80,000 to 110,000 characters), which clients that cap a tool's answer used to cut off. A longer text has a line before it, after the heading: Showing characters 1 to 20000 of 83475. Call again with offset 20000 for the next part. A part ends after a space when there is one in its last fifth, so no word is cut in two, and following each part's offset gives back the whole text. The last part's line ends at the count; an offset past the end says Nothing at offset N: the text has M characters. A text that fits whole has no such line, so short sections answer as before.