@ganintegrity/mcp 1.0.0 → 1.1.1

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 (80) hide show
  1. package/README.md +191 -84
  2. package/dist/{als.d.ts → core/als.d.ts} +11 -4
  3. package/dist/core/als.d.ts.map +1 -0
  4. package/dist/core/als.js.map +1 -0
  5. package/dist/{auth → core/auth}/auth.types.d.ts +6 -0
  6. package/dist/core/auth/auth.types.d.ts.map +1 -0
  7. package/dist/{auth → core/auth}/auth.types.js.map +1 -1
  8. package/dist/core/auth/index.d.ts +34 -0
  9. package/dist/core/auth/index.d.ts.map +1 -0
  10. package/dist/core/auth/index.js +57 -0
  11. package/dist/core/auth/index.js.map +1 -0
  12. package/dist/core/define.d.ts +80 -0
  13. package/dist/core/define.d.ts.map +1 -0
  14. package/dist/core/define.js +52 -0
  15. package/dist/core/define.js.map +1 -0
  16. package/dist/core/dispatch.d.ts +35 -0
  17. package/dist/core/dispatch.d.ts.map +1 -0
  18. package/dist/core/dispatch.js +57 -0
  19. package/dist/core/dispatch.js.map +1 -0
  20. package/dist/{errors → core/errors}/errors.types.d.ts +21 -0
  21. package/dist/core/errors/errors.types.d.ts.map +1 -0
  22. package/dist/core/errors/errors.types.js.map +1 -0
  23. package/dist/{errors → core/errors}/index.d.ts +4 -0
  24. package/dist/core/errors/index.d.ts.map +1 -0
  25. package/dist/{errors → core/errors}/index.js +4 -0
  26. package/dist/core/errors/index.js.map +1 -0
  27. package/dist/core/test-helpers.d.ts +20 -0
  28. package/dist/core/test-helpers.d.ts.map +1 -0
  29. package/dist/core/test-helpers.js +38 -0
  30. package/dist/core/test-helpers.js.map +1 -0
  31. package/dist/core/tool/index.d.ts +19 -0
  32. package/dist/core/tool/index.d.ts.map +1 -0
  33. package/dist/{tool → core/tool}/index.js +28 -25
  34. package/dist/core/tool/index.js.map +1 -0
  35. package/dist/{tool → core/tool}/tool.types.d.ts +38 -2
  36. package/dist/core/tool/tool.types.d.ts.map +1 -0
  37. package/dist/{tool → core/tool}/tool.types.js.map +1 -1
  38. package/dist/{auth/index.d.ts → express/auth.d.ts} +10 -9
  39. package/dist/express/auth.d.ts.map +1 -0
  40. package/dist/express/auth.js +49 -0
  41. package/dist/express/auth.js.map +1 -0
  42. package/dist/express/express.types.d.ts +37 -0
  43. package/dist/express/express.types.d.ts.map +1 -0
  44. package/dist/express/express.types.js +2 -0
  45. package/dist/express/express.types.js.map +1 -0
  46. package/dist/express/index.d.ts +41 -0
  47. package/dist/express/index.d.ts.map +1 -0
  48. package/dist/express/index.js +59 -0
  49. package/dist/express/index.js.map +1 -0
  50. package/dist/index.d.ts +21 -18
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +10 -4
  53. package/dist/index.js.map +1 -1
  54. package/package.json +8 -1
  55. package/dist/als.d.ts.map +0 -1
  56. package/dist/als.js.map +0 -1
  57. package/dist/auth/auth.types.d.ts.map +0 -1
  58. package/dist/auth/index.d.ts.map +0 -1
  59. package/dist/auth/index.js +0 -74
  60. package/dist/auth/index.js.map +0 -1
  61. package/dist/errors/errors.types.d.ts.map +0 -1
  62. package/dist/errors/errors.types.js.map +0 -1
  63. package/dist/errors/index.d.ts.map +0 -1
  64. package/dist/errors/index.js.map +0 -1
  65. package/dist/server/index.d.ts +0 -18
  66. package/dist/server/index.d.ts.map +0 -1
  67. package/dist/server/index.js +0 -130
  68. package/dist/server/index.js.map +0 -1
  69. package/dist/server/server.types.d.ts +0 -78
  70. package/dist/server/server.types.d.ts.map +0 -1
  71. package/dist/server/server.types.js +0 -2
  72. package/dist/server/server.types.js.map +0 -1
  73. package/dist/tool/index.d.ts +0 -26
  74. package/dist/tool/index.d.ts.map +0 -1
  75. package/dist/tool/index.js.map +0 -1
  76. package/dist/tool/tool.types.d.ts.map +0 -1
  77. /package/dist/{als.js → core/als.js} +0 -0
  78. /package/dist/{auth → core/auth}/auth.types.js +0 -0
  79. /package/dist/{errors → core/errors}/errors.types.js +0 -0
  80. /package/dist/{tool → core/tool}/tool.types.js +0 -0
@@ -1,78 +0,0 @@
1
- import type { Request, RequestHandler, Router } from "express";
2
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import type { Postgan } from "@ganintegrity/postgan";
4
- import type { Logger } from "pino";
5
- import type { AuthUser } from "../auth/auth.types.ts";
6
- import type { McpErrorMapper } from "../errors/errors.types.ts";
7
- /**
8
- * Configuration for `createMcpServer()`.
9
- */
10
- export interface CreateMcpServerOptions {
11
- /** MCP server name advertised to clients during initialisation. */
12
- name: string;
13
- /** MCP server version advertised to clients during initialisation. */
14
- version: string;
15
- /**
16
- * Service logger. The library calls `logger.child({ component: "mcp" })`
17
- * internally and further childs with `sessionId` / `userId` / `company`
18
- * per request and with `tool` / `sessionId` per tool call.
19
- */
20
- logger: Logger;
21
- /**
22
- * Resolve a bearer token to a user. See `McpAuthOptions.tokenToUser`.
23
- * Reject by throwing — the library responds `401`.
24
- */
25
- tokenToUser: (token: string) => Promise<AuthUser>;
26
- /**
27
- * Express middleware that attaches a `Postgan` instance to `req.postgan`.
28
- * Mounted automatically between the auth middleware and the JSON-RPC
29
- * dispatcher; tools open per-call transactions against `ctx.postgan`.
30
- *
31
- * The library is neutral about how Postgan is constructed — supply your
32
- * service's existing setup-postgan middleware.
33
- */
34
- setupPostgan: RequestHandler;
35
- /**
36
- * Translate a thrown error into an MCP envelope. Return `null` to fall
37
- * through to a redacted `INTERNAL_ERROR` envelope — appropriate for
38
- * anything you don't want surfaced to the agent. Without a mapper every
39
- * thrown error becomes `INTERNAL_ERROR`.
40
- */
41
- errorMapper?: McpErrorMapper;
42
- }
43
- /**
44
- * Return value of `createMcpServer()`.
45
- */
46
- export interface CreateMcpServerResult {
47
- /**
48
- * Tool-registration target. Pass to `tool()` at boot, once per tool.
49
- * Treat as opaque — `tool()` is the only supported way to use it.
50
- */
51
- server: McpServer;
52
- /**
53
- * Attach the MCP route handlers (auth + setupPostgan + JSON-RPC dispatch)
54
- * to the supplied Express router. Caller decides the mount path
55
- * (`app.use("/mcp", router)`).
56
- *
57
- * Resolves once the route is attached. Never throws.
58
- */
59
- mount: (target: Router) => Promise<void>;
60
- }
61
- export type RegisterToolArgs = Parameters<McpServer["registerTool"]>;
62
- export type ReqWithUserPostgan = Request & {
63
- user?: AuthUser;
64
- postgan?: Postgan;
65
- };
66
- export interface ToolRegistration {
67
- name: RegisterToolArgs[0];
68
- config: RegisterToolArgs[1];
69
- handler: RegisterToolArgs[2];
70
- }
71
- export interface HandleRequestDeps {
72
- name: string;
73
- version: string;
74
- registrations: readonly ToolRegistration[];
75
- logger: Logger;
76
- errorMapper?: McpErrorMapper;
77
- }
78
- //# sourceMappingURL=server.types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.types.d.ts","sourceRoot":"","sources":["../../src/server/server.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAClD;;;;;;;OAOG;IACH,YAAY,EAAE,cAAc,CAAC;IAC7B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,cAAc,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,MAAM,EAAE,SAAS,CAAC;IAClB;;;;;;OAMG;IACH,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAID,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;AAErE,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG;IACzC,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC1B,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC5B,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,cAAc,CAAC;CAC9B"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=server.types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.types.js","sourceRoot":"","sources":["../../src/server/server.types.ts"],"names":[],"mappings":""}
@@ -1,26 +0,0 @@
1
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import type { z } from "zod";
3
- import type { ToolSpec } from "./tool.types.ts";
4
- /**
5
- * Register a tool against the MCP server returned by `createMcpServer()`.
6
- * The wrapper around your handler:
7
- *
8
- * 1. Builds a {@link ToolContext} from the active request scope.
9
- * 2. Opens a fresh `Postgan.Transaction` before calling your handler.
10
- * 3. On resolve, commits the transaction and returns a `CallToolResult`
11
- * where the handler's return value is surfaced both as a JSON `text`
12
- * content block (for non-structured-aware clients) and as
13
- * `structuredContent` (for AI-SDK clients).
14
- * 4. On throw, rolls back the transaction and routes the error through
15
- * the consumer's `McpErrorMapper` (passed to `createMcpServer`) to
16
- * build an MCP error envelope.
17
- *
18
- * Registration itself is synchronous and does not throw. The wrapped handler
19
- * **may** throw at request time — but only if it is invoked outside an
20
- * active request scope, which indicates a programming bug (the handler was
21
- * dispatched without going through `mount()`'s ALS wrapper). Such throws
22
- * propagate to the SDK transport and surface as an HTTP 500. Errors raised
23
- * by your own handler logic are caught and never propagate.
24
- */
25
- export declare function tool<Schema extends z.ZodObject, Output extends Record<string, unknown>>(server: McpServer, spec: ToolSpec<Schema, Output>): void;
26
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tool/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAI7B,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AA6B7D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,IAAI,CAClB,MAAM,SAAS,CAAC,CAAC,SAAS,EAC1B,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAiDzD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tool/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD;;;;;GAKG;AACH,KAAK,UAAU,eAA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