mcp-server-taxcode 0.1.1__py3-none-any.whl

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.
@@ -0,0 +1,307 @@
1
+ Metadata-Version: 2.5
2
+ Name: mcp-server-taxcode
3
+ Version: 0.1.1
4
+ Summary: Enterprise Model Context Protocol (MCP) server for Tax Code
5
+ Project-URL: Homepage, https://github.com/christianclaudio/mcp-server-taxcode
6
+ Project-URL: Documentation, https://github.com/christianclaudio/mcp-server-taxcode#readme
7
+ Project-URL: Repository, https://github.com/christianclaudio/mcp-server-taxcode.git
8
+ Project-URL: Issues, https://github.com/christianclaudio/mcp-server-taxcode/issues
9
+ Project-URL: Changelog, https://github.com/christianclaudio/mcp-server-taxcode/releases
10
+ Author-email: Christian Claudio <christianclaudio@mail.com>
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: agents,ai,fastmcp,mcp,model-context-protocol
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.10
25
+ Requires-Dist: duckdb>=1.5.6
26
+ Requires-Dist: fastmcp>=4.1.0
27
+ Requires-Dist: httpx>=0.28.1
28
+ Requires-Dist: mcp>=2.3.0
29
+ Requires-Dist: pydantic-settings>=2.15.0
30
+ Requires-Dist: pydantic>=2.13.5
31
+ Provides-Extra: code-mode
32
+ Requires-Dist: fastmcp[code-mode]>=4.1.0; extra == 'code-mode'
33
+ Provides-Extra: dev
34
+ Requires-Dist: fastmcp[code-mode]>=4.1.0; extra == 'dev'
35
+ Requires-Dist: mypy>=2.4.0; extra == 'dev'
36
+ Requires-Dist: opentelemetry-sdk>=1.45.1; extra == 'dev'
37
+ Requires-Dist: pytest-asyncio>=1.4.0; extra == 'dev'
38
+ Requires-Dist: pytest-cov>=7.1.0; extra == 'dev'
39
+ Requires-Dist: pytest>=9.1.1; extra == 'dev'
40
+ Requires-Dist: ruff>=0.16.10; extra == 'dev'
41
+ Requires-Dist: twine>=7.0.0; extra == 'dev'
42
+ Description-Content-Type: text/markdown
43
+
44
+ <!-- mcp-name: io.github.christianclaudio/taxcode -->
45
+
46
+ # 📦 mcp-server-taxcode
47
+
48
+ [![CI](https://github.com/christianclaudio/mcp-server-taxcode/actions/workflows/ci.yml/badge.svg)](https://github.com/christianclaudio/mcp-server-taxcode/actions/workflows/ci.yml)
49
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
50
+ [![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)](https://github.com/christianclaudio/mcp-server-taxcode)
51
+ [![CodeRabbit Reviews](https://img.shields.io/coderabbit/prs/github/christianclaudio/mcp-server-taxcode?labelColor=171717&color=FF570A&label=CodeRabbit+Reviews)](https://coderabbit.ai)
52
+
53
+ > **Enterprise-grade Model Context Protocol (MCP) server for Federal, Territorial, and Multi-State Tax Law.**
54
+ > Authoritative statutory and administrative intelligence covering United States Federal (IRC/CFR), Puerto Rico (Act 60/Ley 1), and state tax corridors (GA, CA, NY, FL, TX, WA, MA, NJ, IL) with deterministic residency and capital gains compliance engines.
55
+
56
+ ---
57
+
58
+ ## 🏗️ Architecture: FastMCP 4 Server Composition
59
+
60
+ ```mermaid
61
+ graph TD
62
+ Client["AI Agent / MCP Host<br>(Claude, Cursor, Antigravity, Snowflake Cortex)"]
63
+ Gateway["FastMCP Root Gateway<br>(stdio / streamable-http)"]
64
+ ParentMW["Parent Middleware<br>(Audit Logging, Timing, Secret Redaction, ReadOnly Gate)"]
65
+ SysSub["System Sub-server (mount: 'system')<br>• system_get_health_status<br>• taxcode://system/reference/capabilities"]
66
+ StatSub["Statutes Sub-server (mount: 'statutes')<br>• statutes_lookup_statute<br>• statutes_search_tax_code<br>• statutes_list_publications"]
67
+ CompSub["Compliance Sub-server (mount: 'compliance')<br>• compliance_evaluate_pr_bona_fide_residency<br>• compliance_calculate_built_in_gain_sourcing<br>• compliance_evaluate_georgia_residency<br>• compliance_evaluate_state_residency"]
68
+ DuckDB["DuckDB In-Memory & File Engine<br>(51 Statutes, 7 Publications, Full-Text Search, Temporal Versions)"]
69
+
70
+ Client <-->|"JSON-RPC (tools/list, tools/call)"| Gateway
71
+ Gateway --> ParentMW
72
+ ParentMW --> SysSub
73
+ ParentMW --> StatSub
74
+ ParentMW --> CompSub
75
+ StatSub <-->|"Point-in-Time & Full-Text Queries"| DuckDB
76
+ CompSub <-->|"Deterministic Statutory Calculations"| DuckDB
77
+ ```
78
+
79
+ ---
80
+
81
+ ## 🚀 Key Features
82
+
83
+ * **Authoritative Multi-Jurisdiction Statutory Catalog**:
84
+ * **Federal (`US`)**: IRC § 933, § 937, § 865, 26 CFR § 1.937-1/2.
85
+ * **Puerto Rico (`PR`)**: Act 60-2019 (Resident Individual Investors & Export Services), Ley 1-2011, Act 22-2012 predecessor versions.
86
+ * **Key State Corridors**: Georgia (O.C.G.A. Title 48), California (RTC § 17014, § 17041, 18 CCR § 17014), New York (Tax Law § 605, § 601, Convenience Rule § 132.18, 5 Primary Domicile Factors § 105.20), Florida (Const. Art. VII § 5, § 222.17 Domicile, § 196.031 Homestead), Texas (Const. art. VIII § 24-a, Franchise Tax § 171.001), Washington (RCW 82.87 Capital Gains Excise Tax), Massachusetts (M.G.L. c. 62 § 4 & Fair Share Surtax), New Jersey (N.J.S.A. 54A & Reciprocal Convenience Rule), Illinois (35 ILCS 5 Flat Tax).
87
+ * **Temporal Statutory Versioning**: Point-in-time statutory lookup with `superseded_year` filtering and descending historical ordering (`tax_year` parameter).
88
+ * **Deterministic Compliance Engines**:
89
+ * `evaluate_pr_bona_fide_residency`: Evaluates IRC § 937 presence (183-day, 549-day 3-year, 90-day US), tax home, and closer connection tests.
90
+ * `calculate_built_in_gain_sourcing`: Allocates Section 937 / Act 60 capital gains across pre-move and post-move holding periods.
91
+ * `evaluate_state_residency`: Multi-state statutory presence day-counter, permanent place of abode (PPA), domicile audit risk flags, and tax liability computation across 9 states.
92
+ * **Profiles & Opt-in ToolSearch**:
93
+ * Domain-mount profiles: `full`, `system`, `statutes`, `compliance`, `readonly`.
94
+ * Job-shaped allowlist profiles: `researcher` (statutes + circulars), `advisor` (cross-border residency + BIG calculations).
95
+ * **Zero Tool Bloat**: Exactly 8 lean, read-only MCP tools exposed with explicit MCP 2.0 annotations (`readOnlyHint=True`).
96
+
97
+ ---
98
+
99
+ ## ⚙️ Configuration
100
+
101
+ | Variable | CLI Flag | Default | Description |
102
+ | :--- | :--- | :--- | :--- |
103
+ | `TAXCODE_API_KEY` | — | `""` | Service API token for authentication |
104
+ | `TAXCODE_BASE_URL` | — | `https://api.example.com` | Upstream REST API base URL |
105
+ | `TAXCODE_MCP_READONLY` | — | `0` | Restrict server execution strictly to safe read-only inspection tools |
106
+ | `TAXCODE_MCP_PROFILE` | `--profile` | `full` | Server profile: `full`, `system`, `statutes`, `compliance`, `readonly`, `researcher`, `advisor` |
107
+ | `TAXCODE_MCP_ENABLE_TOOL_SEARCH` | `--enable-tool-search` | `0` | Replace flat catalog with dynamic search meta-tools (`profile=full` only) |
108
+ | `TAXCODE_MCP_ENABLE_CODE_MODE` | `--enable-code-mode` | `0` | Experimental Code Mode on `full` (requires `code-mode` extra) |
109
+ | `TAXCODE_MCP_AUTH_TOKEN` | — | `""` | Shared bearer token for HTTP transports (`streamable-http`, `sse`) |
110
+ | `TAXCODE_MCP_ALLOW_UNAUTHENTICATED_BIND` | — | `0` | Set to `1` (or `true`/`yes`/`on`) to let an HTTP transport bind a host other than `127.0.0.1`, `::1` or `localhost` with no token. Without it, such a bind exits at startup |
111
+
112
+ ### HTTP transports and authentication
113
+
114
+ Stdio is the default and needs no token. The HTTP transports follow the MCP guidance that a local server binds only to localhost and authenticates every connection:
115
+
116
+ * On `127.0.0.1`, `::1` or `localhost` (the `--host` default is `127.0.0.1`), HTTP runs with or without `TAXCODE_MCP_AUTH_TOKEN`; without it, a warning says requests are not authenticated.
117
+ * On any other host (`0.0.0.0`, `::`, a LAN address), the server refuses to start unless `TAXCODE_MCP_AUTH_TOKEN` is set, or `TAXCODE_MCP_ALLOW_UNAUTHENTICATED_BIND=1` accepts an unauthenticated bind (logged as a warning), for example behind a gateway that authenticates for you.
118
+ * With a token set, every HTTP request needs `Authorization: Bearer <token>`; a missing or wrong token gets HTTP 401.
119
+ * In the default (stateful) HTTP mode, a session idle for 30 minutes expires: its next request gets HTTP 404 and the client must start a new session. Change this with FastMCP's `session_idle_timeout` (on `http_app()`) or `FASTMCP_HTTP_SESSION_IDLE_TIMEOUT` (seconds, or `none` to never expire); see the [FastMCP 4.1.0 release](https://github.com/PrefectHQ/fastmcp/releases/tag/v4.1.0) and [#5229](https://github.com/PrefectHQ/fastmcp/pull/5229).
120
+
121
+ ```bash
122
+ # Local HTTP, loopback only
123
+ taxcode-mcp --transport streamable-http
124
+
125
+ # Public HTTP with a token
126
+ TAXCODE_MCP_AUTH_TOKEN="$(openssl rand -hex 32)" \
127
+ taxcode-mcp --transport streamable-http --host 0.0.0.0 --allowed-host mcp.example.com
128
+ ```
129
+
130
+ ### Docker
131
+
132
+ The image's default command is stdio, so it works as a stdio server out of the box:
133
+
134
+ ```bash
135
+ docker run -i --rm -e TAXCODE_API_KEY=your-api-key ghcr.io/christianclaudio/<name>
136
+ ```
137
+
138
+ To serve Streamable HTTP from the container, bind `0.0.0.0` inside it and pass a token:
139
+
140
+ ```bash
141
+ docker run --rm -p 8000:8000 \
142
+ -e TAXCODE_API_KEY=your-api-key \
143
+ -e TAXCODE_MCP_AUTH_TOKEN=your-long-random-token \
144
+ ghcr.io/christianclaudio/<name> \
145
+ --transport streamable-http --host 0.0.0.0 --port 8000 --allowed-host mcp.example.com
146
+ ```
147
+
148
+
149
+ ---
150
+
151
+ ## 🔌 Integration Guides for AI Assistants & IDEs
152
+
153
+ This server works out-of-the-box with all major AI assistants, IDEs, and CLI tools via standard `stdio` or `streamable-http`.
154
+
155
+ The template is not published to PyPI, so these configs run its `taxcode-mcp` console script from a local clone with `uv run --directory`. Replace `/absolute/path/to/mcp-server-taxcode` with the path of your clone. After `uv tool install .` (or `pip install .`) puts both console scripts, `taxcode-mcp` and `mcp-server-taxcode` (the same server), on your `PATH`, `"command": "taxcode-mcp"` with no `args` works too.
156
+
157
+ <details open>
158
+ <summary><b>🧡 Claude Desktop & Claude Code</b></summary>
159
+
160
+ Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
161
+
162
+ ```json
163
+ {
164
+ "mcpServers": {
165
+ "taxcode": {
166
+ "command": "uv",
167
+ "args": ["run", "--directory", "/absolute/path/to/mcp-server-taxcode", "taxcode-mcp"],
168
+ "env": {
169
+ "TAXCODE_API_KEY": "your-api-key"
170
+ }
171
+ }
172
+ }
173
+ }
174
+ ```
175
+
176
+ For **Claude Code CLI**:
177
+ ```bash
178
+ claude mcp add taxcode -- uv run --directory /absolute/path/to/mcp-server-taxcode taxcode-mcp
179
+ ```
180
+ </details>
181
+
182
+ <details>
183
+ <summary><b>♊ Google Antigravity & Gemini CLI</b></summary>
184
+
185
+ Add to `.agents/mcp_config.json` (or global `~/.gemini/config/mcp_config.json`):
186
+
187
+ ```json
188
+ {
189
+ "mcpServers": {
190
+ "taxcode": {
191
+ "command": "uv",
192
+ "args": ["run", "--directory", "/absolute/path/to/mcp-server-taxcode", "taxcode-mcp"],
193
+ "env": {
194
+ "TAXCODE_API_KEY": "your-api-key"
195
+ }
196
+ }
197
+ }
198
+ }
199
+ ```
200
+ </details>
201
+
202
+ <details>
203
+ <summary><b>❄️ Snowflake Cortex Agent</b></summary>
204
+
205
+ Add to `~/.snowflake/cortex/mcp.json`:
206
+
207
+ ```json
208
+ {
209
+ "mcpServers": {
210
+ "taxcode": {
211
+ "command": "uv",
212
+ "args": ["run", "--directory", "/absolute/path/to/mcp-server-taxcode", "taxcode-mcp"]
213
+ }
214
+ }
215
+ }
216
+ ```
217
+ </details>
218
+
219
+ <details>
220
+ <summary><b>💻 Cursor & Windsurf</b></summary>
221
+
222
+ Add to `~/.cursor/mcp.json`:
223
+
224
+ ```json
225
+ {
226
+ "mcpServers": {
227
+ "taxcode": {
228
+ "command": "uv",
229
+ "args": ["run", "--directory", "/absolute/path/to/mcp-server-taxcode", "taxcode-mcp"]
230
+ }
231
+ }
232
+ }
233
+ ```
234
+ </details>
235
+
236
+ <details>
237
+ <summary><b>⚡ VS Code (Cline, Roo Code, GitHub Copilot Agent Mode)</b></summary>
238
+
239
+ Add to `cline_mcp_settings.json`:
240
+
241
+ ```json
242
+ {
243
+ "mcpServers": {
244
+ "taxcode": {
245
+ "command": "uv",
246
+ "args": ["run", "--directory", "/absolute/path/to/mcp-server-taxcode", "taxcode-mcp"]
247
+ }
248
+ }
249
+ }
250
+ ```
251
+ </details>
252
+
253
+ ---
254
+
255
+ ## 📚 Canonical Documentation & Live Doc MCPs
256
+
257
+ When developing, hardening, or extending MCP servers, consult the official framework and protocol references:
258
+
259
+ * **FastMCP 4 Framework Reference**: [`https://gofastmcp.com/llms.txt`](https://gofastmcp.com/llms.txt) — Server composition (`mount`), hierarchical middleware, transforms (`ToolTransform`, `ToolSearch`), lifespans, and in-memory test clients.
260
+ * **Model Context Protocol Specification**: [`https://modelcontextprotocol.io/llms.txt`](https://modelcontextprotocol.io/llms.txt) — Official Spec (2026-07-28), wire-level JSON-RPC schemas, annotations, and transport framing.
261
+
262
+ ### Live Documentation MCP Endpoints (SSE / Streamable HTTP)
263
+ Connect your AI coding agent directly to live documentation servers:
264
+ * **FastMCP Documentation Server**: `https://gofastmcp.com/mcp` (Tools: `search_fast_mcp`, `query_docs_filesystem_fast_mcp`, `submit_feedback`)
265
+ * **Anthropic MCP Documentation Server**: `https://modelcontextprotocol.io/mcp` (Tools: `search_model_context_protocol`, `query_docs_filesystem_model_context_protocol`, `submit_feedback`)
266
+
267
+ ```json
268
+ {
269
+ "mcpServers": {
270
+ "fastmcp-docs": { "type": "sse", "url": "https://gofastmcp.com/mcp" },
271
+ "mcp-official-docs": { "type": "sse", "url": "https://modelcontextprotocol.io/mcp" }
272
+ }
273
+ }
274
+ ```
275
+
276
+ ---
277
+
278
+ ## 🏃 Local Development & Verification
279
+
280
+ ```bash
281
+ # 1. Install dependencies from the lockfile
282
+ uv sync --locked --extra dev
283
+
284
+ # 2. Run unit tests with 100% coverage requirement
285
+ uv run pytest
286
+
287
+ # 3. Static type checks & linting
288
+ uv run mypy --strict src/
289
+ uv run ruff check .
290
+ uv run ruff format --check .
291
+
292
+ # 4. Tool contract, protocol & drift assertions
293
+ uv run python scripts/check_tool_contract.py
294
+ uv run python scripts/check_openapi_drift.py
295
+ uv run pytest tests/test_protocol.py
296
+ uv run pytest tests/test_e2e_live.py -m e2e # on demand; default CI uses -m 'not e2e'
297
+ ./scripts/check_conformance.sh
298
+
299
+ # 5. AI code review gate (CodeRabbit)
300
+ coderabbit review --agent --uncommitted
301
+ ```
302
+
303
+ ---
304
+
305
+ ## 📄 License
306
+
307
+ Licensed under the **Apache License 2.0**. See [`LICENSE`](LICENSE) for details.
@@ -0,0 +1,19 @@
1
+ taxcode_mcp/__init__.py,sha256=DSuU7pfVjgvQEhy1Y2vfPW4cnmqXHtBks_rZOsGY7mQ,567
2
+ taxcode_mcp/auth.py,sha256=TzlQHeKNQXtS-_mcyzOWc2zcB-BF1g-7j5ObSsr97pM,2787
3
+ taxcode_mcp/client.py,sha256=rOX4pScqfVgBGCvC_GK0b0amJjNbxemnXNXKeBx-4uQ,8885
4
+ taxcode_mcp/config.py,sha256=0XNojC_ozS1YxbG0iUxyROqZEPdrSzV0X5mLv_D2u3o,3176
5
+ taxcode_mcp/db.py,sha256=lbqC2SMAq99KmfxZxQrdnFZ4t1QQjwu_OgIv2xMDhcI,63069
6
+ taxcode_mcp/errors.py,sha256=Lf1MaebWWCyRrgn9hFd-hIYapB-Dd3qeURXpMKFmkWc,18317
7
+ taxcode_mcp/middleware.py,sha256=0SBerSJAzOXGmeTrxmGauwqOIL1bJtT2j3jJhv9Kvm0,7159
8
+ taxcode_mcp/profiles.py,sha256=5vpfDqpPT76oz1C3oMcGjnoQ5w77s4pXjQiizfx3qAw,6722
9
+ taxcode_mcp/server.py,sha256=7wotnSZdd7pgf-EJmAhQAgLcciVdyR4rWbodD-nwo1k,19413
10
+ taxcode_mcp/ssrf.py,sha256=MwiApVj8ACnqc9-c3g6DtZN2idzntSj62a6oPoSuSew,9737
11
+ taxcode_mcp/tools/__init__.py,sha256=bNuQrfBYw6c0wwuny8b8Kxc4qkvu2TfQC-PXbhhiEKo,1018
12
+ taxcode_mcp/tools/compliance.py,sha256=AfvTeUapPWHPPtmWXNBKGjygVbbqTlq-MyYYfOHf6Og,23357
13
+ taxcode_mcp/tools/statutes.py,sha256=IvVS2-_9xhBsedS9LapAQgc0dw9AWpZXSxYEcBdQQQs,4897
14
+ taxcode_mcp/tools/system.py,sha256=iqR-NeVgMHH-FGo2lnnSUbqYXR7YWNJPlwk4HYYxR-Q,2166
15
+ mcp_server_taxcode-0.1.1.dist-info/METADATA,sha256=kAywNytdjUPPKTCigiS9f66VY-u4WlMedKRpCYMHs8s,13977
16
+ mcp_server_taxcode-0.1.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
17
+ mcp_server_taxcode-0.1.1.dist-info/entry_points.txt,sha256=jvvN6W-lP9Cs4ENjcvpbzNK0oQ5Cs2UjvDUxnffPCbw,101
18
+ mcp_server_taxcode-0.1.1.dist-info/licenses/LICENSE,sha256=JELYy1naAhGongmOPVQzEjy8rpL6egBYra8I53liO4Q,10762
19
+ mcp_server_taxcode-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ mcp-server-taxcode = taxcode_mcp.server:main
3
+ taxcode-mcp = taxcode_mcp.server:main
@@ -0,0 +1,190 @@
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
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Christian Claudio
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,14 @@
1
+ """Enterprise Model Context Protocol (MCP) server for Tax Code."""
2
+
3
+ from importlib.metadata import PackageNotFoundError
4
+ from importlib.metadata import version as _dist_version
5
+
6
+ from taxcode_mcp.ssrf import SSRFValidationError, validate_outbound_url
7
+
8
+ # The git tag is the version (uv-dynamic-versioning); never hard-code it here.
9
+ try:
10
+ __version__ = _dist_version("mcp-server-taxcode")
11
+ except PackageNotFoundError: # source tree without an installed distribution
12
+ __version__ = "0.0.0"
13
+
14
+ __all__ = ["SSRFValidationError", "__version__", "validate_outbound_url"]
taxcode_mcp/auth.py ADDED
@@ -0,0 +1,65 @@
1
+ """Bearer token authentication and the bind policy for the HTTP transports.
2
+
3
+ ``TAXCODE_MCP_AUTH_TOKEN`` is enforced through FastMCP's built-in server auth: a
4
+ ``TokenVerifier`` subclass set as the server's ``auth`` provider
5
+ (https://gofastmcp.com/servers/auth/token-verification). FastMCP applies server auth
6
+ only to HTTP transports; stdio is unaffected
7
+ (https://gofastmcp.com/servers/auth/authentication).
8
+
9
+ The MCP spec says a local server SHOULD bind only to localhost and SHOULD authenticate
10
+ every connection
11
+ (https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http).
12
+ FastMCP servers default to ``auth=None``, so ``create_server`` attaches the verifier at build
13
+ whenever the token is set, covering ``fastmcp run`` and ``http_app()`` too.
14
+ ``main()`` also refuses an HTTP bind to any other host unless a token is set or
15
+ ``TAXCODE_MCP_ALLOW_UNAUTHENTICATED_BIND`` opts in.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import hmac
21
+ import os
22
+
23
+ from fastmcp.server.auth import AccessToken, TokenVerifier
24
+
25
+ AUTH_TOKEN_ENV = "TAXCODE_MCP_AUTH_TOKEN"
26
+ ALLOW_UNAUTHENTICATED_BIND_ENV = "TAXCODE_MCP_ALLOW_UNAUTHENTICATED_BIND"
27
+ LOCALHOST_HOSTS = frozenset({"127.0.0.1", "::1", "localhost"})
28
+ _TRUTHY = frozenset({"1", "true", "yes", "on"})
29
+
30
+
31
+ class SharedTokenVerifier(TokenVerifier):
32
+ """Accept exactly one shared bearer token, compared in constant time."""
33
+
34
+ def __init__(self, expected_token: str) -> None:
35
+ stripped = expected_token.strip()
36
+ if not stripped:
37
+ raise ValueError(f"{AUTH_TOKEN_ENV} must be non-empty to enable authentication")
38
+ super().__init__()
39
+ self._expected = stripped.encode("utf-8")
40
+
41
+ def __repr__(self) -> str:
42
+ return f"{type(self).__name__}(expected_token=***REDACTED***)"
43
+
44
+ async def verify_token(self, token: str) -> AccessToken | None:
45
+ """Return an access token when ``token`` matches, else ``None`` (FastMCP answers 401)."""
46
+ if not token.strip():
47
+ return None
48
+ if not hmac.compare_digest(token.encode("utf-8"), self._expected):
49
+ return None
50
+ return AccessToken(token=token, client_id="taxcode-mcp-shared-token", scopes=[])
51
+
52
+
53
+ def read_auth_token() -> str:
54
+ """Return the stripped ``TAXCODE_MCP_AUTH_TOKEN``; whitespace-only counts as unset (``""``)."""
55
+ return os.environ.get(AUTH_TOKEN_ENV, "").strip()
56
+
57
+
58
+ def allow_unauthenticated_bind() -> bool:
59
+ """True when ``TAXCODE_MCP_ALLOW_UNAUTHENTICATED_BIND`` is 1/true/yes/on (any case)."""
60
+ return os.environ.get(ALLOW_UNAUTHENTICATED_BIND_ENV, "").strip().lower() in _TRUTHY
61
+
62
+
63
+ def is_localhost(host: str) -> bool:
64
+ """True for the loopback bind names 127.0.0.1, ::1 (bracketed or not), and localhost."""
65
+ return host.strip().strip("[]").lower() in LOCALHOST_HOSTS