@ansvar/singapore-law-mcp 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE +110 -0
  2. package/README.md +359 -0
  3. package/data/database.db +0 -0
  4. package/dist/__tests__/contract/golden.test.d.ts +2 -0
  5. package/dist/__tests__/contract/golden.test.d.ts.map +1 -0
  6. package/dist/__tests__/contract/golden.test.js +215 -0
  7. package/dist/__tests__/contract/golden.test.js.map +1 -0
  8. package/dist/api/health.d.ts +3 -0
  9. package/dist/api/health.d.ts.map +1 -0
  10. package/dist/api/health.js +101 -0
  11. package/dist/api/health.js.map +1 -0
  12. package/dist/api/mcp.d.ts +3 -0
  13. package/dist/api/mcp.d.ts.map +1 -0
  14. package/dist/api/mcp.js +119 -0
  15. package/dist/api/mcp.js.map +1 -0
  16. package/dist/scripts/build-db.d.ts +11 -0
  17. package/dist/scripts/build-db.d.ts.map +1 -0
  18. package/dist/scripts/build-db.js +375 -0
  19. package/dist/scripts/build-db.js.map +1 -0
  20. package/dist/scripts/drift-detect.d.ts +9 -0
  21. package/dist/scripts/drift-detect.d.ts.map +1 -0
  22. package/dist/scripts/drift-detect.js +62 -0
  23. package/dist/scripts/drift-detect.js.map +1 -0
  24. package/dist/scripts/ingest.d.ts +22 -0
  25. package/dist/scripts/ingest.d.ts.map +1 -0
  26. package/dist/scripts/ingest.js +179 -0
  27. package/dist/scripts/ingest.js.map +1 -0
  28. package/dist/scripts/lib/fetcher.d.ts +47 -0
  29. package/dist/scripts/lib/fetcher.d.ts.map +1 -0
  30. package/dist/scripts/lib/fetcher.js +166 -0
  31. package/dist/scripts/lib/fetcher.js.map +1 -0
  32. package/dist/scripts/lib/parser.d.ts +80 -0
  33. package/dist/scripts/lib/parser.d.ts.map +1 -0
  34. package/dist/scripts/lib/parser.js +333 -0
  35. package/dist/scripts/lib/parser.js.map +1 -0
  36. package/dist/src/capabilities.d.ts +16 -0
  37. package/dist/src/capabilities.d.ts.map +1 -0
  38. package/dist/src/capabilities.js +43 -0
  39. package/dist/src/capabilities.js.map +1 -0
  40. package/dist/src/constants.d.ts +7 -0
  41. package/dist/src/constants.d.ts.map +1 -0
  42. package/dist/src/constants.js +7 -0
  43. package/dist/src/constants.js.map +1 -0
  44. package/dist/src/index.d.ts +8 -0
  45. package/dist/src/index.d.ts.map +1 -0
  46. package/dist/src/index.js +80 -0
  47. package/dist/src/index.js.map +1 -0
  48. package/dist/src/tools/about.d.ts +37 -0
  49. package/dist/src/tools/about.d.ts.map +1 -0
  50. package/dist/src/tools/about.js +46 -0
  51. package/dist/src/tools/about.js.map +1 -0
  52. package/dist/src/tools/build-legal-stance.d.ts +21 -0
  53. package/dist/src/tools/build-legal-stance.d.ts.map +1 -0
  54. package/dist/src/tools/build-legal-stance.js +46 -0
  55. package/dist/src/tools/build-legal-stance.js.map +1 -0
  56. package/dist/src/tools/check-currency.d.ts +20 -0
  57. package/dist/src/tools/check-currency.d.ts.map +1 -0
  58. package/dist/src/tools/check-currency.js +41 -0
  59. package/dist/src/tools/check-currency.js.map +1 -0
  60. package/dist/src/tools/format-citation.d.ts +18 -0
  61. package/dist/src/tools/format-citation.d.ts.map +1 -0
  62. package/dist/src/tools/format-citation.js +31 -0
  63. package/dist/src/tools/format-citation.js.map +1 -0
  64. package/dist/src/tools/get-eu-basis.d.ts +21 -0
  65. package/dist/src/tools/get-eu-basis.d.ts.map +1 -0
  66. package/dist/src/tools/get-eu-basis.js +52 -0
  67. package/dist/src/tools/get-eu-basis.js.map +1 -0
  68. package/dist/src/tools/get-provision-eu-basis.d.ts +20 -0
  69. package/dist/src/tools/get-provision-eu-basis.d.ts.map +1 -0
  70. package/dist/src/tools/get-provision-eu-basis.js +45 -0
  71. package/dist/src/tools/get-provision-eu-basis.js.map +1 -0
  72. package/dist/src/tools/get-provision.d.ts +24 -0
  73. package/dist/src/tools/get-provision.d.ts.map +1 -0
  74. package/dist/src/tools/get-provision.js +84 -0
  75. package/dist/src/tools/get-provision.js.map +1 -0
  76. package/dist/src/tools/get-singapore-implementations.d.ts +25 -0
  77. package/dist/src/tools/get-singapore-implementations.d.ts.map +1 -0
  78. package/dist/src/tools/get-singapore-implementations.js +46 -0
  79. package/dist/src/tools/get-singapore-implementations.js.map +1 -0
  80. package/dist/src/tools/list-sources.d.ts +25 -0
  81. package/dist/src/tools/list-sources.d.ts.map +1 -0
  82. package/dist/src/tools/list-sources.js +41 -0
  83. package/dist/src/tools/list-sources.js.map +1 -0
  84. package/dist/src/tools/registry.d.ts +13 -0
  85. package/dist/src/tools/registry.d.ts.map +1 -0
  86. package/dist/src/tools/registry.js +365 -0
  87. package/dist/src/tools/registry.js.map +1 -0
  88. package/dist/src/tools/search-eu-implementations.d.ts +24 -0
  89. package/dist/src/tools/search-eu-implementations.d.ts.map +1 -0
  90. package/dist/src/tools/search-eu-implementations.js +58 -0
  91. package/dist/src/tools/search-eu-implementations.js.map +1 -0
  92. package/dist/src/tools/search-legislation.d.ts +24 -0
  93. package/dist/src/tools/search-legislation.d.ts.map +1 -0
  94. package/dist/src/tools/search-legislation.js +54 -0
  95. package/dist/src/tools/search-legislation.js.map +1 -0
  96. package/dist/src/tools/validate-citation.d.ts +20 -0
  97. package/dist/src/tools/validate-citation.d.ts.map +1 -0
  98. package/dist/src/tools/validate-citation.js +101 -0
  99. package/dist/src/tools/validate-citation.js.map +1 -0
  100. package/dist/src/tools/validate-eu-compliance.d.ts +20 -0
  101. package/dist/src/tools/validate-eu-compliance.d.ts.map +1 -0
  102. package/dist/src/tools/validate-eu-compliance.js +98 -0
  103. package/dist/src/tools/validate-eu-compliance.js.map +1 -0
  104. package/dist/src/utils/as-of-date.d.ts +9 -0
  105. package/dist/src/utils/as-of-date.d.ts.map +1 -0
  106. package/dist/src/utils/as-of-date.js +25 -0
  107. package/dist/src/utils/as-of-date.js.map +1 -0
  108. package/dist/src/utils/fts-query.d.ts +19 -0
  109. package/dist/src/utils/fts-query.d.ts.map +1 -0
  110. package/dist/src/utils/fts-query.js +47 -0
  111. package/dist/src/utils/fts-query.js.map +1 -0
  112. package/dist/src/utils/metadata.d.ts +16 -0
  113. package/dist/src/utils/metadata.d.ts.map +1 -0
  114. package/dist/src/utils/metadata.js +23 -0
  115. package/dist/src/utils/metadata.js.map +1 -0
  116. package/dist/src/utils/statute-id.d.ts +16 -0
  117. package/dist/src/utils/statute-id.d.ts.map +1 -0
  118. package/dist/src/utils/statute-id.js +36 -0
  119. package/dist/src/utils/statute-id.js.map +1 -0
  120. package/package.json +82 -0
  121. package/server.json +31 -0
package/LICENSE ADDED
@@ -0,0 +1,110 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including
45
+ the original version of the Work and any modifications or additions
46
+ to that Work or Derivative Works thereof, that is intentionally
47
+ submitted to the Licensor for inclusion in the Work by the copyright owner
48
+ or by an individual or Legal Entity authorized to submit on behalf of
49
+ the copyright owner.
50
+
51
+ "Contributor" shall mean Licensor and any individual or Legal Entity
52
+ on behalf of whom a Contribution has been received by the Licensor and
53
+ subsequently incorporated within the Work.
54
+
55
+ 2. Grant of Copyright License. Subject to the terms and conditions of
56
+ this License, each Contributor hereby grants to You a perpetual,
57
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
58
+ copyright license to reproduce, prepare Derivative Works of,
59
+ publicly display, publicly perform, sublicense, and distribute the
60
+ Work and such Derivative Works in Source or Object form.
61
+
62
+ 3. Grant of Patent License. Subject to the terms and conditions of
63
+ this License, each Contributor hereby grants to You a perpetual,
64
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
65
+ (except as stated in this section) patent license to make, have made,
66
+ use, offer to sell, sell, import, and otherwise transfer the Work.
67
+
68
+ 4. Redistribution. You may reproduce and distribute copies of the
69
+ Work or Derivative Works thereof in any medium, with or without
70
+ modifications, and in Source or Object form, provided that You
71
+ meet the following conditions:
72
+
73
+ (a) You must give any other recipients of the Work or
74
+ Derivative Works a copy of this License; and
75
+
76
+ (b) You must cause any modified files to carry prominent notices
77
+ stating that You changed the files; and
78
+
79
+ (c) You must retain, in the Source form of any Derivative Works
80
+ that You distribute, all copyright, patent, trademark, and
81
+ attribution notices from the Source form of the Work; and
82
+
83
+ (d) If the Work includes a "NOTICE" text file, You must include
84
+ a readable copy of the attribution notices contained
85
+ within such NOTICE file.
86
+
87
+ 5. Submission of Contributions.
88
+
89
+ 6. Trademarks. This License does not grant permission to use the trade
90
+ names, trademarks, service marks, or product names of the Licensor.
91
+
92
+ 7. Disclaimer of Warranty.
93
+
94
+ 8. Limitation of Liability.
95
+
96
+ 9. Accepting Warranty or Additional Liability.
97
+
98
+ Copyright 2024 Ansvar Systems AB
99
+
100
+ Licensed under the Apache License, Version 2.0 (the "License");
101
+ you may not use this file except in compliance with the License.
102
+ You may obtain a copy of the License at
103
+
104
+ http://www.apache.org/licenses/LICENSE-2.0
105
+
106
+ Unless required by applicable law or agreed to in writing, software
107
+ distributed under the License is distributed on an "AS IS" BASIS,
108
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
109
+ See the License for the specific language governing permissions and
110
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,359 @@
1
+ # Singapore Law MCP Server
2
+
3
+ **The SSO alternative for the AI age.**
4
+
5
+ [![npm version](https://badge.fury.io/js/%40ansvar/singapore-law-mcp.svg)](https://www.npmjs.com/package/@ansvar/singapore-law-mcp)
6
+ [![MCP Registry](https://img.shields.io/badge/MCP-Registry-blue)](https://registry.modelcontextprotocol.io)
7
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
8
+ [![GitHub stars](https://img.shields.io/github/stars/Ansvar-Systems/Singapore-law-mcp?style=social)](https://github.com/Ansvar-Systems/Singapore-law-mcp)
9
+ [![CI](https://github.com/Ansvar-Systems/Singapore-law-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/Ansvar-Systems/Singapore-law-mcp/actions/workflows/ci.yml)
10
+
11
+ Query **Singapore legislation** -- covering data protection, cybersecurity, corporate law, and more -- directly from Claude, Cursor, or any MCP-compatible client.
12
+
13
+ If you're building legal tech, compliance tools, or doing Singapore legal research, this is your verified reference database.
14
+
15
+ Built by [Ansvar Systems](https://ansvar.eu) -- Stockholm, Sweden
16
+
17
+ ---
18
+
19
+ ## Why This Exists
20
+
21
+ Singapore legal research is scattered across official government databases, commercial legal platforms, and institutional archives. Whether you're:
22
+ - A **lawyer** validating citations in a brief or contract
23
+ - A **compliance officer** checking if a statute is still in force
24
+ - A **legal tech developer** building tools on Singapore law
25
+ - A **researcher** tracing legislative history
26
+
27
+ ...you shouldn't need dozens of browser tabs and manual PDF cross-referencing. Ask Claude. Get the exact provision. With context.
28
+
29
+ This MCP server makes Singapore law **searchable, cross-referenceable, and AI-readable**.
30
+
31
+ ---
32
+
33
+ ## Quick Start
34
+
35
+ ### Use Remotely (No Install Needed)
36
+
37
+ > Connect directly to the hosted version -- zero dependencies, nothing to install.
38
+
39
+ **Endpoint:** `https://singapore-law-mcp.vercel.app/mcp`
40
+
41
+ | Client | How to Connect |
42
+ |--------|---------------|
43
+ | **Claude.ai** | Settings > Connectors > Add Integration > paste URL |
44
+ | **Claude Code** | `claude mcp add singapore-law --transport http https://singapore-law-mcp.vercel.app/mcp` |
45
+ | **Claude Desktop** | Add to config (see below) |
46
+ | **GitHub Copilot** | Add to VS Code settings (see below) |
47
+
48
+ **Claude Desktop** -- add to `claude_desktop_config.json`:
49
+
50
+ ```json
51
+ {
52
+ "mcpServers": {
53
+ "singapore-law": {
54
+ "type": "url",
55
+ "url": "https://singapore-law-mcp.vercel.app/mcp"
56
+ }
57
+ }
58
+ }
59
+ ```
60
+
61
+ **GitHub Copilot** -- add to VS Code `settings.json`:
62
+
63
+ ```json
64
+ {
65
+ "github.copilot.chat.mcp.servers": {
66
+ "singapore-law": {
67
+ "type": "http",
68
+ "url": "https://singapore-law-mcp.vercel.app/mcp"
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ ### Use Locally (npm)
75
+
76
+ ```bash
77
+ npx @ansvar/singapore-law-mcp
78
+ ```
79
+
80
+ **Claude Desktop** -- add to `claude_desktop_config.json`:
81
+
82
+ **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
83
+ **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
84
+
85
+ ```json
86
+ {
87
+ "mcpServers": {
88
+ "singapore-law": {
89
+ "command": "npx",
90
+ "args": ["-y", "@ansvar/singapore-law-mcp"]
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
96
+ **Cursor / VS Code:**
97
+
98
+ ```json
99
+ {
100
+ "mcp.servers": {
101
+ "singapore-law": {
102
+ "command": "npx",
103
+ "args": ["-y", "@ansvar/singapore-law-mcp"]
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ ---
110
+
111
+ ## Example Queries
112
+
113
+ Once connected, just ask naturally:
114
+
115
+ - *"What does the Singapore data protection law say about consent?"*
116
+ - *"Search for cybersecurity requirements in Singapore legislation"*
117
+ - *"Is this statute still in force?"*
118
+ - *"Find provisions about personal data in Singapore law"*
119
+ - *"What EU directives does this Singapore law implement?"*
120
+ - *"Which Singapore laws implement the GDPR?"*
121
+ - *"Validate this legal citation"*
122
+ - *"Build a legal stance on data breach notification requirements"*
123
+
124
+ ---
125
+
126
+ ## Key Legislation Covered
127
+
128
+ | Act | Year | Significance |
129
+ |-----|------|-------------|
130
+ | **Personal Data Protection Act (PDPA)** | 2012 (amended 2020) | Comprehensive data protection law; mandatory data breach notification since 1 February 2021; significant fines up to S$1 million per breach |
131
+ | **Cybersecurity Act** | 2018 | Framework for protection of Critical Information Infrastructure (CII); establishes the Cyber Security Agency (CSA) |
132
+ | **Computer Misuse Act** | 1993 (amended) | Criminalises unauthorised access to computer material, computer service, and cyberattacks |
133
+ | **Electronic Transactions Act** | 2010 | Legal recognition of electronic records and electronic signatures |
134
+ | **Companies Act** | 1967 (revised) | Corporate governance, registration, directors' duties |
135
+ | **Spam Control Act** | 2007 | Regulation of unsolicited commercial electronic messages |
136
+ | **Constitution of the Republic of Singapore** | 1963 | Supreme law; Article 9 protects liberty of the person |
137
+
138
+ ---
139
+
140
+ ## Deployment Tier
141
+
142
+ **SMALL** -- Single tier, bundled SQLite database shipped with the npm package.
143
+
144
+ **Estimated database size:** ~80-150 MB (full corpus of Singapore federal legislation)
145
+
146
+ ---
147
+
148
+ ## Available Tools (13)
149
+
150
+ ### Core Legal Research Tools (8)
151
+
152
+ | Tool | Description |
153
+ |------|-------------|
154
+ | `search_legislation` | FTS5 full-text search across all provisions with BM25 ranking |
155
+ | `get_provision` | Retrieve specific provision by statute + chapter/section |
156
+ | `check_currency` | Check if statute is in force, amended, or repealed |
157
+ | `validate_citation` | Validate citation against database (zero-hallucination check) |
158
+ | `build_legal_stance` | Aggregate citations from statutes for a legal topic |
159
+ | `format_citation` | Format citations per Singapore conventions (full/short/pinpoint) |
160
+ | `list_sources` | List all available statutes with metadata |
161
+ | `about` | Server info, capabilities, and coverage summary |
162
+
163
+ ### EU/International Law Integration Tools (5)
164
+
165
+ | Tool | Description |
166
+ |------|-------------|
167
+ | `get_eu_basis` | Get EU directives/regulations for Singapore statute |
168
+ | `get_singapore_implementations` | Find Singapore laws implementing EU act |
169
+ | `search_eu_implementations` | Search EU documents with Singapore implementation counts |
170
+ | `get_provision_eu_basis` | Get EU law references for specific provision |
171
+ | `validate_eu_compliance` | Check implementation status of EU directives |
172
+
173
+ ---
174
+
175
+ ## Why This Works
176
+
177
+ **Verbatim Source Text (No LLM Processing):**
178
+ - All statute text is ingested from official Singapore government sources
179
+ - Provisions are returned **unchanged** from SQLite FTS5 database rows
180
+ - Zero LLM summarization or paraphrasing -- the database contains regulation text, not AI interpretations
181
+
182
+ **Smart Context Management:**
183
+ - Search returns ranked provisions with BM25 scoring (safe for context)
184
+ - Provision retrieval gives exact text by statute identifier + chapter/section
185
+ - Cross-references help navigate without loading everything at once
186
+
187
+ **Technical Architecture:**
188
+ ```
189
+ Official Sources --> Parse --> SQLite --> FTS5 snippet() --> MCP response
190
+ ^ ^
191
+ Provision parser Verbatim database query
192
+ ```
193
+
194
+ ### Traditional Research vs. This MCP
195
+
196
+ | Traditional Approach | This MCP Server |
197
+ |---------------------|-----------------|
198
+ | Search official databases by statute number | Search by plain language |
199
+ | Navigate multi-chapter statutes manually | Get the exact provision with context |
200
+ | Manual cross-referencing between laws | `build_legal_stance` aggregates across sources |
201
+ | "Is this statute still in force?" --> check manually | `check_currency` tool --> answer in seconds |
202
+ | Find EU basis --> dig through EUR-Lex | `get_eu_basis` --> linked EU directives instantly |
203
+ | No API, no integration | MCP protocol --> AI-native |
204
+
205
+ ---
206
+
207
+ ## Data Sources & Freshness
208
+
209
+ All content is sourced from authoritative Singapore legal databases:
210
+
211
+ - **[Singapore Statutes Online](https://sso.agc.gov.sg)** -- Official Singapore government legal database
212
+
213
+ **Verified data only** -- every citation is validated against official sources. Zero LLM-generated content.
214
+
215
+ ---
216
+
217
+ ## Security
218
+
219
+ This project uses multiple layers of automated security scanning:
220
+
221
+ | Scanner | What It Does | Schedule |
222
+ |---------|-------------|----------|
223
+ | **CodeQL** | Static analysis for security vulnerabilities | Weekly + PRs |
224
+ | **Semgrep** | SAST scanning (OWASP top 10, secrets, TypeScript) | Every push |
225
+ | **Gitleaks** | Secret detection across git history | Every push |
226
+ | **Trivy** | CVE scanning on filesystem and npm dependencies | Daily |
227
+ | **Socket.dev** | Supply chain attack detection | PRs |
228
+ | **Dependabot** | Automated dependency updates | Weekly |
229
+
230
+ See [SECURITY.md](SECURITY.md) for the full policy and vulnerability reporting.
231
+
232
+ ---
233
+
234
+ ## Important Disclaimers
235
+
236
+ ### Legal Advice
237
+
238
+ > **THIS TOOL IS NOT LEGAL ADVICE**
239
+ >
240
+ > Statute text is sourced from official Singapore government publications. However:
241
+ > - This is a **research tool**, not a substitute for professional legal counsel
242
+ > - **Court case coverage is limited** -- do not rely solely on this for case law research
243
+ > - **Verify critical citations** against primary sources for court filings
244
+ > - **EU cross-references** are extracted from statute text, not EUR-Lex full text
245
+
246
+ **Before using professionally, read:** [DISCLAIMER.md](DISCLAIMER.md) | [SECURITY.md](SECURITY.md)
247
+
248
+ ### Client Confidentiality
249
+
250
+ Queries go through the Claude API. For privileged or confidential matters, use on-premise deployment.
251
+
252
+ ---
253
+
254
+ ## Development
255
+
256
+ ### Setup
257
+
258
+ ```bash
259
+ git clone https://github.com/Ansvar-Systems/Singapore-law-mcp
260
+ cd Singapore-law-mcp
261
+ npm install
262
+ npm run build
263
+ npm test
264
+ ```
265
+
266
+ ### Running Locally
267
+
268
+ ```bash
269
+ npm run dev # Start MCP server
270
+ npx @anthropic/mcp-inspector node dist/index.js # Test with MCP Inspector
271
+ ```
272
+
273
+ ---
274
+
275
+ ## Related Projects: Complete Compliance Suite
276
+
277
+ This server is part of **Ansvar's Compliance Suite** -- MCP servers that work together for end-to-end compliance coverage:
278
+
279
+ ### [@ansvar/eu-regulations-mcp](https://github.com/Ansvar-Systems/EU_compliance_MCP)
280
+ **Query 49 EU regulations directly from Claude** -- GDPR, AI Act, DORA, NIS2, MiFID II, eIDAS, and more. Full regulatory text with article-level search. `npx @ansvar/eu-regulations-mcp`
281
+
282
+ ### [@ansvar/us-regulations-mcp](https://github.com/Ansvar-Systems/US_Compliance_MCP)
283
+ **Query US federal and state compliance laws** -- HIPAA, CCPA, SOX, GLBA, FERPA, and more. `npx @ansvar/us-regulations-mcp`
284
+
285
+ ### [@ansvar/security-controls-mcp](https://github.com/Ansvar-Systems/security-controls-mcp)
286
+ **Query 261 security frameworks** -- ISO 27001, NIST CSF, SOC 2, CIS Controls, SCF, and more. `npx @ansvar/security-controls-mcp`
287
+
288
+ ### [@ansvar/automotive-cybersecurity-mcp](https://github.com/Ansvar-Systems/Automotive-MCP)
289
+ **Query UNECE R155/R156 and ISO 21434** -- Automotive cybersecurity compliance. `npx @ansvar/automotive-cybersecurity-mcp`
290
+
291
+ **30+ national law MCPs** covering Australia, Brazil, Canada, China, Denmark, Finland, France, Germany, Ghana, Iceland, India, Ireland, Israel, Italy, Japan, Kenya, Netherlands, Nigeria, Norway, Singapore, Slovenia, South Korea, Sweden, Switzerland, Thailand, UAE, UK, and more.
292
+
293
+ ---
294
+
295
+ ## Contributing
296
+
297
+ Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
298
+
299
+ Priority areas:
300
+ - Court case law expansion
301
+ - EU cross-reference improvements
302
+ - Historical statute versions and amendment tracking
303
+ - Additional statutory instruments and regulations
304
+
305
+ ---
306
+
307
+ ## Roadmap
308
+
309
+ - [x] Core statute database with FTS5 search
310
+ - [x] EU/international law cross-references
311
+ - [x] Vercel Streamable HTTP deployment
312
+ - [x] npm package publication
313
+ - [ ] Court case law expansion
314
+ - [ ] Historical statute versions (amendment tracking)
315
+ - [ ] Preparatory works / explanatory memoranda
316
+ - [ ] Lower court and tribunal decisions
317
+
318
+ ---
319
+
320
+ ## Citation
321
+
322
+ If you use this MCP server in academic research:
323
+
324
+ ```bibtex
325
+ @software{singapore_law_mcp_2025,
326
+ author = {Ansvar Systems AB},
327
+ title = {Singapore Law MCP Server: AI-Powered Legal Research Tool},
328
+ year = {2025},
329
+ url = {https://github.com/Ansvar-Systems/Singapore-law-mcp},
330
+ note = {Singapore legal database with full-text search and EU cross-references}
331
+ }
332
+ ```
333
+
334
+ ---
335
+
336
+ ## License
337
+
338
+ Apache License 2.0. See [LICENSE](./LICENSE) for details.
339
+
340
+ ### Data Licenses
341
+
342
+ - **Statutes & Legislation:** Singapore Government (Singapore Open Data Licence)
343
+ - **EU Metadata:** EUR-Lex (EU public domain)
344
+
345
+ ---
346
+
347
+ ## About Ansvar Systems
348
+
349
+ We build AI-accelerated compliance and legal research tools for the global market. This MCP server started as our internal reference tool -- turns out everyone building compliance tools has the same research frustrations.
350
+
351
+ So we're open-sourcing it.
352
+
353
+ **[ansvar.eu](https://ansvar.eu)** -- Stockholm, Sweden
354
+
355
+ ---
356
+
357
+ <p align="center">
358
+ <sub>Built with care in Stockholm, Sweden</sub>
359
+ </p>
Binary file
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=golden.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"golden.test.d.ts","sourceRoot":"","sources":["../../../__tests__/contract/golden.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,215 @@
1
+ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
2
+ import { createHash } from 'node:crypto';
3
+ import { readFileSync, rmdirSync, rmSync } from 'node:fs';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { dirname, join } from 'node:path';
6
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
7
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
8
+ import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
9
+ import Database from '@ansvar/mcp-sqlite';
10
+ import { registerTools } from '../../src/tools/registry.js';
11
+ const __dirname = dirname(fileURLToPath(import.meta.url));
12
+ function normalizeText(text) {
13
+ return text.replace(/\s+/g, ' ').replace(/[\r\n]+/g, ' ').trim().toLowerCase();
14
+ }
15
+ function sha256(text) {
16
+ return createHash('sha256').update(normalizeText(text)).digest('hex');
17
+ }
18
+ function extractCitationUrls(data) {
19
+ const urls = [];
20
+ const text = JSON.stringify(data);
21
+ const urlRegex = /https?:\/\/[^\s"'<>]+/g;
22
+ let match;
23
+ while ((match = urlRegex.exec(text)) !== null) {
24
+ urls.push(match[0]);
25
+ }
26
+ return urls;
27
+ }
28
+ async function fetchWithTimeout(url, timeoutMs = 10_000) {
29
+ const controller = new AbortController();
30
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
31
+ try {
32
+ return await fetch(url, { signal: controller.signal });
33
+ }
34
+ finally {
35
+ clearTimeout(timer);
36
+ }
37
+ }
38
+ function stringifyData(data) {
39
+ if (typeof data === 'string')
40
+ return data;
41
+ return JSON.stringify(data, null, 0) ?? '';
42
+ }
43
+ async function callTool(mcpClient, name, args) {
44
+ try {
45
+ const result = await mcpClient.callTool({ name, arguments: args });
46
+ const content = result.content;
47
+ const text = content?.[0]?.text ?? '';
48
+ if (result.isError) {
49
+ return { tool: name, ok: false, error: { code: 'TOOL_ERROR', message: text } };
50
+ }
51
+ try {
52
+ const data = JSON.parse(text);
53
+ return { tool: name, ok: true, data };
54
+ }
55
+ catch {
56
+ return { tool: name, ok: true, data: text };
57
+ }
58
+ }
59
+ catch (err) {
60
+ return {
61
+ tool: name,
62
+ ok: false,
63
+ error: { code: 'CALL_ERROR', message: err.message },
64
+ };
65
+ }
66
+ }
67
+ // ---------------------------------------------------------------------------
68
+ // Load fixtures & set up MCP client/server
69
+ // ---------------------------------------------------------------------------
70
+ const fixturesPath = join(__dirname, '..', '..', 'fixtures', 'golden-tests.json');
71
+ const fixtureContent = readFileSync(fixturesPath, 'utf-8');
72
+ const fixture = JSON.parse(fixtureContent);
73
+ const isNightly = process.env['CONTRACT_MODE'] === 'nightly';
74
+ let mcpClient;
75
+ let db;
76
+ // ---------------------------------------------------------------------------
77
+ // Contract test runner
78
+ // ---------------------------------------------------------------------------
79
+ describe(`Contract tests: ${fixture.mcp_name}`, () => {
80
+ beforeAll(async () => {
81
+ const dbPath = process.env['SG_LAW_DB_PATH'] ?? join(__dirname, '..', '..', 'data', 'database.db');
82
+ // Clean up stale lock dir and WAL files
83
+ try {
84
+ rmdirSync(dbPath + '.lock');
85
+ }
86
+ catch { /* ignore */ }
87
+ try {
88
+ rmSync(dbPath + '-wal', { force: true });
89
+ }
90
+ catch { /* ignore */ }
91
+ try {
92
+ rmSync(dbPath + '-shm', { force: true });
93
+ }
94
+ catch { /* ignore */ }
95
+ db = new Database(dbPath, { readonly: true });
96
+ db.pragma('foreign_keys = ON');
97
+ const server = new Server({ name: 'singapore-law-test', version: '0.0.0' }, { capabilities: { tools: {} } });
98
+ registerTools(server, db);
99
+ mcpClient = new Client({ name: 'test-client', version: '0.0.0' }, { capabilities: {} });
100
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
101
+ await server.connect(serverTransport);
102
+ await mcpClient.connect(clientTransport);
103
+ }, 30_000);
104
+ afterAll(() => {
105
+ db?.close();
106
+ });
107
+ for (const test of fixture.tests) {
108
+ describe(`[${test.id}] ${test.description}`, () => {
109
+ let result;
110
+ it('runs without throwing', async () => {
111
+ result = await callTool(mcpClient, test.tool, test.input);
112
+ expect(result).toBeDefined();
113
+ expect(result.tool).toBe(test.tool);
114
+ });
115
+ if (test.assertions.result_not_empty) {
116
+ it('result is not empty', async () => {
117
+ result ??= await callTool(mcpClient, test.tool, test.input);
118
+ if (result.ok) {
119
+ expect(result.data).toBeDefined();
120
+ }
121
+ else {
122
+ expect(result.error).toBeDefined();
123
+ }
124
+ });
125
+ }
126
+ if (test.assertions.text_contains) {
127
+ for (const needle of test.assertions.text_contains) {
128
+ it(`result contains text "${needle}"`, async () => {
129
+ result ??= await callTool(mcpClient, test.tool, test.input);
130
+ const haystack = stringifyData(result.data).toLowerCase();
131
+ expect(haystack).toContain(needle.toLowerCase());
132
+ });
133
+ }
134
+ }
135
+ if (test.assertions.any_result_contains) {
136
+ for (const needle of test.assertions.any_result_contains) {
137
+ it(`any result item contains "${needle}"`, async () => {
138
+ result ??= await callTool(mcpClient, test.tool, test.input);
139
+ const haystack = stringifyData(result.data).toLowerCase();
140
+ expect(haystack).toContain(needle.toLowerCase());
141
+ });
142
+ }
143
+ }
144
+ if (test.assertions.fields_present) {
145
+ it(`result has fields: ${test.assertions.fields_present.join(', ')}`, async () => {
146
+ result ??= await callTool(mcpClient, test.tool, test.input);
147
+ expect(result.ok).toBe(true);
148
+ const data = result.data;
149
+ expect(data).toBeDefined();
150
+ for (const field of test.assertions.fields_present) {
151
+ expect(data).toHaveProperty(field);
152
+ }
153
+ });
154
+ }
155
+ if (test.assertions.text_not_empty) {
156
+ it('result text is not empty', async () => {
157
+ result ??= await callTool(mcpClient, test.tool, test.input);
158
+ const text = stringifyData(result.data);
159
+ expect(text.trim().length).toBeGreaterThan(0);
160
+ });
161
+ }
162
+ if (test.assertions.min_results !== undefined) {
163
+ it(`returns at least ${test.assertions.min_results} results`, async () => {
164
+ result ??= await callTool(mcpClient, test.tool, test.input);
165
+ const data = result.data;
166
+ const items = Array.isArray(data)
167
+ ? data
168
+ : Array.isArray(data?.results)
169
+ ? data.results
170
+ : [];
171
+ expect(items.length).toBeGreaterThanOrEqual(test.assertions.min_results);
172
+ });
173
+ }
174
+ if (test.assertions.citation_url_pattern) {
175
+ it(`citation URLs match pattern: ${test.assertions.citation_url_pattern}`, async () => {
176
+ result ??= await callTool(mcpClient, test.tool, test.input);
177
+ const urls = extractCitationUrls(result.data);
178
+ const pattern = new RegExp(test.assertions.citation_url_pattern);
179
+ expect(urls.length).toBeGreaterThan(0);
180
+ for (const url of urls) {
181
+ expect(url).toMatch(pattern);
182
+ }
183
+ });
184
+ }
185
+ if (test.assertions.upstream_text_hash) {
186
+ const hashAssertion = test.assertions.upstream_text_hash;
187
+ it.skipIf(!isNightly)(`upstream text hash matches for ${hashAssertion.url}`, async () => {
188
+ const response = await fetchWithTimeout(hashAssertion.url);
189
+ expect(response.ok).toBe(true);
190
+ const body = await response.text();
191
+ const hash = sha256(body);
192
+ expect(hash).toBe(hashAssertion.expected_sha256);
193
+ }, 30_000);
194
+ }
195
+ if (test.assertions.citation_resolves) {
196
+ it.skipIf(!isNightly)('citation URLs resolve (HTTP 200)', async () => {
197
+ result ??= await callTool(mcpClient, test.tool, test.input);
198
+ const urls = extractCitationUrls(result.data);
199
+ expect(urls.length).toBeGreaterThan(0);
200
+ for (const url of urls) {
201
+ const response = await fetchWithTimeout(url);
202
+ expect(response.ok, `Expected HTTP 200 for ${url}, got ${response.status}`).toBe(true);
203
+ }
204
+ }, 60_000);
205
+ }
206
+ if (test.assertions.handles_gracefully) {
207
+ it('handles gracefully (no unhandled exception)', async () => {
208
+ result ??= await callTool(mcpClient, test.tool, test.input);
209
+ expect(result.tool).toBe(test.tool);
210
+ });
211
+ }
212
+ });
213
+ }
214
+ });
215
+ //# sourceMappingURL=golden.test.js.map