@cenogram/mcp-server 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +292 -0
- package/dist/api-client.d.ts +203 -0
- package/dist/api-client.js +177 -0
- package/dist/client-id.d.ts +1 -0
- package/dist/client-id.js +38 -0
- package/dist/formatters.d.ts +12 -0
- package/dist/formatters.js +235 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +110 -0
- package/dist/mappings.d.ts +8 -0
- package/dist/mappings.js +49 -0
- package/dist/tools.d.ts +2 -0
- package/dist/tools.js +264 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cenogram (cenogram.pl)
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
# Cenogram MCP Server
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@cenogram/mcp-server)
|
|
4
|
+
[](https://nodejs.org)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
**Polish Real Estate Transaction Data for AI**
|
|
8
|
+
|
|
9
|
+
MCP server for Polish real estate data. Access 7M+ real estate transactions from the national Registry of Prices and Values (Rejestr Cen Nieruchomosci, RCN) directly from Claude, Cursor, or any MCP-compatible AI assistant.
|
|
10
|
+
|
|
11
|
+
Data source: Polish national RCN registry (Rejestr Cen Nieruchomosci) | Platform: [cenogram.pl](https://cenogram.pl)
|
|
12
|
+
|
|
13
|
+
## Get your API key
|
|
14
|
+
|
|
15
|
+
1. Go to [cenogram.pl/api](https://cenogram.pl/api)
|
|
16
|
+
2. Enter your email
|
|
17
|
+
3. You'll receive your `cngrm_...` API key by email
|
|
18
|
+
|
|
19
|
+
Manage your keys at [cenogram.pl/ustawienia](https://cenogram.pl/ustawienia).
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Pick your client. All options below use the hosted server — no local install needed (except npx/stdio).
|
|
24
|
+
|
|
25
|
+
<details open>
|
|
26
|
+
<summary><strong>Claude Code</strong></summary>
|
|
27
|
+
|
|
28
|
+
One command — zero config files:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
claude mcp add cenogram https://mcp.cenogram.pl/mcp \
|
|
32
|
+
-t http -H "Authorization: Bearer YOUR_API_KEY"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
</details>
|
|
36
|
+
|
|
37
|
+
<details>
|
|
38
|
+
<summary><strong>Cursor</strong></summary>
|
|
39
|
+
|
|
40
|
+
Add to `.cursor/mcp.json` in your project:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"mcpServers": {
|
|
45
|
+
"cenogram": {
|
|
46
|
+
"type": "http",
|
|
47
|
+
"url": "https://mcp.cenogram.pl/mcp",
|
|
48
|
+
"headers": {
|
|
49
|
+
"Authorization": "Bearer YOUR_API_KEY"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
</details>
|
|
57
|
+
|
|
58
|
+
<details>
|
|
59
|
+
<summary><strong>Claude Desktop</strong></summary>
|
|
60
|
+
|
|
61
|
+
Add to your config file:
|
|
62
|
+
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
63
|
+
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
64
|
+
|
|
65
|
+
**HTTP remote** (Claude Desktop 0.9+):
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"mcpServers": {
|
|
69
|
+
"cenogram": {
|
|
70
|
+
"type": "http",
|
|
71
|
+
"url": "https://mcp.cenogram.pl/mcp",
|
|
72
|
+
"headers": {
|
|
73
|
+
"Authorization": "Bearer YOUR_API_KEY"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Stdio fallback** (older versions — requires Node.js >= 18):
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"mcpServers": {
|
|
84
|
+
"cenogram": {
|
|
85
|
+
"command": "npx",
|
|
86
|
+
"args": ["-y", "@cenogram/mcp-server@latest"],
|
|
87
|
+
"env": {
|
|
88
|
+
"CENOGRAM_API_KEY": "YOUR_API_KEY"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
</details>
|
|
96
|
+
|
|
97
|
+
<details>
|
|
98
|
+
<summary><strong>VS Code / GitHub Copilot</strong></summary>
|
|
99
|
+
|
|
100
|
+
Add to `.vscode/mcp.json` in your workspace:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"servers": {
|
|
105
|
+
"cenogram": {
|
|
106
|
+
"type": "http",
|
|
107
|
+
"url": "https://mcp.cenogram.pl/mcp",
|
|
108
|
+
"headers": {
|
|
109
|
+
"Authorization": "Bearer YOUR_API_KEY"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
</details>
|
|
117
|
+
|
|
118
|
+
<details>
|
|
119
|
+
<summary><strong>Windsurf</strong></summary>
|
|
120
|
+
|
|
121
|
+
Add to `~/.codeium/windsurf/mcp_config.json`:
|
|
122
|
+
|
|
123
|
+
**HTTP remote:**
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"mcpServers": {
|
|
127
|
+
"cenogram": {
|
|
128
|
+
"type": "http",
|
|
129
|
+
"url": "https://mcp.cenogram.pl/mcp",
|
|
130
|
+
"headers": {
|
|
131
|
+
"Authorization": "Bearer YOUR_API_KEY"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
If HTTP doesn't work, use the **npx (stdio)** option below instead.
|
|
139
|
+
|
|
140
|
+
</details>
|
|
141
|
+
|
|
142
|
+
<details>
|
|
143
|
+
<summary><strong>Cline</strong></summary>
|
|
144
|
+
|
|
145
|
+
In VS Code: Settings > Cline > MCP Servers. Add:
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"cenogram": {
|
|
150
|
+
"type": "http",
|
|
151
|
+
"url": "https://mcp.cenogram.pl/mcp",
|
|
152
|
+
"headers": {
|
|
153
|
+
"Authorization": "Bearer YOUR_API_KEY"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
</details>
|
|
160
|
+
|
|
161
|
+
<details>
|
|
162
|
+
<summary><strong>npx (stdio) — local/offline</strong></summary>
|
|
163
|
+
|
|
164
|
+
Requires **Node.js >= 18**. Use this if you want to run the server locally instead of connecting to the hosted one.
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"mcpServers": {
|
|
169
|
+
"cenogram": {
|
|
170
|
+
"command": "npx",
|
|
171
|
+
"args": ["-y", "@cenogram/mcp-server@latest"],
|
|
172
|
+
"env": {
|
|
173
|
+
"CENOGRAM_API_KEY": "YOUR_API_KEY"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
| Client | Config file |
|
|
181
|
+
|---|---|
|
|
182
|
+
| Cursor | `.cursor/mcp.json` |
|
|
183
|
+
| Claude Code | `.mcp.json` in your project |
|
|
184
|
+
| Claude Desktop | `~/Library/Application Support/Claude/claude_desktop_config.json` |
|
|
185
|
+
| Windsurf | `~/.codeium/windsurf/mcp_config.json` |
|
|
186
|
+
| Cline | VS Code settings > Cline > MCP Servers |
|
|
187
|
+
|
|
188
|
+
</details>
|
|
189
|
+
|
|
190
|
+
## Configuration
|
|
191
|
+
|
|
192
|
+
| Env Variable | Required | Default | Description |
|
|
193
|
+
|---|---|---|---|
|
|
194
|
+
| `CENOGRAM_API_KEY` | **Yes** (stdio) | — | API key from [cenogram.pl/api](https://cenogram.pl/api) |
|
|
195
|
+
| `CENOGRAM_API_URL` | No | `https://cenogram.pl` | API base URL |
|
|
196
|
+
| `MCP_TRANSPORT` | No | `stdio` | Set to `http` for Streamable HTTP mode |
|
|
197
|
+
| `MCP_PORT` | No | `3002` | HTTP server port (HTTP mode only) |
|
|
198
|
+
| `CENOGRAM_CLIENT_ID` | No | auto-generated | Persistent client identifier |
|
|
199
|
+
|
|
200
|
+
You can also use the `--http` CLI flag instead of `MCP_TRANSPORT=http`.
|
|
201
|
+
|
|
202
|
+
## Example Prompts
|
|
203
|
+
|
|
204
|
+
**Polish:**
|
|
205
|
+
- "Jaka jest mediana cen mieszkan w Krakowie w 2025?"
|
|
206
|
+
- "Pokaz transakcje z ulicy Pulawskiej 15 na Mokotowie"
|
|
207
|
+
- "Znajdz transakcje na dzialce 146518_8.0108.27"
|
|
208
|
+
- "Znajdz transakcje gruntow w promieniu 5km od centrum Wroclawia powyzej 500 000 PLN"
|
|
209
|
+
- "Porownaj ceny mieszkan na Mokotowie i Woli"
|
|
210
|
+
- "Pokaz rozklad cen nieruchomosci w Polsce"
|
|
211
|
+
|
|
212
|
+
**English:**
|
|
213
|
+
- "What's the median apartment price in Krakow in 2025?"
|
|
214
|
+
- "Show transactions at Pulawska 15 in Mokotow"
|
|
215
|
+
- "Find all transactions on parcel 146502_8.0901.12 and then search nearby"
|
|
216
|
+
- "Find land transactions within 5km of Wroclaw center above 500,000 PLN"
|
|
217
|
+
- "Compare apartment prices in Mokotow and Wola districts"
|
|
218
|
+
- "Show the price distribution of real estate in Poland"
|
|
219
|
+
|
|
220
|
+
## Tools
|
|
221
|
+
|
|
222
|
+
| Tool | Description | Key Parameters |
|
|
223
|
+
|---|---|---|
|
|
224
|
+
| `search_transactions` | Search transactions with filters | location, street, buildingNumber, parcelId, propertyType, marketType, price/date/area range |
|
|
225
|
+
| `get_price_statistics` | Price/m2 stats by location (residential only) | location (optional) |
|
|
226
|
+
| `get_price_distribution` | Price histogram | bins, maxPrice |
|
|
227
|
+
| `search_by_area` | Search by geographic radius | latitude, longitude, radiusKm |
|
|
228
|
+
| `get_market_overview` | Database overview and stats | (none) |
|
|
229
|
+
| `list_locations` | List available locations | search (optional) |
|
|
230
|
+
| `search_parcels` | Search parcels by cadastral ID prefix | q (parcel ID prefix, min 3 chars) |
|
|
231
|
+
| `search_by_polygon` | Search within a GeoJSON polygon | polygon, propertyType, dateFrom/dateTo |
|
|
232
|
+
| `compare_locations` | Compare stats across 2-5 districts | districts (comma-separated), propertyType |
|
|
233
|
+
|
|
234
|
+
### Location naming
|
|
235
|
+
|
|
236
|
+
- Most cities: use the city name directly (e.g., "Gdansk", "Lublin")
|
|
237
|
+
- Warsaw: use district names ("Mokotow", "Srodmiescie", "Wola") -- "Warszawa" won't match
|
|
238
|
+
- Krakow: use sub-districts ("Krakow-Podgorze", "Krakow-Srodmiescie") — plain "Krakow" won't match
|
|
239
|
+
- Use `list_locations` to find valid names
|
|
240
|
+
|
|
241
|
+
### Property types
|
|
242
|
+
|
|
243
|
+
| Value | Polish | English |
|
|
244
|
+
|---|---|---|
|
|
245
|
+
| `land` | Grunt | Land plot |
|
|
246
|
+
| `building` | Budynek | Building |
|
|
247
|
+
| `developed_land` | Grunt zabudowany | Developed land |
|
|
248
|
+
| `unit` | Lokal | Apartment/unit |
|
|
249
|
+
|
|
250
|
+
### Workflows
|
|
251
|
+
|
|
252
|
+
Results include parcel IDs and GPS coordinates, enabling multi-step research:
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
1. Search by address -> search_transactions(location="Mokotow", street="Pulawska", buildingNumber="15")
|
|
256
|
+
2. Note parcel_id and coordinates from results
|
|
257
|
+
3. Search nearby -> search_by_area(lat=52.19, lng=21.01, radiusKm=2, propertyType="unit")
|
|
258
|
+
4. Compare prices -> get_price_statistics(location="Mokotow")
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
This mimics how a property appraiser finds comparable transactions for valuation reports.
|
|
262
|
+
|
|
263
|
+
## Data
|
|
264
|
+
|
|
265
|
+
- **7M+ transactions** from all of Poland (380+ counties)
|
|
266
|
+
- **Date range:** 2003 - present
|
|
267
|
+
- **Source:** Polish national RCN registry (Rejestr Cen Nieruchomosci)
|
|
268
|
+
- **Refresh:** periodic updates from RCN
|
|
269
|
+
|
|
270
|
+
## Troubleshooting
|
|
271
|
+
|
|
272
|
+
**"Error: CENOGRAM_API_KEY is required"** — This only applies to stdio mode. Make sure `CENOGRAM_API_KEY` is set in the `env` block of your MCP config. For HTTP remote, the key goes in the `Authorization` header instead.
|
|
273
|
+
|
|
274
|
+
**npx hangs or fails** — Check your Node.js version with `node -v`. The stdio mode requires Node.js >= 18. If you're on an older version, use the HTTP remote option instead (no Node.js needed).
|
|
275
|
+
|
|
276
|
+
**"Warszawa" returns 0 results** — Warsaw uses district names (Mokotow, Wola, Srodmiescie, Bemowo, etc.). Use `list_locations(search="warsz")` to find valid names. Same applies to Krakow (use "Krakow-Podgorze", "Krakow-Srodmiescie", etc.).
|
|
277
|
+
|
|
278
|
+
**401 Unauthorized (HTTP mode)** — The `Authorization` header must be `Bearer cngrm_...` (with the `Bearer` prefix). Double-check that the full API key is included, not just the prefix.
|
|
279
|
+
|
|
280
|
+
## Development
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
git clone https://github.com/cenogram/mcp-server.git
|
|
284
|
+
cd mcp-server
|
|
285
|
+
npm install
|
|
286
|
+
npm test
|
|
287
|
+
npm run build
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## License
|
|
291
|
+
|
|
292
|
+
MIT
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
export interface StatsResponse {
|
|
2
|
+
counts: {
|
|
3
|
+
transactions: number;
|
|
4
|
+
parcels: number;
|
|
5
|
+
buildings: number;
|
|
6
|
+
units: number;
|
|
7
|
+
addresses: number;
|
|
8
|
+
};
|
|
9
|
+
prices: {
|
|
10
|
+
total: number;
|
|
11
|
+
avg_price: number;
|
|
12
|
+
median_price: number;
|
|
13
|
+
min_price: number;
|
|
14
|
+
max_price: number;
|
|
15
|
+
};
|
|
16
|
+
dateRange: {
|
|
17
|
+
min_date: string;
|
|
18
|
+
max_date: string;
|
|
19
|
+
};
|
|
20
|
+
byDistrict: {
|
|
21
|
+
district: string;
|
|
22
|
+
transaction_count: number;
|
|
23
|
+
}[];
|
|
24
|
+
byPropertyType: {
|
|
25
|
+
type: number;
|
|
26
|
+
total: number;
|
|
27
|
+
label: string;
|
|
28
|
+
}[];
|
|
29
|
+
byMarketType: {
|
|
30
|
+
type: number;
|
|
31
|
+
total: number;
|
|
32
|
+
label: string;
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
35
|
+
export interface Transaction {
|
|
36
|
+
id: string;
|
|
37
|
+
transaction_date: string;
|
|
38
|
+
property_type: number;
|
|
39
|
+
market_type: number;
|
|
40
|
+
price_gross: number;
|
|
41
|
+
usable_area_m2: number | null;
|
|
42
|
+
price_per_m2: number | null;
|
|
43
|
+
rooms: number | null;
|
|
44
|
+
floor: number | null;
|
|
45
|
+
district: string | null;
|
|
46
|
+
street: string | null;
|
|
47
|
+
building_number: string | null;
|
|
48
|
+
city: string | null;
|
|
49
|
+
parcel_area: number | null;
|
|
50
|
+
unit_function: number | null;
|
|
51
|
+
parcel_id: string | null;
|
|
52
|
+
county_name: string | null;
|
|
53
|
+
voivodeship_name: string | null;
|
|
54
|
+
centroid: {
|
|
55
|
+
type: string;
|
|
56
|
+
coordinates: [number, number];
|
|
57
|
+
} | null;
|
|
58
|
+
}
|
|
59
|
+
export interface TransactionsResponse {
|
|
60
|
+
data: Transaction[];
|
|
61
|
+
pagination: {
|
|
62
|
+
page: number;
|
|
63
|
+
limit: number;
|
|
64
|
+
total: number;
|
|
65
|
+
pages: number;
|
|
66
|
+
estimated?: boolean;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export interface TransactionsSummary {
|
|
70
|
+
median_price_m2: number | null;
|
|
71
|
+
avg_area: number | null;
|
|
72
|
+
min_date: string | null;
|
|
73
|
+
max_date: string | null;
|
|
74
|
+
total: number;
|
|
75
|
+
}
|
|
76
|
+
export interface PricePerM2Row {
|
|
77
|
+
district: string;
|
|
78
|
+
avg_price_m2: number;
|
|
79
|
+
median_price_m2: number;
|
|
80
|
+
count: number;
|
|
81
|
+
}
|
|
82
|
+
export interface HistogramBin {
|
|
83
|
+
bucket: number;
|
|
84
|
+
count: number;
|
|
85
|
+
range_min: number;
|
|
86
|
+
range_max: number;
|
|
87
|
+
}
|
|
88
|
+
export interface CreditInfo {
|
|
89
|
+
balance: number;
|
|
90
|
+
cost: number;
|
|
91
|
+
}
|
|
92
|
+
export interface ApiResponse<T> {
|
|
93
|
+
data: T;
|
|
94
|
+
creditInfo: CreditInfo | null;
|
|
95
|
+
}
|
|
96
|
+
export declare function fetchApi<T>(path: string, params?: Record<string, string>, apiKey?: string): Promise<ApiResponse<T>>;
|
|
97
|
+
export declare function fetchApiPost<T>(path: string, body: unknown, apiKey?: string): Promise<ApiResponse<T>>;
|
|
98
|
+
export declare function getStats(apiKey?: string): Promise<ApiResponse<StatsResponse>>;
|
|
99
|
+
export interface TransactionParams {
|
|
100
|
+
district?: string;
|
|
101
|
+
street?: string;
|
|
102
|
+
buildingNumber?: string;
|
|
103
|
+
parcelId?: string;
|
|
104
|
+
propertyType?: number;
|
|
105
|
+
marketType?: number;
|
|
106
|
+
minPrice?: number;
|
|
107
|
+
maxPrice?: number;
|
|
108
|
+
dateFrom?: string;
|
|
109
|
+
dateTo?: string;
|
|
110
|
+
minArea?: number;
|
|
111
|
+
maxArea?: number;
|
|
112
|
+
bbox?: string;
|
|
113
|
+
limit?: number;
|
|
114
|
+
page?: number;
|
|
115
|
+
sort?: string;
|
|
116
|
+
order?: string;
|
|
117
|
+
}
|
|
118
|
+
export declare function getTransactions(p: TransactionParams, apiKey?: string): Promise<ApiResponse<TransactionsResponse>>;
|
|
119
|
+
export declare function getTransactionsSummary(p: TransactionParams, apiKey?: string): Promise<ApiResponse<TransactionsSummary>>;
|
|
120
|
+
export declare function getPricePerM2(apiKey?: string): Promise<ApiResponse<PricePerM2Row[]>>;
|
|
121
|
+
export declare function getDistricts(apiKey?: string): Promise<ApiResponse<string[]>>;
|
|
122
|
+
export declare function getPriceHistogram(bins?: number, max?: number, apiKey?: string): Promise<ApiResponse<HistogramBin[]>>;
|
|
123
|
+
export interface ParcelSearchResult {
|
|
124
|
+
parcel_id: string;
|
|
125
|
+
district: string | null;
|
|
126
|
+
area_m2: number | null;
|
|
127
|
+
lat: number;
|
|
128
|
+
lng: number;
|
|
129
|
+
}
|
|
130
|
+
export interface ParcelSearchResponse {
|
|
131
|
+
results: ParcelSearchResult[];
|
|
132
|
+
}
|
|
133
|
+
export declare function searchParcels(q: string, limit?: number, apiKey?: string): Promise<ApiResponse<ParcelSearchResponse>>;
|
|
134
|
+
export interface SpatialSearchParams {
|
|
135
|
+
polygon: {
|
|
136
|
+
type: "Polygon";
|
|
137
|
+
coordinates: number[][][];
|
|
138
|
+
};
|
|
139
|
+
propertyType?: number;
|
|
140
|
+
marketType?: number;
|
|
141
|
+
minPrice?: number;
|
|
142
|
+
maxPrice?: number;
|
|
143
|
+
dateFrom?: string;
|
|
144
|
+
dateTo?: string;
|
|
145
|
+
minArea?: number;
|
|
146
|
+
maxArea?: number;
|
|
147
|
+
district?: string;
|
|
148
|
+
street?: string;
|
|
149
|
+
limit?: number;
|
|
150
|
+
}
|
|
151
|
+
export interface SpatialFeatureProperties {
|
|
152
|
+
id: string;
|
|
153
|
+
price_gross: number;
|
|
154
|
+
transaction_date: string;
|
|
155
|
+
property_type: number;
|
|
156
|
+
market_type: number;
|
|
157
|
+
usable_area_m2: number | null;
|
|
158
|
+
price_per_m2: number | null;
|
|
159
|
+
rooms: number | null;
|
|
160
|
+
floor: number | null;
|
|
161
|
+
street: string | null;
|
|
162
|
+
building_number: string | null;
|
|
163
|
+
city: string | null;
|
|
164
|
+
district: string | null;
|
|
165
|
+
parcel_area: number | null;
|
|
166
|
+
}
|
|
167
|
+
export interface SpatialFeature {
|
|
168
|
+
type: "Feature";
|
|
169
|
+
geometry: {
|
|
170
|
+
type: string;
|
|
171
|
+
coordinates: [number, number];
|
|
172
|
+
} | null;
|
|
173
|
+
properties: SpatialFeatureProperties;
|
|
174
|
+
}
|
|
175
|
+
export interface SpatialSearchResponse {
|
|
176
|
+
type: "FeatureCollection";
|
|
177
|
+
features: SpatialFeature[];
|
|
178
|
+
truncated: boolean;
|
|
179
|
+
total: number;
|
|
180
|
+
}
|
|
181
|
+
export declare function searchByPolygon(p: SpatialSearchParams, apiKey?: string): Promise<ApiResponse<SpatialSearchResponse>>;
|
|
182
|
+
export interface CompareEntry {
|
|
183
|
+
median_price_m2: number | null;
|
|
184
|
+
avg_area: number | null;
|
|
185
|
+
min_date: string | null;
|
|
186
|
+
max_date: string | null;
|
|
187
|
+
total: number;
|
|
188
|
+
suggestions?: string[];
|
|
189
|
+
}
|
|
190
|
+
export type CompareResponse = Record<string, CompareEntry>;
|
|
191
|
+
export interface CompareParams {
|
|
192
|
+
districts: string;
|
|
193
|
+
propertyType?: number;
|
|
194
|
+
marketType?: number;
|
|
195
|
+
minPrice?: number;
|
|
196
|
+
maxPrice?: number;
|
|
197
|
+
dateFrom?: string;
|
|
198
|
+
dateTo?: string;
|
|
199
|
+
minArea?: number;
|
|
200
|
+
maxArea?: number;
|
|
201
|
+
street?: string;
|
|
202
|
+
}
|
|
203
|
+
export declare function compareLocations(p: CompareParams, apiKey?: string): Promise<ApiResponse<CompareResponse>>;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { getClientId } from "./client-id.js";
|
|
2
|
+
const BASE_URL = process.env.CENOGRAM_API_URL || "https://cenogram.pl";
|
|
3
|
+
function extractCreditInfo(res) {
|
|
4
|
+
if (!res.headers)
|
|
5
|
+
return null;
|
|
6
|
+
const balance = parseInt(res.headers.get("X-Credits-Balance") ?? "", 10);
|
|
7
|
+
const cost = parseInt(res.headers.get("X-Credits-Cost") ?? "", 10);
|
|
8
|
+
if (isNaN(balance) || isNaN(cost))
|
|
9
|
+
return null;
|
|
10
|
+
return { balance, cost };
|
|
11
|
+
}
|
|
12
|
+
// ── Shared HTTP helpers ────────────────────────────────────────────
|
|
13
|
+
function buildHeaders(apiKey) {
|
|
14
|
+
const headers = {
|
|
15
|
+
"X-Source": "mcp-server",
|
|
16
|
+
"X-Cenogram-Client-Id": getClientId(),
|
|
17
|
+
};
|
|
18
|
+
const key = apiKey ?? process.env.CENOGRAM_API_KEY;
|
|
19
|
+
if (key)
|
|
20
|
+
headers["Authorization"] = `Bearer ${key}`;
|
|
21
|
+
return headers;
|
|
22
|
+
}
|
|
23
|
+
async function handleErrorResponse(res) {
|
|
24
|
+
if (res.status === 402) {
|
|
25
|
+
const body = await res.json().catch(() => ({}));
|
|
26
|
+
throw new Error(`Niewystarczające tokeny API. Saldo: ${body.currentBalance ?? 0}, wymagane: ${body.creditsRequired ?? "?"}. Doładuj: https://cenogram.pl/api#cennik`);
|
|
27
|
+
}
|
|
28
|
+
if (res.status === 429) {
|
|
29
|
+
const retryAfter = res.headers?.get?.("Retry-After");
|
|
30
|
+
const days = retryAfter ? Math.ceil(parseInt(retryAfter, 10) / 86400) : null;
|
|
31
|
+
const resetInfo = days !== null ? ` Reset za ${days} ${days === 1 ? "dzień" : "dni"}.` : "";
|
|
32
|
+
throw new Error(`Zbyt wiele zapytań.${resetInfo}`);
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`API error: HTTP ${res.status}`);
|
|
35
|
+
}
|
|
36
|
+
function toQueryParams(obj) {
|
|
37
|
+
const params = {};
|
|
38
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
39
|
+
if (v != null && v !== "")
|
|
40
|
+
params[k] = String(v);
|
|
41
|
+
}
|
|
42
|
+
return params;
|
|
43
|
+
}
|
|
44
|
+
// ── HTTP client ─────────────────────────────────────────────────────
|
|
45
|
+
export async function fetchApi(path, params, apiKey) {
|
|
46
|
+
const url = new URL(path, BASE_URL);
|
|
47
|
+
if (params) {
|
|
48
|
+
for (const [k, v] of Object.entries(params)) {
|
|
49
|
+
if (v !== undefined && v !== "")
|
|
50
|
+
url.searchParams.set(k, v);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const controller = new AbortController();
|
|
54
|
+
const timeout = setTimeout(() => controller.abort(), 10_000);
|
|
55
|
+
try {
|
|
56
|
+
const res = await fetch(url.toString(), { signal: controller.signal, headers: buildHeaders(apiKey) });
|
|
57
|
+
if (!res.ok)
|
|
58
|
+
await handleErrorResponse(res);
|
|
59
|
+
return { data: (await res.json()), creditInfo: extractCreditInfo(res) };
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
clearTimeout(timeout);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export async function fetchApiPost(path, body, apiKey) {
|
|
66
|
+
const url = new URL(path, BASE_URL);
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
const timeout = setTimeout(() => controller.abort(), 30_000);
|
|
69
|
+
try {
|
|
70
|
+
const headers = buildHeaders(apiKey);
|
|
71
|
+
headers["Content-Type"] = "application/json";
|
|
72
|
+
const res = await fetch(url.toString(), {
|
|
73
|
+
method: "POST",
|
|
74
|
+
signal: controller.signal,
|
|
75
|
+
headers,
|
|
76
|
+
body: JSON.stringify(body),
|
|
77
|
+
});
|
|
78
|
+
if (!res.ok)
|
|
79
|
+
await handleErrorResponse(res);
|
|
80
|
+
return { data: (await res.json()), creditInfo: extractCreditInfo(res) };
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
clearTimeout(timeout);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// ── Typed wrappers ──────────────────────────────────────────────────
|
|
87
|
+
export function getStats(apiKey) {
|
|
88
|
+
return fetchApi("/api/stats", undefined, apiKey);
|
|
89
|
+
}
|
|
90
|
+
export function getTransactions(p, apiKey) {
|
|
91
|
+
return fetchApi("/api/transactions", toQueryParams({
|
|
92
|
+
district: p.district,
|
|
93
|
+
street: p.street,
|
|
94
|
+
buildingNumber: p.buildingNumber,
|
|
95
|
+
parcelId: p.parcelId,
|
|
96
|
+
propertyType: p.propertyType,
|
|
97
|
+
marketType: p.marketType,
|
|
98
|
+
minPrice: p.minPrice,
|
|
99
|
+
maxPrice: p.maxPrice,
|
|
100
|
+
dateFrom: p.dateFrom,
|
|
101
|
+
dateTo: p.dateTo,
|
|
102
|
+
minArea: p.minArea,
|
|
103
|
+
maxArea: p.maxArea,
|
|
104
|
+
bbox: p.bbox,
|
|
105
|
+
limit: p.limit,
|
|
106
|
+
page: p.page,
|
|
107
|
+
sort: p.sort,
|
|
108
|
+
order: p.order,
|
|
109
|
+
}), apiKey);
|
|
110
|
+
}
|
|
111
|
+
export function getTransactionsSummary(p, apiKey) {
|
|
112
|
+
return fetchApi("/api/transactions/summary", toQueryParams({
|
|
113
|
+
district: p.district,
|
|
114
|
+
street: p.street,
|
|
115
|
+
propertyType: p.propertyType,
|
|
116
|
+
marketType: p.marketType,
|
|
117
|
+
minPrice: p.minPrice,
|
|
118
|
+
maxPrice: p.maxPrice,
|
|
119
|
+
dateFrom: p.dateFrom,
|
|
120
|
+
dateTo: p.dateTo,
|
|
121
|
+
minArea: p.minArea,
|
|
122
|
+
maxArea: p.maxArea,
|
|
123
|
+
bbox: p.bbox,
|
|
124
|
+
}), apiKey);
|
|
125
|
+
}
|
|
126
|
+
export function getPricePerM2(apiKey) {
|
|
127
|
+
return fetchApi("/api/price-per-m2", undefined, apiKey);
|
|
128
|
+
}
|
|
129
|
+
export function getDistricts(apiKey) {
|
|
130
|
+
return fetchApi("/api/districts", undefined, apiKey);
|
|
131
|
+
}
|
|
132
|
+
export function getPriceHistogram(bins = 20, max = 3_000_000, apiKey) {
|
|
133
|
+
return fetchApi("/api/stats/price-histogram", toQueryParams({ bins, max }), apiKey);
|
|
134
|
+
}
|
|
135
|
+
export function searchParcels(q, limit, apiKey) {
|
|
136
|
+
return fetchApi("/api/parcels/search", toQueryParams({ q, limit }), apiKey);
|
|
137
|
+
}
|
|
138
|
+
export function searchByPolygon(p, apiKey) {
|
|
139
|
+
const body = { polygon: p.polygon };
|
|
140
|
+
if (p.propertyType != null)
|
|
141
|
+
body.propertyType = p.propertyType;
|
|
142
|
+
if (p.marketType != null)
|
|
143
|
+
body.marketType = p.marketType;
|
|
144
|
+
if (p.minPrice != null)
|
|
145
|
+
body.minPrice = p.minPrice;
|
|
146
|
+
if (p.maxPrice != null)
|
|
147
|
+
body.maxPrice = p.maxPrice;
|
|
148
|
+
if (p.dateFrom)
|
|
149
|
+
body.dateFrom = p.dateFrom;
|
|
150
|
+
if (p.dateTo)
|
|
151
|
+
body.dateTo = p.dateTo;
|
|
152
|
+
if (p.minArea != null)
|
|
153
|
+
body.minArea = p.minArea;
|
|
154
|
+
if (p.maxArea != null)
|
|
155
|
+
body.maxArea = p.maxArea;
|
|
156
|
+
if (p.district)
|
|
157
|
+
body.district = p.district;
|
|
158
|
+
if (p.street)
|
|
159
|
+
body.street = p.street;
|
|
160
|
+
if (p.limit != null)
|
|
161
|
+
body.limit = p.limit;
|
|
162
|
+
return fetchApiPost("/api/transactions/spatial", body, apiKey);
|
|
163
|
+
}
|
|
164
|
+
export function compareLocations(p, apiKey) {
|
|
165
|
+
return fetchApi("/api/transactions/summary/compare", toQueryParams({
|
|
166
|
+
districts: p.districts,
|
|
167
|
+
propertyType: p.propertyType,
|
|
168
|
+
marketType: p.marketType,
|
|
169
|
+
minPrice: p.minPrice,
|
|
170
|
+
maxPrice: p.maxPrice,
|
|
171
|
+
dateFrom: p.dateFrom,
|
|
172
|
+
dateTo: p.dateTo,
|
|
173
|
+
minArea: p.minArea,
|
|
174
|
+
maxArea: p.maxArea,
|
|
175
|
+
street: p.street,
|
|
176
|
+
}), apiKey);
|
|
177
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getClientId(): string;
|