forgingstack-ration 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jonathan Battles
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,96 @@
1
+ Metadata-Version: 2.4
2
+ Name: forgingstack-ration
3
+ Version: 0.1.0
4
+ Summary: One quota pool, many agents, no overruns.
5
+ License: MIT
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # ForgingStack Ration
12
+
13
+ One quota pool, many agents, no overruns.
14
+
15
+ mcp-name: io.github.jdkabattles/forgingstack-ration
16
+
17
+ This is the **public client** for Ration. The service itself — the
18
+ token bucket, the receipt chain, the key store, and billing — runs
19
+ on ForgingStack's private service and is **not** in this repo.
20
+ Copying this repo does not give you the service: you still need an
21
+ API key and credits, from signup below.
22
+
23
+ Live API: https://forgingstack-ration.jkbattles.workers.dev
24
+
25
+ ## What it does
26
+
27
+ A principal creates a pool with a capacity, a refill rate, a
28
+ per-agent cap, and a burst limit. Agents draw units from it. The
29
+ pool enforces the limits and issues a hash-chained receipt for
30
+ every draw attempt — allowed **and** denied.
31
+
32
+ A draw is denied when:
33
+
34
+ - the units exceed the burst limit (`draw_exceeds_burst`)
35
+ - the pool does not have enough available units
36
+ (`pool_insufficient_units`)
37
+ - the agent's allowed draws inside the rolling 60-minute window
38
+ would exceed the per-agent cap (`per_agent_cap_exceeded`)
39
+
40
+ The per-agent cap window is a rolling 60 minutes — a documented
41
+ design choice, not a calendar window.
42
+
43
+ ## Signup (v1)
44
+
45
+ ```bash
46
+ curl -X POST https://forgingstack-ration.jkbattles.workers.dev/v1/signup \
47
+ -H "Content-Type: application/json" \
48
+ -d '{"email":"you@example.com"}'
49
+ ```
50
+
51
+ Returns an API key **once** and 100 starter credits. Save the key
52
+ immediately — it is stored only as a hash and cannot be shown again.
53
+ Click the verification link in the signup email before the key can
54
+ create pools or draw: until then, pool creation and draws return
55
+ 403 `email_not_verified`.
56
+
57
+ ## Buying more credits
58
+
59
+ 1 credit per pool creation, 1 credit per draw call (allowed or
60
+ denied). Top-ups, pool reads, pool lists, and deletes are free.
61
+
62
+ ```bash
63
+ curl -X POST https://forgingstack-ration.jkbattles.workers.dev/v1/billing/checkout \
64
+ -H "X-API-Key: YOUR_PRIMARY_KEY"
65
+ ```
66
+
67
+ Returns the Stripe Payment Link: **$10 for 1,000 credits**. Pay on
68
+ Stripe's hosted page with the same email you signed up with.
69
+ Credits land once the payment is verified (within the hour).
70
+
71
+ ## Use it (MCP, stdio)
72
+
73
+ Set the key, then run the MCP server in this repo:
74
+
75
+ ```bash
76
+ export FORGINGSTACK_API_KEY="your-key-here"
77
+ python -m app.mcp_server
78
+ ```
79
+
80
+ Tools: `create_pool`, `draw`, `get_pool`, `list_pools`,
81
+ `topup_pool`, `delete_pool`, `get_credits`, `get_receipt`.
82
+ See `SKILL.md` for when to use it and when not to.
83
+
84
+ ## Price
85
+
86
+ 1 credit per pool creation. 1 credit per draw call — a denied draw
87
+ still costs 1 credit, the draw was performed. An idempotent replay
88
+ (same `Idempotency-Key`) is free and returns the original receipt.
89
+
90
+ ## Files in this repo
91
+
92
+ - `app/mcp_server.py` — MCP wrapper client (stdio, stdlib only)
93
+ - `SKILL.md` — when to use it, how to read allowed/denied
94
+ - `agent-card.json` — A2A-style discovery card
95
+ - `server.json` — MCP Registry metadata
96
+ - `pyproject.toml` — package metadata for the MCP client
@@ -0,0 +1,86 @@
1
+ # ForgingStack Ration
2
+
3
+ One quota pool, many agents, no overruns.
4
+
5
+ mcp-name: io.github.jdkabattles/forgingstack-ration
6
+
7
+ This is the **public client** for Ration. The service itself — the
8
+ token bucket, the receipt chain, the key store, and billing — runs
9
+ on ForgingStack's private service and is **not** in this repo.
10
+ Copying this repo does not give you the service: you still need an
11
+ API key and credits, from signup below.
12
+
13
+ Live API: https://forgingstack-ration.jkbattles.workers.dev
14
+
15
+ ## What it does
16
+
17
+ A principal creates a pool with a capacity, a refill rate, a
18
+ per-agent cap, and a burst limit. Agents draw units from it. The
19
+ pool enforces the limits and issues a hash-chained receipt for
20
+ every draw attempt — allowed **and** denied.
21
+
22
+ A draw is denied when:
23
+
24
+ - the units exceed the burst limit (`draw_exceeds_burst`)
25
+ - the pool does not have enough available units
26
+ (`pool_insufficient_units`)
27
+ - the agent's allowed draws inside the rolling 60-minute window
28
+ would exceed the per-agent cap (`per_agent_cap_exceeded`)
29
+
30
+ The per-agent cap window is a rolling 60 minutes — a documented
31
+ design choice, not a calendar window.
32
+
33
+ ## Signup (v1)
34
+
35
+ ```bash
36
+ curl -X POST https://forgingstack-ration.jkbattles.workers.dev/v1/signup \
37
+ -H "Content-Type: application/json" \
38
+ -d '{"email":"you@example.com"}'
39
+ ```
40
+
41
+ Returns an API key **once** and 100 starter credits. Save the key
42
+ immediately — it is stored only as a hash and cannot be shown again.
43
+ Click the verification link in the signup email before the key can
44
+ create pools or draw: until then, pool creation and draws return
45
+ 403 `email_not_verified`.
46
+
47
+ ## Buying more credits
48
+
49
+ 1 credit per pool creation, 1 credit per draw call (allowed or
50
+ denied). Top-ups, pool reads, pool lists, and deletes are free.
51
+
52
+ ```bash
53
+ curl -X POST https://forgingstack-ration.jkbattles.workers.dev/v1/billing/checkout \
54
+ -H "X-API-Key: YOUR_PRIMARY_KEY"
55
+ ```
56
+
57
+ Returns the Stripe Payment Link: **$10 for 1,000 credits**. Pay on
58
+ Stripe's hosted page with the same email you signed up with.
59
+ Credits land once the payment is verified (within the hour).
60
+
61
+ ## Use it (MCP, stdio)
62
+
63
+ Set the key, then run the MCP server in this repo:
64
+
65
+ ```bash
66
+ export FORGINGSTACK_API_KEY="your-key-here"
67
+ python -m app.mcp_server
68
+ ```
69
+
70
+ Tools: `create_pool`, `draw`, `get_pool`, `list_pools`,
71
+ `topup_pool`, `delete_pool`, `get_credits`, `get_receipt`.
72
+ See `SKILL.md` for when to use it and when not to.
73
+
74
+ ## Price
75
+
76
+ 1 credit per pool creation. 1 credit per draw call — a denied draw
77
+ still costs 1 credit, the draw was performed. An idempotent replay
78
+ (same `Idempotency-Key`) is free and returns the original receipt.
79
+
80
+ ## Files in this repo
81
+
82
+ - `app/mcp_server.py` — MCP wrapper client (stdio, stdlib only)
83
+ - `SKILL.md` — when to use it, how to read allowed/denied
84
+ - `agent-card.json` — A2A-style discovery card
85
+ - `server.json` — MCP Registry metadata
86
+ - `pyproject.toml` — package metadata for the MCP client
File without changes
@@ -0,0 +1,235 @@
1
+ """MCP wrapper client for ForgingStack Ration, v0.1.0.
2
+
3
+ An agent-native service must be usable by agents, not just by humans
4
+ with curl. MCP is the standard interface agents already speak, so the
5
+ wrapper exposes the same live REST API as MCP tools, with no duplicated
6
+ decision logic: every tool call goes through the REST API, so metering
7
+ and receipts stay in one place. The service itself is private; this
8
+ file is only a client.
9
+
10
+ Protocol: JSON-RPC 2.0 over stdio, no new dependencies (stdlib only).
11
+ Supported methods: initialize, ping, tools/list, tools/call.
12
+ Notifications (no id, e.g. notifications/initialized) get no response.
13
+
14
+ Environment:
15
+ FORGINGSTACK_API_BASE default https://forgingstack-ration.jkbattles.workers.dev
16
+ FORGINGSTACK_API_KEY required; sign up via POST /v1/signup (key shown once)
17
+
18
+ Run: python -m app.mcp_server
19
+ """
20
+
21
+ import json
22
+ import os
23
+ import sys
24
+ import urllib.error
25
+ import urllib.request
26
+
27
+ BASE = os.environ.get(
28
+ "FORGINGSTACK_API_BASE",
29
+ "https://forgingstack-ration.jkbattles.workers.dev",
30
+ )
31
+ API_KEY = os.environ.get("FORGINGSTACK_API_KEY", "")
32
+
33
+ TOOLS = [
34
+ {
35
+ "name": "create_pool",
36
+ "description": "Create a token-bucket quota pool shared by many agents. "
37
+ "Costs 1 credit. Returns the pool with its starting availability.",
38
+ "inputSchema": {
39
+ "type": "object",
40
+ "properties": {
41
+ "name": {"type": "string"},
42
+ "capacity_units": {"type": "integer"},
43
+ "refill_units_per_minute": {"type": "number"},
44
+ "per_agent_cap_units": {"type": "integer"},
45
+ "burst_units": {"type": "integer"},
46
+ },
47
+ "required": [
48
+ "name", "capacity_units", "refill_units_per_minute",
49
+ "per_agent_cap_units", "burst_units",
50
+ ],
51
+ },
52
+ },
53
+ {
54
+ "name": "draw",
55
+ "description": "Draw units from a pool for one agent. Returns allowed "
56
+ "or denied, a reason, and a hash-chained receipt. Costs 1 credit "
57
+ "per draw call, allowed or denied; an idempotency key replay is free.",
58
+ "inputSchema": {
59
+ "type": "object",
60
+ "properties": {
61
+ "pool_id": {"type": "integer"},
62
+ "agent_id": {"type": "string"},
63
+ "units": {"type": "integer"},
64
+ "idempotency_key": {"type": "string"},
65
+ },
66
+ "required": ["pool_id", "agent_id", "units"],
67
+ },
68
+ },
69
+ {
70
+ "name": "get_pool",
71
+ "description": "Fetch one pool by id, with its current available units "
72
+ "(refill applied).",
73
+ "inputSchema": {
74
+ "type": "object",
75
+ "properties": {"pool_id": {"type": "integer"}},
76
+ "required": ["pool_id"],
77
+ },
78
+ },
79
+ {
80
+ "name": "list_pools",
81
+ "description": "List all pools owned by the configured API key.",
82
+ "inputSchema": {"type": "object", "properties": {}},
83
+ },
84
+ {
85
+ "name": "topup_pool",
86
+ "description": "Add units to a pool, clamped at capacity. Free — no "
87
+ "billing credit is charged.",
88
+ "inputSchema": {
89
+ "type": "object",
90
+ "properties": {
91
+ "pool_id": {"type": "integer"},
92
+ "units": {"type": "integer"},
93
+ },
94
+ "required": ["pool_id", "units"],
95
+ },
96
+ },
97
+ {
98
+ "name": "delete_pool",
99
+ "description": "Delete a pool and its draws. No billing credit is "
100
+ "charged or refunded.",
101
+ "inputSchema": {
102
+ "type": "object",
103
+ "properties": {"pool_id": {"type": "integer"}},
104
+ "required": ["pool_id"],
105
+ },
106
+ },
107
+ {
108
+ "name": "get_credits",
109
+ "description": "Remaining credit balance for the configured API key.",
110
+ "inputSchema": {"type": "object", "properties": {}},
111
+ },
112
+ {
113
+ "name": "get_receipt",
114
+ "description": "Fetch a past draw receipt by id.",
115
+ "inputSchema": {
116
+ "type": "object",
117
+ "properties": {"receipt_id": {"type": "integer"}},
118
+ "required": ["receipt_id"],
119
+ },
120
+ },
121
+ ]
122
+
123
+
124
+ def _http(method, path, body=None, idempotency_key=None):
125
+ req = urllib.request.Request(
126
+ BASE + path,
127
+ data=json.dumps(body).encode() if body is not None else None,
128
+ method=method,
129
+ )
130
+ req.add_header("X-API-Key", API_KEY)
131
+ req.add_header("Content-Type", "application/json")
132
+ # A User-Agent is required: the default Python urllib agent is
133
+ # rejected (Cloudflare 1010) through some egress paths.
134
+ req.add_header("User-Agent", "ForgingStack-Ration/0.1.0")
135
+ if idempotency_key:
136
+ req.add_header("Idempotency-Key", idempotency_key)
137
+ try:
138
+ with urllib.request.urlopen(req, timeout=30) as resp:
139
+ return resp.status, json.loads(resp.read().decode() or "{}")
140
+ except urllib.error.HTTPError as e:
141
+ try:
142
+ return e.code, json.loads(e.read().decode() or "{}")
143
+ except Exception:
144
+ return e.code, {"detail": "api error"}
145
+
146
+
147
+ def _text(payload, is_error=False):
148
+ return {
149
+ "content": [{"type": "text", "text": json.dumps(payload)}],
150
+ "isError": is_error,
151
+ }
152
+
153
+
154
+ def handle(msg):
155
+ method = msg.get("method")
156
+ params = msg.get("params") or {}
157
+ if method == "initialize":
158
+ return {
159
+ "protocolVersion": "2024-11-05",
160
+ "capabilities": {"tools": {}},
161
+ "serverInfo": {"name": "forgingstack-ration", "version": "0.1.0"},
162
+ }
163
+ if method == "ping":
164
+ return {}
165
+ if method == "tools/list":
166
+ return {"tools": TOOLS}
167
+ if method == "tools/call":
168
+ name = params.get("name")
169
+ args = params.get("arguments") or {}
170
+ if name == "create_pool":
171
+ body = {k: args[k] for k in
172
+ ("name", "capacity_units", "refill_units_per_minute",
173
+ "per_agent_cap_units", "burst_units")}
174
+ status, data = _http("POST", "/v1/pools", body)
175
+ return _text(data, is_error=status >= 400)
176
+ if name == "draw":
177
+ body = {"agent_id": args["agent_id"], "units": args["units"]}
178
+ status, data = _http(
179
+ "POST", f"/v1/pools/{args['pool_id']}/draw", body,
180
+ args.get("idempotency_key"),
181
+ )
182
+ return _text(data, is_error=status >= 400)
183
+ if name == "get_pool":
184
+ status, data = _http("GET", f"/v1/pools/{args['pool_id']}")
185
+ return _text(data, is_error=status >= 400)
186
+ if name == "list_pools":
187
+ status, data = _http("GET", "/v1/pools")
188
+ return _text(data, is_error=status >= 400)
189
+ if name == "topup_pool":
190
+ status, data = _http(
191
+ "POST", f"/v1/pools/{args['pool_id']}/topup",
192
+ {"units": args["units"]},
193
+ )
194
+ return _text(data, is_error=status >= 400)
195
+ if name == "delete_pool":
196
+ status, data = _http("DELETE", f"/v1/pools/{args['pool_id']}")
197
+ return _text(data, is_error=status >= 400)
198
+ if name == "get_credits":
199
+ status, data = _http("GET", "/v1/credits")
200
+ return _text(data, is_error=status >= 400)
201
+ if name == "get_receipt":
202
+ status, data = _http(
203
+ "GET", f"/v1/receipts/{args['receipt_id']}"
204
+ )
205
+ return _text(data, is_error=status >= 400)
206
+ raise ValueError(f"unknown tool: {name}")
207
+ raise ValueError(f"unknown method: {method}")
208
+
209
+
210
+ def main():
211
+ for line in sys.stdin:
212
+ line = line.strip()
213
+ if not line:
214
+ continue
215
+ try:
216
+ msg = json.loads(line)
217
+ except json.JSONDecodeError:
218
+ continue
219
+ # Notifications carry no id and get no response.
220
+ if "id" not in msg:
221
+ continue
222
+ try:
223
+ result = handle(msg)
224
+ out = {"jsonrpc": "2.0", "id": msg["id"], "result": result}
225
+ except Exception as exc: # noqa: BLE001 - MCP error surface
226
+ out = {
227
+ "jsonrpc": "2.0", "id": msg["id"],
228
+ "error": {"code": -32603, "message": str(exc)},
229
+ }
230
+ sys.stdout.write(json.dumps(out) + "\n")
231
+ sys.stdout.flush()
232
+
233
+
234
+ if __name__ == "__main__":
235
+ main()
@@ -0,0 +1,96 @@
1
+ Metadata-Version: 2.4
2
+ Name: forgingstack-ration
3
+ Version: 0.1.0
4
+ Summary: One quota pool, many agents, no overruns.
5
+ License: MIT
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # ForgingStack Ration
12
+
13
+ One quota pool, many agents, no overruns.
14
+
15
+ mcp-name: io.github.jdkabattles/forgingstack-ration
16
+
17
+ This is the **public client** for Ration. The service itself — the
18
+ token bucket, the receipt chain, the key store, and billing — runs
19
+ on ForgingStack's private service and is **not** in this repo.
20
+ Copying this repo does not give you the service: you still need an
21
+ API key and credits, from signup below.
22
+
23
+ Live API: https://forgingstack-ration.jkbattles.workers.dev
24
+
25
+ ## What it does
26
+
27
+ A principal creates a pool with a capacity, a refill rate, a
28
+ per-agent cap, and a burst limit. Agents draw units from it. The
29
+ pool enforces the limits and issues a hash-chained receipt for
30
+ every draw attempt — allowed **and** denied.
31
+
32
+ A draw is denied when:
33
+
34
+ - the units exceed the burst limit (`draw_exceeds_burst`)
35
+ - the pool does not have enough available units
36
+ (`pool_insufficient_units`)
37
+ - the agent's allowed draws inside the rolling 60-minute window
38
+ would exceed the per-agent cap (`per_agent_cap_exceeded`)
39
+
40
+ The per-agent cap window is a rolling 60 minutes — a documented
41
+ design choice, not a calendar window.
42
+
43
+ ## Signup (v1)
44
+
45
+ ```bash
46
+ curl -X POST https://forgingstack-ration.jkbattles.workers.dev/v1/signup \
47
+ -H "Content-Type: application/json" \
48
+ -d '{"email":"you@example.com"}'
49
+ ```
50
+
51
+ Returns an API key **once** and 100 starter credits. Save the key
52
+ immediately — it is stored only as a hash and cannot be shown again.
53
+ Click the verification link in the signup email before the key can
54
+ create pools or draw: until then, pool creation and draws return
55
+ 403 `email_not_verified`.
56
+
57
+ ## Buying more credits
58
+
59
+ 1 credit per pool creation, 1 credit per draw call (allowed or
60
+ denied). Top-ups, pool reads, pool lists, and deletes are free.
61
+
62
+ ```bash
63
+ curl -X POST https://forgingstack-ration.jkbattles.workers.dev/v1/billing/checkout \
64
+ -H "X-API-Key: YOUR_PRIMARY_KEY"
65
+ ```
66
+
67
+ Returns the Stripe Payment Link: **$10 for 1,000 credits**. Pay on
68
+ Stripe's hosted page with the same email you signed up with.
69
+ Credits land once the payment is verified (within the hour).
70
+
71
+ ## Use it (MCP, stdio)
72
+
73
+ Set the key, then run the MCP server in this repo:
74
+
75
+ ```bash
76
+ export FORGINGSTACK_API_KEY="your-key-here"
77
+ python -m app.mcp_server
78
+ ```
79
+
80
+ Tools: `create_pool`, `draw`, `get_pool`, `list_pools`,
81
+ `topup_pool`, `delete_pool`, `get_credits`, `get_receipt`.
82
+ See `SKILL.md` for when to use it and when not to.
83
+
84
+ ## Price
85
+
86
+ 1 credit per pool creation. 1 credit per draw call — a denied draw
87
+ still costs 1 credit, the draw was performed. An idempotent replay
88
+ (same `Idempotency-Key`) is free and returns the original receipt.
89
+
90
+ ## Files in this repo
91
+
92
+ - `app/mcp_server.py` — MCP wrapper client (stdio, stdlib only)
93
+ - `SKILL.md` — when to use it, how to read allowed/denied
94
+ - `agent-card.json` — A2A-style discovery card
95
+ - `server.json` — MCP Registry metadata
96
+ - `pyproject.toml` — package metadata for the MCP client
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ app/__init__.py
5
+ app/mcp_server.py
6
+ forgingstack_ration.egg-info/PKG-INFO
7
+ forgingstack_ration.egg-info/SOURCES.txt
8
+ forgingstack_ration.egg-info/dependency_links.txt
9
+ forgingstack_ration.egg-info/entry_points.txt
10
+ forgingstack_ration.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ forgingstack-ration = app.mcp_server:main
@@ -0,0 +1,22 @@
1
+ # MCP server package for ForgingStack Ration (stdlib only).
2
+ # The live REST API is a separate private service, not this package.
3
+
4
+ [build-system]
5
+ requires = ["setuptools>=61"]
6
+ build-backend = "setuptools.build_meta"
7
+
8
+ [project]
9
+ name = "forgingstack-ration"
10
+ version = "0.1.0"
11
+ description = "One quota pool, many agents, no overruns."
12
+ license = {text="MIT"}
13
+ readme = "README.md"
14
+ requires-python = ">=3.10"
15
+ dependencies = []
16
+
17
+
18
+ [project.scripts]
19
+ forgingstack-ration = "app.mcp_server:main"
20
+
21
+ [tool.setuptools.packages.find]
22
+ include = ["app*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+