sens-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.
- sens_mcp-0.1.0/.github/workflows/publish.yml +47 -0
- sens_mcp-0.1.0/.gitignore +8 -0
- sens_mcp-0.1.0/PKG-INFO +157 -0
- sens_mcp-0.1.0/README.md +137 -0
- sens_mcp-0.1.0/configs/claude_desktop_config.json +11 -0
- sens_mcp-0.1.0/configs/cursor_mcp.json +11 -0
- sens_mcp-0.1.0/examples/curl/api_requests.sh +42 -0
- sens_mcp-0.1.0/examples/python/async_stream.py +39 -0
- sens_mcp-0.1.0/examples/python/get_prices.py +39 -0
- sens_mcp-0.1.0/examples/python/list_tariffs.py +35 -0
- sens_mcp-0.1.0/examples/typescript/get_prices.ts +49 -0
- sens_mcp-0.1.0/examples/typescript/package.json +14 -0
- sens_mcp-0.1.0/npm-wrapper/README.md +45 -0
- sens_mcp-0.1.0/npm-wrapper/bin/sens-mcp.js +37 -0
- sens_mcp-0.1.0/npm-wrapper/package.json +34 -0
- sens_mcp-0.1.0/npm-wrapper/test/sens-mcp.test.js +24 -0
- sens_mcp-0.1.0/pyproject.toml +44 -0
- sens_mcp-0.1.0/src/sens_mcp/__init__.py +3 -0
- sens_mcp-0.1.0/src/sens_mcp/__main__.py +8 -0
- sens_mcp-0.1.0/src/sens_mcp/client.py +238 -0
- sens_mcp-0.1.0/src/sens_mcp/discovery.py +261 -0
- sens_mcp-0.1.0/src/sens_mcp/formatter.py +89 -0
- sens_mcp-0.1.0/src/sens_mcp/models.py +129 -0
- sens_mcp-0.1.0/src/sens_mcp/server.py +200 -0
- sens_mcp-0.1.0/tests/test_client.py +72 -0
- sens_mcp-0.1.0/tests/test_discovery.py +90 -0
- sens_mcp-0.1.0/tests/test_formatter.py +66 -0
- sens_mcp-0.1.0/tests/test_live_integration.py +226 -0
- sens_mcp-0.1.0/tests/test_server_tools.py +154 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
# Tag-triggered, not on every push to main -- publishing a package version is a deliberate
|
|
4
|
+
# release action, not something that should happen on every merge. Push a tag matching the
|
|
5
|
+
# version in both pyproject.toml and npm-wrapper/package.json (e.g. v0.1.0) to release both.
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
tags:
|
|
9
|
+
- 'v*'
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
publish-pypi:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
permissions:
|
|
15
|
+
id-token: write # not used yet (no Trusted Publishing configured on PyPI), harmless to request
|
|
16
|
+
contents: read
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: '3.12'
|
|
23
|
+
|
|
24
|
+
- run: pip install build
|
|
25
|
+
- run: python -m build
|
|
26
|
+
|
|
27
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
28
|
+
with:
|
|
29
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
30
|
+
|
|
31
|
+
publish-npm:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
defaults:
|
|
34
|
+
run:
|
|
35
|
+
working-directory: npm-wrapper
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
|
|
39
|
+
- uses: actions/setup-node@v4
|
|
40
|
+
with:
|
|
41
|
+
node-version: '20'
|
|
42
|
+
registry-url: 'https://registry.npmjs.org'
|
|
43
|
+
|
|
44
|
+
- run: npm test
|
|
45
|
+
- run: npm publish
|
|
46
|
+
env:
|
|
47
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_API_TOKEN }}
|
sens_mcp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sens-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server and developer starter kit for the SENS Polish Energy Data API
|
|
5
|
+
Author: SENS
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: energy,mcp,model-context-protocol,poland,sens
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Requires-Dist: httpx>=0.27
|
|
13
|
+
Requires-Dist: mcp<2.0.0,>=1.2.0
|
|
14
|
+
Requires-Dist: pydantic>=2.6
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
18
|
+
Requires-Dist: respx>=0.21; extra == 'dev'
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# sens-mcp
|
|
22
|
+
|
|
23
|
+
An MCP (Model Context Protocol) server and developer starter kit for the
|
|
24
|
+
[SENS Energy Data API](https://api.getsens.energy) — the Polish electricity
|
|
25
|
+
market data API (distribution operators, tariffs, and composite price
|
|
26
|
+
calculations).
|
|
27
|
+
|
|
28
|
+
It solves the "cold start" problem for LLMs and AI agents (Claude Desktop,
|
|
29
|
+
Cursor, LangChain, n8n, ...) talking to the API: the Polish energy market has
|
|
30
|
+
its own vocabulary (OSD vs. sprzedawca, tariff groups `G11`/`G12`/`G12w`/...)
|
|
31
|
+
that models don't know out of the box, and raw REST responses are too large
|
|
32
|
+
and too easy to miscalculate against by hand.
|
|
33
|
+
|
|
34
|
+
`sens-mcp` provides:
|
|
35
|
+
- **Zero-shot discoverability** — an MCP resource (`sens://market/cheat-sheet`)
|
|
36
|
+
and discovery tools (`resolve_operator`, `search_tariffs`) that teach the
|
|
37
|
+
model the market vocabulary in under ~400 tokens.
|
|
38
|
+
- **Actionable self-correction** — tool errors return structured JSON with
|
|
39
|
+
suggestions (`did you mean G12w?`) instead of raw HTTP failures, so an
|
|
40
|
+
agent in a ReAct loop can repair its own next call.
|
|
41
|
+
- **Single source of truth calculations** — all price/volume math happens on
|
|
42
|
+
the SENS backend; the toolkit never re-derives totals client-side.
|
|
43
|
+
- **Non-blocking startup** — the server boots instantly with an embedded
|
|
44
|
+
fallback market schema; live tariff metadata refreshes in the background.
|
|
45
|
+
|
|
46
|
+
## Quickstart
|
|
47
|
+
|
|
48
|
+
### Run via `uvx` (recommended, no install step)
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
export SENS_API_KEY=sens_live_your_key_here
|
|
52
|
+
uvx sens-mcp
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Or install with pip
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install sens-mcp
|
|
59
|
+
export SENS_API_KEY=sens_live_your_key_here
|
|
60
|
+
python -m sens_mcp
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Environment variables
|
|
64
|
+
|
|
65
|
+
| Variable | Required | Default | Description |
|
|
66
|
+
|---|---|---|---|
|
|
67
|
+
| `SENS_API_KEY` | Yes | — | Your SENS API key. Sent as the `X-API-KEY` header. |
|
|
68
|
+
| `SENS_BASE_URL` | No | `https://api.getsens.energy` | Override for staging/self-hosted deployments. |
|
|
69
|
+
|
|
70
|
+
## Using it with an AI agent
|
|
71
|
+
|
|
72
|
+
### Claude Desktop
|
|
73
|
+
|
|
74
|
+
Add to `claude_desktop_config.json` (see [`configs/claude_desktop_config.json`](configs/claude_desktop_config.json)):
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"mcpServers": {
|
|
79
|
+
"sens-energy": {
|
|
80
|
+
"command": "uvx",
|
|
81
|
+
"args": ["sens-mcp"],
|
|
82
|
+
"env": {
|
|
83
|
+
"SENS_API_KEY": "sens_live_your_key_here"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Cursor
|
|
91
|
+
|
|
92
|
+
Add to `.cursor/mcp.json` (see [`configs/cursor_mcp.json`](configs/cursor_mcp.json)) — same shape as above.
|
|
93
|
+
|
|
94
|
+
## Tools exposed
|
|
95
|
+
|
|
96
|
+
| Tool | Purpose |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `resolve_operator(query, region=None)` | Fuzzy-resolve a city or company name (typo-tolerant) to the exact `osd`/`sprzedawca` strings the API expects. |
|
|
99
|
+
| `search_tariffs(customer_type, zone_preference=None, operator=None)` | Discover valid tariff codes for a customer profile (home / small business / industry). |
|
|
100
|
+
| `get_prices(osd, taryfa, ...)` | Fetch composite electricity prices and rate breakdown; pass `annual_kwh` for exact volume-weighted totals. |
|
|
101
|
+
| `get_tariff_components(tariff_id)` | Inspect a tariff's URE-approved fixed/variable rate components. |
|
|
102
|
+
|
|
103
|
+
Resource: `sens://market/cheat-sheet` — a Markdown cheat sheet of Polish
|
|
104
|
+
electricity market vocabulary (OSDs, tariff groups, price component
|
|
105
|
+
structure).
|
|
106
|
+
|
|
107
|
+
## Developer examples (no MCP required)
|
|
108
|
+
|
|
109
|
+
Standalone snippets that hit the SENS REST API directly:
|
|
110
|
+
|
|
111
|
+
- [`examples/python/get_prices.py`](examples/python/get_prices.py)
|
|
112
|
+
- [`examples/python/list_tariffs.py`](examples/python/list_tariffs.py)
|
|
113
|
+
- [`examples/python/async_stream.py`](examples/python/async_stream.py) — delta sync via `since`
|
|
114
|
+
- [`examples/typescript/get_prices.ts`](examples/typescript/get_prices.ts)
|
|
115
|
+
- [`examples/curl/api_requests.sh`](examples/curl/api_requests.sh)
|
|
116
|
+
|
|
117
|
+
## API reference (essentials)
|
|
118
|
+
|
|
119
|
+
- Base URL: `https://api.getsens.energy`
|
|
120
|
+
- Auth: `X-API-KEY: <your key>` header (not Bearer, not a query param).
|
|
121
|
+
- `GET /api/v1/prices` — `osd`, `sprzedawca`, `taryfa`, `market`, `date`,
|
|
122
|
+
`annual_kwh`, `region`, `since`, `page`, `size` (max 1000).
|
|
123
|
+
- `GET /api/v1/tariffs` — `since`/`If-Modified-Since` for delta queries,
|
|
124
|
+
`page`, `size`.
|
|
125
|
+
- `GET /api/v1/tariffs/components?tariff_id=...` — component breakdown for a
|
|
126
|
+
single tariff, also supports `since`.
|
|
127
|
+
|
|
128
|
+
Full Swagger/OpenAPI docs: `https://api.getsens.energy/api/docs`.
|
|
129
|
+
Full developer documentation (quickstart, MCP integration guide, market
|
|
130
|
+
vocabulary): [docs.getsens.energy](https://docs.getsens.energy).
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
python3 -m venv .venv
|
|
136
|
+
source .venv/bin/activate
|
|
137
|
+
pip install -e ".[dev]"
|
|
138
|
+
pytest
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Tests mock all HTTP calls with [`respx`](https://lundberg.github.io/respx/) —
|
|
142
|
+
nothing in the default test suite hits the live API.
|
|
143
|
+
|
|
144
|
+
### Live integration suite (opt-in)
|
|
145
|
+
|
|
146
|
+
`tests/test_live_integration.py` runs the real server as a subprocess over
|
|
147
|
+
the real MCP stdio protocol against the real production SENS API, and checks
|
|
148
|
+
byte-for-byte parity between MCP tool responses and raw `httpx` calls to the
|
|
149
|
+
same endpoints. Excluded by default; run explicitly with a real key:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
SENS_API_KEY=<a real key> pytest -m live tests/test_live_integration.py -v
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT
|
sens_mcp-0.1.0/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# sens-mcp
|
|
2
|
+
|
|
3
|
+
An MCP (Model Context Protocol) server and developer starter kit for the
|
|
4
|
+
[SENS Energy Data API](https://api.getsens.energy) — the Polish electricity
|
|
5
|
+
market data API (distribution operators, tariffs, and composite price
|
|
6
|
+
calculations).
|
|
7
|
+
|
|
8
|
+
It solves the "cold start" problem for LLMs and AI agents (Claude Desktop,
|
|
9
|
+
Cursor, LangChain, n8n, ...) talking to the API: the Polish energy market has
|
|
10
|
+
its own vocabulary (OSD vs. sprzedawca, tariff groups `G11`/`G12`/`G12w`/...)
|
|
11
|
+
that models don't know out of the box, and raw REST responses are too large
|
|
12
|
+
and too easy to miscalculate against by hand.
|
|
13
|
+
|
|
14
|
+
`sens-mcp` provides:
|
|
15
|
+
- **Zero-shot discoverability** — an MCP resource (`sens://market/cheat-sheet`)
|
|
16
|
+
and discovery tools (`resolve_operator`, `search_tariffs`) that teach the
|
|
17
|
+
model the market vocabulary in under ~400 tokens.
|
|
18
|
+
- **Actionable self-correction** — tool errors return structured JSON with
|
|
19
|
+
suggestions (`did you mean G12w?`) instead of raw HTTP failures, so an
|
|
20
|
+
agent in a ReAct loop can repair its own next call.
|
|
21
|
+
- **Single source of truth calculations** — all price/volume math happens on
|
|
22
|
+
the SENS backend; the toolkit never re-derives totals client-side.
|
|
23
|
+
- **Non-blocking startup** — the server boots instantly with an embedded
|
|
24
|
+
fallback market schema; live tariff metadata refreshes in the background.
|
|
25
|
+
|
|
26
|
+
## Quickstart
|
|
27
|
+
|
|
28
|
+
### Run via `uvx` (recommended, no install step)
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
export SENS_API_KEY=sens_live_your_key_here
|
|
32
|
+
uvx sens-mcp
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Or install with pip
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install sens-mcp
|
|
39
|
+
export SENS_API_KEY=sens_live_your_key_here
|
|
40
|
+
python -m sens_mcp
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Environment variables
|
|
44
|
+
|
|
45
|
+
| Variable | Required | Default | Description |
|
|
46
|
+
|---|---|---|---|
|
|
47
|
+
| `SENS_API_KEY` | Yes | — | Your SENS API key. Sent as the `X-API-KEY` header. |
|
|
48
|
+
| `SENS_BASE_URL` | No | `https://api.getsens.energy` | Override for staging/self-hosted deployments. |
|
|
49
|
+
|
|
50
|
+
## Using it with an AI agent
|
|
51
|
+
|
|
52
|
+
### Claude Desktop
|
|
53
|
+
|
|
54
|
+
Add to `claude_desktop_config.json` (see [`configs/claude_desktop_config.json`](configs/claude_desktop_config.json)):
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"mcpServers": {
|
|
59
|
+
"sens-energy": {
|
|
60
|
+
"command": "uvx",
|
|
61
|
+
"args": ["sens-mcp"],
|
|
62
|
+
"env": {
|
|
63
|
+
"SENS_API_KEY": "sens_live_your_key_here"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Cursor
|
|
71
|
+
|
|
72
|
+
Add to `.cursor/mcp.json` (see [`configs/cursor_mcp.json`](configs/cursor_mcp.json)) — same shape as above.
|
|
73
|
+
|
|
74
|
+
## Tools exposed
|
|
75
|
+
|
|
76
|
+
| Tool | Purpose |
|
|
77
|
+
|---|---|
|
|
78
|
+
| `resolve_operator(query, region=None)` | Fuzzy-resolve a city or company name (typo-tolerant) to the exact `osd`/`sprzedawca` strings the API expects. |
|
|
79
|
+
| `search_tariffs(customer_type, zone_preference=None, operator=None)` | Discover valid tariff codes for a customer profile (home / small business / industry). |
|
|
80
|
+
| `get_prices(osd, taryfa, ...)` | Fetch composite electricity prices and rate breakdown; pass `annual_kwh` for exact volume-weighted totals. |
|
|
81
|
+
| `get_tariff_components(tariff_id)` | Inspect a tariff's URE-approved fixed/variable rate components. |
|
|
82
|
+
|
|
83
|
+
Resource: `sens://market/cheat-sheet` — a Markdown cheat sheet of Polish
|
|
84
|
+
electricity market vocabulary (OSDs, tariff groups, price component
|
|
85
|
+
structure).
|
|
86
|
+
|
|
87
|
+
## Developer examples (no MCP required)
|
|
88
|
+
|
|
89
|
+
Standalone snippets that hit the SENS REST API directly:
|
|
90
|
+
|
|
91
|
+
- [`examples/python/get_prices.py`](examples/python/get_prices.py)
|
|
92
|
+
- [`examples/python/list_tariffs.py`](examples/python/list_tariffs.py)
|
|
93
|
+
- [`examples/python/async_stream.py`](examples/python/async_stream.py) — delta sync via `since`
|
|
94
|
+
- [`examples/typescript/get_prices.ts`](examples/typescript/get_prices.ts)
|
|
95
|
+
- [`examples/curl/api_requests.sh`](examples/curl/api_requests.sh)
|
|
96
|
+
|
|
97
|
+
## API reference (essentials)
|
|
98
|
+
|
|
99
|
+
- Base URL: `https://api.getsens.energy`
|
|
100
|
+
- Auth: `X-API-KEY: <your key>` header (not Bearer, not a query param).
|
|
101
|
+
- `GET /api/v1/prices` — `osd`, `sprzedawca`, `taryfa`, `market`, `date`,
|
|
102
|
+
`annual_kwh`, `region`, `since`, `page`, `size` (max 1000).
|
|
103
|
+
- `GET /api/v1/tariffs` — `since`/`If-Modified-Since` for delta queries,
|
|
104
|
+
`page`, `size`.
|
|
105
|
+
- `GET /api/v1/tariffs/components?tariff_id=...` — component breakdown for a
|
|
106
|
+
single tariff, also supports `since`.
|
|
107
|
+
|
|
108
|
+
Full Swagger/OpenAPI docs: `https://api.getsens.energy/api/docs`.
|
|
109
|
+
Full developer documentation (quickstart, MCP integration guide, market
|
|
110
|
+
vocabulary): [docs.getsens.energy](https://docs.getsens.energy).
|
|
111
|
+
|
|
112
|
+
## Development
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
python3 -m venv .venv
|
|
116
|
+
source .venv/bin/activate
|
|
117
|
+
pip install -e ".[dev]"
|
|
118
|
+
pytest
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Tests mock all HTTP calls with [`respx`](https://lundberg.github.io/respx/) —
|
|
122
|
+
nothing in the default test suite hits the live API.
|
|
123
|
+
|
|
124
|
+
### Live integration suite (opt-in)
|
|
125
|
+
|
|
126
|
+
`tests/test_live_integration.py` runs the real server as a subprocess over
|
|
127
|
+
the real MCP stdio protocol against the real production SENS API, and checks
|
|
128
|
+
byte-for-byte parity between MCP tool responses and raw `httpx` calls to the
|
|
129
|
+
same endpoints. Excluded by default; run explicitly with a real key:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
SENS_API_KEY=<a real key> pytest -m live tests/test_live_integration.py -v
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
MIT
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# cURL examples for the SENS Energy Data API.
|
|
3
|
+
#
|
|
4
|
+
# Usage:
|
|
5
|
+
# export SENS_API_KEY=sens_live_your_key_here
|
|
6
|
+
# ./api_requests.sh
|
|
7
|
+
|
|
8
|
+
set -euo pipefail
|
|
9
|
+
|
|
10
|
+
BASE_URL="${SENS_BASE_URL:-https://api.getsens.energy}"
|
|
11
|
+
|
|
12
|
+
if [[ -z "${SENS_API_KEY:-}" ]]; then
|
|
13
|
+
echo "Set SENS_API_KEY before running this script." >&2
|
|
14
|
+
exit 1
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
echo "== Get composite prices for TAURON G12w, 3000 kWh/year =="
|
|
18
|
+
curl -sS -H "X-API-KEY: ${SENS_API_KEY}" \
|
|
19
|
+
--get "${BASE_URL}/api/v1/prices" \
|
|
20
|
+
--data-urlencode "osd=TAURON Dystrybucja S.A." \
|
|
21
|
+
--data-urlencode "taryfa=G12w" \
|
|
22
|
+
--data-urlencode "annual_kwh=3000" | head -c 2000
|
|
23
|
+
echo
|
|
24
|
+
|
|
25
|
+
echo "== List first page of tariffs =="
|
|
26
|
+
curl -sS -H "X-API-KEY: ${SENS_API_KEY}" \
|
|
27
|
+
--get "${BASE_URL}/api/v1/tariffs" \
|
|
28
|
+
--data-urlencode "page=0" \
|
|
29
|
+
--data-urlencode "size=20" | head -c 2000
|
|
30
|
+
echo
|
|
31
|
+
|
|
32
|
+
echo "== Delta-fetch tariffs changed since a date =="
|
|
33
|
+
curl -sS -H "X-API-KEY: ${SENS_API_KEY}" \
|
|
34
|
+
--get "${BASE_URL}/api/v1/tariffs" \
|
|
35
|
+
--data-urlencode "since=2026-08-01" | head -c 2000
|
|
36
|
+
echo
|
|
37
|
+
|
|
38
|
+
echo "== Get tariff components for a specific tariff_id =="
|
|
39
|
+
curl -sS -H "X-API-KEY: ${SENS_API_KEY}" \
|
|
40
|
+
--get "${BASE_URL}/api/v1/tariffs/components" \
|
|
41
|
+
--data-urlencode "tariff_id=REPLACE_WITH_TARIFF_ID" | head -c 2000
|
|
42
|
+
echo
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Async delta-sync example: poll /api/v1/tariffs with `since` to fetch only
|
|
2
|
+
rows that changed after a given timestamp — useful for keeping a local cache
|
|
3
|
+
warm without re-downloading the full tariff catalog each time.
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
export SENS_API_KEY=sens_live_your_key_here
|
|
7
|
+
python async_stream.py
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import asyncio
|
|
13
|
+
import os
|
|
14
|
+
from datetime import datetime, timedelta, timezone
|
|
15
|
+
|
|
16
|
+
import httpx
|
|
17
|
+
|
|
18
|
+
BASE_URL = os.environ.get("SENS_BASE_URL", "https://api.getsens.energy")
|
|
19
|
+
API_KEY = os.environ["SENS_API_KEY"]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
async def fetch_since(client: httpx.AsyncClient, since: str) -> list[dict]:
|
|
23
|
+
resp = await client.get("/api/v1/tariffs", params={"since": since, "size": 1000})
|
|
24
|
+
resp.raise_for_status()
|
|
25
|
+
data = resp.json()
|
|
26
|
+
return data.get("items", data.get("content", []))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
async def main() -> None:
|
|
30
|
+
since = (datetime.now(timezone.utc) - timedelta(days=1)).isoformat()
|
|
31
|
+
async with httpx.AsyncClient(base_url=BASE_URL, headers={"X-API-KEY": API_KEY}, timeout=15.0) as client:
|
|
32
|
+
rows = await fetch_since(client, since)
|
|
33
|
+
print(f"{len(rows)} tariff rows changed since {since}")
|
|
34
|
+
for row in rows[:10]:
|
|
35
|
+
print(f" {row.get('tariff_code')} updated_at={row.get('updated_at')}")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if __name__ == "__main__":
|
|
39
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Fetch composite electricity prices from the SENS API directly (no MCP).
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
export SENS_API_KEY=sens_live_your_key_here
|
|
5
|
+
python get_prices.py
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
import httpx
|
|
13
|
+
|
|
14
|
+
BASE_URL = os.environ.get("SENS_BASE_URL", "https://api.getsens.energy")
|
|
15
|
+
API_KEY = os.environ["SENS_API_KEY"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main() -> None:
|
|
19
|
+
resp = httpx.get(
|
|
20
|
+
f"{BASE_URL}/api/v1/prices",
|
|
21
|
+
params={
|
|
22
|
+
"osd": "TAURON Dystrybucja S.A.",
|
|
23
|
+
"taryfa": "G12w",
|
|
24
|
+
"annual_kwh": 3000,
|
|
25
|
+
},
|
|
26
|
+
headers={"X-API-KEY": API_KEY},
|
|
27
|
+
timeout=15.0,
|
|
28
|
+
)
|
|
29
|
+
resp.raise_for_status()
|
|
30
|
+
data = resp.json()
|
|
31
|
+
|
|
32
|
+
print(f"mode: {data['meta']['mode']}")
|
|
33
|
+
for offer in data.get("offers", []):
|
|
34
|
+
summary = offer.get("summary", {})
|
|
35
|
+
print(f" {offer['tariff_code']}: avg {summary.get('total_avg_pln_per_kwh')} PLN/kWh")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if __name__ == "__main__":
|
|
39
|
+
main()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""List tariffs from the SENS API with pagination.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
export SENS_API_KEY=sens_live_your_key_here
|
|
5
|
+
python list_tariffs.py
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
import httpx
|
|
13
|
+
|
|
14
|
+
BASE_URL = os.environ.get("SENS_BASE_URL", "https://api.getsens.energy")
|
|
15
|
+
API_KEY = os.environ["SENS_API_KEY"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main() -> None:
|
|
19
|
+
page = 0
|
|
20
|
+
size = 100
|
|
21
|
+
with httpx.Client(base_url=BASE_URL, headers={"X-API-KEY": API_KEY}, timeout=15.0) as client:
|
|
22
|
+
while True:
|
|
23
|
+
resp = client.get("/api/v1/tariffs", params={"page": page, "size": size})
|
|
24
|
+
resp.raise_for_status()
|
|
25
|
+
data = resp.json()
|
|
26
|
+
items = data.get("items", data.get("content", []))
|
|
27
|
+
for row in items:
|
|
28
|
+
print(f"{row.get('tariff_code'):8s} {row.get('operator_name')}")
|
|
29
|
+
if len(items) < size:
|
|
30
|
+
break
|
|
31
|
+
page += 1
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if __name__ == "__main__":
|
|
35
|
+
main()
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Fetch composite electricity prices from the SENS API directly (no MCP).
|
|
2
|
+
//
|
|
3
|
+
// Usage:
|
|
4
|
+
// export SENS_API_KEY=sens_live_your_key_here
|
|
5
|
+
// npx tsx get_prices.ts
|
|
6
|
+
|
|
7
|
+
const BASE_URL = process.env.SENS_BASE_URL ?? "https://api.getsens.energy";
|
|
8
|
+
const API_KEY = process.env.SENS_API_KEY;
|
|
9
|
+
|
|
10
|
+
if (!API_KEY) {
|
|
11
|
+
throw new Error("Set SENS_API_KEY before running this example.");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface OfferSummary {
|
|
15
|
+
total_avg_pln_per_kwh?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface Offer {
|
|
19
|
+
tariff_code: string;
|
|
20
|
+
summary: OfferSummary;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface PriceResponse {
|
|
24
|
+
meta: { mode: string };
|
|
25
|
+
offers: Offer[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function main(): Promise<void> {
|
|
29
|
+
const url = new URL(`${BASE_URL}/api/v1/prices`);
|
|
30
|
+
url.searchParams.set("osd", "TAURON Dystrybucja S.A.");
|
|
31
|
+
url.searchParams.set("taryfa", "G12w");
|
|
32
|
+
url.searchParams.set("annual_kwh", "3000");
|
|
33
|
+
|
|
34
|
+
const res = await fetch(url, { headers: { "X-API-KEY": API_KEY as string } });
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
throw new Error(`SENS API error: ${res.status} ${await res.text()}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const data = (await res.json()) as PriceResponse;
|
|
40
|
+
console.log(`mode: ${data.meta.mode}`);
|
|
41
|
+
for (const offer of data.offers ?? []) {
|
|
42
|
+
console.log(` ${offer.tariff_code}: avg ${offer.summary?.total_avg_pln_per_kwh} PLN/kWh`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
main().catch((err) => {
|
|
47
|
+
console.error(err);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sens-mcp-examples-ts",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "TypeScript examples for the SENS Energy Data API",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"get-prices": "tsx get_prices.ts"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"tsx": "^4.7.0",
|
|
12
|
+
"typescript": "^5.4.0"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @getsens/mcp-server
|
|
2
|
+
|
|
3
|
+
`npx`-installable wrapper for [`sens-mcp`](https://pypi.org/project/sens-mcp/)
|
|
4
|
+
(the real MCP server — a Python package, distributed via `uv`/`pip`).
|
|
5
|
+
|
|
6
|
+
This package exists only so Node/npm users have a familiar `npx` entry point.
|
|
7
|
+
It does not reimplement anything: it checks for `uv` on your `PATH` and then
|
|
8
|
+
runs `uvx sens-mcp`, forwarding all arguments and environment variables
|
|
9
|
+
(including `SENS_API_KEY`).
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- [`uv`](https://docs.astral.sh/uv/getting-started/installation/) installed
|
|
14
|
+
and on your `PATH`. If it isn't, the wrapper prints an install link and
|
|
15
|
+
exits — it does not attempt to install anything on your behalf.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
export SENS_API_KEY=sens_live_your_key_here
|
|
21
|
+
npx @getsens/mcp-server
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or in an MCP client config (e.g. Claude Desktop):
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"mcpServers": {
|
|
29
|
+
"sens-energy": {
|
|
30
|
+
"command": "npx",
|
|
31
|
+
"args": ["-y", "@getsens/mcp-server"],
|
|
32
|
+
"env": { "SENS_API_KEY": "sens_live_your_key_here" }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
See the [full documentation](https://docs.getsens.energy) for everything
|
|
39
|
+
`sens-mcp` provides (tools, resources, market vocabulary).
|
|
40
|
+
|
|
41
|
+
## Development
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm test
|
|
45
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const childProcess = require("node:child_process");
|
|
5
|
+
|
|
6
|
+
function hasUvx() {
|
|
7
|
+
const check = childProcess.spawnSync("uvx", ["--version"], { stdio: "ignore" });
|
|
8
|
+
return check.error === undefined && check.status === 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function main() {
|
|
12
|
+
if (!hasUvx()) {
|
|
13
|
+
console.error(
|
|
14
|
+
"sens-mcp needs `uv` (the Python package manager) to run — it wasn't found on your PATH.\n" +
|
|
15
|
+
"Install it from https://docs.astral.sh/uv/getting-started/installation/ and try again."
|
|
16
|
+
);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const result = childProcess.spawnSync("uvx", ["sens-mcp", ...process.argv.slice(2)], {
|
|
21
|
+
stdio: "inherit",
|
|
22
|
+
env: process.env,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (result.error) {
|
|
26
|
+
console.error(`Failed to launch sens-mcp via uvx: ${result.error.message}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
process.exit(result.status ?? 1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = { hasUvx };
|
|
34
|
+
|
|
35
|
+
if (require.main === module) {
|
|
36
|
+
main();
|
|
37
|
+
}
|