krs-poland-mcp-server 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Piotr Kolawa
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,51 @@
1
+ ![logo](logo.png)
2
+
3
+ # krs-poland-mcp-server
4
+
5
+ The MCP server for KRS Poland public API.
6
+
7
+ ## Installation
8
+
9
+ To install the package, run the following command:
10
+
11
+ ```bash
12
+ npm install -g krs-poland-mcp-server
13
+ ```
14
+
15
+ ## Usage with NPX
16
+
17
+ You can also use `npx` to run the server without installing it globally:
18
+
19
+ ```bash
20
+ npx krs-poland-mcp-server
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ After installation, you can run the server with the following command:
26
+
27
+ ```bash
28
+ krs-poland-mcp-server
29
+ ```
30
+
31
+ Alternatively, you can run the server using `npm start`:
32
+
33
+ ```bash
34
+ npm start
35
+ ```
36
+
37
+ ## Usage with LLM clients
38
+
39
+ This MCP server can be used to provide tools to LLM clients. To serve the tools, run the following command:
40
+
41
+ ```bash
42
+ npx krs-poland-mcp-server serve
43
+ ```
44
+
45
+ ## Author
46
+
47
+ Piotr Kolawa ([@pkolawa](https://github.com/pkolawa))
48
+
49
+ ## License
50
+
51
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
package/build/index.js ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import { server } from "./server.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ async function main() {
5
+ const transport = new StdioServerTransport();
6
+ await server.connect(transport);
7
+ console.error("KRS MCP Server running on stdio");
8
+ }
9
+ if (process.argv[1] === (import.meta && import.meta.url && new URL(import.meta.url).pathname)) {
10
+ main().catch((error) => {
11
+ console.error("Fatal error in main():", error);
12
+ process.exit(1);
13
+ });
14
+ }
@@ -0,0 +1,17 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { getKrsCurrentExtractTool } from "./tools/currentExtract.js";
3
+ import { getKrsFullExtractTool } from "./tools/fullExtract.js";
4
+ export const server = new McpServer({
5
+ name: "krs",
6
+ version: "1.0.0",
7
+ });
8
+ server.registerTool("Get Current KRS Record", {
9
+ title: "get-krs-current-extract",
10
+ description: "Get current status of the entity in KRS",
11
+ inputSchema: getKrsCurrentExtractTool.schema
12
+ }, (params, extra) => getKrsCurrentExtractTool.handler(params, extra));
13
+ server.registerTool("Get Full KRS Record", {
14
+ title: "get-krs-full-extract",
15
+ description: "Get full status of the entity in KRS",
16
+ inputSchema: getKrsFullExtractTool.schema
17
+ }, (params, extra) => getKrsFullExtractTool.handler(params, extra));
@@ -0,0 +1,48 @@
1
+ import { z } from "zod";
2
+ import { makeKRSRequest, buildExtractUrl } from "../utils/api.js";
3
+ import { formatCompanyHeadline } from "../utils/format.js";
4
+ /**
5
+ * KRS Open API – odpis aktualny (JSON)
6
+ * rejestr: 'P' (przedsiębiorców) | 'S' (stowarzyszeń)
7
+ */
8
+ export const getKrsCurrentExtractTool = {
9
+ description: "Pobierz odpis aktualny KRS (JSON) dla wskazanego numeru KRS i rejestru (P/S).",
10
+ schema: {
11
+ krs: z
12
+ .string()
13
+ .regex(/^[0]\d{9}$/, "Numer KRS powinien mieć 10 cyfr")
14
+ .describe("Numer KRS (10 cyfr)"),
15
+ rejestr: z
16
+ .string()
17
+ .length(1, "Rejestr musi być pojedynczym znakiem: P lub S")
18
+ .regex(/^[pPsS]$/, "Rejestr musi być literą P lub S (wielkość liter bez znaczenia)")
19
+ .transform((val) => val.toUpperCase())
20
+ .describe("Rejestr: P – przedsiębiorców, S – stowarzyszeń (P/S, wielkość liter bez znaczenia)"),
21
+ },
22
+ handler: async (args, _extra) => {
23
+ const { krs, rejestr } = args;
24
+ const url = buildExtractUrl({ type: "OdpisAktualny", rejestr, krs });
25
+ const extract = await makeKRSRequest(url);
26
+ if (!extract) {
27
+ return {
28
+ content: [
29
+ {
30
+ type: "text",
31
+ text: `Nie udało się pobrać odpisu aktualnego dla KRS ${krs} (${rejestr}).`,
32
+ _meta: {},
33
+ },
34
+ ],
35
+ };
36
+ }
37
+ const headline = formatCompanyHeadline(extract);
38
+ return {
39
+ content: [
40
+ {
41
+ type: "text",
42
+ text: `Odpis aktualny – ${headline}\n\n(Zwrócono obiekt JSON z odpisem aktualnym)\n\n${JSON.stringify(extract, null, 2)}`,
43
+ _meta: {},
44
+ }
45
+ ],
46
+ };
47
+ },
48
+ };
@@ -0,0 +1,47 @@
1
+ import { z } from "zod";
2
+ import { makeKRSRequest, buildExtractUrl } from "../utils/api.js";
3
+ import { formatCompanyHeadline } from "../utils/format.js";
4
+ /**
5
+ * KRS Open API – odpis pełny (JSON)
6
+ */
7
+ export const getKrsFullExtractTool = {
8
+ description: "Pobierz odpis pełny KRS (JSON) dla wskazanego numeru KRS i rejestru (P/S).",
9
+ schema: {
10
+ krs: z
11
+ .string()
12
+ .regex(/^[0]\d{9}$/, "Numer KRS powinien mieć 10 cyfr")
13
+ .describe("Numer KRS (10 cyfr)"),
14
+ rejestr: z
15
+ .string()
16
+ .length(1, "Rejestr musi być pojedynczym znakiem: P lub S")
17
+ .regex(/^[pPsS]$/, "Rejestr musi być literą P lub S (wielkość liter bez znaczenia)")
18
+ .transform((val) => val.toUpperCase())
19
+ .describe("Rejestr: P – przedsiębiorców, S – stowarzyszeń (P/S, wielkość liter bez znaczenia)"),
20
+ },
21
+ handler: async (args, _extra) => {
22
+ const { krs, rejestr } = args;
23
+ const url = buildExtractUrl({ type: "OdpisPelny", rejestr, krs });
24
+ const extract = await makeKRSRequest(url);
25
+ if (!extract) {
26
+ return {
27
+ content: [
28
+ {
29
+ type: "text",
30
+ text: `Nie udało się pobrać odpisu pełnego dla KRS ${krs} (${rejestr}).`,
31
+ _meta: {},
32
+ },
33
+ ],
34
+ };
35
+ }
36
+ const headline = formatCompanyHeadline(extract);
37
+ return {
38
+ content: [
39
+ {
40
+ type: "text",
41
+ text: `Odpis pełny – ${headline}\n\n(Zwrócono obiekt JSON z odpisem pełnym)\n\n${JSON.stringify(extract, null, 2)}`,
42
+ _meta: {},
43
+ }
44
+ ],
45
+ };
46
+ },
47
+ };
@@ -0,0 +1,6 @@
1
+ import { getKrsCurrentExtractTool } from "./currentExtract.js";
2
+ import { getKrsFullExtractTool } from "./fullExtract.js";
3
+ export const tools = {
4
+ "get-krs-current-extract": getKrsCurrentExtractTool,
5
+ "get-krs-full-extract": getKrsFullExtractTool,
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ const USER_AGENT = "krs-mcp/1.0";
2
+ // Known public base for KRS Open API (REST returning JSON odpisy).
3
+ // If MS changes routing/domains, adjust this single constant.
4
+ const KRS_API_BASE = "https://api-krs.ms.gov.pl/api/krs";
5
+ /**
6
+ * Build URL for KRS odpis (OdpisAktualny/OdpisPelny).
7
+ * Historically documented as REST with typ odpisu + KRS + rejestr (P/S), JSON in response.
8
+ * Example effective form (subject to MS routing):
9
+ * `${KRS_API_BASE}/{typ_odpisu}/{rejestr}/{krs}`
10
+ */
11
+ export function buildExtractUrl(opts) {
12
+ const { type, rejestr, krs } = opts;
13
+ // Prefer path params; keep query fallback if needed by future changes.
14
+ return `${KRS_API_BASE}/${type}/${krs}?rejestr=${rejestr}&format=json`;
15
+ }
16
+ export async function makeKRSRequest(url) {
17
+ const headers = { Accept: "application/json" };
18
+ try {
19
+ const res = await fetch(url, { headers });
20
+ if (!res.ok)
21
+ throw new Error(`HTTP ${res.status}`);
22
+ return (await res.json());
23
+ }
24
+ catch (err) {
25
+ console.error("KRS request error:", err);
26
+ return null;
27
+ }
28
+ }
@@ -0,0 +1,9 @@
1
+ export function formatCompanyHeadline(extract) {
2
+ // The JSON structure differs by section; we pick common safe fields if present:
3
+ const krs = extract?.dzial1?.danePodstawowe?.numerKRS ?? extract?.podstawoweDane?.numerKRS ?? "KRS ?";
4
+ const name = extract?.dzial1?.danePodstawowe?.nazwa ??
5
+ extract?.podstawoweDane?.nazwa ??
6
+ extract?.nazwa ??
7
+ "Nieznana nazwa";
8
+ return `${name} (KRS ${krs})`;
9
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "krs-poland-mcp-server",
3
+ "version": "1.0.0",
4
+ "description": "The MCP server for KRS Poland public API.",
5
+ "main": "./src/index.ts",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "build": "tsc && echo '#!/usr/bin/env node' | cat - build/index.js > build/index.tmp && mv build/index.tmp build/index.js && node -e \"require('fs').chmodSync('build/index.js', '755')\"",
9
+ "start": "node build/index.js"
10
+ },
11
+
12
+ "files": ["build"],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/pkolawa/mcp-krs-poland.git"
16
+ },
17
+ "keywords": ["mcp", "poland", "krs"],
18
+ "author": {
19
+ "name": "Piotr Kolawa",
20
+ "email": "piotr.kolawa@gmail.com"
21
+ },
22
+ "license": "MIT",
23
+ "type": "module",
24
+ "bin": {
25
+ "krs-poland-mcp-server": "./build/index.js"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/pkolawa/mcp-krs-poland/issues"
29
+ },
30
+ "homepage": "https://github.com/pkolawa/mcp-krs-poland#readme",
31
+ "dependencies": {
32
+ "@modelcontextprotocol/sdk": "^1.18.0",
33
+ "zod": "^3.25.76"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^24.3.1",
37
+ "typescript": "^5.9.2"
38
+ }
39
+ }