rulinglens-mcp 0.1.0__tar.gz
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.
- rulinglens_mcp-0.1.0/PKG-INFO +42 -0
- rulinglens_mcp-0.1.0/README.md +28 -0
- rulinglens_mcp-0.1.0/pyproject.toml +24 -0
- rulinglens_mcp-0.1.0/rulinglens_mcp/__init__.py +291 -0
- rulinglens_mcp-0.1.0/rulinglens_mcp/__main__.py +10 -0
- rulinglens_mcp-0.1.0/rulinglens_mcp.egg-info/PKG-INFO +42 -0
- rulinglens_mcp-0.1.0/rulinglens_mcp.egg-info/SOURCES.txt +9 -0
- rulinglens_mcp-0.1.0/rulinglens_mcp.egg-info/dependency_links.txt +1 -0
- rulinglens_mcp-0.1.0/rulinglens_mcp.egg-info/entry_points.txt +2 -0
- rulinglens_mcp-0.1.0/rulinglens_mcp.egg-info/top_level.txt +1 -0
- rulinglens_mcp-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rulinglens-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: RulingLens as an MCP server: the HS code with the CBP rulings behind it, for Claude, Cursor and any MCP client
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://rulinglens.com
|
|
7
|
+
Project-URL: Source, https://github.com/kforkarim/RulingLens
|
|
8
|
+
Keywords: mcp,hs code,tariff,customs,classification
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Office/Business
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# rulinglens-mcp
|
|
16
|
+
|
|
17
|
+
RulingLens as an MCP server. Three tools over the RulingLens API, standard library only:
|
|
18
|
+
|
|
19
|
+
- `classify_product` — name and description → the six-digit HS subheading, the three most
|
|
20
|
+
similar earlier CBP rulings and whether they carry the same code, and the eight-digit U.S.
|
|
21
|
+
lines for a broker's review.
|
|
22
|
+
- `audit_entries` — a CSV, Excel or CBP 7501 PDF → every line re-classified and sorted,
|
|
23
|
+
disagreements first.
|
|
24
|
+
- `usage` — the plan and what is left this period.
|
|
25
|
+
|
|
26
|
+
Needs an API key from a RulingLens account (Starter plan or above): Account → API keys.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
pip install rulinglens-mcp # or run without installing: uvx rulinglens-mcp
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Claude Desktop (`claude_desktop_config.json`) or Cursor (`.cursor/mcp.json`):
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{ "mcpServers": { "rulinglens": { "command": "rulinglens-mcp", "env": { "RULINGLENS_API_KEY": "rl_live_..." } } } }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Claude Code: `claude mcp add rulinglens -e RULINGLENS_API_KEY=rl_live_... -- rulinglens-mcp`
|
|
39
|
+
|
|
40
|
+
Nothing here names a code to file: six digits are measured, the line is for review, and
|
|
41
|
+
the ten-digit suffix is the broker's. Source and the measurement record:
|
|
42
|
+
https://github.com/kforkarim/RulingLens
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# rulinglens-mcp
|
|
2
|
+
|
|
3
|
+
RulingLens as an MCP server. Three tools over the RulingLens API, standard library only:
|
|
4
|
+
|
|
5
|
+
- `classify_product` — name and description → the six-digit HS subheading, the three most
|
|
6
|
+
similar earlier CBP rulings and whether they carry the same code, and the eight-digit U.S.
|
|
7
|
+
lines for a broker's review.
|
|
8
|
+
- `audit_entries` — a CSV, Excel or CBP 7501 PDF → every line re-classified and sorted,
|
|
9
|
+
disagreements first.
|
|
10
|
+
- `usage` — the plan and what is left this period.
|
|
11
|
+
|
|
12
|
+
Needs an API key from a RulingLens account (Starter plan or above): Account → API keys.
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
pip install rulinglens-mcp # or run without installing: uvx rulinglens-mcp
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Claude Desktop (`claude_desktop_config.json`) or Cursor (`.cursor/mcp.json`):
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{ "mcpServers": { "rulinglens": { "command": "rulinglens-mcp", "env": { "RULINGLENS_API_KEY": "rl_live_..." } } } }
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Claude Code: `claude mcp add rulinglens -e RULINGLENS_API_KEY=rl_live_... -- rulinglens-mcp`
|
|
25
|
+
|
|
26
|
+
Nothing here names a code to file: six digits are measured, the line is for review, and
|
|
27
|
+
the ten-digit suffix is the broker's. Source and the measurement record:
|
|
28
|
+
https://github.com/kforkarim/RulingLens
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rulinglens-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "RulingLens as an MCP server: the HS code with the CBP rulings behind it, for Claude, Cursor and any MCP client"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = []
|
|
13
|
+
keywords = ["mcp", "hs code", "tariff", "customs", "classification"]
|
|
14
|
+
classifiers = ["Programming Language :: Python :: 3", "Operating System :: OS Independent", "Topic :: Office/Business"]
|
|
15
|
+
|
|
16
|
+
[project.urls]
|
|
17
|
+
Homepage = "https://rulinglens.com"
|
|
18
|
+
Source = "https://github.com/kforkarim/RulingLens"
|
|
19
|
+
|
|
20
|
+
[project.scripts]
|
|
21
|
+
rulinglens-mcp = "rulinglens_mcp.__main__:main"
|
|
22
|
+
|
|
23
|
+
[tool.setuptools]
|
|
24
|
+
packages = ["rulinglens_mcp"]
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"""RulingLens as an MCP server: three tools over the public /v1 API.
|
|
2
|
+
|
|
3
|
+
Runs over stdio, which is what Claude Desktop, Claude Code, Cursor and most other
|
|
4
|
+
assistants speak. Standard library only. Configure with two environment variables:
|
|
5
|
+
|
|
6
|
+
RULINGLENS_API_KEY an API key from your RulingLens account page (rl_live_…)
|
|
7
|
+
RULINGLENS_URL the service, default https://rulinglens.com
|
|
8
|
+
|
|
9
|
+
Tools
|
|
10
|
+
classify_product name + description → six-digit subheading, the three nearest earlier
|
|
11
|
+
CBP rulings, the ruling-backed mark, the eight-digit lines for review
|
|
12
|
+
audit_entries a CSV, Excel or 7501 PDF (path or base64) → the audit, with buckets
|
|
13
|
+
usage the plan and what is left this period
|
|
14
|
+
|
|
15
|
+
Every call is marked X-RulingLens-Client: mcp so the account's ledger shows where it came
|
|
16
|
+
from. Nothing here names a code to file; the tool descriptions say so to the assistant.
|
|
17
|
+
"""
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import base64
|
|
21
|
+
import json
|
|
22
|
+
import os
|
|
23
|
+
import sys
|
|
24
|
+
import time
|
|
25
|
+
import urllib.error
|
|
26
|
+
import urllib.request
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
from typing import Any
|
|
29
|
+
|
|
30
|
+
__all__ = ["serve", "TOOLS", "call_tool"]
|
|
31
|
+
|
|
32
|
+
PROTOCOL_VERSION = "2024-11-05"
|
|
33
|
+
SERVER = {"name": "rulinglens", "version": "1.0.0"}
|
|
34
|
+
DEFAULT_URL = "https://rulinglens.com"
|
|
35
|
+
POLL_SECONDS = 3.0
|
|
36
|
+
AUDIT_WAIT_SECONDS = 900.0
|
|
37
|
+
|
|
38
|
+
_NOTE = ("The six-digit subheading is the measured answer (ruling-backed answers were right 244 of 275 times in testing). "
|
|
39
|
+
"The eight-digit line is for the broker's review (992 of 1,135 when it commits). Statistical suffixes are listed "
|
|
40
|
+
"from the schedule, not chosen. Do not present any code as the code to file; a licensed broker decides the line.")
|
|
41
|
+
|
|
42
|
+
TOOLS: list[dict[str, Any]] = [
|
|
43
|
+
{
|
|
44
|
+
"name": "classify_product",
|
|
45
|
+
"description": "Recommend the six-digit HS subheading for one product, with the three most similar earlier CBP rulings "
|
|
46
|
+
"and whether they back the answer, plus the eight-digit U.S. rate lines under it for review. " + _NOTE,
|
|
47
|
+
"inputSchema": {"type": "object", "required": ["description"], "properties": {
|
|
48
|
+
"name": {"type": "string", "description": "Short product name (optional)", "maxLength": 120},
|
|
49
|
+
"description": {"type": "string", "description": "What the product is: material, function, form, how it is used. "
|
|
50
|
+
"Do not include a tariff code.", "maxLength": 2000}}},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "audit_entries",
|
|
54
|
+
"description": "Audit a file of entry lines that already carry HTS codes (CSV, Excel or a CBP 7501 PDF). Each line is "
|
|
55
|
+
"re-classified at six digits and sorted into DISAGREES / UNCLEAR / BACKED with the rulings and the duty "
|
|
56
|
+
"difference at the Column 1 general rate. Needs the Pro or Team plan or a quarter-audit bundle. " + _NOTE,
|
|
57
|
+
"inputSchema": {"type": "object", "properties": {
|
|
58
|
+
"path": {"type": "string", "description": "Path to the file on this computer"},
|
|
59
|
+
"filename": {"type": "string", "description": "File name, when sending content instead of a path"},
|
|
60
|
+
"content_base64": {"type": "string", "description": "The file's bytes, base64, when no path is available"},
|
|
61
|
+
"mapping": {"type": "object", "description": "Optional: which column holds each field, e.g. "
|
|
62
|
+
"{\"description\": \"Item Description\", \"filed_code\": \"HTS Number\"}",
|
|
63
|
+
"additionalProperties": {"type": "string"}},
|
|
64
|
+
"wait": {"type": "boolean", "description": "Wait for the audit to finish (default true, up to 15 minutes)"}}},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "usage",
|
|
68
|
+
"description": "The account's plan and what is left this period: checks and audit lines.",
|
|
69
|
+
"inputSchema": {"type": "object", "properties": {}},
|
|
70
|
+
},
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ApiFailure(Exception):
|
|
75
|
+
def __init__(self, status: int, body: Any) -> None:
|
|
76
|
+
super().__init__(f"{status}")
|
|
77
|
+
self.status, self.body = status, body
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Client:
|
|
81
|
+
def __init__(self, url: str | None = None, key: str | None = None) -> None:
|
|
82
|
+
self.url = (url or os.environ.get("RULINGLENS_URL") or DEFAULT_URL).rstrip("/")
|
|
83
|
+
self.key = key or (os.environ.get("RULINGLENS_API_KEY") or "").strip()
|
|
84
|
+
if not self.key:
|
|
85
|
+
raise SystemExit("RULINGLENS_API_KEY is not set; make a key on your RulingLens account page")
|
|
86
|
+
|
|
87
|
+
def _request(self, method: str, path: str, *, body: bytes | None = None, content_type: str | None = None,
|
|
88
|
+
extra: dict[str, str] | None = None, timeout: float = 120.0) -> Any:
|
|
89
|
+
headers = {"Authorization": "Bearer " + self.key, "X-RulingLens-Client": "mcp", "Accept": "application/json",
|
|
90
|
+
"User-Agent": "rulinglens-mcp/1.0", **(extra or {})}
|
|
91
|
+
if content_type:
|
|
92
|
+
headers["Content-Type"] = content_type
|
|
93
|
+
request = urllib.request.Request(self.url + path, data=body, method=method, headers=headers)
|
|
94
|
+
try:
|
|
95
|
+
with urllib.request.urlopen(request, timeout=timeout) as response:
|
|
96
|
+
status, raw = response.status, response.read()
|
|
97
|
+
except urllib.error.HTTPError as error:
|
|
98
|
+
status, raw = error.code, error.read()
|
|
99
|
+
except (urllib.error.URLError, TimeoutError, OSError) as error:
|
|
100
|
+
raise ApiFailure(0, {"error": "unreachable", "message": f"RulingLens could not be reached: {type(error).__name__}"}) from error
|
|
101
|
+
try:
|
|
102
|
+
parsed = json.loads(raw.decode("utf-8")) if raw.strip() else None
|
|
103
|
+
except (UnicodeDecodeError, ValueError):
|
|
104
|
+
parsed = {"error": "unreadable", "message": raw[:200].decode("utf-8", "replace")}
|
|
105
|
+
if status >= 400:
|
|
106
|
+
raise ApiFailure(status, parsed)
|
|
107
|
+
return parsed
|
|
108
|
+
|
|
109
|
+
def classify(self, name: str, description: str) -> Any:
|
|
110
|
+
return self._request("POST", "/v1/classify", body=json.dumps({"name": name, "description": description}).encode(),
|
|
111
|
+
content_type="application/json", timeout=150.0)
|
|
112
|
+
|
|
113
|
+
def usage(self) -> Any:
|
|
114
|
+
return self._request("GET", "/v1/me")
|
|
115
|
+
|
|
116
|
+
def audit(self, filename: str, data: bytes, mapping: dict | None, *, wait: bool) -> Any:
|
|
117
|
+
extra = {"X-Filename": filename}
|
|
118
|
+
if mapping:
|
|
119
|
+
extra["X-Mapping"] = json.dumps(mapping)
|
|
120
|
+
started = self._request("POST", "/v1/audits", body=data, content_type="application/octet-stream", extra=extra, timeout=120.0)
|
|
121
|
+
if not wait or not isinstance(started, dict) or not started.get("id"):
|
|
122
|
+
return started
|
|
123
|
+
audit_id, deadline = started["id"], time.monotonic() + AUDIT_WAIT_SECONDS
|
|
124
|
+
while time.monotonic() < deadline:
|
|
125
|
+
status = self._request("GET", f"/v1/audits/{audit_id}")
|
|
126
|
+
if isinstance(status, dict) and status.get("status") in ("done", "failed"):
|
|
127
|
+
if status.get("status") == "done":
|
|
128
|
+
report = self._request("GET", f"/v1/audits/{audit_id}/report.json", timeout=120.0)
|
|
129
|
+
# The report files need the API key, so a browser cannot open them by address; the signed-in
|
|
130
|
+
# Audits page can, and lists this audit with its report.
|
|
131
|
+
return {"audit": status, "report_page": f"{self.url}/#audits",
|
|
132
|
+
"report_api_url": f"{self.url}/v1/audits/{audit_id}/report.html", "findings": _compact(report)}
|
|
133
|
+
return status
|
|
134
|
+
time.sleep(POLL_SECONDS)
|
|
135
|
+
return {**started, "note": "still running; ask again with the audit id", "status_url": f"{self.url}/v1/audits/{audit_id}"}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _compact(report: Any) -> Any:
|
|
139
|
+
"""The report for an assistant: buckets first, each finding trimmed to what a person acts on."""
|
|
140
|
+
if not isinstance(report, dict):
|
|
141
|
+
return report
|
|
142
|
+
out = {"counts": report.get("counts"), "duty": report.get("duty"), "notes": report.get("notes"), "lines": []}
|
|
143
|
+
for f in report.get("findings") or []:
|
|
144
|
+
pick = f.get("line_pick") or {}
|
|
145
|
+
out["lines"].append({
|
|
146
|
+
"row": f.get("row"), "reference": f.get("reference"), "name": f.get("name"), "filed_code": f.get("filed_code"),
|
|
147
|
+
"bucket": f.get("bucket"), "variant": f.get("variant"), "recommended_hs6": f.get("recommended_hs6"),
|
|
148
|
+
"label": f.get("label"), "agreeing_rulings": f.get("agreeing_rulings"), "reason": f.get("reason"),
|
|
149
|
+
"line_for_review": pick.get("line_dotted"), "line_status": pick.get("status"), "line_needs": pick.get("missing_fact"),
|
|
150
|
+
"duty_difference_usd": (f.get("duty") or {}).get("difference_usd") if isinstance(f.get("duty"), dict) else None,
|
|
151
|
+
"rulings": [{"number": r.get("ruling_number"), "hs6": r.get("hs6"), "agrees": r.get("agrees_with_recommendation"), "url": r.get("url")}
|
|
152
|
+
for r in (f.get("rulings") or [])[:3]],
|
|
153
|
+
})
|
|
154
|
+
out["lines"].sort(key=lambda l: ({"DISAGREES": 0, "UNCLEAR": 1, "BACKED": 2}.get(l["bucket"], 3), l["row"] or 0))
|
|
155
|
+
return out
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def call_tool(client: Client, name: str, arguments: dict[str, Any]) -> dict[str, Any]:
|
|
159
|
+
"""Run one tool; returns an MCP tools/call result."""
|
|
160
|
+
try:
|
|
161
|
+
if name == "classify_product":
|
|
162
|
+
description = str(arguments.get("description") or "").strip()
|
|
163
|
+
if not description:
|
|
164
|
+
return _error("Give a product description.")
|
|
165
|
+
answer = client.classify(str(arguments.get("name") or "")[:120], description[:2000])
|
|
166
|
+
return _ok(_classify_summary(answer), answer)
|
|
167
|
+
if name == "usage":
|
|
168
|
+
return _ok(json.dumps(client.usage(), indent=2), client.usage())
|
|
169
|
+
if name == "audit_entries":
|
|
170
|
+
path = arguments.get("path")
|
|
171
|
+
if path:
|
|
172
|
+
file_path = Path(str(path)).expanduser()
|
|
173
|
+
if not file_path.is_file():
|
|
174
|
+
return _error(f"No file at {file_path}")
|
|
175
|
+
if file_path.stat().st_size > 25 * 1024 * 1024:
|
|
176
|
+
return _error("Files up to 25 MB.")
|
|
177
|
+
data, filename = file_path.read_bytes(), file_path.name
|
|
178
|
+
elif arguments.get("content_base64"):
|
|
179
|
+
try:
|
|
180
|
+
data = base64.b64decode(str(arguments["content_base64"]), validate=True)
|
|
181
|
+
except Exception:
|
|
182
|
+
return _error("content_base64 is not valid base64.")
|
|
183
|
+
filename = str(arguments.get("filename") or "upload.csv")
|
|
184
|
+
else:
|
|
185
|
+
return _error("Give a path or content_base64.")
|
|
186
|
+
mapping = arguments.get("mapping") if isinstance(arguments.get("mapping"), dict) else None
|
|
187
|
+
answer = client.audit(filename, data, mapping, wait=arguments.get("wait", True) is not False)
|
|
188
|
+
return _ok(_audit_summary(answer), answer)
|
|
189
|
+
return _error(f"Unknown tool {name}")
|
|
190
|
+
except ApiFailure as failure:
|
|
191
|
+
body = failure.body if isinstance(failure.body, dict) else {"message": str(failure.body)}
|
|
192
|
+
return _error(f"RulingLens answered {failure.status or 'nothing'}: {body.get('error', '')} {body.get('message', '')}".strip(), body)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _ok(text: str, structured: Any) -> dict[str, Any]:
|
|
196
|
+
return {"content": [{"type": "text", "text": text}], "structuredContent": structured if isinstance(structured, dict) else {"result": structured},
|
|
197
|
+
"isError": False}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _error(text: str, structured: Any = None) -> dict[str, Any]:
|
|
201
|
+
out = {"content": [{"type": "text", "text": text}], "isError": True}
|
|
202
|
+
if isinstance(structured, dict):
|
|
203
|
+
out["structuredContent"] = structured
|
|
204
|
+
return out
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _classify_summary(answer: Any) -> str:
|
|
208
|
+
if not isinstance(answer, dict) or not isinstance(answer.get("result"), dict):
|
|
209
|
+
return json.dumps(answer)[:2000]
|
|
210
|
+
result = answer["result"]
|
|
211
|
+
rec = result.get("recommendation") or {}
|
|
212
|
+
rel = rec.get("reliability") or {}
|
|
213
|
+
hs6 = str(rec.get("recommended_hs6") or "")
|
|
214
|
+
words = ((result.get("codes") or {}).get(hs6) or {})
|
|
215
|
+
lines = [f"Recommended subheading: {hs6[:4]}.{hs6[4:]} — {words.get('subheading') or ''}".rstrip(" —"),
|
|
216
|
+
f"Mark: {rel.get('label')} ({rel.get('agreeing')} of {rel.get('considered')} nearest earlier rulings carry this code). {rel.get('summary') or ''}".strip()]
|
|
217
|
+
for r in rel.get("rulings") or []:
|
|
218
|
+
lines.append(f" - {str(r.get('ruling_number') or '').upper()} ({r.get('date')}): {r.get('hs6')} "
|
|
219
|
+
f"{'same' if r.get('agrees_with_recommendation') else 'different'} — {r.get('subject') or ''} {r.get('url') or ''}".rstrip())
|
|
220
|
+
others = [f"{a[:4]}.{a[4:]}" for a in rec.get("alternatives") or []]
|
|
221
|
+
if others:
|
|
222
|
+
lines.append("Other codes considered: " + ", ".join(others))
|
|
223
|
+
ln = result.get("lines") or {}
|
|
224
|
+
pick = ln.get("pick") or {}
|
|
225
|
+
if pick.get("line_dotted"):
|
|
226
|
+
lines.append(f"Eight-digit line for the broker's review: {pick['line_dotted']} ({pick.get('status')}). {pick.get('why') or ''}".strip())
|
|
227
|
+
elif pick.get("status") == "UNSETTLED":
|
|
228
|
+
lines.append(f"Eight-digit line not settled by the description; needed: {pick.get('missing_fact')}")
|
|
229
|
+
if ln.get("rate_lines"):
|
|
230
|
+
lines.append(f"{len(ln['rate_lines'])} rate lines under {hs6[:4]}.{hs6[4:]}; statistical suffixes are listed in the structured result.")
|
|
231
|
+
lines.append(f"Checks used this period: {answer.get('used')} of {answer.get('limit')}.")
|
|
232
|
+
lines.append(_NOTE)
|
|
233
|
+
return "\n".join(lines)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _audit_summary(answer: Any) -> str:
|
|
237
|
+
if not isinstance(answer, dict):
|
|
238
|
+
return json.dumps(answer)[:2000]
|
|
239
|
+
if "findings" not in answer:
|
|
240
|
+
return json.dumps(answer, indent=2)[:3000]
|
|
241
|
+
f = answer["findings"]
|
|
242
|
+
counts = f.get("counts") or {}
|
|
243
|
+
out = [f"Audit done: {counts.get('DISAGREES', 0)} disagree, {counts.get('UNCLEAR', 0)} unclear, {counts.get('BACKED', 0)} backed, "
|
|
244
|
+
f"{counts.get('NOT_CHECKED', 0)} not checked, {counts.get('skipped_before_checking', 0)} skipped. "
|
|
245
|
+
f"Full report: open {answer.get('report_page') or answer.get('report_url')} while signed in (the Audits page)."]
|
|
246
|
+
lines = f.get("lines") or []
|
|
247
|
+
for line in lines[:25]:
|
|
248
|
+
label = " ".join(part for part in (line.get("reference"), line.get("name")) if part)
|
|
249
|
+
out.append(f" - row {line['row']} {label} filed {line['filed_code']} → {line['bucket']}: "
|
|
250
|
+
f"{line.get('recommended_hs6')} ({line.get('agreeing_rulings')} rulings agree). {line.get('reason') or ''}".rstrip())
|
|
251
|
+
if len(lines) > 25:
|
|
252
|
+
out.append(f" ... and {len(lines) - 25} more lines in the full report.")
|
|
253
|
+
out.append(_NOTE)
|
|
254
|
+
return "\n".join(out)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
# ----------------------------------------------------------------------------- JSON-RPC over stdio
|
|
258
|
+
def _respond(stream, message: dict[str, Any]) -> None:
|
|
259
|
+
stream.write(json.dumps(message, ensure_ascii=False) + "\n")
|
|
260
|
+
stream.flush()
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def serve(stdin=None, stdout=None, client: Client | None = None) -> None:
|
|
264
|
+
stdin = stdin or sys.stdin
|
|
265
|
+
stdout = stdout or sys.stdout
|
|
266
|
+
client = client or Client()
|
|
267
|
+
for raw in stdin:
|
|
268
|
+
raw = raw.strip()
|
|
269
|
+
if not raw:
|
|
270
|
+
continue
|
|
271
|
+
try:
|
|
272
|
+
message = json.loads(raw)
|
|
273
|
+
except ValueError:
|
|
274
|
+
_respond(stdout, {"jsonrpc": "2.0", "id": None, "error": {"code": -32700, "message": "parse error"}})
|
|
275
|
+
continue
|
|
276
|
+
method, msg_id, params = message.get("method"), message.get("id"), message.get("params") or {}
|
|
277
|
+
if method == "initialize":
|
|
278
|
+
_respond(stdout, {"jsonrpc": "2.0", "id": msg_id, "result": {
|
|
279
|
+
"protocolVersion": PROTOCOL_VERSION, "capabilities": {"tools": {}}, "serverInfo": SERVER,
|
|
280
|
+
"instructions": "RulingLens recommends six-digit HS subheadings with CBP ruling evidence and audits codes on file. " + _NOTE}})
|
|
281
|
+
elif method == "notifications/initialized" or (method or "").startswith("notifications/"):
|
|
282
|
+
continue
|
|
283
|
+
elif method == "ping":
|
|
284
|
+
_respond(stdout, {"jsonrpc": "2.0", "id": msg_id, "result": {}})
|
|
285
|
+
elif method == "tools/list":
|
|
286
|
+
_respond(stdout, {"jsonrpc": "2.0", "id": msg_id, "result": {"tools": TOOLS}})
|
|
287
|
+
elif method == "tools/call":
|
|
288
|
+
result = call_tool(client, str(params.get("name")), params.get("arguments") or {})
|
|
289
|
+
_respond(stdout, {"jsonrpc": "2.0", "id": msg_id, "result": result})
|
|
290
|
+
elif msg_id is not None:
|
|
291
|
+
_respond(stdout, {"jsonrpc": "2.0", "id": msg_id, "error": {"code": -32601, "message": f"method not found: {method}"}})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rulinglens-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: RulingLens as an MCP server: the HS code with the CBP rulings behind it, for Claude, Cursor and any MCP client
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://rulinglens.com
|
|
7
|
+
Project-URL: Source, https://github.com/kforkarim/RulingLens
|
|
8
|
+
Keywords: mcp,hs code,tariff,customs,classification
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Office/Business
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# rulinglens-mcp
|
|
16
|
+
|
|
17
|
+
RulingLens as an MCP server. Three tools over the RulingLens API, standard library only:
|
|
18
|
+
|
|
19
|
+
- `classify_product` — name and description → the six-digit HS subheading, the three most
|
|
20
|
+
similar earlier CBP rulings and whether they carry the same code, and the eight-digit U.S.
|
|
21
|
+
lines for a broker's review.
|
|
22
|
+
- `audit_entries` — a CSV, Excel or CBP 7501 PDF → every line re-classified and sorted,
|
|
23
|
+
disagreements first.
|
|
24
|
+
- `usage` — the plan and what is left this period.
|
|
25
|
+
|
|
26
|
+
Needs an API key from a RulingLens account (Starter plan or above): Account → API keys.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
pip install rulinglens-mcp # or run without installing: uvx rulinglens-mcp
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Claude Desktop (`claude_desktop_config.json`) or Cursor (`.cursor/mcp.json`):
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{ "mcpServers": { "rulinglens": { "command": "rulinglens-mcp", "env": { "RULINGLENS_API_KEY": "rl_live_..." } } } }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Claude Code: `claude mcp add rulinglens -e RULINGLENS_API_KEY=rl_live_... -- rulinglens-mcp`
|
|
39
|
+
|
|
40
|
+
Nothing here names a code to file: six digits are measured, the line is for review, and
|
|
41
|
+
the ten-digit suffix is the broker's. Source and the measurement record:
|
|
42
|
+
https://github.com/kforkarim/RulingLens
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
rulinglens_mcp/__init__.py
|
|
4
|
+
rulinglens_mcp/__main__.py
|
|
5
|
+
rulinglens_mcp.egg-info/PKG-INFO
|
|
6
|
+
rulinglens_mcp.egg-info/SOURCES.txt
|
|
7
|
+
rulinglens_mcp.egg-info/dependency_links.txt
|
|
8
|
+
rulinglens_mcp.egg-info/entry_points.txt
|
|
9
|
+
rulinglens_mcp.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rulinglens_mcp
|