@integraledger/lcp-mcp-server 0.9.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +16 -0
  4. package/README.md +121 -0
  5. package/dist/annotations.d.ts +41 -0
  6. package/dist/annotations.d.ts.map +1 -0
  7. package/dist/annotations.js +41 -0
  8. package/dist/annotations.js.map +1 -0
  9. package/dist/bin.d.ts +3 -0
  10. package/dist/bin.d.ts.map +1 -0
  11. package/dist/bin.js +5 -0
  12. package/dist/bin.js.map +1 -0
  13. package/dist/dispatch.d.ts +53 -0
  14. package/dist/dispatch.d.ts.map +1 -0
  15. package/dist/dispatch.js +81 -0
  16. package/dist/dispatch.js.map +1 -0
  17. package/dist/index.d.ts +9 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +8 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/node-ports.d.ts +21 -0
  22. package/dist/node-ports.d.ts.map +1 -0
  23. package/dist/node-ports.js +33 -0
  24. package/dist/node-ports.js.map +1 -0
  25. package/dist/ports.d.ts +23 -0
  26. package/dist/ports.d.ts.map +1 -0
  27. package/dist/ports.js +2 -0
  28. package/dist/ports.js.map +1 -0
  29. package/dist/server.d.ts +45 -0
  30. package/dist/server.d.ts.map +1 -0
  31. package/dist/server.js +67 -0
  32. package/dist/server.js.map +1 -0
  33. package/dist/stdio.d.ts +15 -0
  34. package/dist/stdio.d.ts.map +1 -0
  35. package/dist/stdio.js +17 -0
  36. package/dist/stdio.js.map +1 -0
  37. package/dist/tools/compute-atrhash.d.ts +15 -0
  38. package/dist/tools/compute-atrhash.d.ts.map +1 -0
  39. package/dist/tools/compute-atrhash.js +66 -0
  40. package/dist/tools/compute-atrhash.js.map +1 -0
  41. package/dist/tools/extract-reference.d.ts +19 -0
  42. package/dist/tools/extract-reference.d.ts.map +1 -0
  43. package/dist/tools/extract-reference.js +65 -0
  44. package/dist/tools/extract-reference.js.map +1 -0
  45. package/dist/tools/generate-legal-context.d.ts +20 -0
  46. package/dist/tools/generate-legal-context.d.ts.map +1 -0
  47. package/dist/tools/generate-legal-context.js +99 -0
  48. package/dist/tools/generate-legal-context.js.map +1 -0
  49. package/dist/tools/place-reference.d.ts +19 -0
  50. package/dist/tools/place-reference.d.ts.map +1 -0
  51. package/dist/tools/place-reference.js +69 -0
  52. package/dist/tools/place-reference.js.map +1 -0
  53. package/dist/tools/scaffold-integration.d.ts +15 -0
  54. package/dist/tools/scaffold-integration.d.ts.map +1 -0
  55. package/dist/tools/scaffold-integration.js +168 -0
  56. package/dist/tools/scaffold-integration.js.map +1 -0
  57. package/dist/tools/verify-before-pay.d.ts +29 -0
  58. package/dist/tools/verify-before-pay.d.ts.map +1 -0
  59. package/dist/tools/verify-before-pay.js +158 -0
  60. package/dist/tools/verify-before-pay.js.map +1 -0
  61. package/dist/version.d.ts +25 -0
  62. package/dist/version.d.ts.map +1 -0
  63. package/dist/version.js +37 -0
  64. package/dist/version.js.map +1 -0
  65. package/dist/well-known.d.ts +33 -0
  66. package/dist/well-known.d.ts.map +1 -0
  67. package/dist/well-known.js +45 -0
  68. package/dist/well-known.js.map +1 -0
  69. package/package.json +73 -0
  70. package/src/annotations.ts +53 -0
  71. package/src/bin.ts +5 -0
  72. package/src/dispatch.ts +122 -0
  73. package/src/index.ts +15 -0
  74. package/src/node-ports.ts +38 -0
  75. package/src/ports.ts +23 -0
  76. package/src/server.ts +70 -0
  77. package/src/stdio.ts +25 -0
  78. package/src/tools/compute-atrhash.ts +87 -0
  79. package/src/tools/extract-reference.ts +86 -0
  80. package/src/tools/generate-legal-context.ts +127 -0
  81. package/src/tools/place-reference.ts +96 -0
  82. package/src/tools/scaffold-integration.ts +183 -0
  83. package/src/tools/verify-before-pay.ts +194 -0
  84. package/src/version.ts +42 -0
  85. package/src/well-known.ts +51 -0
@@ -0,0 +1,51 @@
1
+ /** LCP §2.1: the one location a service publishes its legal context at. */
2
+ export const WELL_KNOWN_PATH = "/.well-known/legal-context.json";
3
+
4
+ /**
5
+ * The canonical discovery URL for a service, from either a bare origin or the well-known URL itself.
6
+ *
7
+ * IDEMPOTENT over both spellings on purpose: an agent that already holds the full
8
+ * `https://seller.example/.well-known/legal-context.json` and one that holds only `https://seller.example`
9
+ * are the same caller a moment apart, and appending the path twice would 404 against a conformant seller.
10
+ *
11
+ * PARSED, NEVER CONCATENATED, and the refusals are why. Appending to the raw string put the well-known path
12
+ * INSIDE whatever the input already carried: `https://x.example?level=3` became
13
+ * `https://x.example?level=3/.well-known/legal-context.json`, which fails on the wire as a broken discovery
14
+ * document at the service root instead of as the input error it is. So the input is parsed, and three
15
+ * shapes are refused BY NAME rather than silently rewritten:
16
+ *
17
+ * - **A query or a fragment.** LCP §2.1 defines the well-known URI with no parameters, and a query a
18
+ * conformant seller ignores is a request for behaviour the standard does not define — appending one as
19
+ * a private hint only works against a server that already agreed to read it. The level a document
20
+ * satisfies is read off the document.
21
+ * - **Credentials in the authority.** `URL`'s `origin` drops them, so parsing `https://u:p@h.example`
22
+ * would hand back a URL addressed differently from the one the caller supplied — the one thing
23
+ * concatenation got right. Silently changing who is being talked to is worse than refusing.
24
+ * - **No network origin at all.** `mailto:`, `data:`, `file:`, `urn:` — each accepted by the tools'
25
+ * `z.url()`, and none of them has a well-known location.
26
+ *
27
+ * SCHEME IS NOT CHECKED HERE. `agent-guard`'s fetcher is HTTPS-only and refuses `http:` on the way out; a
28
+ * second copy of that rule in this function would be duplicated truth with nothing keeping the two in step.
29
+ *
30
+ * A THROW is the right shape inside a tool handler: the MCP SDK surfaces a handler throw as an
31
+ * `isError: true` `tools/call` result, so the model reads the refusal rather than a transport failure.
32
+ */
33
+ export function legalContextUrl(serviceUrl: string): string {
34
+ const url = new URL(serviceUrl);
35
+ if (url.origin === "null")
36
+ throw new Error(
37
+ `not a service URL — \`${serviceUrl}\` has no network origin, so it has no well-known location`,
38
+ );
39
+ if (url.search !== "" || url.hash !== "")
40
+ throw new Error(
41
+ `not a service URL — \`${serviceUrl}\` carries a query or fragment, and LCP §2.1 defines the well-known URI with neither`,
42
+ );
43
+ if (url.username !== "" || url.password !== "")
44
+ throw new Error(
45
+ `not a service URL — \`${serviceUrl}\` carries credentials in its authority, which the well-known location does not preserve`,
46
+ );
47
+ const path = url.pathname.replace(/\/+$/, "");
48
+ return path.endsWith(WELL_KNOWN_PATH)
49
+ ? `${url.origin}${path}`
50
+ : `${url.origin}${path}${WELL_KNOWN_PATH}`;
51
+ }