@lightdash-tools/mcp 0.9.0 → 0.12.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 (229) hide show
  1. package/README.md +27 -22
  2. package/dist/audit/server-profile.d.ts +13 -0
  3. package/dist/audit/server-profile.js +28 -0
  4. package/dist/audit/server-profile.test.js +21 -0
  5. package/dist/auth/oauth-broker/pending-store.test.d.ts +1 -1
  6. package/dist/auth/oauth-broker/pending-store.test.js +1 -1
  7. package/dist/auth/request-state-key.d.ts +2 -2
  8. package/dist/auth/request-state-key.js +2 -2
  9. package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +1 -1
  10. package/dist/auth/resource-server/lightdash-oauth-middleware.js +1 -1
  11. package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +14 -14
  12. package/dist/auth/resource-server/oauth-protected-resource.d.ts +6 -6
  13. package/dist/auth/resource-server/oauth-protected-resource.js +8 -8
  14. package/dist/auth/resource-server/token-scopes.d.ts +1 -1
  15. package/dist/auth/resource-server/token-scopes.js +1 -1
  16. package/dist/auth/resource-server/www-authenticate.test.js +11 -11
  17. package/dist/bin.js +54 -58
  18. package/dist/config/env.d.ts +3 -1
  19. package/dist/config/env.js +4 -2
  20. package/dist/config/load-mcp-config.js +8 -36
  21. package/dist/config/load-mcp-config.test.js +8 -2
  22. package/dist/config/normalize-url.d.ts +1 -1
  23. package/dist/config/normalize-url.js +1 -1
  24. package/dist/config/normalize-url.test.js +16 -16
  25. package/dist/config/obsolete-env.d.ts +5 -0
  26. package/dist/config/obsolete-env.js +48 -0
  27. package/dist/config/obsolete-env.test.js +22 -0
  28. package/dist/config/runtime.js +1 -1
  29. package/dist/governance/available-projects.d.ts +1 -1
  30. package/dist/governance/available-projects.js +1 -1
  31. package/dist/governance/mcp-post-factory-context.d.ts +15 -0
  32. package/dist/governance/mcp-post-factory-context.js +22 -0
  33. package/dist/governance/mcp-post-factory-context.test.js +34 -0
  34. package/dist/http.integration.test.js +11 -15
  35. package/dist/index.d.ts +5 -1
  36. package/dist/index.js +29 -16
  37. package/dist/policy/content-reader.d.ts +10 -5
  38. package/dist/policy/content-reader.js +23 -9
  39. package/dist/policy/content-reader.test.js +4 -3
  40. package/dist/policy/envelope.d.ts +4 -2
  41. package/dist/policy/envelope.js +2 -2
  42. package/dist/policy/envelope.test.d.ts +1 -0
  43. package/dist/policy/envelope.test.js +28 -0
  44. package/dist/profiles/ai-agent-ops/v1/index.d.ts +6 -0
  45. package/dist/profiles/ai-agent-ops/v1/index.js +20 -0
  46. package/dist/{personas → profiles}/ai-agent-ops/v1/prompts.js +2 -2
  47. package/dist/{personas → profiles}/ai-agent-ops/v1/prompts.test.js +2 -2
  48. package/dist/{personas → profiles}/ai-agent-ops/v1/resources/playbooks/core.md +1 -1
  49. package/dist/{personas → profiles}/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +1 -1
  50. package/dist/{personas → profiles}/ai-agent-ops/v1/resources/playbooks/release-gate.md +1 -1
  51. package/dist/{personas → profiles}/ai-agent-ops/v1/resources/playbooks.js +4 -4
  52. package/dist/profiles/content-developer/v1/index.d.ts +8 -0
  53. package/dist/profiles/content-developer/v1/index.js +22 -0
  54. package/dist/{personas → profiles}/content-developer/v1/prompts.js +6 -6
  55. package/dist/{personas → profiles}/content-developer/v1/prompts.test.js +61 -6
  56. package/dist/{personas → profiles}/content-developer/v1/resources/playbooks/chart-types.md +31 -16
  57. package/dist/{personas → profiles}/content-developer/v1/resources/playbooks/core.md +9 -5
  58. package/dist/{personas → profiles}/content-developer/v1/resources/playbooks/dashboard-design.md +3 -3
  59. package/dist/{personas → profiles}/content-developer/v1/resources/playbooks/dashboards.md +12 -7
  60. package/dist/{personas → profiles}/content-developer/v1/resources/playbooks.js +4 -2
  61. package/dist/profiles/content-governance/v1/index.d.ts +7 -0
  62. package/dist/profiles/content-governance/v1/index.js +21 -0
  63. package/dist/{personas → profiles}/content-governance/v1/prompts.test.js +2 -2
  64. package/dist/{personas → profiles}/content-governance/v1/resources/playbooks/core.md +2 -2
  65. package/dist/{personas → profiles}/content-governance/v1/resources/playbooks.js +4 -4
  66. package/dist/profiles/content-reader/v1/index.d.ts +6 -0
  67. package/dist/profiles/content-reader/v1/index.js +20 -0
  68. package/dist/{personas → profiles}/content-reader/v1/prompts.test.js +2 -2
  69. package/dist/{personas → profiles}/content-reader/v1/resources/playbooks/core.md +1 -1
  70. package/dist/{personas → profiles}/content-reader/v1/resources/playbooks/discover.md +1 -1
  71. package/dist/{personas → profiles}/content-reader/v1/resources/playbooks.js +2 -2
  72. package/dist/profiles/data-analyst/v1/index.d.ts +6 -0
  73. package/dist/profiles/data-analyst/v1/index.js +20 -0
  74. package/dist/profiles/data-analyst/v1/prompts.d.ts +5 -0
  75. package/dist/profiles/data-analyst/v1/prompts.js +41 -0
  76. package/dist/profiles/data-analyst/v1/prompts.test.d.ts +4 -0
  77. package/dist/profiles/data-analyst/v1/prompts.test.js +26 -0
  78. package/dist/profiles/data-analyst/v1/resources/playbooks/core.md +41 -0
  79. package/dist/profiles/data-analyst/v1/resources/playbooks/explore.md +26 -0
  80. package/dist/profiles/data-analyst/v1/resources/playbooks/index.md +8 -0
  81. package/dist/profiles/data-analyst/v1/resources/playbooks.d.ts +10 -0
  82. package/dist/profiles/data-analyst/v1/resources/playbooks.js +33 -0
  83. package/dist/profiles/index.d.ts +24 -0
  84. package/dist/profiles/index.js +73 -0
  85. package/dist/profiles/index.test.d.ts +1 -0
  86. package/dist/profiles/index.test.js +121 -0
  87. package/dist/{personas → profiles}/lib/playbook-resources.d.ts +8 -7
  88. package/dist/{personas → profiles}/lib/playbook-resources.js +15 -15
  89. package/dist/profiles/organization-audit/v1/index.d.ts +6 -0
  90. package/dist/profiles/organization-audit/v1/index.js +20 -0
  91. package/dist/{personas → profiles}/organization-audit/v1/prompts.test.js +2 -2
  92. package/dist/{personas → profiles}/organization-audit/v1/resources/playbooks.js +2 -2
  93. package/dist/profiles/profile.membership.test.d.ts +1 -0
  94. package/dist/profiles/profile.membership.test.js +36 -0
  95. package/dist/profiles/semantic-layer/v1/index.d.ts +6 -0
  96. package/dist/profiles/semantic-layer/v1/index.js +19 -0
  97. package/dist/{personas → profiles}/semantic-layer/v1/prompts.test.js +2 -2
  98. package/dist/{personas → profiles}/semantic-layer/v1/resources/playbooks.js +2 -2
  99. package/dist/profiles/types.d.ts +18 -0
  100. package/dist/{personas → profiles}/types.js +1 -1
  101. package/dist/protocol-contract.test.js +48 -3
  102. package/dist/server/capabilities.d.ts +6 -6
  103. package/dist/server/capabilities.js +11 -10
  104. package/dist/server/capabilities.test.js +8 -9
  105. package/dist/server/server.js +7 -7
  106. package/dist/stdio.process.test.js +61 -7
  107. package/dist/tools/ai-agents/agents.d.ts +1 -1
  108. package/dist/tools/ai-agents/agents.js +1 -1
  109. package/dist/tools/ai-agents/evaluations.d.ts +1 -1
  110. package/dist/tools/ai-agents/evaluations.js +1 -1
  111. package/dist/tools/ai-agents/helpers.d.ts +2 -3
  112. package/dist/tools/ai-agents/helpers.js +2 -4
  113. package/dist/tools/ai-agents/threads.d.ts +1 -1
  114. package/dist/tools/ai-agents/threads.js +1 -1
  115. package/dist/tools/composition/explain-content.js +3 -1
  116. package/dist/tools/index.d.ts +1 -1
  117. package/dist/tools/index.js +1 -1
  118. package/dist/tools/index.test.js +16 -10
  119. package/dist/tools/lib/schema-fields.d.ts +2 -0
  120. package/dist/tools/lib/schema-fields.js +4 -1
  121. package/dist/tools/lib/stable-stringify.d.ts +1 -1
  122. package/dist/tools/lib/stable-stringify.js +1 -1
  123. package/dist/tools/organization/invariants.test.d.ts +1 -1
  124. package/dist/tools/organization/invariants.test.js +5 -5
  125. package/dist/tools/project/developer-content-preview.d.ts +1 -1
  126. package/dist/tools/project/developer-content-preview.js +1 -1
  127. package/dist/tools/project/developer-content-shared.d.ts +1 -1
  128. package/dist/tools/project/developer-content-shared.js +1 -1
  129. package/dist/tools/project/developer-get-chart-as-code.test.js +1 -1
  130. package/dist/tools/project/invariants.test.d.ts +1 -1
  131. package/dist/tools/project/invariants.test.js +8 -8
  132. package/dist/tools/project/parameters.js +8 -3
  133. package/dist/tools/project/projects.d.ts +1 -4
  134. package/dist/tools/project/projects.js +32 -12
  135. package/dist/tools/project/projects.test.js +30 -7
  136. package/dist/tools/project/reader-content.js +6 -3
  137. package/dist/tools/project/reader-execution.js +4 -2
  138. package/dist/tools/project/reader-export-chart-image.js +1 -1
  139. package/dist/tools/project/reader-export-chart-image.test.js +2 -2
  140. package/dist/tools/project/spaces.js +12 -4
  141. package/dist/tools/project/spaces.test.d.ts +1 -0
  142. package/dist/tools/project/spaces.test.js +47 -0
  143. package/dist/tools/query/bounded-saved-query.d.ts +4 -3
  144. package/dist/tools/query/bounded-saved-query.js +3 -5
  145. package/dist/tools/query/lifecycle.js +10 -8
  146. package/dist/tools/query/query-ledger.d.ts +2 -1
  147. package/dist/tools/query/reader-tool-helpers.d.ts +4 -2
  148. package/dist/tools/query/reader-tool-helpers.js +7 -2
  149. package/dist/tools/query/run-metric-query.d.ts +6 -0
  150. package/dist/tools/query/run-metric-query.js +94 -0
  151. package/dist/tools/query/run-metric-query.test.d.ts +4 -0
  152. package/dist/tools/query/run-metric-query.test.js +116 -0
  153. package/dist/tools/registry.d.ts +8 -8
  154. package/dist/tools/registry.js +10 -6
  155. package/dist/tools/semantic/explores.js +43 -17
  156. package/dist/tools/semantic/metrics.js +22 -8
  157. package/dist/tools/semantic/query.js +25 -17
  158. package/dist/tools/shared.d.ts +1 -1
  159. package/dist/tools/shared.js +5 -5
  160. package/dist/tools/shared.test.js +4 -4
  161. package/dist/transports/streamable-http.js +46 -36
  162. package/dist/transports/streamable-http.test.js +9 -9
  163. package/package.json +6 -6
  164. package/dist/audit/server-persona.d.ts +0 -10
  165. package/dist/audit/server-persona.js +0 -19
  166. package/dist/governance/client-capabilities-cache.d.ts +0 -44
  167. package/dist/governance/client-capabilities-cache.js +0 -142
  168. package/dist/governance/client-capabilities-cache.test.js +0 -148
  169. package/dist/personas/ai-agent-ops/v1/index.d.ts +0 -8
  170. package/dist/personas/ai-agent-ops/v1/index.js +0 -41
  171. package/dist/personas/content-developer/v1/index.d.ts +0 -10
  172. package/dist/personas/content-developer/v1/index.js +0 -52
  173. package/dist/personas/content-governance/v1/index.d.ts +0 -9
  174. package/dist/personas/content-governance/v1/index.js +0 -29
  175. package/dist/personas/content-reader/v1/index.d.ts +0 -8
  176. package/dist/personas/content-reader/v1/index.js +0 -38
  177. package/dist/personas/index.d.ts +0 -23
  178. package/dist/personas/index.js +0 -78
  179. package/dist/personas/index.test.js +0 -124
  180. package/dist/personas/organization-audit/v1/index.d.ts +0 -8
  181. package/dist/personas/organization-audit/v1/index.js +0 -42
  182. package/dist/personas/persona.parity.test.js +0 -30
  183. package/dist/personas/semantic-layer/v1/index.d.ts +0 -8
  184. package/dist/personas/semantic-layer/v1/index.js +0 -32
  185. package/dist/personas/types.d.ts +0 -19
  186. /package/dist/{governance/client-capabilities-cache.test.d.ts → audit/server-profile.test.d.ts} +0 -0
  187. /package/dist/{personas/index.test.d.ts → config/obsolete-env.test.d.ts} +0 -0
  188. /package/dist/{personas/persona.parity.test.d.ts → governance/mcp-post-factory-context.test.d.ts} +0 -0
  189. /package/dist/{personas → profiles}/ai-agent-ops/v1/prompts.d.ts +0 -0
  190. /package/dist/{personas → profiles}/ai-agent-ops/v1/prompts.test.d.ts +0 -0
  191. /package/dist/{personas → profiles}/ai-agent-ops/v1/resources/playbooks/evaluation.md +0 -0
  192. /package/dist/{personas → profiles}/ai-agent-ops/v1/resources/playbooks/index.md +0 -0
  193. /package/dist/{personas → profiles}/ai-agent-ops/v1/resources/playbooks.d.ts +0 -0
  194. /package/dist/{personas → profiles}/content-developer/v1/prompts.d.ts +0 -0
  195. /package/dist/{personas → profiles}/content-developer/v1/prompts.test.d.ts +0 -0
  196. /package/dist/{personas → profiles}/content-developer/v1/resources/playbooks/content-move.md +0 -0
  197. /package/dist/{personas → profiles}/content-developer/v1/resources/playbooks/index.md +0 -0
  198. /package/dist/{personas → profiles}/content-developer/v1/resources/playbooks.d.ts +0 -0
  199. /package/dist/{personas → profiles}/content-governance/v1/prompts.d.ts +0 -0
  200. /package/dist/{personas → profiles}/content-governance/v1/prompts.js +0 -0
  201. /package/dist/{personas → profiles}/content-governance/v1/prompts.test.d.ts +0 -0
  202. /package/dist/{personas → profiles}/content-governance/v1/resources/playbooks/charts.md +0 -0
  203. /package/dist/{personas → profiles}/content-governance/v1/resources/playbooks/dashboards.md +0 -0
  204. /package/dist/{personas → profiles}/content-governance/v1/resources/playbooks/index.md +0 -0
  205. /package/dist/{personas → profiles}/content-governance/v1/resources/playbooks.d.ts +0 -0
  206. /package/dist/{personas → profiles}/content-reader/v1/prompts.d.ts +0 -0
  207. /package/dist/{personas → profiles}/content-reader/v1/prompts.js +0 -0
  208. /package/dist/{personas → profiles}/content-reader/v1/prompts.test.d.ts +0 -0
  209. /package/dist/{personas → profiles}/content-reader/v1/resources/playbooks/compare.md +0 -0
  210. /package/dist/{personas → profiles}/content-reader/v1/resources/playbooks/explain-run.md +0 -0
  211. /package/dist/{personas → profiles}/content-reader/v1/resources/playbooks/index.md +0 -0
  212. /package/dist/{personas → profiles}/content-reader/v1/resources/playbooks.d.ts +0 -0
  213. /package/dist/{personas → profiles}/organization-audit/v1/prompts.d.ts +0 -0
  214. /package/dist/{personas → profiles}/organization-audit/v1/prompts.js +0 -0
  215. /package/dist/{personas → profiles}/organization-audit/v1/prompts.test.d.ts +0 -0
  216. /package/dist/{personas → profiles}/organization-audit/v1/resources/playbooks/access.md +0 -0
  217. /package/dist/{personas → profiles}/organization-audit/v1/resources/playbooks/content.md +0 -0
  218. /package/dist/{personas → profiles}/organization-audit/v1/resources/playbooks/core.md +0 -0
  219. /package/dist/{personas → profiles}/organization-audit/v1/resources/playbooks/deliveries.md +0 -0
  220. /package/dist/{personas → profiles}/organization-audit/v1/resources/playbooks/index.md +0 -0
  221. /package/dist/{personas → profiles}/organization-audit/v1/resources/playbooks.d.ts +0 -0
  222. /package/dist/{personas → profiles}/semantic-layer/v1/prompts.d.ts +0 -0
  223. /package/dist/{personas → profiles}/semantic-layer/v1/prompts.js +0 -0
  224. /package/dist/{personas → profiles}/semantic-layer/v1/prompts.test.d.ts +0 -0
  225. /package/dist/{personas → profiles}/semantic-layer/v1/resources/playbooks/compose-compile.md +0 -0
  226. /package/dist/{personas → profiles}/semantic-layer/v1/resources/playbooks/core.md +0 -0
  227. /package/dist/{personas → profiles}/semantic-layer/v1/resources/playbooks/explore.md +0 -0
  228. /package/dist/{personas → profiles}/semantic-layer/v1/resources/playbooks/index.md +0 -0
  229. /package/dist/{personas → profiles}/semantic-layer/v1/resources/playbooks.d.ts +0 -0
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const client_1 = require("@lightdash-tools/client");
4
4
  const common_1 = require("@lightdash-tools/common");
5
5
  const vitest_1 = require("vitest");
6
- const server_persona_js_1 = require("../audit/server-persona.js");
6
+ const server_profile_js_1 = require("../audit/server-profile.js");
7
7
  const available_projects_js_1 = require("../governance/available-projects.js");
8
8
  const project_pin_js_1 = require("../governance/project-pin.js");
9
9
  const shared_js_1 = require("./shared.js");
@@ -42,8 +42,8 @@ const PROJECT_B = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb';
42
42
  const result = await handler({});
43
43
  (0, vitest_1.expect)(result.content[0].text).toBe('success');
44
44
  });
45
- (0, vitest_1.it)('audit entry includes channel, clientSessionId, and personaId', async () => {
46
- (0, server_persona_js_1.bindServerPersona)(mockServer, 'semantic-layer');
45
+ (0, vitest_1.it)('audit entry includes channel, clientSessionId, and profileId', async () => {
46
+ (0, server_profile_js_1.bindServerProfile)(mockServer, 'semantic-layer');
47
47
  (0, shared_js_1.registerToolSafe)(mockServer, 'audit_attrs', {
48
48
  description: 'Audit attrs',
49
49
  inputSchema: {},
@@ -57,7 +57,7 @@ const PROJECT_B = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb';
57
57
  message: `${shared_js_1.TOOL_PREFIX}audit_attrs success`,
58
58
  status: 'success',
59
59
  clientSessionId: 'mcp-client-session-9',
60
- personaId: 'semantic-layer',
60
+ profileId: 'semantic-layer',
61
61
  tool: `${shared_js_1.TOOL_PREFIX}audit_attrs`,
62
62
  }));
63
63
  });
@@ -4,6 +4,7 @@ exports.createStreamableHttpServer = createStreamableHttpServer;
4
4
  exports.startStreamableHttpServer = startStreamableHttpServer;
5
5
  const node_http_1 = require("node:http");
6
6
  const node_1 = require("@modelcontextprotocol/node");
7
+ const server_1 = require("@modelcontextprotocol/server");
7
8
  const audit_js_1 = require("../audit/audit.js");
8
9
  const tool_audit_context_js_1 = require("../audit/tool-audit-context.js");
9
10
  const auth_mode_js_1 = require("../auth/auth-mode.js");
@@ -18,12 +19,24 @@ const token_hash_js_1 = require("../auth/token-hash.js");
18
19
  const load_mcp_config_js_1 = require("../config/load-mcp-config.js");
19
20
  const runtime_js_1 = require("../config/runtime.js");
20
21
  const available_projects_js_1 = require("../governance/available-projects.js");
21
- const client_capabilities_cache_js_1 = require("../governance/client-capabilities-cache.js");
22
+ const mcp_post_factory_context_js_1 = require("../governance/mcp-post-factory-context.js");
22
23
  const project_pin_js_1 = require("../governance/project-pin.js");
23
- const index_js_1 = require("../personas/index.js");
24
+ const index_js_1 = require("../profiles/index.js");
24
25
  const server_js_1 = require("../server/server.js");
25
26
  const http_body_js_1 = require("./http-body.js");
26
27
  const http_response_js_1 = require("./http-response.js");
28
+ function reportMcpHttpError(error) {
29
+ console.error('MCP HTTP error:', error);
30
+ }
31
+ function createProcessMcpHttpHandler() {
32
+ return (0, server_1.createMcpHandler)(() => {
33
+ const store = (0, mcp_post_factory_context_js_1.getMcpPostFactoryStore)();
34
+ if (!store) {
35
+ throw new Error('MCP request factory context is missing');
36
+ }
37
+ return (0, server_js_1.createLightdashMcpServer)(store.contextProvider, { profile: store.profile });
38
+ }, { legacy: 'stateless', onerror: reportMcpHttpError });
39
+ }
27
40
  function listen(server, port, host) {
28
41
  return new Promise((resolve, reject) => {
29
42
  server.once('error', reject);
@@ -78,7 +91,7 @@ function handleHealth(path, res, config) {
78
91
  }
79
92
  }
80
93
  /**
81
- * Auth helpers for persona MCP routes. PRM path resolution lives in
94
+ * Auth helpers for profile MCP routes. PRM path resolution lives in
82
95
  * `oauth-protected-resource.ts` (single owner for well-known PRM grammar).
83
96
  */
84
97
  async function ensureEndpointAuth(req, res, config, mcpPath) {
@@ -130,12 +143,12 @@ function createContextProviderForRequest(config, req) {
130
143
  return createEnvContextProvider(config);
131
144
  }
132
145
  /**
133
- * Handles a MCP POST by creating a fresh stateless transport + server per request.
134
- * No session affinity — each POST is independent (ADR-0019).
146
+ * Auth / Origin / pin run outside the handler. ALS supplies profile + provider
147
+ * so the process-lifetime createMcpHandler factory can build a fresh McpServer.
135
148
  */
136
149
  async function handleMcpPost(ctx) {
137
- const { req, res, config, persona } = ctx;
138
- if (!(await ensureEndpointAuth(req, res, config, persona.path))) {
150
+ const { req, res, config, profile, nodeHandler } = ctx;
151
+ if (!(await ensureEndpointAuth(req, res, config, profile.path))) {
139
152
  (0, http_body_js_1.drainRequestBody)(req);
140
153
  return;
141
154
  }
@@ -153,18 +166,8 @@ async function handleMcpPost(ctx) {
153
166
  }
154
167
  }
155
168
  const contextProvider = createContextProviderForRequest(config, req);
156
- const transport = new node_1.NodeStreamableHTTPServerTransport({ sessionIdGenerator: undefined });
157
- const server = (0, server_js_1.createLightdashMcpServer)(contextProvider, { persona });
158
169
  const auditAuth = getOAuthAuditContext(req);
159
- (0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(server, body, auditAuth, persona.path);
160
- try {
161
- await server.connect(transport);
162
- await (0, tool_audit_context_js_1.runWithToolAuditAuthAsync)(auditAuth, () => transport.handleRequest(req, res, body));
163
- }
164
- finally {
165
- await transport.close().catch(() => undefined);
166
- await server.close().catch(() => undefined);
167
- }
170
+ await (0, mcp_post_factory_context_js_1.runWithMcpPostFactoryAsync)({ contextProvider, profile }, () => (0, tool_audit_context_js_1.runWithToolAuditAuthAsync)(auditAuth, () => nodeHandler(req, res, body)));
168
171
  }
169
172
  async function createStreamableHttpServer(config) {
170
173
  var _a;
@@ -176,9 +179,11 @@ async function createStreamableHttpServer(config) {
176
179
  (0, audit_js_1.initAuditLog)((0, runtime_js_1.getAuditLogPath)());
177
180
  let httpConfig = inputConfig;
178
181
  let oauthBroker;
182
+ const mcpHttpHandler = createProcessMcpHttpHandler();
183
+ const mcpNodeHandler = (0, node_1.toNodeHandler)(mcpHttpHandler, { onerror: reportMcpHttpError });
179
184
  const server = (0, node_http_1.createServer)((req, res) => {
180
- handleHttpRequest(req, res, httpConfig, oauthBroker).catch((err) => {
181
- console.error('MCP HTTP handler error:', err);
185
+ handleHttpRequest(req, res, httpConfig, oauthBroker, mcpNodeHandler).catch((err) => {
186
+ reportMcpHttpError(err);
182
187
  if (!res.headersSent) {
183
188
  (0, http_response_js_1.sendJson)(res, 500, { error: 'Internal Server Error' });
184
189
  }
@@ -196,20 +201,25 @@ async function createStreamableHttpServer(config) {
196
201
  port,
197
202
  baseUrl,
198
203
  config: httpConfig,
199
- close: () => new Promise((resolve, reject) => {
200
- server.close((err) => {
201
- if (err)
202
- reject(err);
203
- else
204
- resolve();
204
+ close: async () => {
205
+ await mcpHttpHandler.close().catch((err) => {
206
+ reportMcpHttpError(err);
207
+ });
208
+ await new Promise((resolve, reject) => {
209
+ server.close((err) => {
210
+ if (err)
211
+ reject(err);
212
+ else
213
+ resolve();
214
+ });
205
215
  });
206
- }),
216
+ },
207
217
  };
208
218
  }
209
219
  function startStreamableHttpServer(config) {
210
220
  void createStreamableHttpServer(config)
211
221
  .then(({ baseUrl, config: httpConfig }) => {
212
- const paths = (0, index_js_1.listPersonaPaths)()
222
+ const paths = (0, index_js_1.listProfilePaths)()
213
223
  .map((p) => `${baseUrl}${p}`)
214
224
  .join(', ');
215
225
  console.error(`Lightdash MCP server listening on ${paths} (auth: ${httpConfig.authMode})`);
@@ -230,14 +240,14 @@ function requestOrigin(req) {
230
240
  * Applies CORS reflect headers without blocking.
231
241
  * When `reflectAnyOrigin` is true (OAuth AS / PRM), always echo Origin and ignore
232
242
  * `ALLOWED_ORIGINS` so Cursor loopback (`http://localhost:8787`) can read token JSON
233
- * even if persona MCP routes use a browser allowlist.
243
+ * even if profile MCP routes use a browser allowlist.
234
244
  */
235
245
  function applyOptionalCorsHeaders(req, res, config, reflectAnyOrigin = false) {
236
246
  const allowed = reflectAnyOrigin ? [] : config.allowedOrigins;
237
247
  (0, http_response_js_1.applyResponseHeaders)(res, (0, http_response_js_1.buildCorsHeaders)(requestOrigin(req), allowed, reflectAnyOrigin));
238
248
  }
239
249
  /**
240
- * Validates Origin and applies CORS headers for persona MCP routes.
250
+ * Validates Origin and applies CORS headers for profile MCP routes.
241
251
  * Short-circuits OPTIONS preflight with 204; returns true when the request is fully handled.
242
252
  */
243
253
  function applyOriginGuardAndCors(req, res, config) {
@@ -278,26 +288,26 @@ async function handlePublicHttpPaths(req, res, config, path, oauthBroker) {
278
288
  }
279
289
  return false;
280
290
  }
281
- async function handleHttpRequest(req, res, config, oauthBroker) {
291
+ async function handleHttpRequest(req, res, config, oauthBroker, nodeHandler) {
282
292
  var _a, _b;
283
293
  const path = (_b = ((_a = req.url) !== null && _a !== void 0 ? _a : '').split('?')[0]) !== null && _b !== void 0 ? _b : '';
284
294
  if (await handlePublicHttpPaths(req, res, config, path, oauthBroker)) {
285
295
  return;
286
296
  }
287
- // Persona MCP routes: Origin allowlist is enforced (CSRF / browser blast-radius).
297
+ // Profile MCP routes: Origin allowlist is enforced (CSRF / browser blast-radius).
288
298
  if (applyOriginGuardAndCors(req, res, config)) {
289
299
  return;
290
300
  }
291
- const persona = (0, index_js_1.getPersonaByPath)(path);
292
- if (!persona) {
301
+ const profile = (0, index_js_1.getProfileByPath)(path);
302
+ if (!profile) {
293
303
  (0, http_response_js_1.sendJson)(res, 404, { error: 'Not Found' });
294
304
  return;
295
305
  }
296
- // Sessionless: only POST is supported on persona MCP paths.
306
+ // Sessionless: only POST is supported on profile MCP paths.
297
307
  if (req.method !== 'POST') {
298
308
  res.writeHead(405, { Allow: 'POST' }).end();
299
309
  return;
300
310
  }
301
311
  const pinnedProjectUuid = (0, project_pin_js_1.extractPinnedProjectFromRequest)(req);
302
- await (0, project_pin_js_1.runWithProjectPinAsync)(pinnedProjectUuid, () => handleMcpPost({ req, res, config, persona }));
312
+ await (0, project_pin_js_1.runWithProjectPinAsync)(pinnedProjectUuid, () => handleMcpPost({ req, res, config, profile, nodeHandler }));
303
313
  }
@@ -6,9 +6,9 @@ const www_authenticate_js_1 = require("../auth/resource-server/www-authenticate.
6
6
  const env_js_1 = require("../config/env.js");
7
7
  const load_mcp_config_js_1 = require("../config/load-mcp-config.js");
8
8
  const test_mcp_http_config_js_1 = require("../config/test-mcp-http-config.js");
9
- const index_js_1 = require("../personas/content-reader/v1/index.js");
10
- const index_js_2 = require("../personas/organization-audit/v1/index.js");
11
- const index_js_3 = require("../personas/semantic-layer/v1/index.js");
9
+ const index_js_1 = require("../profiles/content-reader/v1/index.js");
10
+ const index_js_2 = require("../profiles/organization-audit/v1/index.js");
11
+ const index_js_3 = require("../profiles/semantic-layer/v1/index.js");
12
12
  const http_response_js_1 = require("./http-response.js");
13
13
  const streamable_http_js_1 = require("./streamable-http.js");
14
14
  const oauthConfig = (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
@@ -65,18 +65,18 @@ function clearMcpEnv() {
65
65
  });
66
66
  (0, vitest_1.describe)('streamable HTTP OAuth metadata', () => {
67
67
  (0, vitest_1.it)('builds protected resource metadata with MCP host as authorization_servers', () => {
68
- const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_3.SEMANTIC_LAYER_PERSONA_PATH);
68
+ const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_3.SEMANTIC_LAYER_PROFILE_PATH);
69
69
  (0, vitest_1.expect)(metadata.authorization_servers).toEqual(['https://mcp.example.com']);
70
- (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_3.SEMANTIC_LAYER_PERSONA_PATH}`);
70
+ (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_3.SEMANTIC_LAYER_PROFILE_PATH}`);
71
71
  (0, vitest_1.expect)((0, oauth_protected_resource_js_1.getAuthorizationServerMetadataUrl)(metadata.authorization_servers[0])).toBe('https://mcp.example.com/.well-known/oauth-authorization-server');
72
72
  });
73
73
  (0, vitest_1.it)('builds organization-audit protected resource metadata', () => {
74
- const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_2.ORGANIZATION_AUDIT_PERSONA_PATH);
75
- (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_2.ORGANIZATION_AUDIT_PERSONA_PATH}`);
74
+ const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_2.ORGANIZATION_AUDIT_PROFILE_PATH);
75
+ (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_2.ORGANIZATION_AUDIT_PROFILE_PATH}`);
76
76
  });
77
77
  (0, vitest_1.it)('builds content-reader protected resource metadata', () => {
78
- const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_1.CONTENT_READER_PERSONA_PATH);
79
- (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_1.CONTENT_READER_PERSONA_PATH}`);
78
+ const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_1.CONTENT_READER_PROFILE_PATH);
79
+ (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_1.CONTENT_READER_PROFILE_PATH}`);
80
80
  });
81
81
  (0, vitest_1.it)('builds WWW-Authenticate challenges with resource_metadata for OAuth clients', () => {
82
82
  const header = (0, www_authenticate_js_1.buildWwwAuthenticateHeader)({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lightdash-tools/mcp",
3
- "version": "0.9.0",
4
- "description": "MCP server for Lightdash semantic-layer, organization-audit, content-reader, content-developer, content-governance, and ai-agent-ops personas.",
3
+ "version": "0.12.0",
4
+ "description": "MCP server for Lightdash semantic-layer, organization-audit, content-reader, content-developer, content-governance, and ai-agent-ops profiles.",
5
5
  "keywords": [],
6
6
  "repository": {
7
7
  "type": "git",
@@ -22,10 +22,10 @@
22
22
  "@modelcontextprotocol/node": "2.0.0",
23
23
  "@modelcontextprotocol/server": "2.0.0",
24
24
  "commander": "^15.0.0",
25
- "hono": "^4.12.32",
25
+ "hono": "^4.13.0",
26
26
  "zod": "^4.4.3",
27
- "@lightdash-tools/client": "0.9.0",
28
- "@lightdash-tools/common": "0.9.0"
27
+ "@lightdash-tools/client": "0.12.0",
28
+ "@lightdash-tools/common": "0.12.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@modelcontextprotocol/client": "2.0.0",
@@ -35,7 +35,7 @@
35
35
  "access": "public"
36
36
  },
37
37
  "scripts": {
38
- "build": "rm -rf dist && tsc && for p in semantic-layer organization-audit content-reader content-developer content-governance ai-agent-ops; do mkdir -p dist/personas/$p/v1/resources/playbooks && cp -R src/personas/$p/v1/resources/playbooks/. dist/personas/$p/v1/resources/playbooks/; done",
38
+ "build": "rm -rf dist && tsc && for p in semantic-layer organization-audit content-reader content-developer content-governance ai-agent-ops data-analyst; do mkdir -p dist/profiles/$p/v1/resources/playbooks && cp -R src/profiles/$p/v1/resources/playbooks/. dist/profiles/$p/v1/resources/playbooks/; done",
39
39
  "start": "node dist/index.js",
40
40
  "start:http": "node dist/http.js",
41
41
  "test": "pnpm --dir ../.. exec vitest run packages/mcp/src"
@@ -1,10 +0,0 @@
1
- /**
2
- * Bind an MCP server instance to a persona id for audit attribution.
3
- * Call once in registerCapabilities before registering tools; registerToolSafe
4
- * reads it at wrap time. Tool behavior that needs personaId still uses
5
- * registerToolsByIds options (e.g. get_project) — that path is separate.
6
- */
7
- /** Associate a persona id with an MCP server (call before registering tools). */
8
- export declare function bindServerPersona(server: object, personaId: string): void;
9
- /** Persona id bound to this server, if any. */
10
- export declare function getServerPersona(server: object): string | undefined;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- /**
3
- * Bind an MCP server instance to a persona id for audit attribution.
4
- * Call once in registerCapabilities before registering tools; registerToolSafe
5
- * reads it at wrap time. Tool behavior that needs personaId still uses
6
- * registerToolsByIds options (e.g. get_project) — that path is separate.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.bindServerPersona = bindServerPersona;
10
- exports.getServerPersona = getServerPersona;
11
- const serverPersona = new WeakMap();
12
- /** Associate a persona id with an MCP server (call before registering tools). */
13
- function bindServerPersona(server, personaId) {
14
- serverPersona.set(server, personaId);
15
- }
16
- /** Persona id bound to this server, if any. */
17
- function getServerPersona(server) {
18
- return serverPersona.get(server);
19
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * Principal- and persona-scoped, process-local client capabilities cache (ADR-0019).
3
- *
4
- * Sessionless HTTP creates a fresh McpServer per POST, so initialize-declared
5
- * capabilities would otherwise be lost on tools/call. Cache is best-effort
6
- * same-replica (like in-memory OAuth); clients may also send per-request
7
- * `_meta[CLIENT_CAPABILITIES_META_KEY]`.
8
- *
9
- * Anonymous principals (shared-key / none with no subject or tokenHash) never
10
- * use the cache — last-writer-wins would cross clients on one process.
11
- *
12
- * OAuth clients are keyed by tokenHash (not subject) so concurrent MCP hosts
13
- * for the same user do not overwrite each other's capabilities. Per-request
14
- * `_meta[CLIENT_CAPABILITIES_META_KEY]` remains the multi-replica escape hatch.
15
- */
16
- import type { ToolAuditAuthContext } from '../audit/tool-audit-context.js';
17
- import type { ClientCapabilities, McpServer } from '@modelcontextprotocol/server';
18
- export declare const CLIENT_CAPABILITIES_CACHE_TTL_MS: number;
19
- /** Same shape as tool-audit auth; tokenHash → subject → anonymous. */
20
- export type CapabilitiesPrincipal = ToolAuditAuthContext;
21
- export declare function resolveCapabilitiesPrincipalKey(principal: CapabilitiesPrincipal, scope?: string): string;
22
- export declare function rememberClientCapabilities(principal: CapabilitiesPrincipal, clientCapabilities: ClientCapabilities, options?: {
23
- ttlMs?: number;
24
- scope?: string;
25
- }): void;
26
- export declare function getRememberedClientCapabilities(principal: CapabilitiesPrincipal, scope?: string): ClientCapabilities | undefined;
27
- export declare function resetClientCapabilitiesCacheForTests(): void;
28
- /** Capabilities from initialize params or per-request `_meta` envelope. */
29
- export declare function extractClientCapabilitiesFromBody(body: unknown): {
30
- clientCapabilities?: ClientCapabilities;
31
- fromInitialize: boolean;
32
- };
33
- /**
34
- * Seed connection-scoped client capabilities on a fresh per-request McpServer.
35
- * Mirrors SDK-internal seedClientIdentityFromEnvelope (not public on 2.0.0).
36
- */
37
- export declare function seedClientCapabilitiesOntoServer(mcpServer: McpServer, clientCapabilities: ClientCapabilities | undefined): void;
38
- /**
39
- * Remember initialize caps, or seed the fresh server from envelope meta / cache.
40
- * Call after createLightdashMcpServer, before transport.handleRequest.
41
- * On initialize, only cache — the SDK seeds this connection from params.
42
- * `scope` (e.g. persona.path) isolates cache entries across HTTP personas.
43
- */
44
- export declare function prepareServerClientCapabilities(mcpServer: McpServer, body: unknown, principal: CapabilitiesPrincipal, scope?: string): void;
@@ -1,142 +0,0 @@
1
- "use strict";
2
- /**
3
- * Principal- and persona-scoped, process-local client capabilities cache (ADR-0019).
4
- *
5
- * Sessionless HTTP creates a fresh McpServer per POST, so initialize-declared
6
- * capabilities would otherwise be lost on tools/call. Cache is best-effort
7
- * same-replica (like in-memory OAuth); clients may also send per-request
8
- * `_meta[CLIENT_CAPABILITIES_META_KEY]`.
9
- *
10
- * Anonymous principals (shared-key / none with no subject or tokenHash) never
11
- * use the cache — last-writer-wins would cross clients on one process.
12
- *
13
- * OAuth clients are keyed by tokenHash (not subject) so concurrent MCP hosts
14
- * for the same user do not overwrite each other's capabilities. Per-request
15
- * `_meta[CLIENT_CAPABILITIES_META_KEY]` remains the multi-replica escape hatch.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.CLIENT_CAPABILITIES_CACHE_TTL_MS = void 0;
19
- exports.resolveCapabilitiesPrincipalKey = resolveCapabilitiesPrincipalKey;
20
- exports.rememberClientCapabilities = rememberClientCapabilities;
21
- exports.getRememberedClientCapabilities = getRememberedClientCapabilities;
22
- exports.resetClientCapabilitiesCacheForTests = resetClientCapabilitiesCacheForTests;
23
- exports.extractClientCapabilitiesFromBody = extractClientCapabilitiesFromBody;
24
- exports.seedClientCapabilitiesOntoServer = seedClientCapabilitiesOntoServer;
25
- exports.prepareServerClientCapabilities = prepareServerClientCapabilities;
26
- const server_1 = require("@modelcontextprotocol/server");
27
- exports.CLIENT_CAPABILITIES_CACHE_TTL_MS = 30 * 60000;
28
- const ANONYMOUS_PRINCIPAL = 'anonymous';
29
- const cache = new Map();
30
- function resolveCapabilitiesPrincipalKey(principal, scope) {
31
- let key;
32
- if (typeof principal.tokenHash === 'string' && principal.tokenHash.length > 0) {
33
- key = `token:${principal.tokenHash}`;
34
- }
35
- else if (typeof principal.subject === 'string' && principal.subject.length > 0) {
36
- key = `subject:${principal.subject}`;
37
- }
38
- else {
39
- key = ANONYMOUS_PRINCIPAL;
40
- }
41
- if (typeof scope === 'string' && scope.length > 0) {
42
- return `${key}@${scope}`;
43
- }
44
- return key;
45
- }
46
- function hasCapabilitiesPrincipal(principal) {
47
- return ((typeof principal.tokenHash === 'string' && principal.tokenHash.length > 0) ||
48
- (typeof principal.subject === 'string' && principal.subject.length > 0));
49
- }
50
- function rememberClientCapabilities(principal, clientCapabilities, options) {
51
- var _a;
52
- if (!hasCapabilitiesPrincipal(principal)) {
53
- return;
54
- }
55
- const key = resolveCapabilitiesPrincipalKey(principal, options === null || options === void 0 ? void 0 : options.scope);
56
- const ttlMs = (_a = options === null || options === void 0 ? void 0 : options.ttlMs) !== null && _a !== void 0 ? _a : exports.CLIENT_CAPABILITIES_CACHE_TTL_MS;
57
- cache.set(key, {
58
- clientCapabilities,
59
- expiresAt: Date.now() + ttlMs,
60
- });
61
- }
62
- function getRememberedClientCapabilities(principal, scope) {
63
- if (!hasCapabilitiesPrincipal(principal)) {
64
- return undefined;
65
- }
66
- const key = resolveCapabilitiesPrincipalKey(principal, scope);
67
- const entry = cache.get(key);
68
- if (!entry) {
69
- return undefined;
70
- }
71
- if (entry.expiresAt < Date.now()) {
72
- cache.delete(key);
73
- return undefined;
74
- }
75
- return entry.clientCapabilities;
76
- }
77
- function resetClientCapabilitiesCacheForTests() {
78
- cache.clear();
79
- }
80
- function asSingleJsonRpcRequest(body) {
81
- // Streamable HTTP does not support JSON-RPC batches; ignore arrays here.
82
- if (body === undefined || body === null || Array.isArray(body)) {
83
- return undefined;
84
- }
85
- if (typeof body !== 'object') {
86
- return undefined;
87
- }
88
- return body;
89
- }
90
- /** Capabilities from initialize params or per-request `_meta` envelope. */
91
- function extractClientCapabilitiesFromBody(body) {
92
- var _a, _b;
93
- const msg = asSingleJsonRpcRequest(body);
94
- if (!msg) {
95
- return { fromInitialize: false };
96
- }
97
- if (msg.method === 'initialize') {
98
- const caps = (_a = msg.params) === null || _a === void 0 ? void 0 : _a.capabilities;
99
- return caps !== undefined
100
- ? { clientCapabilities: caps, fromInitialize: true }
101
- : { fromInitialize: true };
102
- }
103
- const meta = (_b = msg.params) === null || _b === void 0 ? void 0 : _b._meta;
104
- if (meta !== undefined && typeof meta === 'object') {
105
- const fromMeta = Reflect.get(meta, server_1.CLIENT_CAPABILITIES_META_KEY);
106
- if (fromMeta !== undefined) {
107
- return { clientCapabilities: fromMeta, fromInitialize: false };
108
- }
109
- }
110
- return { fromInitialize: false };
111
- }
112
- /**
113
- * Seed connection-scoped client capabilities on a fresh per-request McpServer.
114
- * Mirrors SDK-internal seedClientIdentityFromEnvelope (not public on 2.0.0).
115
- */
116
- function seedClientCapabilitiesOntoServer(mcpServer, clientCapabilities) {
117
- if (clientCapabilities === undefined) {
118
- return;
119
- }
120
- // SDK Server stores initialize-scoped identity privately; 2025-era elicitation
121
- // shim reads `_clientCapabilities` via getClientCapabilities().
122
- const lowLevel = mcpServer.server;
123
- lowLevel._clientCapabilities = clientCapabilities;
124
- }
125
- /**
126
- * Remember initialize caps, or seed the fresh server from envelope meta / cache.
127
- * Call after createLightdashMcpServer, before transport.handleRequest.
128
- * On initialize, only cache — the SDK seeds this connection from params.
129
- * `scope` (e.g. persona.path) isolates cache entries across HTTP personas.
130
- */
131
- function prepareServerClientCapabilities(mcpServer, body, principal, scope) {
132
- var _a;
133
- const extracted = extractClientCapabilitiesFromBody(body);
134
- if (extracted.fromInitialize) {
135
- if (extracted.clientCapabilities !== undefined) {
136
- rememberClientCapabilities(principal, extracted.clientCapabilities, { scope });
137
- }
138
- return;
139
- }
140
- const caps = (_a = extracted.clientCapabilities) !== null && _a !== void 0 ? _a : getRememberedClientCapabilities(principal, scope);
141
- seedClientCapabilitiesOntoServer(mcpServer, caps);
142
- }
@@ -1,148 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const server_1 = require("@modelcontextprotocol/server");
4
- const vitest_1 = require("vitest");
5
- const client_capabilities_cache_js_1 = require("./client-capabilities-cache.js");
6
- (0, vitest_1.describe)('client-capabilities-cache', () => {
7
- (0, vitest_1.beforeEach)(() => {
8
- (0, client_capabilities_cache_js_1.resetClientCapabilitiesCacheForTests)();
9
- });
10
- (0, vitest_1.it)('resolves principal key preferring tokenHash then subject', () => {
11
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.resolveCapabilitiesPrincipalKey)({ subject: 'u1', tokenHash: 't1' })).toBe('token:t1');
12
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.resolveCapabilitiesPrincipalKey)({ tokenHash: 't1' })).toBe('token:t1');
13
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.resolveCapabilitiesPrincipalKey)({ subject: 'u1' })).toBe('subject:u1');
14
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.resolveCapabilitiesPrincipalKey)({})).toBe('anonymous');
15
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.resolveCapabilitiesPrincipalKey)({ subject: 'u1' }, '/content-governance/v1/mcp')).toBe('subject:u1@/content-governance/v1/mcp');
16
- });
17
- (0, vitest_1.it)('isolates cache entries for same subject with different tokenHash', () => {
18
- (0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1', tokenHash: 'token-a' }, { elicitation: { form: {} } });
19
- (0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1', tokenHash: 'token-b' }, { roots: {} });
20
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1', tokenHash: 'token-a' })).toEqual({
21
- elicitation: { form: {} },
22
- });
23
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1', tokenHash: 'token-b' })).toEqual({
24
- roots: {},
25
- });
26
- });
27
- (0, vitest_1.it)('skips cache for anonymous principals to avoid cross-client collision', () => {
28
- (0, client_capabilities_cache_js_1.rememberClientCapabilities)({}, { elicitation: { form: {} } });
29
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({})).toBeUndefined();
30
- const server = new server_1.McpServer({ name: 't', version: '0.0.0' });
31
- (0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(server, {
32
- jsonrpc: '2.0',
33
- method: 'initialize',
34
- params: { capabilities: { elicitation: { form: {} } } },
35
- id: 1,
36
- }, {});
37
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({})).toBeUndefined();
38
- (0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(server, {
39
- jsonrpc: '2.0',
40
- method: 'tools/call',
41
- params: { name: 'x', arguments: {} },
42
- id: 2,
43
- }, {});
44
- (0, vitest_1.expect)(readSeededClientCapabilities(server)).toBeUndefined();
45
- });
46
- (0, vitest_1.it)('isolates cache entries by persona scope', () => {
47
- (0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { elicitation: { form: {} } }, { scope: '/content-governance/v1/mcp' });
48
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1' }, '/semantic-layer/v1/mcp')).toBeUndefined();
49
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1' }, '/content-governance/v1/mcp')).toEqual({ elicitation: { form: {} } });
50
- });
51
- (0, vitest_1.it)('remembers and returns capabilities until TTL expires', () => {
52
- (0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { elicitation: { form: {} } }, { ttlMs: 60000 });
53
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1' })).toEqual({
54
- elicitation: { form: {} },
55
- });
56
- (0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { elicitation: { form: {} } }, { ttlMs: -1 });
57
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1' })).toBeUndefined();
58
- });
59
- (0, vitest_1.it)('overwrites capabilities on re-initialize for the same principal', () => {
60
- (0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { roots: {} });
61
- (0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { elicitation: { form: {} } });
62
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1' })).toEqual({
63
- elicitation: { form: {} },
64
- });
65
- });
66
- (0, vitest_1.it)('extracts capabilities from initialize and from _meta', () => {
67
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.extractClientCapabilitiesFromBody)({
68
- jsonrpc: '2.0',
69
- method: 'initialize',
70
- params: {
71
- capabilities: { elicitation: { form: {} } },
72
- clientInfo: { name: 't', version: '1' },
73
- },
74
- id: 1,
75
- })).toEqual({
76
- fromInitialize: true,
77
- clientCapabilities: { elicitation: { form: {} } },
78
- });
79
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.extractClientCapabilitiesFromBody)({
80
- jsonrpc: '2.0',
81
- method: 'tools/call',
82
- params: {
83
- name: 'x',
84
- arguments: {},
85
- _meta: { [server_1.CLIENT_CAPABILITIES_META_KEY]: { elicitation: { form: {} } } },
86
- },
87
- id: 2,
88
- })).toEqual({
89
- fromInitialize: false,
90
- clientCapabilities: { elicitation: { form: {} } },
91
- });
92
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.extractClientCapabilitiesFromBody)([{ method: 'initialize' }])).toEqual({
93
- fromInitialize: false,
94
- });
95
- });
96
- (0, vitest_1.it)('seeds Server getClientCapabilities for elicitation shim', () => {
97
- const server = new server_1.McpServer({ name: 'test', version: '0.0.0' });
98
- (0, vitest_1.expect)(readSeededClientCapabilities(server)).toBeUndefined();
99
- (0, client_capabilities_cache_js_1.seedClientCapabilitiesOntoServer)(server, { elicitation: { form: {} } });
100
- (0, vitest_1.expect)(readSeededClientCapabilities(server)).toEqual({ elicitation: { form: {} } });
101
- });
102
- (0, vitest_1.it)('prepare remembers initialize then seeds a fresh server from cache', () => {
103
- const scope = '/content-governance/v1/mcp';
104
- const first = new server_1.McpServer({ name: 'a', version: '0.0.0' });
105
- (0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(first, {
106
- jsonrpc: '2.0',
107
- method: 'initialize',
108
- params: {
109
- protocolVersion: '2024-11-05',
110
- capabilities: { elicitation: { form: {} } },
111
- clientInfo: { name: 'c', version: '1' },
112
- },
113
- id: 1,
114
- }, { subject: 'user-a' }, scope);
115
- // Initialize path only remembers; SDK seeds this connection from params.
116
- (0, vitest_1.expect)(readSeededClientCapabilities(first)).toBeUndefined();
117
- (0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'user-a' }, scope)).toEqual({
118
- elicitation: { form: {} },
119
- });
120
- const second = new server_1.McpServer({ name: 'b', version: '0.0.0' });
121
- (0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(second, {
122
- jsonrpc: '2.0',
123
- method: 'tools/call',
124
- params: { name: 'lightdash_delete_chart', arguments: {} },
125
- id: 2,
126
- }, { subject: 'user-a' }, scope);
127
- (0, vitest_1.expect)(readSeededClientCapabilities(second)).toEqual({ elicitation: { form: {} } });
128
- });
129
- (0, vitest_1.it)('prepare prefers per-request _meta over cache', () => {
130
- (0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { roots: {} });
131
- const server = new server_1.McpServer({ name: 't', version: '0.0.0' });
132
- (0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(server, {
133
- jsonrpc: '2.0',
134
- method: 'tools/call',
135
- params: {
136
- name: 'x',
137
- arguments: {},
138
- _meta: { [server_1.CLIENT_CAPABILITIES_META_KEY]: { elicitation: { form: {} } } },
139
- },
140
- id: 1,
141
- }, { subject: 'u1' });
142
- (0, vitest_1.expect)(readSeededClientCapabilities(server)).toEqual({ elicitation: { form: {} } });
143
- });
144
- });
145
- /** Read seeded identity without calling deprecated getClientCapabilities(). */
146
- function readSeededClientCapabilities(mcpServer) {
147
- return mcpServer.server._clientCapabilities;
148
- }