und-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.
und_mcp-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Up Next Data
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.
und_mcp-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,368 @@
1
+ Metadata-Version: 2.4
2
+ Name: und-mcp
3
+ Version: 0.1.0
4
+ Summary: A small local MCP wrapper exposing the und public API (/api/v1) as Claude tools.
5
+ Author: Up Next Data
6
+ License: MIT
7
+ Project-URL: Homepage, https://www.upnextdata.com
8
+ Keywords: mcp,und,api
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Environment :: Console
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: mcp==2.3.0
20
+ Requires-Dist: httpx==0.28.1
21
+ Provides-Extra: test
22
+ Requires-Dist: pytest>=8.0; extra == "test"
23
+ Dynamic: license-file
24
+
25
+ # und-mcp
26
+
27
+ A small, local **Model Context Protocol (MCP)** wrapper that exposes the **und
28
+ public API** as tools you can call from **Claude Desktop** or **Claude Code**.
29
+
30
+ It runs **on your machine** over **stdio**. It holds **your** API key, makes
31
+ **read-only** `GET` calls to the und public API, and returns the results to
32
+ Claude. It contains no business logic beyond mapping each named tool to a single
33
+ API request.
34
+
35
+ ## What it does
36
+
37
+ The wrapper exposes one tool in v1:
38
+
39
+ | Tool | What it returns |
40
+ |------|-----------------|
41
+ | `run_test(limit, offset)` | Your key's identity plus a project-scoped sample of `und_master_summary` rows (filtered to your key's project). Use it to confirm your key works and to see exactly what your key's project can read. |
42
+
43
+ `run_test` maps to `GET {UND_API_URL}/api/v1/test`. The `/test` endpoint
44
+ returns a **project-scoped sample of `und_master_summary`** — specifically,
45
+ `und_master_summary` rows filtered by your key's project name (its `vendor`
46
+ field). Keys are project-scoped, **including `rep` projects**: a `rep` key does
47
+ **not** automatically reach the vendors it is associated with, so it may return
48
+ no rows. The `limit` argument is capped at 200 server-side; `offset` paginates
49
+ the sample.
50
+
51
+ More data tools will be added in a later release as the API grows.
52
+
53
+ ## API documentation (for clients and AI tools)
54
+
55
+ The API publishes an **auto-generated OpenAPI spec** at
56
+ `{UND_API_URL}/api/v1/docs/openapi.json` (public, no key required; Swagger UI
57
+ at `/api/v1/docs/ui`, ReDoc at `/api/v1/docs/redoc`). The spec is generated
58
+ from the server code, so it is the **single source of truth** for the
59
+ endpoints, their query parameters (including the `limit`/`offset` pagination
60
+ contract), and the request/response schemas. **Clients and AI tools should
61
+ consume that document** to learn the API's shapes instead of guessing or
62
+ relying on prose documentation: fetch it at `{UND_API_URL}/api/v1/docs/openapi.json`,
63
+ and treat the error envelope there (`{"error", "status"}` with fixed
64
+ server-defined messages) as the complete set of error responses.
65
+
66
+ ## Prerequisites
67
+
68
+ - **Python 3.11+**
69
+ - An **und API key** (`und_...`) scoped to your project — **vendor or
70
+ `rep`**. **Ask the und team to issue one for you.** Keys are project-scoped:
71
+ the API only ever returns data your key's project is authorized to read.
72
+ - The **confirmed und API host** (the base URL, e.g. an `https://...` host).
73
+ **Ask the und team for the confirmed HTTPS host** and set it via
74
+ `UND_API_URL` or `config.toml` **before using a real key** — the wrapper has
75
+ **no default host** and will not start on a key alone.
76
+
77
+ ## Quickstart (no Python experience needed)
78
+
79
+ This path is for **non-technical clients** — it needs **no Python knowledge**
80
+ and no pre-existing Python setup. The `uv` tool installs and runs the wrapper
81
+ for you, so you can skip straight to configuring Claude.
82
+
83
+ **1. Install [uv](https://docs.astral.sh/uv/)** with the official one-liner
84
+ for your platform:
85
+
86
+ macOS / Linux:
87
+
88
+ ```bash
89
+ curl -LsSf https://astral.sh/uv/install.sh | sh
90
+ ```
91
+
92
+ Windows (PowerShell):
93
+
94
+ ```powershell
95
+ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
96
+ ```
97
+
98
+ **2. Configure Claude Desktop.** Edit
99
+ `claude_desktop_config.json` (on macOS:
100
+ `~/Library/Application Support/Claude/claude_desktop_config.json`):
101
+
102
+ ```json
103
+ {
104
+ "mcpServers": {
105
+ "und": {
106
+ "command": "uvx",
107
+ "args": ["und-mcp"],
108
+ "env": {
109
+ "UND_API_URL": "https://api.example.com",
110
+ "UND_API_KEY": "und_..."
111
+ }
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ Both values are **required** — a key without `UND_API_URL` will not start the
118
+ server. The `UND_API_URL` value above is an obvious **placeholder**
119
+ (`api.example.com` is a reserved domain, **not** a live host) — **obtain the
120
+ confirmed und API host from the und team and replace the placeholder before
121
+ using a real key**.
122
+
123
+ **3. Restart Claude Desktop.** You'll see the `und` server and its
124
+ `run_test` tool available.
125
+
126
+ ## Installation
127
+
128
+ Two supported paths install the `und-mcp` command (both pin `mcp==2.3.0` +
129
+ `httpx==0.28.1`):
130
+
131
+ **Recommended — install with `pipx`:**
132
+
133
+ ```bash
134
+ pipx install und-mcp
135
+ ```
136
+
137
+ (`pipx` needs a **Python 3.11+** interpreter available to it — see
138
+ Prerequisites.)
139
+
140
+ **Zero-install — run with `uvx`:**
141
+
142
+ ```bash
143
+ uvx und-mcp
144
+ ```
145
+
146
+ `uvx` fetches and runs the wrapper on demand, installing nothing permanent
147
+ (it is what the Quickstart uses via Claude Desktop's `args`).
148
+
149
+ ### Installing from source
150
+
151
+ If you **already have a repo checkout** of this project (contributors), you
152
+ can instead install from source as a fallback:
153
+
154
+ ```bash
155
+ # from this directory
156
+ pip install .
157
+ ```
158
+
159
+ ## Configuration
160
+
161
+ Provide **both** your key **and** your API base URL — the URL is **required
162
+ and has no default**, so a key alone will not start the wrapper. Two ways
163
+ (values may also be mixed: any value that is missing or blank in the
164
+ environment is read from the file):
165
+
166
+ **Environment variables**:
167
+
168
+ - `UND_API_KEY` — **required.** Your `und_...` key.
169
+ - `UND_API_URL` — **required** (and nonblank, well-formed). The confirmed und
170
+ API host: an `https://` URL (a normal URL path is fine). For **local
171
+ testing only**, `http://` is accepted **only** for loopback hosts
172
+ (`http://localhost[:PORT]`, `http://127.0.0.1[:PORT]`, `http://[::1][:PORT]`).
173
+ Non-loopback `http://`, other schemes, embedded `user:pass@` credentials,
174
+ and malformed hosts or ports are rejected with a clear error **before** the
175
+ server starts or any request goes out.
176
+
177
+ **Deliberately unsupported URL forms** — three valid-but-unusual URLs are
178
+ rejected by design (safe over-strictness: rejected before the server starts,
179
+ with the same clear error that never echoes the URL): trailing-dot FQDNs (`https://api.example.com.`), expanded or
180
+ zero-compressed IPv6 loopback
181
+ literals other than `[::1]` (e.g. `http://[0:0:0:0:0:0:0:1]`), and
182
+ IPv4-mapped IPv6 hosts (`https://[::ffff:127.0.0.1]`). A raw space inside the
183
+ URL path **is** accepted — the HTTP client percent-encodes it.
184
+
185
+ **Or a config file** at `~/.config/und-mcp/config.toml`:
186
+
187
+ ```toml
188
+ api_url = "https://api.example.com" # required; PLACEHOLDER -- replace with the confirmed host before use
189
+ api_key = "und_..." # required
190
+ ```
191
+
192
+ The `api_url` value above is an obvious **placeholder** (`api.example.com` is
193
+ a reserved domain, **not** a live host) — **replace it with the confirmed und
194
+ API host before use**.
195
+
196
+ Environment variables take precedence over the file. If a value is missing or
197
+ blank in the environment, the file is consulted as a **fallback** for that
198
+ value. Only when **both** `UND_API_URL` and `UND_API_KEY` are set to
199
+ nonblank values is the file not read at all. Only when a value is **still**
200
+ missing or blank **after both sources are checked** does the wrapper exit
201
+ with a clear error message (it never logs your key, and it never echoes the
202
+ supplied URL in an error either). A resolved URL that fails validation —
203
+ e.g. non-loopback `http://` — exits with the same kind of clear error,
204
+ **before** the server is constructed or any request is made.
205
+
206
+ > **⚠️ There is no default API host, and non-local hosts must use HTTPS.**
207
+ > The wrapper accepts `https://` URLs for any host, and `http://` **only** for
208
+ > loopback hosts (`localhost`, `127.0.0.1`, `[::1]`). Note that **HTTPS does
209
+ > not verify host ownership**: it only proves the connection reached a host
210
+ > with a valid certificate for that name. Before you supply a **real API
211
+ > key**, **obtain the confirmed und API host (HTTPS) from the und team** and
212
+ > confirm it matches what you set in `UND_API_URL` (env or `config.toml`) —
213
+ > using a real key before the host is confirmed risks sending it to the wrong
214
+ > place. The **loopback `http://` exception is for local testing only**: it
215
+ > works with **any** key, so use it against a local stand-in, never as a
216
+ > substitute for the confirmed host.
217
+
218
+ > **The config file holds a plaintext secret.** `config.toml` stores your key
219
+ > in **plaintext** on disk. Keep it private: restrict its permissions (e.g.
220
+ > `chmod 600`), and never commit it, sync it to a shared or cloud location, or
221
+ > share it. The same care applies to any environment you export the key into.
222
+
223
+ ## Claude Desktop
224
+
225
+ Edit `claude_desktop_config.json` (on macOS:
226
+ `~/Library/Application Support/Claude/claude_desktop_config.json`):
227
+
228
+ ```json
229
+ {
230
+ "mcpServers": {
231
+ "und": {
232
+ "command": "und-mcp",
233
+ "env": {
234
+ "UND_API_URL": "https://api.example.com",
235
+ "UND_API_KEY": "und_..."
236
+ }
237
+ }
238
+ }
239
+ }
240
+ ```
241
+
242
+ Both values are **required** — a key without `UND_API_URL` will not start the
243
+ server. The `UND_API_URL` value above is an obvious **placeholder**
244
+ (`api.example.com` is a reserved domain, **not** a live host) — **obtain the
245
+ confirmed und API host from the und team and replace the placeholder before
246
+ using a real key**.
247
+
248
+ Restart Claude Desktop. You'll see the `und` server and its `run_test` tool
249
+ available.
250
+
251
+ ## Claude Code
252
+
253
+ Register the stdio server. **Options go before the `--` separator; everything
254
+ after the `--` is the command Claude Code launches (and its arguments) — not a
255
+ Claude flag:**
256
+
257
+ ```bash
258
+ # if installed with pipx
259
+ claude mcp add --transport stdio und-mcp -- und-mcp
260
+
261
+ # zero-install alternative (uvx fetches and runs it on demand)
262
+ claude mcp add --transport stdio und-mcp -- uvx und-mcp
263
+ ```
264
+
265
+ Claude Code hands the server its **key and API URL** in one of two ways
266
+ (both are required; any value that is missing or blank in the environment is
267
+ read from the file):
268
+
269
+ - **Local config file (recommended).** Create `~/.config/und-mcp/config.toml`
270
+ with **both** `api_url` and `api_key`, as shown in
271
+ [Configuration](#configuration). The wrapper reads it automatically, so the
272
+ key never appears in a shell command, your shell history, or a project file.
273
+ - **Explicitly configured environment.** Pass repeatable `--env KEY=VALUE`
274
+ flags **before** the `--`:
275
+
276
+ ```bash
277
+ claude mcp add --transport stdio \
278
+ --env UND_API_URL="<confirmed API host>" \
279
+ --env UND_API_KEY="<paste key here>" \
280
+ und-mcp -- und-mcp
281
+ ```
282
+
283
+ Don't paste a real key into a shell command like this: it is stored verbatim
284
+ in the saved MCP config and also remains in your shell history. If you prefer
285
+ the environment, set `UND_API_URL` / `UND_API_KEY` in your shell profile or
286
+ in the environment you launch Claude Code from, and register the server with
287
+ no `--env` flags.
288
+
289
+ Whichever way you choose, the value ends up stored in **plaintext** on disk
290
+ (the config file, or the saved MCP config), so treat that file as a secret and
291
+ keep it private.
292
+
293
+ ## Auditable by design
294
+
295
+ A live API key sits next to this code, so it's built to be read in a few
296
+ minutes:
297
+
298
+ - **stdio only** — no HTTP/`serve` mode, no OAuth, no listening socket.
299
+ - **No telemetry, no background calls** — the only network activity is the
300
+ explicit `GET` your tool triggers, on demand.
301
+ - **Read-only** — no write/delete endpoints.
302
+ - **Error-sanitizing** — API error responses are mapped to short, actionable
303
+ messages; arbitrary server error bodies are never echoed back to Claude.
304
+ - **Proxy-immune** — the HTTP client is built with `trust_env=False`, so
305
+ proxy/netrc settings in the environment cannot redirect requests.
306
+ - **~150 lines** of plain Python: `config.py`, `client.py`, `server.py`.
307
+
308
+ ## SDK version note
309
+
310
+ The MCP Python SDK is in fast flux. This wrapper is pinned to **`mcp==2.3.0`**
311
+ (the v2 line, where `FastMCP` was renamed to `MCPServer`). If you upgrade the
312
+ `mcp` SDK or Claude and the tools stop appearing, you may need a corresponding
313
+ `und-mcp` bump. Keep the pinned version in `pyproject.toml` as your reference.
314
+
315
+ ## Troubleshooting
316
+
317
+ - **`UND_API_URL is not set`** — the URL is required and has no default; a
318
+ key alone will not start the server. Obtain the confirmed und API host from
319
+ the und team, set `UND_API_URL` (env or `api_url` in `config.toml`), then
320
+ restart Claude. For local testing, an explicit loopback HTTP URL such as
321
+ `http://127.0.0.1:PORT` works.
322
+ - **`UND_API_KEY is not set`** — set the key (env or `config.toml`), then
323
+ restart Claude.
324
+ - **`UND_API_URL is invalid ...`** — the URL failed validation. Only
325
+ `https://` is accepted for non-local hosts; `http://` only for loopback
326
+ hosts (`localhost`, `127.0.0.1`, `[::1]`, optional port); embedded
327
+ `user:pass@` credentials and malformed hosts or ports are rejected. Set an
328
+ `https://` URL to the confirmed und API host (or a loopback `http://` URL
329
+ for local testing), then restart Claude.
330
+ - **`rejected the key (401/403)`** from a tool — your key is invalid, revoked,
331
+ or expired. Ask the und team to reissue it.
332
+ - **`Rate limited by the und API (429)...`** — you hit the API rate limit; if
333
+ the server sent a numeric `Retry-After`, the tool tells Claude the wait
334
+ duration before retrying.
335
+ - **No tools listed** — check the SDK version note above.
336
+
337
+ ## Running the tests
338
+
339
+ Install the wrapper (with the test extra) **into the Python environment you
340
+ will run the tests with**, then run the suite from that same environment.
341
+ Quote the editable test-extra argument so the shell does not glob `.[test]`:
342
+
343
+ ```bash
344
+ # from this directory
345
+ python -m pip install -e '.[test]'
346
+ python -m pytest tests -q
347
+ ```
348
+
349
+ The stdio end-to-end tests resolve the **`und-mcp` console script from the
350
+ `sysconfig` scripts directory of the very Python environment running pytest**
351
+ (`bin` on POSIX, `Scripts` on Windows, including the Windows `.exe` launcher)
352
+ and spawn it as a subprocess. There is **no** hard-coded venv path and **no**
353
+ fallback to an unrelated `und-mcp` on `PATH`: the console script must belong to
354
+ the environment running the tests. Run the suite with whichever environment has
355
+ the wrapper and its test dependencies installed, e.g. from the repository root:
356
+
357
+ ```bash
358
+ env PYTHONDONTWRITEBYTECODE=1 wrapper/.venv/bin/python -m pytest -q -p no:cacheprovider wrapper/tests
359
+ ```
360
+
361
+ If `und-mcp` is not installed in the environment that runs the tests, the
362
+ suite fails up front with a clear, actionable error telling you to install it
363
+ (`python -m pip install -e '.[test]'`), instead of a confusing spawn error
364
+ mid-test.
365
+
366
+ The suite drives the real entry point over an actual stdio channel against an
367
+ ephemeral `127.0.0.1` HTTP server, with a synthetic key — no real API, no
368
+ network access beyond loopback.