onhand-mcp 0.1.0a1__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.
- onhand_mcp-0.1.0a1/.gitignore +20 -0
- onhand_mcp-0.1.0a1/LICENSE +21 -0
- onhand_mcp-0.1.0a1/PKG-INFO +30 -0
- onhand_mcp-0.1.0a1/README.md +20 -0
- onhand_mcp-0.1.0a1/onhand/__init__.py +18 -0
- onhand_mcp-0.1.0a1/onhand/_generated.py +93 -0
- onhand_mcp-0.1.0a1/onhand/client.py +98 -0
- onhand_mcp-0.1.0a1/onhand/py.typed +1 -0
- onhand_mcp-0.1.0a1/pyproject.toml +19 -0
- onhand_mcp-0.1.0a1/tests/test_client.py +80 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
node_modules
|
|
2
|
+
.pnpm-store
|
|
3
|
+
dist
|
|
4
|
+
.next
|
|
5
|
+
.turbo
|
|
6
|
+
.DS_Store
|
|
7
|
+
*.log
|
|
8
|
+
coverage
|
|
9
|
+
.stripe-test-clocks
|
|
10
|
+
.env
|
|
11
|
+
.env.*
|
|
12
|
+
!.env.example
|
|
13
|
+
*.tsbuildinfo
|
|
14
|
+
|
|
15
|
+
# regenerated by `next dev`; apps/web/AGENTS.md is the tracked original
|
|
16
|
+
apps/web/CLAUDE.md
|
|
17
|
+
|
|
18
|
+
# macOS/iCloud duplicate artifacts ("context 2.ts", "Dockerfile 2")
|
|
19
|
+
* [0-9]
|
|
20
|
+
* [0-9].*
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pathlight Ventures
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: onhand-mcp
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: Python client for the Onhand public API
|
|
5
|
+
Project-URL: Homepage, https://askonhand.com/use
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# Onhand Python SDK
|
|
12
|
+
|
|
13
|
+
Thin, typed access to the versioned Onhand public API with no runtime
|
|
14
|
+
dependencies.
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install onhand-mcp
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from onhand import OnhandClient
|
|
22
|
+
|
|
23
|
+
onhand = OnhandClient("https://mcp.askonhand.com")
|
|
24
|
+
result = onhand.search_offerings(
|
|
25
|
+
{"lat": 41.88, "lng": -87.63, "q": "running shoes", "surface": "chatgpt"}
|
|
26
|
+
)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Pass `token_provider` for authenticated methods. The callback is evaluated for
|
|
30
|
+
each request, and the SDK never persists the token.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Onhand Python SDK
|
|
2
|
+
|
|
3
|
+
Thin, typed access to the versioned Onhand public API with no runtime
|
|
4
|
+
dependencies.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install onhand-mcp
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
from onhand import OnhandClient
|
|
12
|
+
|
|
13
|
+
onhand = OnhandClient("https://mcp.askonhand.com")
|
|
14
|
+
result = onhand.search_offerings(
|
|
15
|
+
{"lat": 41.88, "lng": -87.63, "q": "running shoes", "surface": "chatgpt"}
|
|
16
|
+
)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Pass `token_provider` for authenticated methods. The callback is evaluated for
|
|
20
|
+
each request, and the SDK never persists the token.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from ._generated import (
|
|
2
|
+
SearchOffering,
|
|
3
|
+
SearchOfferingsInput,
|
|
4
|
+
SearchOfferingsResponse,
|
|
5
|
+
SearchWebsiteItem,
|
|
6
|
+
WebsiteItemBand,
|
|
7
|
+
)
|
|
8
|
+
from .client import OnhandApiError, OnhandClient
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"OnhandApiError",
|
|
12
|
+
"OnhandClient",
|
|
13
|
+
"SearchOffering",
|
|
14
|
+
"SearchOfferingsInput",
|
|
15
|
+
"SearchOfferingsResponse",
|
|
16
|
+
"SearchWebsiteItem",
|
|
17
|
+
"WebsiteItemBand",
|
|
18
|
+
]
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Generated from the Onhand OpenAPI contract. Do not edit.
|
|
2
|
+
from collections.abc import Callable
|
|
3
|
+
from typing import Literal, TypedDict, cast
|
|
4
|
+
|
|
5
|
+
Surface = Literal["onhand", "claude", "chatgpt", "grok", "cursor", "muse", "gemini"]
|
|
6
|
+
OfferingKind = Literal["item", "service"]
|
|
7
|
+
TrustTier = Literal[1, 2, 3]
|
|
8
|
+
Freshness = Literal["fresh", "aging", "stale"]
|
|
9
|
+
SourceType = Literal["register", "merchant_upload", "website_prefill"]
|
|
10
|
+
Availability = Literal["in_stock", "low", "out", "bookable", "unavailable", "unknown"] | None
|
|
11
|
+
WebsiteItemBand = Literal["listed_on_website", "possibly_offered"]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class _SearchOfferingsInputRequired(TypedDict):
|
|
15
|
+
lat: float
|
|
16
|
+
lng: float
|
|
17
|
+
q: str
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SearchOfferingsInput(_SearchOfferingsInputRequired, total=False):
|
|
21
|
+
radius_m: int
|
|
22
|
+
surface: Surface
|
|
23
|
+
attributes: dict[str, str]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class SearchOfferingImage(TypedDict):
|
|
27
|
+
url: str
|
|
28
|
+
alt: str | None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class SearchOffering(TypedDict):
|
|
32
|
+
offering_id: str
|
|
33
|
+
title: str
|
|
34
|
+
business_id: str
|
|
35
|
+
display_name: str
|
|
36
|
+
price_cents: int
|
|
37
|
+
kind: OfferingKind
|
|
38
|
+
distance_meters: float
|
|
39
|
+
trust_tier: TrustTier
|
|
40
|
+
freshness: Freshness
|
|
41
|
+
data_age_seconds: int
|
|
42
|
+
source_type: SourceType
|
|
43
|
+
availability: Availability
|
|
44
|
+
section: str | None
|
|
45
|
+
description: str | None
|
|
46
|
+
duration_minutes: int | None
|
|
47
|
+
last_confirmed_at: str | None
|
|
48
|
+
attributes: dict[str, str]
|
|
49
|
+
images: list[SearchOfferingImage]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class SearchWebsiteItem(TypedDict):
|
|
53
|
+
business_id: str
|
|
54
|
+
display_name: str
|
|
55
|
+
title: str
|
|
56
|
+
kind: Literal["item", "service"]
|
|
57
|
+
section: str | None
|
|
58
|
+
distance_meters: float
|
|
59
|
+
source_type: Literal["public_website"]
|
|
60
|
+
band: WebsiteItemBand
|
|
61
|
+
label: str
|
|
62
|
+
source_url: str
|
|
63
|
+
last_seen_at: str
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class SearchOfferingsResponse(TypedDict):
|
|
67
|
+
data: list[SearchOffering]
|
|
68
|
+
website_items: list[SearchWebsiteItem]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class ErrorDetail(TypedDict):
|
|
72
|
+
code: str
|
|
73
|
+
message: str
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class ErrorResponse(TypedDict):
|
|
77
|
+
error: ErrorDetail
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
GeneratedRequester = Callable[[str, str, object], object]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class GeneratedOnhandApi:
|
|
84
|
+
def __init__(self, request: GeneratedRequester) -> None:
|
|
85
|
+
self._request = request
|
|
86
|
+
|
|
87
|
+
def search_offerings(
|
|
88
|
+
self, input: SearchOfferingsInput
|
|
89
|
+
) -> SearchOfferingsResponse:
|
|
90
|
+
return cast(
|
|
91
|
+
SearchOfferingsResponse,
|
|
92
|
+
self._request("POST", "/v1/offerings/search", input),
|
|
93
|
+
)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import time
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from typing import cast
|
|
5
|
+
from urllib.error import HTTPError, URLError
|
|
6
|
+
from urllib.request import Request, urlopen
|
|
7
|
+
|
|
8
|
+
from ._generated import GeneratedOnhandApi, SearchOfferingsInput, SearchOfferingsResponse
|
|
9
|
+
|
|
10
|
+
SDK_VERSION = "0.1.0a1"
|
|
11
|
+
TokenProvider = Callable[[], str | None]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class OnhandApiError(Exception):
|
|
15
|
+
def __init__(
|
|
16
|
+
self, code: str, message: str, status: int, request_id: str | None = None
|
|
17
|
+
) -> None:
|
|
18
|
+
super().__init__(message)
|
|
19
|
+
self.code = code
|
|
20
|
+
self.status = status
|
|
21
|
+
self.request_id = request_id
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class OnhandClient:
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
base_url: str,
|
|
28
|
+
*,
|
|
29
|
+
token_provider: TokenProvider | None = None,
|
|
30
|
+
timeout: float = 10.0,
|
|
31
|
+
max_retries: int = 2,
|
|
32
|
+
retry_delay: float = 0.1,
|
|
33
|
+
) -> None:
|
|
34
|
+
self._base_url = base_url.rstrip("/")
|
|
35
|
+
self._token_provider = token_provider
|
|
36
|
+
self._timeout = timeout
|
|
37
|
+
self._max_retries = max_retries
|
|
38
|
+
self._retry_delay = retry_delay
|
|
39
|
+
self._api = GeneratedOnhandApi(self._request)
|
|
40
|
+
|
|
41
|
+
def search_offerings(
|
|
42
|
+
self, input: SearchOfferingsInput
|
|
43
|
+
) -> SearchOfferingsResponse:
|
|
44
|
+
return self._api.search_offerings(input)
|
|
45
|
+
|
|
46
|
+
def _request(self, method: str, path: str, body: object) -> object:
|
|
47
|
+
for attempt in range(self._max_retries + 1):
|
|
48
|
+
token = self._token_provider() if self._token_provider else None
|
|
49
|
+
headers = {
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
"X-Onhand-Client-Version": SDK_VERSION,
|
|
52
|
+
}
|
|
53
|
+
if token:
|
|
54
|
+
headers["Authorization"] = f"Bearer {token}"
|
|
55
|
+
request = Request(
|
|
56
|
+
f"{self._base_url}{path}",
|
|
57
|
+
data=json.dumps(body).encode(),
|
|
58
|
+
headers=headers,
|
|
59
|
+
method=method,
|
|
60
|
+
)
|
|
61
|
+
try:
|
|
62
|
+
with urlopen(request, timeout=self._timeout) as response:
|
|
63
|
+
return cast(object, json.loads(response.read()))
|
|
64
|
+
except HTTPError as error:
|
|
65
|
+
if attempt < self._max_retries and _retryable(error.code):
|
|
66
|
+
self._delay(attempt)
|
|
67
|
+
continue
|
|
68
|
+
payload = _error_payload(error.read())
|
|
69
|
+
raise OnhandApiError(
|
|
70
|
+
payload.get("code", "http_error"),
|
|
71
|
+
payload.get("message", f"Onhand request failed ({error.code})."),
|
|
72
|
+
error.code,
|
|
73
|
+
error.headers.get("X-Request-Id") if error.headers else None,
|
|
74
|
+
) from error
|
|
75
|
+
except (TimeoutError, URLError) as error:
|
|
76
|
+
if attempt < self._max_retries:
|
|
77
|
+
self._delay(attempt)
|
|
78
|
+
continue
|
|
79
|
+
raise OnhandApiError(
|
|
80
|
+
"transport_error", "Onhand request failed.", 0
|
|
81
|
+
) from error
|
|
82
|
+
raise OnhandApiError("transport_error", "Onhand request failed.", 0)
|
|
83
|
+
|
|
84
|
+
def _delay(self, attempt: int) -> None:
|
|
85
|
+
time.sleep(self._retry_delay * (2**attempt))
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _retryable(status: int) -> bool:
|
|
89
|
+
return status == 429 or status >= 500
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _error_payload(raw: bytes) -> dict[str, str]:
|
|
93
|
+
try:
|
|
94
|
+
payload = json.loads(raw)
|
|
95
|
+
error = payload.get("error", {}) if isinstance(payload, dict) else {}
|
|
96
|
+
return error if isinstance(error, dict) else {}
|
|
97
|
+
except (UnicodeDecodeError, json.JSONDecodeError):
|
|
98
|
+
return {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27,<2"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "onhand-mcp"
|
|
7
|
+
version = "0.1.0a1"
|
|
8
|
+
description = "Python client for the Onhand public API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
dependencies = []
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Homepage = "https://askonhand.com/use"
|
|
17
|
+
|
|
18
|
+
[tool.hatch.build.targets.wheel]
|
|
19
|
+
packages = ["onhand"]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import sys
|
|
3
|
+
import unittest
|
|
4
|
+
from io import BytesIO
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from unittest.mock import patch
|
|
7
|
+
from urllib.error import HTTPError, URLError
|
|
8
|
+
|
|
9
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
10
|
+
|
|
11
|
+
from onhand import OnhandApiError, OnhandClient # noqa: E402
|
|
12
|
+
|
|
13
|
+
FIXTURE = json.loads(
|
|
14
|
+
(Path(__file__).resolve().parents[3] / "test/fixtures/public-api/search.json")
|
|
15
|
+
.read_text()
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class FakeResponse:
|
|
20
|
+
def __init__(self, body: object) -> None:
|
|
21
|
+
self._body = json.dumps(body).encode()
|
|
22
|
+
|
|
23
|
+
def __enter__(self):
|
|
24
|
+
return self
|
|
25
|
+
|
|
26
|
+
def __exit__(self, *_args):
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
def read(self) -> bytes:
|
|
30
|
+
return self._body
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class OnhandClientTest(unittest.TestCase):
|
|
34
|
+
@patch("onhand.client.urlopen")
|
|
35
|
+
def test_generated_route_auth_and_metadata(self, open_url):
|
|
36
|
+
open_url.return_value = FakeResponse(FIXTURE["response"])
|
|
37
|
+
client = OnhandClient(
|
|
38
|
+
"https://api.example/", token_provider=lambda: "secret-token"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
self.assertEqual(client.search_offerings(FIXTURE["request"]), FIXTURE["response"])
|
|
42
|
+
request = open_url.call_args.args[0]
|
|
43
|
+
headers = {key.lower(): value for key, value in request.header_items()}
|
|
44
|
+
self.assertEqual(request.full_url, "https://api.example/v1/offerings/search")
|
|
45
|
+
self.assertEqual(headers["authorization"], "Bearer secret-token")
|
|
46
|
+
self.assertEqual(headers["x-onhand-client-version"], "0.1.0a1")
|
|
47
|
+
|
|
48
|
+
@patch("onhand.client.urlopen")
|
|
49
|
+
def test_typed_api_error(self, open_url):
|
|
50
|
+
open_url.side_effect = HTTPError(
|
|
51
|
+
"https://api.example",
|
|
52
|
+
400,
|
|
53
|
+
"Bad request",
|
|
54
|
+
{"X-Request-Id": "req-error"},
|
|
55
|
+
BytesIO(
|
|
56
|
+
json.dumps(
|
|
57
|
+
{"error": {"code": "invalid_request", "message": "Bad request."}}
|
|
58
|
+
).encode()
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
client = OnhandClient("https://api.example", max_retries=0)
|
|
62
|
+
|
|
63
|
+
with self.assertRaises(OnhandApiError) as raised:
|
|
64
|
+
client.search_offerings(FIXTURE["request"])
|
|
65
|
+
self.assertEqual(raised.exception.code, "invalid_request")
|
|
66
|
+
self.assertEqual(raised.exception.status, 400)
|
|
67
|
+
self.assertEqual(raised.exception.request_id, "req-error")
|
|
68
|
+
|
|
69
|
+
@patch("onhand.client.time.sleep")
|
|
70
|
+
@patch("onhand.client.urlopen")
|
|
71
|
+
def test_retries_transient_transport_failures(self, open_url, _sleep):
|
|
72
|
+
open_url.side_effect = [URLError("offline"), FakeResponse(FIXTURE["response"])]
|
|
73
|
+
client = OnhandClient("https://api.example", max_retries=1)
|
|
74
|
+
|
|
75
|
+
self.assertEqual(client.search_offerings(FIXTURE["request"]), FIXTURE["response"])
|
|
76
|
+
self.assertEqual(open_url.call_count, 2)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
if __name__ == "__main__":
|
|
80
|
+
unittest.main()
|