law-mcp-server 0.1.5 → 0.1.6

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/dist/lawApi.js CHANGED
@@ -40,7 +40,23 @@ export const fetchLawData = async (lawId, revisionDate) => {
40
40
  };
41
41
  export const searchLaws = async (keyword) => {
42
42
  const base = config.apiBase.endsWith("/") ? config.apiBase : `${config.apiBase}/`;
43
- const url = new URL(`lawsearch`, base);
44
- url.searchParams.set("keyword", keyword);
45
- return request(url.toString());
43
+ const queryUrl = new URL(`lawsearch`, base);
44
+ queryUrl.searchParams.set("keyword", keyword);
45
+ try {
46
+ return await request(queryUrl.toString());
47
+ }
48
+ catch (error) {
49
+ const message = error instanceof Error ? error.message : String(error);
50
+ if (message.includes("404")) {
51
+ const pathUrl = new URL(`lawsearch/${encodeURIComponent(keyword)}`, base);
52
+ try {
53
+ return await request(pathUrl.toString());
54
+ }
55
+ catch (err) {
56
+ const msg = err instanceof Error ? err.message : String(err);
57
+ throw new Error(`Law search failed for keyword "${keyword}". Tried query and path styles. Upstream: ${msg}`);
58
+ }
59
+ }
60
+ throw error;
61
+ }
46
62
  };
package/dist/src/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { StdioJsonRpcServer } from "./mcp.js";
3
3
  import { tools, resolveTool } from "./tools.js";
4
4
  const server = new StdioJsonRpcServer();
5
- const serverInfo = { name: "law-mcp-server", version: "0.1.3" };
5
+ const serverInfo = { name: "law-mcp-server", version: "0.1.5" };
6
6
  server.register("initialize", async (params) => {
7
7
  const payload = (params ?? {});
8
8
  const protocolVersion = typeof payload.protocolVersion === "string"
@@ -47,7 +47,24 @@ export const searchLaws = async (keyword) => {
47
47
  const base = config.apiBase.endsWith("/")
48
48
  ? config.apiBase
49
49
  : `${config.apiBase}/`;
50
- const url = new URL(`lawsearch`, base);
51
- url.searchParams.set("keyword", keyword);
52
- return request(url.toString());
50
+ const queryUrl = new URL(`lawsearch`, base);
51
+ queryUrl.searchParams.set("keyword", keyword);
52
+ try {
53
+ return await request(queryUrl.toString());
54
+ }
55
+ catch (error) {
56
+ const message = error instanceof Error ? error.message : String(error);
57
+ if (message.includes("404")) {
58
+ // Some deployments expect the keyword in the path; retry once
59
+ const pathUrl = new URL(`lawsearch/${encodeURIComponent(keyword)}`, base);
60
+ try {
61
+ return await request(pathUrl.toString());
62
+ }
63
+ catch (err) {
64
+ const msg = err instanceof Error ? err.message : String(err);
65
+ throw new Error(`Law search failed for keyword "${keyword}". Tried query and path styles. Upstream: ${msg}`);
66
+ }
67
+ }
68
+ throw error;
69
+ }
53
70
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "law-mcp-server",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "MCP server for e-Gov law API consistency checks",
6
6
  "files": [