@clipform/mcp-server 3.3.2 → 3.8.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.
@@ -0,0 +1,102 @@
1
+ import {
2
+ CURRENT_PLAN_VERSIONS,
3
+ PLAN_LIMITS,
4
+ callApi
5
+ } from "./chunk-JRASOR5T.js";
6
+ import {
7
+ getMcpAuth
8
+ } from "./chunk-VPF6MLKM.js";
9
+
10
+ // src/lib/caps.ts
11
+ var FULL_CAPS = Object.freeze({ media: true, research: true });
12
+ function capsFromToolsets(toolsets) {
13
+ if (toolsets === void 0) return FULL_CAPS;
14
+ return {
15
+ media: toolsets.includes("media"),
16
+ research: toolsets.includes("research")
17
+ };
18
+ }
19
+
20
+ // src/lib/anon-notice.ts
21
+ var ANON_PREVIEW_NOTICE = "Preview accounts are temporary - claim yours to keep your forms.";
22
+ function anonPreviewNotice() {
23
+ return getMcpAuth()?.is_anonymous ? ANON_PREVIEW_NOTICE : null;
24
+ }
25
+
26
+ // src/lib/session-context.ts
27
+ async function getSessionContextWithAuth() {
28
+ let me;
29
+ const authCtx = getMcpAuth();
30
+ if (authCtx?.loadInternalContent && !authCtx.api_key) {
31
+ const free = PLAN_LIMITS[CURRENT_PLAN_VERSIONS[0]];
32
+ me = {
33
+ auth_mode: "anonymous",
34
+ plan: {
35
+ name: free.name,
36
+ tier: free.tier,
37
+ node_limit: free.node_limit,
38
+ form_limit: free.form_limit ?? null,
39
+ custom_theme: free.custom_theme
40
+ }
41
+ };
42
+ } else {
43
+ let result;
44
+ try {
45
+ result = await callApi("/me", { method: "GET" });
46
+ } catch {
47
+ return { text: "", authMode: "anonymous" };
48
+ }
49
+ if (!result.ok) return { text: "", authMode: "anonymous" };
50
+ me = result.data;
51
+ }
52
+ const apiAuthMode = getMcpAuth()?.is_anonymous ? "anonymous" : me.auth_mode ?? "anonymous";
53
+ const authMode = apiAuthMode === "anonymous" ? "anonymous" : "authenticated";
54
+ const plan = me.plan;
55
+ const lines = [];
56
+ lines.push("## Your Session");
57
+ if (authMode === "authenticated") {
58
+ lines.push(
59
+ apiAuthMode === "api_key" ? "Auth: API key (workspace-scoped)" : "Auth: signed in (connected to a Clipform account)"
60
+ );
61
+ lines.push(`Workspace: ${me.workspace?.name ?? "Unknown"}`);
62
+ } else {
63
+ lines.push("Auth: anonymous (not connected to a Clipform account)");
64
+ if (me.workspace) {
65
+ lines.push(`Workspace: ${me.workspace.name}`);
66
+ }
67
+ }
68
+ lines.push(`Plan: ${plan.name} (tier ${plan.tier})`);
69
+ if (plan.node_limit !== null) {
70
+ lines.push(`Question limit: ${plan.node_limit} per form`);
71
+ } else {
72
+ lines.push("Questions: unlimited");
73
+ }
74
+ if (plan.form_limit !== null) {
75
+ lines.push(`Form limit: ${plan.form_limit} forms`);
76
+ } else {
77
+ lines.push("Forms: unlimited");
78
+ }
79
+ if (plan.custom_theme === false) {
80
+ lines.push("Custom themes: not available on this plan");
81
+ }
82
+ if (authMode === "anonymous") {
83
+ lines.push(`
84
+ Anonymous session: forms are not tied to a Clipform account until you sign in.`);
85
+ lines.push(ANON_PREVIEW_NOTICE);
86
+ }
87
+ return { text: lines.join("\n"), authMode };
88
+ }
89
+ async function getSessionContext() {
90
+ const { text } = await getSessionContextWithAuth();
91
+ return text;
92
+ }
93
+
94
+ export {
95
+ FULL_CAPS,
96
+ capsFromToolsets,
97
+ ANON_PREVIEW_NOTICE,
98
+ anonPreviewNotice,
99
+ getSessionContextWithAuth,
100
+ getSessionContext
101
+ };
102
+ //# sourceMappingURL=chunk-S6RYUVDM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/caps.ts","../src/lib/anon-notice.ts","../src/lib/session-context.ts"],"sourcesContent":["import type { McpToolset } from \"@vid-master/config\";\n\n/**\n * What a connected surface can actually do, derived from the connect-time\n * toolset filter (#3309) so the guidance layers (server instructions, prompt\n * recipes, `clipform_get_workflow`, craft guides) never reference a tool the\n * surface doesn't register (#3681).\n *\n * The Claude Connectors Directory surface (`mcp.clipform.io/forms`) is\n * account + forms only: no media generation and no research helpers. A\n * workflow that still says \"call clipform_generate_tts\" there sends the model\n * at a tool that doesn't exist, which shows up in review as failed tool\n * calls. Every guidance producer takes a ServerCaps and gates on it.\n */\nexport interface ServerCaps {\n /** Narration, video, image, music, render, and asset tools are registered. */\n media: boolean;\n /** News lookup and the generation audit log are registered. */\n research: boolean;\n}\n\n/** Every toolset registered - stdio/npx and the bare remote endpoint. */\nexport const FULL_CAPS: ServerCaps = Object.freeze({ media: true, research: true });\n\nexport function capsFromToolsets(toolsets?: readonly McpToolset[]): ServerCaps {\n if (toolsets === undefined) return FULL_CAPS;\n return {\n media: toolsets.includes(\"media\"),\n research: toolsets.includes(\"research\"),\n };\n}\n","import { getMcpAuth } from \"./auth-context.js\";\n\n/**\n * #4650: anonymous (preview) accounts are temporary. Date-free by design -\n * the purge is not enforced yet, so no expiry date or day count is promised\n * (exact dates are follow-up #4662). Defined once; every anonymous-lane\n * surface (create/update_form text, whoami, session resource) reuses it.\n */\nexport const ANON_PREVIEW_NOTICE =\n \"Preview accounts are temporary - claim yours to keep your forms.\";\n\n/** The notice for an anonymous MCP caller, or null for everyone else. */\nexport function anonPreviewNotice(): string | null {\n return getMcpAuth()?.is_anonymous ? ANON_PREVIEW_NOTICE : null;\n}\n","import { BUSINESS, PLAN_LIMITS, CURRENT_PLAN_VERSIONS } from \"@vid-master/config\";\nimport { callApi } from \"./api-client.js\";\nimport { ANON_PREVIEW_NOTICE } from \"./anon-notice.js\";\nimport { getMcpAuth } from \"./auth-context.js\";\n\nexport type AuthMode = \"authenticated\" | \"anonymous\";\n\nexport interface SessionContextResult {\n text: string;\n authMode: AuthMode;\n}\n\nexport async function getSessionContextWithAuth(): Promise<SessionContextResult> {\n let me: any;\n const authCtx = getMcpAuth();\n if (authCtx?.loadInternalContent && !authCtx.api_key) {\n // #4657: the no-workspace anon lane (get_workflow with no mint) has no\n // workspace for /me to describe, so plan caps default to Free.\n const free = PLAN_LIMITS[CURRENT_PLAN_VERSIONS[0]];\n me = {\n auth_mode: \"anonymous\",\n plan: {\n name: free.name,\n tier: free.tier,\n node_limit: free.node_limit,\n form_limit: free.form_limit ?? null,\n custom_theme: free.custom_theme,\n },\n };\n } else {\n let result;\n try {\n result = await callApi(\"/me\", { method: \"GET\" });\n } catch {\n return { text: \"\", authMode: \"anonymous\" };\n }\n if (!result.ok) return { text: \"\", authMode: \"anonymous\" };\n me = result.data as any;\n }\n // The API's auth_mode is \"api_key\" | \"oauth\" | \"session\" | \"anonymous\".\n // Anything credentialed counts as authenticated - the old `=== \"oauth\"`\n // check matched nothing the API returns, so API-key sessions were labelled\n // anonymous with a \"sign in to unlock\" nudge right next to their real\n // plan (#412 F6).\n // The anon MCP lane runs as a minted bot key (/me says \"api_key\"), so the\n // auth context is the truth for anonymous (#4653).\n const apiAuthMode: string = getMcpAuth()?.is_anonymous\n ? \"anonymous\"\n : ((me.auth_mode as string) ?? \"anonymous\");\n const authMode: AuthMode = apiAuthMode === \"anonymous\" ? \"anonymous\" : \"authenticated\";\n const plan = me.plan;\n const lines: string[] = [];\n\n lines.push(\"## Your Session\");\n if (authMode === \"authenticated\") {\n lines.push(\n apiAuthMode === \"api_key\"\n ? \"Auth: API key (workspace-scoped)\"\n : \"Auth: signed in (connected to a Clipform account)\"\n );\n // Workspace NAME only - the workspace UUID and the raw user_id/company_id\n // are internal database identifiers the model never needs (response\n // hygiene / disclosure guard, #2976).\n lines.push(`Workspace: ${me.workspace?.name ?? \"Unknown\"}`);\n } else {\n lines.push(\"Auth: anonymous (not connected to a Clipform account)\");\n if (me.workspace) {\n lines.push(`Workspace: ${me.workspace.name}`);\n }\n }\n lines.push(`Plan: ${plan.name} (tier ${plan.tier})`);\n if (plan.node_limit !== null) {\n lines.push(`Question limit: ${plan.node_limit} per form`);\n } else {\n lines.push(\"Questions: unlimited\");\n }\n if (plan.form_limit !== null) {\n lines.push(`Form limit: ${plan.form_limit} forms`);\n } else {\n lines.push(\"Forms: unlimited\");\n }\n if (plan.custom_theme === false) {\n lines.push(\"Custom themes: not available on this plan\");\n }\n if (authMode === \"anonymous\") {\n // Neutral statement of fact, no upsell/CTA copy (commerce sweep, #2976):\n // an anonymous session's forms are not tied to an account until one signs in.\n lines.push(`\\nAnonymous session: forms are not tied to a Clipform account until you sign in.`);\n lines.push(ANON_PREVIEW_NOTICE);\n }\n\n return { text: lines.join(\"\\n\"), authMode };\n}\n\nexport async function getSessionContext(): Promise<string> {\n const { text } = await getSessionContextWithAuth();\n return text;\n}\n"],"mappings":";;;;;;;;;;AAsBO,IAAM,YAAwB,OAAO,OAAO,EAAE,OAAO,MAAM,UAAU,KAAK,CAAC;AAE3E,SAAS,iBAAiB,UAA8C;AAC7E,MAAI,aAAa,OAAW,QAAO;AACnC,SAAO;AAAA,IACL,OAAO,SAAS,SAAS,OAAO;AAAA,IAChC,UAAU,SAAS,SAAS,UAAU;AAAA,EACxC;AACF;;;ACtBO,IAAM,sBACX;AAGK,SAAS,oBAAmC;AACjD,SAAO,WAAW,GAAG,eAAe,sBAAsB;AAC5D;;;ACFA,eAAsB,4BAA2D;AAC/E,MAAI;AACJ,QAAM,UAAU,WAAW;AAC3B,MAAI,SAAS,uBAAuB,CAAC,QAAQ,SAAS;AAGpD,UAAM,OAAO,YAAY,sBAAsB,CAAC,CAAC;AACjD,SAAK;AAAA,MACH,WAAW;AAAA,MACX,MAAM;AAAA,QACJ,MAAM,KAAK;AAAA,QACX,MAAM,KAAK;AAAA,QACX,YAAY,KAAK;AAAA,QACjB,YAAY,KAAK,cAAc;AAAA,QAC/B,cAAc,KAAK;AAAA,MACrB;AAAA,IACF;AAAA,EACF,OAAO;AACL,QAAI;AACJ,QAAI;AACF,eAAS,MAAM,QAAQ,OAAO,EAAE,QAAQ,MAAM,CAAC;AAAA,IACjD,QAAQ;AACN,aAAO,EAAE,MAAM,IAAI,UAAU,YAAY;AAAA,IAC3C;AACA,QAAI,CAAC,OAAO,GAAI,QAAO,EAAE,M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
5
  import {
2
6
  ALL_VARIANTS,
3
7
  FORM_TYPES,
4
8
  FORM_TYPE_KEYS,
5
- FULL_CAPS,
6
- callApi,
7
- getSessionContext
8
- } from "./chunk-65MTGAFF.js";
9
+ callApi
10
+ } from "./chunk-JRASOR5T.js";
11
+ import {
12
+ getMcpAuth
13
+ } from "./chunk-VPF6MLKM.js";
9
14
 
10
15
  // src/lib/guides.ts
11
16
  var guidesPromise = null;
12
17
  async function loadGuides() {
13
- const result = await callApi("/internal/mcp/guides", { method: "GET" });
14
- if (!result.ok) {
15
- throw new Error(`Failed to load guides: ${result.error}`);
18
+ const loader = getMcpAuth()?.loadInternalContent;
19
+ let data;
20
+ if (loader) {
21
+ data = await loader("guides");
22
+ } else {
23
+ const result = await callApi("/internal/mcp/guides", { method: "GET" });
24
+ if (!result.ok) {
25
+ throw new Error(`Failed to load guides: ${result.error}`);
26
+ }
27
+ data = result.data;
16
28
  }
17
- const guides = result.data.guides ?? [];
29
+ const guides = data.guides ?? [];
18
30
  return new Map(guides.map((g) => [g.uri, g]));
19
31
  }
20
32
  async function fetchGuideText(uri) {
@@ -143,4 +155,4 @@ export {
143
155
  getGuideUri,
144
156
  registerResources
145
157
  };
146
- //# sourceMappingURL=chunk-KHRY3A3M.js.map
158
+ //# sourceMappingURL=chunk-V5AI2TSQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/guides.ts","../src/resources.ts"],"sourcesContent":["import { callApi } from \"./api-client.js\";\nimport { getMcpAuth } from \"./auth-context.js\";\nimport type { ServerCaps } from \"./caps.js\";\n\n/**\n * Craft guide bodies live server-side (#470) - the npm package is a shim\n * that fetches them at runtime instead of bundling them in the tarball.\n * One fetch per process (all ~30KB of guides in a single response), cached;\n * a failed fetch is NOT cached so the next read retries.\n */\n\nexport interface RemoteGuide {\n type: string;\n variant: string | null;\n uri: string;\n mimeType: string;\n text: string;\n}\n\nlet guidesPromise: Promise<Map<string, RemoteGuide>> | null = null;\n\nasync function loadGuides(): Promise<Map<string, RemoteGuide>> {\n // #4657: the anonymous no-workspace lane serves the static guides in-process.\n const loader = getMcpAuth()?.loadInternalContent;\n let data: Record<string, unknown>;\n if (loader) {\n data = await loader(\"guides\");\n } else {\n const result = await callApi(\"/internal/mcp/guides\", { method: \"GET\" });\n if (!result.ok) {\n throw new Error(`Failed to load guides: ${result.error}`);\n }\n data = result.data;\n }\n const guides = (data as { guides?: RemoteGuide[] }).guides ?? [];\n return new Map(guides.map((g) => [g.uri, g]));\n}\n\n/** Fetch a guide body by its clipform:// URI. Returns null when unavailable. */\nexport async function fetchGuideText(uri: string): Promise<string | null> {\n if (!guidesPromise) {\n guidesPromise = loadGuides();\n }\n try {\n const guides = await guidesPromise;\n return guides.get(uri)?.text ?? null;\n } catch (err) {\n guidesPromise = null; // don't cache failures - retry on the next read\n // Loud, not silent: a misconfigured API_URL/key otherwise degrades every\n // guide to the stub with nothing in the logs.\n console.error(`[guides] Failed to fetch ${uri}: ${err instanceof Error ? err.message : String(err)}`);\n return null;\n }\n}\n\n/** Shown in place of a guide when the API is unreachable or unauthenticated. */\nexport function guideFallbackText(uri: string): string {\n return [\n `# Guide unavailable`,\n ``,\n `The craft guide (${uri}) could not be loaded from the Clipform API.`,\n `Guides are served at runtime and need a reachable API with a valid key -`,\n `check API_URL and CLIPFORM_API_KEY, then try again.`,\n ``,\n `General principles in the meantime: write narration for the ear (short,`,\n `conversational), never reveal answers in narration or media, and keep`,\n `forms tight - every question must earn its place.`,\n ].join(\"\\n\");\n}\n\n/**\n * Craft guide bodies are written for the full tool surface and mention the\n * narration/video tools by name. On a surface that doesn't register them\n * (the Claude Connectors Directory resource, #3681) prefix the guide with a\n * note so the model doesn't chase tools it can't call. The body itself is\n * untouched - the craft (question design, pacing) is the same either way.\n */\nexport function applyCapsToGuide(text: string, caps: ServerCaps): string {\n if (caps.media) return text;\n return [\n \"> **This connection exposes form-building tools only** - no narration, video, image, or music tools. Where this guide mentions narration, media, or rendering, skip that part and carry the same craft into the written question text.\",\n \"\",\n text,\n ].join(\"\\n\");\n}\n","import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { getSessionContext } from \"./lib/session-context.js\";\nimport { FORM_TYPE_KEYS, FORM_TYPES, ALL_VARIANTS } from \"@vid-master/config\";\n\nexport const GUIDE_TYPES = FORM_TYPE_KEYS as readonly string[] as readonly [string, ...string[]];\nexport type GuideType = (typeof FORM_TYPE_KEYS)[number];\n\nexport const QUIZ_VARIANTS = ALL_VARIANTS as readonly string[] as readonly [string, ...string[]];\nexport type QuizVariant = (typeof ALL_VARIANTS)[number];\n// Guide BODIES are not bundled here (#470): the npm tarball ships only this\n// registration metadata. Text is fetched from the API at runtime - see\n// lib/guides.ts (cached per process, stub fallback when unreachable).\nimport { fetchGuideText, guideFallbackText, applyCapsToGuide } from \"./lib/guides.js\";\nimport { FULL_CAPS, type ServerCaps } from \"./lib/caps.js\";\n\nconst GUIDE_DESCRIPTIONS: Record<GuideType, string> = {\n \"quiz\": \"Craft knowledge for writing engaging quizzes - difficulty curves, question psychology, narration style, scoring\",\n \"survey\": \"Craft knowledge for feedback surveys, NPS, and research forms - brevity, rating scales, respondent fatigue\",\n \"interview\": \"Craft knowledge for building interview forms - warm-up pacing, open questions, consent, video responses\",\n \"funnel\": \"Craft knowledge for lead qualification funnels - planned feature, conditional routing coming soon\",\n \"testimonial\": \"Craft knowledge for collecting testimonials and customer stories on video - storytelling prompts, comfort techniques, consent\",\n \"application\": \"Craft knowledge for application and evaluation forms - multi-section structure, video responses for behavioural questions, screening\",\n \"booking\": \"Craft knowledge for event registration and booking forms - minimal friction, video welcome, confirmation flow\",\n};\n\n// Sourced from config (single source of truth) so the agent-facing resource\n// descriptions can't drift from FORM_TYPES.quiz.variant_descriptions (#2534,\n// the exact pair packages/config/CLAUDE.md warns about).\nconst QUIZ_VARIANT_DESCRIPTIONS = FORM_TYPES.quiz.variant_descriptions;\n\nexport function getGuideUri(type: GuideType, variant?: QuizVariant): string {\n if (type === \"quiz\" && variant) {\n return `clipform://guides/quiz/${variant}`;\n }\n return `clipform://guides/${type}`;\n}\n\nasync function readGuide(uri: string, caps: ServerCaps): Promise<string> {\n return applyCapsToGuide((await fetchGuideText(uri)) ?? guideFallbackText(uri), caps);\n}\n\nexport function registerResources(server: McpServer, caps: ServerCaps = FULL_CAPS) {\n for (const type of GUIDE_TYPES) {\n server.registerResource(\n `guide-${type}`,\n getGuideUri(type),\n {\n description: GUIDE_DESCRIPTIONS[type],\n mimeType: \"text/markdown\",\n annotations: { audience: [\"assistant\" as const], priority: 0.8 },\n },\n async () => ({\n contents: [{\n uri: getGuideUri(type),\n mimeType: \"text/markdown\",\n text: await readGuide(getGuideUri(type), caps),\n }],\n }),\n );\n }\n\n for (const variant of QUIZ_VARIANTS) {\n server.registerResource(\n `guide-quiz-${variant}`,\n getGuideUri(\"quiz\", variant),\n {\n description: QUIZ_VARIANT_DESCRIPTIONS[variant],\n mimeType: \"text/markdown\",\n annotations: { audience: [\"assistant\" as const], priority: 0.8 },\n },\n async () => ({\n contents: [{\n uri: getGuideUri(\"quiz\", variant),\n mimeType: \"text/markdown\",\n text: await readGuide(getGuideUri(\"quiz\", variant), caps),\n }],\n }),\n );\n }\n\n server.registerResource(\n \"context-session\",\n \"clipform://context/session\",\n {\n description:\n \"Current session info: auth mode, workspace name, plan name, and node/form limits. Read this before planning content to know your constraints.\",\n mimeType: \"text/markdown\",\n annotations: { audience: [\"assistant\"], priority: 1.0 },\n },\n async () => {\n const text = await getSessionContext();\n return {\n contents: [\n {\n uri: \"clipform://context/session\",\n mimeType: \"text/markdown\",\n text: text || \"Session context unavailable - API may not be reachable.\",\n },\n ],\n };\n }\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,IAAI,gBAA0D;AAE9D,eAAe,aAAgD;AAE7D,QAAM,SAAS,WAAW,GAAG;AAC7B,MAAI;AACJ,MAAI,QAAQ;AACV,WAAO,MAAM,OAAO,QAAQ;AAAA,EAC9B,OAAO;AACL,UAAM,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ACV,YAAM,OAAO,MAAM,kBAAkB;AACrC,aAAO;AAAA,QACL,UAAU;AAAA,UACR;AAAA,YACE,KAAK;AAAA,YACL,UAAU;AAAA,YACV,MAAM,QAAQ;AAAA,UAChB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -3,6 +3,8 @@ import { AsyncLocalStorage } from "async_hooks";
3
3
  var MCP_ANONYMOUS_HEADER = "x-clipform-anonymous";
4
4
  var MCP_AUTH_VIA_HEADER = "x-clipform-auth-via";
5
5
  var MCP_MINT_PROOF_HEADER = "x-clipform-mcp-mint-proof";
6
+ var MCP_SESSION_PROOF_HEADER = "x-clipform-mcp-session-proof";
7
+ var MCP_SESSION_ID_HEADER = "x-clipform-mcp-session-id";
6
8
  var storage = new AsyncLocalStorage();
7
9
  function runWithMcpAuth(ctx, fn) {
8
10
  return storage.run(ctx, fn);
@@ -20,8 +22,10 @@ export {
20
22
  MCP_ANONYMOUS_HEADER,
21
23
  MCP_AUTH_VIA_HEADER,
22
24
  MCP_MINT_PROOF_HEADER,
25
+ MCP_SESSION_PROOF_HEADER,
26
+ MCP_SESSION_ID_HEADER,
23
27
  runWithMcpAuth,
24
28
  getMcpAuth,
25
29
  runWithMcpTool
26
30
  };
27
- //# sourceMappingURL=chunk-A5CFGL27.js.map
31
+ //# sourceMappingURL=chunk-VPF6MLKM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/auth-context.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\n/**\n * Identity of the end-user a given MCP request is acting on behalf of.\n *\n * Populated by the in-process host (apps/api) after validating an OAuth\n * Bearer on /mcp. The MCP tool layer reads it to decide which workspace\n * forms should land in and which plan tier gates apply.\n *\n * NOT populated when the server runs as a local stdio process (npx) - in\n * that mode tools fall back to edit-token based auth.\n */\nexport interface McpAuthContext {\n user_id: string;\n workspace_id: string;\n scopes: string[];\n tool_name?: string;\n api_key?: string;\n // Set when the human behind this tool call is an anonymous Supabase\n // session (apps/api's app-chat lane, #2983/#2984) - api-client.ts's\n // getAuthHeaders reads it to mark the outgoing bot-key HTTP request so the\n // API can propagate the restriction even though the request itself\n // authenticates with an API key, not a JWT.\n is_anonymous?: boolean;\n // Set on the OAuth branch of apps/api's mcp/handler.ts when this request's\n // bot API key was resolved on behalf of an OAuth-connected user (#3716) -\n // api-client.ts's getAuthHeaders reads it to mark the outgoing request so\n // /v1/me can report auth_mode \"oauth\" instead of the generic \"api_key\" the\n // bot-key lane would otherwise get, even though the request itself\n // authenticates with an API key, not an OAuth token.\n auth_via?: \"oauth\";\n // #3330 review fix (blocker 1): an HMAC proof (apps/api's mcp-mint-proof.ts)\n // that THIS exact request's #1415 anon lane freshly minted a brand-new anon\n // identity for `workspace_id` - set only on the mint branch of\n // resolveAnonymousMcpAuth, never when auth was resolved via an inbound\n // form_id (even the caller's own). Lets create-form.ts safely offer a\n // same-UID claim link without ever deriving \"who to bind it to\" from a\n // body-supplied id, which would let a batch smuggling another tenant's\n // form_id alongside a create_form call mint a claim token for THAT\n // tenant's identity instead of the caller's own.\n mcp_mint_proof?: string;\n // #4090: sibling of mcp_mint_proof, set when the anon lane REUSED a\n // server-verified session binding (#4652) instead of minting. HMAC-bound\n // to the bound {workspace, uid}; lets create-form.ts re-surface the claim\n // link on later forms in the session.\n mcp_session_proof?: string;\n // #3822: set ONLY on the OAuth branch of apps/api's mcp/handler.ts. Lets a\n // single tool call target another workspace the connected user belongs to\n // (per-call, never per-request - see the #3330 note in the package\n // CLAUDE.md). The host re-checks membership on every call and returns that\n // workspace's own bot key, or null to mean \"act in the default workspace\n // unchanged\" (target is the default, or a form_id the user can't reach -\n // the API then answers exactly as it did before targeting existed). Anon + stdio contexts never carry it, so they\n // stay pinned to one workspace.\n resolveWorkspace?: (target: {\n workspace_id?: string;\n form_id?: string;\n }) => Promise<{ workspace_id: string; workspace_name: string; api_key: string } | null>;\n // #3822: the workspaces the connected user may target (same set\n // resolveWorkspace accepts). OAuth lane only.\n listWorkspaces?: () => Promise<{ id: string; name: string }[]>;\n // #3822: the workspace picked at authorize time - what a call with no\n // `workspace_id` acts in. OAuth lane only (workspace_id above is swapped\n // per call when a target is resolved, this never is).\n default_workspace_id?: string;\n // #4657: set ONLY by apps/api's mcp/handler.ts for an anonymous request made\n // entirely of `anon_no_workspace` tools (get_guide / get_workflow /\n // list_assets). That lane has NO credential of any kind: the static content\n // is served in-process through this loader instead of an HTTP callApi, so no\n // secret or key ever sits in the anonymous context. Tools use it when\n // present and callApi otherwise (stdio / published behaviour unchanged).\n // #4657: decoded PostHog MCP `$session_id` from the inbound Mcp-Session-Id -\n // ANALYTICS ONLY (stamped on funnel events). api-client.ts forwards it as\n // MCP_SESSION_ID_HEADER; nothing about identity or access derives from it.\n mcp_session_id?: string;\n loadInternalContent?: (\n kind: \"guides\" | \"assets\",\n params?: { type?: string }\n ) => Promise<Record<string, unknown>>;\n}\n\n/**\n * Marker header the in-process MCP tool layer sets on its outgoing API\n * requests (api-client.ts) when `is_anonymous` is true, so an anonymous\n * app-chat session can't launder itself into an unrestricted API-key caller\n * by asking the bot to publish/mint credentials on its behalf. apps/api's\n * authMiddleware / workspaceAccessMiddleware / requireWorkspaceWriteAuth\n * read this on the API-key path and set isAnonymous accordingly - trusting\n * it is safe because it can only RESTRICT a caller: a real integration that\n * sets this header on its own API-key requests only denies itself, it can\n * never use it to gain anonymous-JWT privileges it doesn't already have.\n */\nexport const MCP_ANONYMOUS_HEADER = \"x-clipform-anonymous\";\n\n/**\n * Marker header the in-process MCP tool layer sets on its outgoing API\n * requests (api-client.ts) when `auth_via` is \"oauth\", so /v1/me can report\n * `auth_mode: \"oauth\"` for an OAuth-connected user instead of the generic\n * \"api_key\" the bot-key lane would otherwise get (#3716). Label-only: it\n * changes nothing but the reported string. Trusting it from the wire is\n * safe because a direct API-key caller who sets this header on their own\n * request only mislabels their own whoami output - they gain no privilege,\n * exactly the same reasoning as MCP_ANONYMOUS_HEADER above (except that\n * header can only restrict, and this one can only relabel).\n */\nexport const MCP_AUTH_VIA_HEADER = \"x-clipform-auth-via\";\n\n/**\n * Carries `mcp_mint_proof` on the same outgoing bot-key request. Unlike\n * MCP_ANONYMOUS_HEADER (a boolean that can only ever RESTRICT), this header's\n * VALUE matters - it names an identity a claim token gets bound to - so its\n * value is HMAC-signed (mcp-mint-proof.ts) rather than trusted raw: a direct\n * external caller reaching `POST /v1/forms` with any valid workspace API key\n * could otherwise hand-set an unsigned \"mint uid\" header to an arbitrary\n * victim's uid themselves (#3330 review).\n */\nexport const MCP_MINT_PROOF_HEADER = \"x-clipform-mcp-mint-proof\";\n\n/** #4090: carries `mcp_session_proof` (same trust model as MCP_MINT_PROOF_HEADER: HMAC-verified server-side, never trusted raw). */\nexport const MCP_SESSION_PROOF_HEADER = \"x-clipform-mcp-session-proof\";\n\n/** Carries `mcp_session_id` to the API for funnel analytics only (#4657). */\nexport const MCP_SESSION_ID_HEADER = \"x-clipform-mcp-session-id\";\n\nconst storage = new AsyncLocalStorage<McpAuthContext>();\n\nexport function runWithMcpAuth<T>(ctx: McpAuthContext, fn: () => Promise<T> | T): Promise<T> | T {\n return storage.run(ctx, fn);\n}\n\nexport function getMcpAuth(): McpAuthContext | undefined {\n return storage.getStore();\n}\n\nexport function runWithMcpTool<T>(toolName: string, fn: () => Promise<T> | T): Promise<T> | T {\n const parent = storage.getStore();\n if (!parent) return fn();\n return storage.run({ ...parent, tool_name: toolName }, fn);\n}\n"],"mappings":";AAAA,SAAS,yBAAyB;AA4F3B,IAAM,uBAAuB;AAa7B,IAAM,sBAAsB;AAW5B,IAAM,wBAAwB;AAG9B,IAAM,2BAA2B;AAGjC,IAAM,wBAAwB;AAErC,IAAM,UAAU,IAAI,kBAAkC;AAE/C,SAAS,eAAkB,KAAqB,IAA0C;AAC/F,SAAO,QAAQ,IAAI,KAAK,EAAE;AAC5B;AAEO,SAAS,aAAyC;AACvD,SAAO,QAAQ,SAAS;AAC1B;AAEO,SAAS,eAAkB,UAAkB,IAA0C;AAC5F,QAAM,SAAS,QAAQ,SAAS;AAChC,MAAI,CAAC,OAAQ,QAAO,GAAG;AACvB,SAAO,QAAQ,IAAI,EAAE,GAAG,QAAQ,WAAW,SAAS,GAAG,EAAE;AAC3D;","names":[]}
package/dist/index.js CHANGED
@@ -2,11 +2,12 @@
2
2
  import {
3
3
  JSONRPCMessageSchema,
4
4
  createServer
5
- } from "./chunk-7I765YTD.js";
6
- import "./chunk-5J5N7KTW.js";
7
- import "./chunk-KHRY3A3M.js";
8
- import "./chunk-65MTGAFF.js";
9
- import "./chunk-A5CFGL27.js";
5
+ } from "./chunk-FC7D3235.js";
6
+ import "./chunk-KWR2WJQI.js";
7
+ import "./chunk-V5AI2TSQ.js";
8
+ import "./chunk-S6RYUVDM.js";
9
+ import "./chunk-JRASOR5T.js";
10
+ import "./chunk-VPF6MLKM.js";
10
11
  import {
11
12
  setMcpVersion
12
13
  } from "./chunk-PBQ5BQWD.js";
@@ -17,10 +18,10 @@ import { readFileSync } from "fs";
17
18
  import { dirname, join } from "path";
18
19
  import { fileURLToPath } from "url";
19
20
 
20
- // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
21
+ // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
21
22
  import process2 from "process";
22
23
 
23
- // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
24
+ // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
24
25
  var STDIO_DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024;
25
26
  var ReadBuffer = class {
26
27
  constructor(options) {
@@ -57,7 +58,7 @@ function serializeMessage(message) {
57
58
  return JSON.stringify(message) + "\n";
58
59
  }
59
60
 
60
- // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
61
+ // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
61
62
  var StdioServerTransport = class {
62
63
  constructor(_stdin = process2.stdin, _stdout = process2.stdout, options) {
63
64
  this._stdin = _stdin;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/src/server/stdio.ts","../../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/src/shared/stdio.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { createServer } from \"./server.js\";\nimport { setMcpVersion } from \"./lib/telemetry.js\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst pkg = JSON.parse(readFileSync(join(__dirname, \"..\", \"package.json\"), \"utf-8\"));\nsetMcpVersion(pkg.version);\n\nconst telemetryOff =\n process.env.DO_NOT_TRACK === \"1\" || process.env.CLIPFORM_TELEMETRY === \"off\";\n\nconst server = createServer();\nconst transport = new StdioServerTransport();\nawait server.connect(transport);\nconsole.error(`Clipform MCP Server v${pkg.version} running on stdio`);\nif (!telemetryOff) {\n console.error(\"Telemetry enabled (server errors only). Set DO_NOT_TRACK=1 to disable.\");\n}\n",null,null],"mappings":";;;;;;;;;;;;;;;AACA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;;;ACH9B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zE,IAAM,SAAS,aAAa;AAC5B,IAAM,YAAY,IAAI,qBAAqB;AAC3C,MAAM,OAAO,QAAQ,SAAS;AAC9B,QAAQ,MAAM,wBAAwB,IAAI,OAAO,mBAAmB;AACpE,IAAI,CAAC,cAAc;AACjB,UAAQ,MAAM,wEAAwE;AACxF;","names":["process","process"]}
1
+ {"version":3,"sources":["../src/index.ts","../../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/src/server/stdio.ts","../../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/src/shared/stdio.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { createServer } from \"./server.js\";\nimport { setMcpVersion } from \"./lib/telemetry.js\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst pkg = JSON.parse(readFileSync(join(__dirname, \"..\", \"package.json\"), \"utf-8\"));\nsetMcpVersion(pkg.version);\n\nconst telemetryOff =\n process.env.DO_NOT_TRACK === \"1\" || process.env.CLIPFORM_TELEMETRY === \"off\";\n\nconst server = createServer();\nconst transport = new StdioServerTransport();\nawait server.connect(transport);\nconsole.error(`Clipform MCP Server v${pkg.version} running on stdio`);\nif (!telemetryOff) {\n console.error(\"Telemetry enabled (server errors only). Set DO_NOT_TRACK=1 to disable.\");\n}\n",null,null],"mappings":";;;;;;;;;;;;;;;;AACA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;;;ACH9B,OAAOA,cAAa;;;ACEb,IAAM,gCAAgC,KAAK,OAAO;AAKnD,IAAO,aAAP,MAAiB;EAInB,YAAY,SAAoC;AAC5C,SAAK,iBAAiB,SAAS,iBAAiB;EACpD;EAEA,OAAO,OA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AC,cAAc;AACjB,UAAQ,MAAM,wEAAwE;AACxF;","names":["process","process"]}
@@ -24,9 +24,26 @@ interface InstrumentServerOptions {
24
24
  */
25
25
  reportMissing?: boolean;
26
26
  }
27
+ /**
28
+ * #4623: per-request telemetry context stamped on every `$mcp_tool_call` /
29
+ * `$mcp_intent` in `beforeSend`. Analytics labels only - never an authority.
30
+ * Absent on the in-process lane, which then behaves exactly as before.
31
+ */
32
+ interface McpTelemetryContext {
33
+ /** Resolved client bucket (chatgpt/claude_connector/mcp_other/automated). Kept
34
+ * separate from the SDK's raw `$mcp_client_name`, which is NOT overwritten. */
35
+ clientOrigin?: string;
36
+ authMode?: "oauth" | "anon" | "api_key" | "none";
37
+ workspaceId?: string;
38
+ /** Anon lane: the minted/resolved anon uid, used as the distinctId so anon
39
+ * tool calls join the person instead of all landing on "anonymous". */
40
+ anonUid?: string;
41
+ /** ChatGPT `_meta["openai/locale"]` (BCP 47). Language hint only - never location. */
42
+ clientLocale?: string;
43
+ }
27
44
  declare function buildInstrumentOptions(mcpAuth: {
28
45
  user_id?: string;
29
- } | null, opts?: InstrumentServerOptions): MCPAnalyticsOptions;
46
+ } | null, opts?: InstrumentServerOptions, telemetry?: McpTelemetryContext): MCPAnalyticsOptions;
30
47
  /**
31
48
  * Wraps the per-request/per-connection server with PostHog MCP analytics
32
49
  * (#3408, extended in-process #3432), additively - `mcp_request`/`$exception`
@@ -37,6 +54,6 @@ declare function buildInstrumentOptions(mcpAuth: {
37
54
  */
38
55
  declare function instrumentServer(server: unknown, posthogClient: McpAnalyticsClient | null, mcpAuth: {
39
56
  user_id?: string;
40
- } | null, opts?: InstrumentServerOptions): void;
57
+ } | null, opts?: InstrumentServerOptions, telemetry?: McpTelemetryContext): void;
41
58
 
42
- export { type InstrumentServerOptions, buildInstrumentOptions, getMcpAnalyticsClient, instrumentServer, setMcpAnalyticsClient };
59
+ export { type InstrumentServerOptions, type McpTelemetryContext, buildInstrumentOptions, getMcpAnalyticsClient, instrumentServer, setMcpAnalyticsClient };