teryt-mcp 0.1.2 → 0.1.3

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
+ import * as _mcp_craftman_core from '@mcp-craftman/core';
2
+ import { RuntimeConfig } from '@mcp-craftman/node';
3
+
4
+ type DatasetCode = "TERC" | "SIMC" | "ULIC" | "WMRODZ";
5
+
6
+ type SourceFile = {
7
+ readonly dataset: DatasetCode;
8
+ readonly content: Uint8Array;
9
+ readonly sourceUrl: string;
10
+ readonly stateDate: string;
11
+ };
12
+ type TerytSource = {
13
+ readonly download: (dataset: DatasetCode) => Promise<SourceFile>;
14
+ };
15
+
16
+ type CreateAppOverrides = {
17
+ readonly syncSource?: TerytSource;
18
+ };
19
+ declare function createApp(config?: RuntimeConfig, overrides?: CreateAppOverrides): _mcp_craftman_core.McpApp;
20
+
21
+ export { createApp as c };
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var terytMcpVersion = "0.1.2";
2
+ var terytMcpVersion = "0.1.3";
3
3
 
4
4
  // src/features/server-status/application/get-server-status.ts
5
5
  function getServerStatus(input) {
@@ -71,210 +71,6 @@ function createServerStatusTool(input) {
71
71
  import { createMcpApp } from "@mcp-craftman/core";
72
72
  import { loadRuntimeConfig } from "@mcp-craftman/node";
73
73
 
74
- // src/features/get-place/infrastructure/in-memory-place-details-repository.ts
75
- var fixturePlaces = [
76
- {
77
- id: "0009876",
78
- name: "Boles\u0142awiec",
79
- stateDate: "2026-01-01",
80
- unitId: "02-01-01-1"
81
- },
82
- {
83
- id: "0012345",
84
- name: "Stara Wie\u015B",
85
- stateDate: "2026-01-01",
86
- unitId: "02-01-02-2"
87
- }
88
- ];
89
- var InMemoryPlaceDetailsRepository = class {
90
- async getPlace(id) {
91
- return fixturePlaces.find((place) => place.id === id) ?? null;
92
- }
93
- };
94
-
95
- // src/features/get-street/infrastructure/in-memory-street-details-repository.ts
96
- var fixtureStreets = [
97
- {
98
- code: "0000123",
99
- id: "0009876-0000123",
100
- name: "Marsza\u0142kowska",
101
- placeId: "0009876",
102
- stateDate: "2026-01-01"
103
- },
104
- {
105
- code: "0000456",
106
- id: "0009876-0000456",
107
- name: "Rynek",
108
- placeId: "0009876",
109
- stateDate: "2026-01-01"
110
- }
111
- ];
112
- var InMemoryStreetDetailsRepository = class {
113
- async getStreet(id) {
114
- return fixtureStreets.find((street) => street.id === id || street.code === id) ?? null;
115
- }
116
- };
117
-
118
- // src/features/get-unit/infrastructure/in-memory-unit-details-repository.ts
119
- var fixtureStateDate = "2026-01-01";
120
- var fixtureUnits = [
121
- {
122
- id: "02",
123
- name: "DOLNO\u015AL\u0104SKIE",
124
- stateDate: fixtureStateDate,
125
- type: "wojew\xF3dztwo"
126
- },
127
- {
128
- id: "02-01-01-1",
129
- name: "Boles\u0142awiec",
130
- stateDate: fixtureStateDate,
131
- type: "gmina miejska"
132
- },
133
- {
134
- id: "02-01-02-2",
135
- name: "Boles\u0142awiec",
136
- stateDate: fixtureStateDate,
137
- type: "gmina wiejska"
138
- }
139
- ];
140
- var InMemoryUnitDetailsRepository = class {
141
- async getUnit(id) {
142
- return fixtureUnits.find((unit) => unit.id === id) ?? null;
143
- }
144
- };
145
-
146
- // src/features/resolve-address/infrastructure/in-memory-address-repository.ts
147
- var fixturePlace = {
148
- id: "0009876",
149
- name: "Boles\u0142awiec"
150
- };
151
- var fixtureStateDate2 = "2026-01-01";
152
- var fixtureUnit = {
153
- id: "02-01-01-1",
154
- name: "Boles\u0142awiec",
155
- type: "gmina miejska"
156
- };
157
- var fixtureAddresses = [
158
- {
159
- id: "0009876-0000123",
160
- place: fixturePlace,
161
- stateDate: fixtureStateDate2,
162
- street: {
163
- code: "0000123",
164
- id: "0009876-0000123",
165
- name: "Marsza\u0142kowska"
166
- },
167
- unit: fixtureUnit
168
- },
169
- {
170
- id: "0009876-0000456",
171
- place: fixturePlace,
172
- stateDate: fixtureStateDate2,
173
- street: {
174
- code: "0000456",
175
- id: "0009876-0000456",
176
- name: "Rynek"
177
- },
178
- unit: fixtureUnit
179
- }
180
- ];
181
- var InMemoryAddressRepository = class {
182
- async listAddresses() {
183
- return fixtureAddresses;
184
- }
185
- };
186
-
187
- // src/features/search-places/infrastructure/in-memory-place-repository.ts
188
- var fixtureStateDate3 = "2026-01-01";
189
- var fixturePlaces2 = [
190
- {
191
- id: "0009876",
192
- name: "Boles\u0142awiec",
193
- stateDate: fixtureStateDate3,
194
- unitId: "02-01-01-1"
195
- },
196
- {
197
- id: "0011111",
198
- name: "Krak\xF3w",
199
- stateDate: fixtureStateDate3,
200
- unitId: "12-61-01-1"
201
- },
202
- {
203
- id: "0012222",
204
- name: "Warszawa",
205
- stateDate: fixtureStateDate3,
206
- unitId: "14-65-01-1"
207
- },
208
- {
209
- id: "0012345",
210
- name: "Stara Wie\u015B",
211
- stateDate: fixtureStateDate3,
212
- unitId: "02-01-02-2"
213
- },
214
- {
215
- id: "0013333",
216
- name: "D\u0105browa",
217
- stateDate: fixtureStateDate3,
218
- unitId: "24-01-01-2"
219
- }
220
- ];
221
- var InMemoryPlaceRepository = class {
222
- async listPlaces() {
223
- return fixturePlaces2;
224
- }
225
- };
226
-
227
- // src/features/search-streets/infrastructure/in-memory-street-repository.ts
228
- var fixtureStreets2 = [
229
- {
230
- code: "0000123",
231
- id: "0009876-0000123",
232
- name: "Marsza\u0142kowska",
233
- placeId: "0009876",
234
- stateDate: "2026-01-01"
235
- },
236
- {
237
- code: "0000456",
238
- id: "0009876-0000456",
239
- name: "Rynek",
240
- placeId: "0009876",
241
- stateDate: "2026-01-01"
242
- }
243
- ];
244
- var InMemoryStreetRepository = class {
245
- async listStreets() {
246
- return fixtureStreets2;
247
- }
248
- };
249
-
250
- // src/features/search-units/infrastructure/in-memory-unit-repository.ts
251
- var fixtureStateDate4 = "2026-01-01";
252
- var fixtureUnits2 = [
253
- {
254
- id: "02",
255
- name: "DOLNO\u015AL\u0104SKIE",
256
- stateDate: fixtureStateDate4,
257
- type: "wojew\xF3dztwo"
258
- },
259
- {
260
- id: "02-01-01-1",
261
- name: "Boles\u0142awiec",
262
- stateDate: fixtureStateDate4,
263
- type: "gmina miejska"
264
- },
265
- {
266
- id: "02-01-02-2",
267
- name: "Boles\u0142awiec",
268
- stateDate: fixtureStateDate4,
269
- type: "gmina wiejska"
270
- }
271
- ];
272
- var InMemoryUnitRepository = class {
273
- async listUnits() {
274
- return fixtureUnits2;
275
- }
276
- };
277
-
278
74
  // src/features/source-status/infrastructure/eteryt-source-catalog.ts
279
75
  var SOURCE_URL = "https://eteryt.stat.gov.pl/eTeryt/";
280
76
  var EterytSourceCatalog = class {
@@ -820,7 +616,7 @@ function insertStreets(db, rows) {
820
616
  `${row.values.SYM ?? ""}-${row.values.SYM_UL ?? ""}`,
821
617
  row.values.SYM ?? "",
822
618
  row.values.SYM_UL ?? "",
823
- [row.values.CECHA, row.values.NAZWA_1, row.values.NAZWA_2].filter(Boolean).join(" "),
619
+ [row.values.NAZWA_1, row.values.NAZWA_2].filter(Boolean).join(" "),
824
620
  row.values.SYM ?? "",
825
621
  row.values.STAN_NA ?? ""
826
622
  ]);
@@ -837,7 +633,7 @@ function findImport(imports, dataset) {
837
633
  return imported;
838
634
  }
839
635
  function createUnitId2(values) {
840
- return [values.WOJ ?? "", values.POW ?? "", values.GMI ?? "", values.RODZ ?? values.RODZ_GMI ?? ""].join("-");
636
+ return [values.WOJ, values.POW, values.GMI, values.RODZ ?? values.RODZ_GMI].filter(Boolean).join("-");
841
637
  }
842
638
 
843
639
  // src/features/sync-database/infrastructure/sqlite-database-builder.ts
@@ -937,6 +733,176 @@ function rollback(db) {
937
733
  }
938
734
  }
939
735
 
736
+ // src/features/sync-database/infrastructure/sqlite-query.ts
737
+ import { readFile as readFile2 } from "fs/promises";
738
+ import { join as join5 } from "path";
739
+ import initSqlJs2 from "sql.js";
740
+ var sqlJs2;
741
+ async function withTerytDatabase(dataDir, callback) {
742
+ let content;
743
+ try {
744
+ content = await readFile2(join5(dataDir, "teryt.sqlite"));
745
+ } catch (error) {
746
+ if (isMissingFile2(error)) {
747
+ const db2 = await createEmptyDatabase();
748
+ try {
749
+ return callback(db2);
750
+ } finally {
751
+ db2.close();
752
+ }
753
+ }
754
+ throw error;
755
+ }
756
+ const SQL = await loadSqlJs2();
757
+ const db = new SQL.Database(content);
758
+ try {
759
+ return callback(db);
760
+ } finally {
761
+ db.close();
762
+ }
763
+ }
764
+ function queryOne(db, sql, params, map) {
765
+ return queryMany(db, sql, params, map)[0] ?? null;
766
+ }
767
+ function queryMany(db, sql, params, map) {
768
+ const statement = db.prepare(sql);
769
+ const rows = [];
770
+ try {
771
+ statement.bind([...params]);
772
+ while (statement.step()) {
773
+ rows.push(map(statement.getAsObject()));
774
+ }
775
+ } finally {
776
+ statement.free();
777
+ }
778
+ return rows;
779
+ }
780
+ async function createEmptyDatabase() {
781
+ const SQL = await loadSqlJs2();
782
+ const db = new SQL.Database();
783
+ db.run("CREATE TABLE places (id TEXT, name TEXT, stateDate TEXT, unitId TEXT)");
784
+ db.run("CREATE TABLE streets (SYM_UL TEXT, id TEXT, name TEXT, placeId TEXT, stateDate TEXT)");
785
+ db.run("CREATE TABLE units (id TEXT, name TEXT, stateDate TEXT, type TEXT)");
786
+ return db;
787
+ }
788
+ function loadSqlJs2() {
789
+ sqlJs2 ??= initSqlJs2();
790
+ return sqlJs2;
791
+ }
792
+ function isMissingFile2(error) {
793
+ return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
794
+ }
795
+
796
+ // src/features/sync-database/infrastructure/sqlite-teryt-repository.ts
797
+ var SqliteTerytRepository = class {
798
+ constructor(dataDir) {
799
+ this.dataDir = dataDir;
800
+ }
801
+ dataDir;
802
+ async getPlace(id) {
803
+ return withTerytDatabase(this.dataDir, (db) => queryOne(db, "SELECT id, name, stateDate, unitId FROM places WHERE id = ?", [id], mapPlace));
804
+ }
805
+ async getStreet(id) {
806
+ return withTerytDatabase(
807
+ this.dataDir,
808
+ (db) => queryOne(
809
+ db,
810
+ "SELECT SYM_UL AS code, id, name, placeId, stateDate FROM streets WHERE id = ? OR SYM_UL = ?",
811
+ [id, id],
812
+ mapStreet
813
+ )
814
+ );
815
+ }
816
+ async getUnit(id) {
817
+ return withTerytDatabase(this.dataDir, (db) => queryOne(db, "SELECT id, name, stateDate, type FROM units WHERE id = ?", [id], mapUnit));
818
+ }
819
+ async listAddresses() {
820
+ return withTerytDatabase(
821
+ this.dataDir,
822
+ (db) => queryMany(
823
+ db,
824
+ `SELECT
825
+ streets.id AS id,
826
+ streets.stateDate AS stateDate,
827
+ streets.SYM_UL AS streetCode,
828
+ streets.name AS streetName,
829
+ places.id AS placeId,
830
+ places.name AS placeName,
831
+ units.id AS unitId,
832
+ units.name AS unitName,
833
+ units.type AS unitType
834
+ FROM streets
835
+ JOIN places ON places.id = streets.placeId
836
+ JOIN units ON units.id = places.unitId
837
+ ORDER BY places.name, streets.name, streets.id`,
838
+ [],
839
+ mapAddress
840
+ )
841
+ );
842
+ }
843
+ async listPlaces() {
844
+ return withTerytDatabase(this.dataDir, (db) => queryMany(db, "SELECT id, name, stateDate, unitId FROM places ORDER BY name, id", [], mapPlace));
845
+ }
846
+ async listStreets() {
847
+ return withTerytDatabase(
848
+ this.dataDir,
849
+ (db) => queryMany(db, "SELECT SYM_UL AS code, id, name, placeId, stateDate FROM streets ORDER BY name, id", [], mapStreet)
850
+ );
851
+ }
852
+ async listUnits() {
853
+ return withTerytDatabase(this.dataDir, (db) => queryMany(db, "SELECT id, name, stateDate, type FROM units ORDER BY name, id", [], mapUnit));
854
+ }
855
+ };
856
+ function mapPlace(row) {
857
+ return {
858
+ id: readText(row.id),
859
+ name: readText(row.name),
860
+ stateDate: readText(row.stateDate),
861
+ unitId: readText(row.unitId)
862
+ };
863
+ }
864
+ function mapStreet(row) {
865
+ return {
866
+ code: readText(row.code),
867
+ id: readText(row.id),
868
+ name: readText(row.name),
869
+ placeId: readText(row.placeId),
870
+ stateDate: readText(row.stateDate)
871
+ };
872
+ }
873
+ function mapUnit(row) {
874
+ return {
875
+ id: readText(row.id),
876
+ name: readText(row.name),
877
+ stateDate: readText(row.stateDate),
878
+ type: readText(row.type)
879
+ };
880
+ }
881
+ function mapAddress(row) {
882
+ const streetId = readText(row.id);
883
+ return {
884
+ id: streetId,
885
+ place: {
886
+ id: readText(row.placeId),
887
+ name: readText(row.placeName)
888
+ },
889
+ stateDate: readText(row.stateDate),
890
+ street: {
891
+ code: readText(row.streetCode),
892
+ id: streetId,
893
+ name: readText(row.streetName)
894
+ },
895
+ unit: {
896
+ id: readText(row.unitId),
897
+ name: readText(row.unitName),
898
+ type: readText(row.unitType)
899
+ }
900
+ };
901
+ }
902
+ function readText(value) {
903
+ return typeof value === "string" ? value : "";
904
+ }
905
+
940
906
  // src/mcp/registry.ts
941
907
  import { createCapabilityRegistry } from "@mcp-craftman/core";
942
908
 
@@ -2317,6 +2283,7 @@ function createApp(config = loadRuntimeConfig(), overrides = {}) {
2317
2283
  const syncLockStore = new FileLockStore(config.dataDir);
2318
2284
  const syncManifestStore = new JsonSyncManifestStore(config.dataDir);
2319
2285
  const syncSource = overrides.syncSource ?? new EterytSource();
2286
+ const terytRepository = new SqliteTerytRepository(config.dataDir);
2320
2287
  return createMcpApp({
2321
2288
  name: "teryt-mcp",
2322
2289
  version: terytMcpVersion,
@@ -2324,13 +2291,13 @@ function createApp(config = loadRuntimeConfig(), overrides = {}) {
2324
2291
  config,
2325
2292
  manifestStore,
2326
2293
  sourceCatalog,
2327
- addressRepository: new InMemoryAddressRepository(),
2328
- placeDetailsRepository: new InMemoryPlaceDetailsRepository(),
2329
- placeRepository: new InMemoryPlaceRepository(),
2330
- streetDetailsRepository: new InMemoryStreetDetailsRepository(),
2331
- streetRepository: new InMemoryStreetRepository(),
2332
- unitDetailsRepository: new InMemoryUnitDetailsRepository(),
2333
- unitRepository: new InMemoryUnitRepository(),
2294
+ addressRepository: terytRepository,
2295
+ placeDetailsRepository: terytRepository,
2296
+ placeRepository: terytRepository,
2297
+ streetDetailsRepository: terytRepository,
2298
+ streetRepository: terytRepository,
2299
+ unitDetailsRepository: terytRepository,
2300
+ unitRepository: terytRepository,
2334
2301
  sync: {
2335
2302
  databaseBuilder: new SqliteDatabaseBuilder(),
2336
2303
  fileStore: syncFileStore,
@@ -2343,16 +2310,35 @@ function createApp(config = loadRuntimeConfig(), overrides = {}) {
2343
2310
  });
2344
2311
  }
2345
2312
 
2346
- // src/server/serve.ts
2347
- import { loadRuntimeConfig as loadRuntimeConfig2, serveMcpApp } from "@mcp-craftman/node";
2348
- async function serve(config = loadRuntimeConfig2()) {
2349
- return serveMcpApp(createApp, {
2350
- config
2351
- });
2313
+ // src/runtime/config.ts
2314
+ import { homedir } from "os";
2315
+ import { resolve } from "path";
2316
+ import { loadRuntimeConfig as loadRuntimeConfig2 } from "@mcp-craftman/node";
2317
+ function loadTerytRuntimeConfig(env = process.env) {
2318
+ const config = loadRuntimeConfig2(env);
2319
+ return {
2320
+ ...config,
2321
+ dataDir: resolveTerytDataDir(env)
2322
+ };
2323
+ }
2324
+ function resolveTerytDataDir(env) {
2325
+ if (env.MCP_DATA_DIR) {
2326
+ return resolve(env.MCP_DATA_DIR);
2327
+ }
2328
+ if (env.XDG_CACHE_HOME) {
2329
+ return resolve(env.XDG_CACHE_HOME, "teryt-mcp");
2330
+ }
2331
+ if (process.platform === "darwin") {
2332
+ return resolve(homedir(), "Library", "Caches", "teryt-mcp");
2333
+ }
2334
+ if (process.platform === "win32" && env.LOCALAPPDATA) {
2335
+ return resolve(env.LOCALAPPDATA, "teryt-mcp");
2336
+ }
2337
+ return resolve(homedir(), ".cache", "teryt-mcp");
2352
2338
  }
2353
2339
 
2354
2340
  export {
2355
2341
  getServerStatus,
2356
2342
  createApp,
2357
- serve
2343
+ loadTerytRuntimeConfig
2358
2344
  };
@@ -0,0 +1,16 @@
1
+ import {
2
+ createApp,
3
+ loadTerytRuntimeConfig
4
+ } from "./chunk-LDGYCOB4.js";
5
+
6
+ // src/server/serve.ts
7
+ import { serveMcpApp } from "@mcp-craftman/node";
8
+ async function serve(config = loadTerytRuntimeConfig()) {
9
+ return serveMcpApp(createApp, {
10
+ config
11
+ });
12
+ }
13
+
14
+ export {
15
+ serve
16
+ };
package/dist/cli.d.ts CHANGED
@@ -1,23 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { RuntimeConfig, CliIo } from '@mcp-craftman/node';
3
- import * as _mcp_craftman_core from '@mcp-craftman/core';
4
-
5
- type DatasetCode = "TERC" | "SIMC" | "ULIC" | "WMRODZ";
6
-
7
- type SourceFile = {
8
- readonly dataset: DatasetCode;
9
- readonly content: Uint8Array;
10
- readonly sourceUrl: string;
11
- readonly stateDate: string;
12
- };
13
- type TerytSource = {
14
- readonly download: (dataset: DatasetCode) => Promise<SourceFile>;
15
- };
16
-
17
- type CreateAppOverrides = {
18
- readonly syncSource?: TerytSource;
19
- };
20
- declare function createApp(config?: RuntimeConfig, overrides?: CreateAppOverrides): _mcp_craftman_core.McpApp;
2
+ import { CliIo } from '@mcp-craftman/node';
3
+ import { c as createApp } from './app-DumxnZvs.js';
4
+ import '@mcp-craftman/core';
21
5
 
22
6
  type TerytCliIo = CliIo & {
23
7
  readonly appFactory?: typeof createApp;
package/dist/cli.js CHANGED
@@ -1,15 +1,17 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ serve
4
+ } from "./chunk-R2QUAOGP.js";
2
5
  import {
3
6
  createApp,
4
7
  getServerStatus,
5
- serve
6
- } from "./chunk-Q5BJHXKD.js";
8
+ loadTerytRuntimeConfig
9
+ } from "./chunk-LDGYCOB4.js";
7
10
 
8
11
  // src/cli.ts
9
12
  import {
10
13
  createDefaultCliIo,
11
14
  isCliEntrypoint,
12
- loadRuntimeConfig,
13
15
  writeCliToolStructuredContent,
14
16
  writeJson
15
17
  } from "@mcp-craftman/node";
@@ -17,11 +19,11 @@ import { mcpCraftmanCoreVersion } from "@mcp-craftman/core";
17
19
  async function runCli(argv = process.argv.slice(2), io = defaultIo()) {
18
20
  const [command, ...args] = argv;
19
21
  if (command === "serve") {
20
- await serve(loadRuntimeConfig(io.env));
22
+ await serve(loadTerytRuntimeConfig(io.env));
21
23
  return;
22
24
  }
23
25
  if (command === "status") {
24
- const config = loadRuntimeConfig(io.env);
26
+ const config = loadTerytRuntimeConfig(io.env);
25
27
  writeJson(
26
28
  io.stdout,
27
29
  getServerStatus({
@@ -47,7 +49,10 @@ async function runCli(argv = process.argv.slice(2), io = defaultIo()) {
47
49
  throw new Error(`Unknown command: ${command ?? "<missing>"}`);
48
50
  }
49
51
  async function writeCliToolResult(stream, toolName, input, io) {
50
- await writeCliToolStructuredContent(stream, io.appFactory ?? createApp, toolName, input, io.env);
52
+ await writeCliToolStructuredContent(stream, io.appFactory ?? createApp, toolName, input, {
53
+ ...io.env,
54
+ MCP_DATA_DIR: loadTerytRuntimeConfig(io.env).dataDir
55
+ });
51
56
  }
52
57
  function defaultIo() {
53
58
  return createDefaultCliIo();
package/dist/main.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  serve
3
- } from "./chunk-Q5BJHXKD.js";
3
+ } from "./chunk-R2QUAOGP.js";
4
+ import "./chunk-LDGYCOB4.js";
4
5
 
5
6
  // src/main.ts
6
7
  await serve();
@@ -0,0 +1,15 @@
1
+ import { c as createApp } from './app-DumxnZvs.js';
2
+ import '@mcp-craftman/core';
3
+ import '@mcp-craftman/node';
4
+
5
+ type PostinstallIo = {
6
+ readonly env: NodeJS.ProcessEnv;
7
+ readonly stderr: NodeJS.WritableStream;
8
+ };
9
+ type PostinstallOptions = {
10
+ readonly appFactory?: typeof createApp;
11
+ readonly io?: PostinstallIo;
12
+ };
13
+ declare function runPostinstallSync(options?: PostinstallOptions): Promise<void>;
14
+
15
+ export { runPostinstallSync };
@@ -0,0 +1,42 @@
1
+ import {
2
+ createApp,
3
+ loadTerytRuntimeConfig
4
+ } from "./chunk-LDGYCOB4.js";
5
+
6
+ // src/postinstall.ts
7
+ import { callTool } from "@mcp-craftman/core";
8
+ import { isCliEntrypoint } from "@mcp-craftman/node";
9
+ var skipValues = /* @__PURE__ */ new Set(["1", "true", "yes"]);
10
+ async function runPostinstallSync(options = {}) {
11
+ const io = options.io ?? {
12
+ env: process.env,
13
+ stderr: process.stderr
14
+ };
15
+ if (skipValues.has((io.env.TERYT_MCP_SKIP_POSTINSTALL_SYNC ?? "").toLowerCase())) {
16
+ io.stderr.write("teryt-mcp postinstall: skipping initial sync.\n");
17
+ return;
18
+ }
19
+ const config = loadTerytRuntimeConfig(io.env);
20
+ const appFactory = options.appFactory ?? createApp;
21
+ const result = await callTool(appFactory(config), "sync_database", {
22
+ mode: "missing"
23
+ });
24
+ const status = readStatus(result.structuredContent);
25
+ io.stderr.write(`teryt-mcp postinstall: initial sync ${status} in ${config.dataDir}.
26
+ `);
27
+ }
28
+ function readStatus(content) {
29
+ if (typeof content === "object" && content !== null && "status" in content && typeof content.status === "string") {
30
+ return content.status;
31
+ }
32
+ return "completed";
33
+ }
34
+ if (isCliEntrypoint("postinstall.js")) {
35
+ runPostinstallSync().catch((error) => {
36
+ process.stderr.write(`teryt-mcp postinstall: initial sync failed: ${error instanceof Error ? error.message : String(error)}
37
+ `);
38
+ });
39
+ }
40
+ export {
41
+ runPostinstallSync
42
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teryt-mcp",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "private": false,
5
5
  "description": "MCP server for the official Polish TERYT registry.",
6
6
  "type": "module",
@@ -38,7 +38,8 @@
38
38
  "node": ">=20.19.0"
39
39
  },
40
40
  "scripts": {
41
- "build": "tsup src/main.ts src/cli.ts --format esm --dts --clean",
41
+ "build": "tsup src/main.ts src/cli.ts src/postinstall.ts --format esm --dts --clean",
42
+ "postinstall": "node dist/postinstall.js",
42
43
  "quality": "mcp-craftman quality",
43
44
  "test": "vitest run"
44
45
  }