skybridge 0.0.0-dev.7ff08e5 → 0.0.0-dev.800101e

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 (126) hide show
  1. package/README.md +123 -124
  2. package/dist/cli/use-typescript-check.js +1 -1
  3. package/dist/cli/use-typescript-check.js.map +1 -1
  4. package/dist/commands/create.d.ts +9 -0
  5. package/dist/commands/create.js +30 -0
  6. package/dist/commands/create.js.map +1 -0
  7. package/dist/server/asset-base-url-transform-plugin.d.ts +1 -0
  8. package/dist/server/asset-base-url-transform-plugin.js +16 -1
  9. package/dist/server/asset-base-url-transform-plugin.js.map +1 -1
  10. package/dist/server/asset-base-url-transform-plugin.test.js +51 -1
  11. package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -1
  12. package/dist/server/auth.d.ts +20 -0
  13. package/dist/server/auth.js +28 -0
  14. package/dist/server/auth.js.map +1 -0
  15. package/dist/server/content-helpers.d.ts +40 -0
  16. package/dist/server/content-helpers.js +33 -0
  17. package/dist/server/content-helpers.js.map +1 -1
  18. package/dist/server/file-ref.d.ts +20 -0
  19. package/dist/server/file-ref.js +19 -0
  20. package/dist/server/file-ref.js.map +1 -1
  21. package/dist/server/index.d.ts +2 -1
  22. package/dist/server/index.js +1 -0
  23. package/dist/server/index.js.map +1 -1
  24. package/dist/server/middleware.d.ts +16 -3
  25. package/dist/server/middleware.js.map +1 -1
  26. package/dist/server/server.d.ts +204 -2
  27. package/dist/server/server.js +152 -59
  28. package/dist/server/server.js.map +1 -1
  29. package/dist/test/view.test.js +45 -0
  30. package/dist/test/view.test.js.map +1 -1
  31. package/dist/web/bridges/apps-sdk/adaptor.d.ts +3 -1
  32. package/dist/web/bridges/apps-sdk/adaptor.js +12 -1
  33. package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
  34. package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -0
  35. package/dist/web/bridges/apps-sdk/bridge.js +1 -0
  36. package/dist/web/bridges/apps-sdk/bridge.js.map +1 -1
  37. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +11 -0
  38. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +11 -0
  39. package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -1
  40. package/dist/web/bridges/get-adaptor.d.ts +7 -0
  41. package/dist/web/bridges/get-adaptor.js +7 -0
  42. package/dist/web/bridges/get-adaptor.js.map +1 -1
  43. package/dist/web/bridges/mcp-app/adaptor.d.ts +3 -1
  44. package/dist/web/bridges/mcp-app/adaptor.js +9 -0
  45. package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
  46. package/dist/web/bridges/mcp-app/bridge.d.ts +1 -0
  47. package/dist/web/bridges/mcp-app/bridge.js +1 -0
  48. package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
  49. package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +12 -0
  50. package/dist/web/bridges/mcp-app/use-mcp-app-context.js +12 -0
  51. package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
  52. package/dist/web/bridges/types.d.ts +55 -1
  53. package/dist/web/bridges/types.js.map +1 -1
  54. package/dist/web/bridges/use-host-context.d.ts +5 -0
  55. package/dist/web/bridges/use-host-context.js +5 -0
  56. package/dist/web/bridges/use-host-context.js.map +1 -1
  57. package/dist/web/create-store.d.ts +26 -0
  58. package/dist/web/create-store.js +26 -0
  59. package/dist/web/create-store.js.map +1 -1
  60. package/dist/web/data-llm.d.ts +33 -0
  61. package/dist/web/data-llm.js +28 -0
  62. package/dist/web/data-llm.js.map +1 -1
  63. package/dist/web/generate-helpers.d.ts +2 -0
  64. package/dist/web/generate-helpers.js +2 -0
  65. package/dist/web/generate-helpers.js.map +1 -1
  66. package/dist/web/hooks/index.d.ts +1 -0
  67. package/dist/web/hooks/index.js +1 -0
  68. package/dist/web/hooks/index.js.map +1 -1
  69. package/dist/web/hooks/test/utils.d.ts +6 -2
  70. package/dist/web/hooks/test/utils.js +13 -2
  71. package/dist/web/hooks/test/utils.js.map +1 -1
  72. package/dist/web/hooks/use-call-tool.d.ts +45 -0
  73. package/dist/web/hooks/use-call-tool.js +28 -0
  74. package/dist/web/hooks/use-call-tool.js.map +1 -1
  75. package/dist/web/hooks/use-call-tool.test.js +27 -2
  76. package/dist/web/hooks/use-call-tool.test.js.map +1 -1
  77. package/dist/web/hooks/use-display-mode.d.ts +20 -0
  78. package/dist/web/hooks/use-display-mode.js +20 -0
  79. package/dist/web/hooks/use-display-mode.js.map +1 -1
  80. package/dist/web/hooks/use-download.d.ts +5 -0
  81. package/dist/web/hooks/use-download.js +8 -0
  82. package/dist/web/hooks/use-download.js.map +1 -0
  83. package/dist/web/hooks/use-download.test.d.ts +1 -0
  84. package/dist/web/hooks/use-download.test.js +95 -0
  85. package/dist/web/hooks/use-download.test.js.map +1 -0
  86. package/dist/web/hooks/use-files.d.ts +32 -0
  87. package/dist/web/hooks/use-files.js +32 -0
  88. package/dist/web/hooks/use-files.js.map +1 -1
  89. package/dist/web/hooks/use-layout.d.ts +2 -0
  90. package/dist/web/hooks/use-layout.js +2 -0
  91. package/dist/web/hooks/use-layout.js.map +1 -1
  92. package/dist/web/hooks/use-open-external.d.ts +17 -0
  93. package/dist/web/hooks/use-open-external.js +16 -0
  94. package/dist/web/hooks/use-open-external.js.map +1 -1
  95. package/dist/web/hooks/use-request-close.d.ts +14 -0
  96. package/dist/web/hooks/use-request-close.js +13 -0
  97. package/dist/web/hooks/use-request-close.js.map +1 -1
  98. package/dist/web/hooks/use-request-modal.d.ts +16 -1
  99. package/dist/web/hooks/use-request-modal.js +16 -1
  100. package/dist/web/hooks/use-request-modal.js.map +1 -1
  101. package/dist/web/hooks/use-request-size.d.ts +17 -0
  102. package/dist/web/hooks/use-request-size.js +16 -0
  103. package/dist/web/hooks/use-request-size.js.map +1 -1
  104. package/dist/web/hooks/use-send-follow-up-message.d.ts +17 -0
  105. package/dist/web/hooks/use-send-follow-up-message.js +17 -0
  106. package/dist/web/hooks/use-send-follow-up-message.js.map +1 -1
  107. package/dist/web/hooks/use-set-open-in-app-url.d.ts +17 -0
  108. package/dist/web/hooks/use-set-open-in-app-url.js +17 -0
  109. package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -1
  110. package/dist/web/hooks/use-tool-info.d.ts +33 -0
  111. package/dist/web/hooks/use-tool-info.js +26 -0
  112. package/dist/web/hooks/use-tool-info.js.map +1 -1
  113. package/dist/web/hooks/use-user.d.ts +2 -0
  114. package/dist/web/hooks/use-user.js +2 -0
  115. package/dist/web/hooks/use-user.js.map +1 -1
  116. package/dist/web/hooks/use-view-state.d.ts +21 -0
  117. package/dist/web/hooks/use-view-state.js.map +1 -1
  118. package/dist/web/mount-view.d.ts +19 -0
  119. package/dist/web/mount-view.js +19 -0
  120. package/dist/web/mount-view.js.map +1 -1
  121. package/dist/web/plugin/plugin.d.ts +28 -0
  122. package/dist/web/plugin/plugin.js +33 -0
  123. package/dist/web/plugin/plugin.js.map +1 -1
  124. package/dist/web/types.d.ts +4 -0
  125. package/dist/web/types.js.map +1 -1
  126. package/package.json +6 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,GAClB,MAAM,gEAAgE,CAAC;AAIxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACpF,OAAO,EAEL,iBAAiB,GAClB,MAAM,gEAAgE,CAAC;AACxE,OAAO,EAEL,qBAAqB,GACtB,MAAM,iDAAiD,CAAC;AAGzD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAoC;IAEpC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC5C,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACxB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YAC/B,IAAI,EAAE,CAAC;YACP,OAAO;QACT,CAAC;QACD,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type BearerAuthMiddlewareOptions,\n requireBearerAuth,\n} from \"@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js\";\n\nimport type { RequestHandler } from \"express\";\n\nexport { InvalidTokenError } from \"@modelcontextprotocol/sdk/server/auth/errors.js\";\nexport {\n type BearerAuthMiddlewareOptions,\n requireBearerAuth,\n} from \"@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js\";\nexport {\n type AuthMetadataOptions,\n mcpAuthMetadataRouter,\n} from \"@modelcontextprotocol/sdk/server/auth/router.js\";\nexport type { AuthInfo } from \"@modelcontextprotocol/sdk/server/auth/types.js\";\n\n/**\n * Like `requireBearerAuth`, but lets requests through when no\n * `Authorization` header is present. Used for mixed-auth servers where some\n * tools are public and others require sign-in: each tool enforces its own\n * `securitySchemes` against `extra.authInfo`.\n *\n * Behavior:\n * - No `Authorization` header → `next()` without `req.auth`.\n * - Valid Bearer token → `req.auth` set, same as `requireBearerAuth`.\n * - Invalid / malformed / expired / insufficient-scope → same error response\n * as `requireBearerAuth` (401/403). Sending a bad token is still a client\n * error.\n */\nexport function optionalBearerAuth(\n options: BearerAuthMiddlewareOptions,\n): RequestHandler {\n const required = requireBearerAuth(options);\n return (req, res, next) => {\n if (!req.headers.authorization) {\n next();\n return;\n }\n return required(req, res, next);\n };\n}\n"]}
@@ -1,12 +1,46 @@
1
1
  import type { AudioContent, EmbeddedResource, ImageContent, ResourceLink, TextContent } from "@modelcontextprotocol/sdk/types.js";
2
+ /**
3
+ * MCP content annotations applied to any returned block.
4
+ *
5
+ * - `audience` — who is meant to see the content (`"user"`, `"assistant"`, or both).
6
+ * - `priority` — relative importance hint for the host.
7
+ * - `lastModified` — ISO timestamp for when the content was produced.
8
+ */
2
9
  type ContentAnnotations = {
3
10
  audience?: ("user" | "assistant")[];
4
11
  priority?: number;
5
12
  lastModified?: string;
6
13
  };
14
+ /**
15
+ * Build an MCP text content block.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * return { content: [text("Found 3 results.")] };
20
+ * ```
21
+ */
7
22
  export declare function text(value: string, annotations?: ContentAnnotations): TextContent;
23
+ /**
24
+ * Build an MCP image content block.
25
+ *
26
+ * `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is
27
+ * **already base64-encoded**. Passing a raw byte-string will produce invalid
28
+ * content.
29
+ */
8
30
  export declare function image(data: string | Uint8Array, mimeType: string, annotations?: ContentAnnotations): ImageContent;
31
+ /**
32
+ * Build an MCP audio content block.
33
+ *
34
+ * `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is
35
+ * **already base64-encoded**.
36
+ */
9
37
  export declare function audio(data: string | Uint8Array, mimeType: string, annotations?: ContentAnnotations): AudioContent;
38
+ /**
39
+ * Build an MCP embedded resource — the full content travels inline. Use this
40
+ * when the client needs the bytes themselves rather than a link.
41
+ *
42
+ * Pass either `text` (UTF-8 string) or `blob` (base64-encoded bytes).
43
+ */
10
44
  export declare function embeddedResource(resource: {
11
45
  uri: string;
12
46
  mimeType?: string;
@@ -16,6 +50,12 @@ export declare function embeddedResource(resource: {
16
50
  mimeType?: string;
17
51
  blob: string;
18
52
  }, annotations?: ContentAnnotations): EmbeddedResource;
53
+ /**
54
+ * Build an MCP resource link — a `type: "resource_link"` block carrying a URI
55
+ * the client can fetch (or subscribe to) on demand. Use a link when the
56
+ * client should retrieve the bytes itself; use {@link embeddedResource} when
57
+ * the content must travel inline with the response.
58
+ */
19
59
  export declare function resourceLink(link: {
20
60
  uri: string;
21
61
  name: string;
@@ -10,9 +10,24 @@ function toBase64(data) {
10
10
  }
11
11
  return Buffer.from(data).toString("base64");
12
12
  }
13
+ /**
14
+ * Build an MCP text content block.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * return { content: [text("Found 3 results.")] };
19
+ * ```
20
+ */
13
21
  export function text(value, annotations) {
14
22
  return { type: "text", text: value, ...(annotations && { annotations }) };
15
23
  }
24
+ /**
25
+ * Build an MCP image content block.
26
+ *
27
+ * `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is
28
+ * **already base64-encoded**. Passing a raw byte-string will produce invalid
29
+ * content.
30
+ */
16
31
  export function image(data, mimeType, annotations) {
17
32
  return {
18
33
  type: "image",
@@ -21,6 +36,12 @@ export function image(data, mimeType, annotations) {
21
36
  ...(annotations && { annotations }),
22
37
  };
23
38
  }
39
+ /**
40
+ * Build an MCP audio content block.
41
+ *
42
+ * `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is
43
+ * **already base64-encoded**.
44
+ */
24
45
  export function audio(data, mimeType, annotations) {
25
46
  return {
26
47
  type: "audio",
@@ -29,6 +50,12 @@ export function audio(data, mimeType, annotations) {
29
50
  ...(annotations && { annotations }),
30
51
  };
31
52
  }
53
+ /**
54
+ * Build an MCP embedded resource — the full content travels inline. Use this
55
+ * when the client needs the bytes themselves rather than a link.
56
+ *
57
+ * Pass either `text` (UTF-8 string) or `blob` (base64-encoded bytes).
58
+ */
32
59
  export function embeddedResource(resource, annotations) {
33
60
  return {
34
61
  type: "resource",
@@ -36,6 +63,12 @@ export function embeddedResource(resource, annotations) {
36
63
  ...(annotations && { annotations }),
37
64
  };
38
65
  }
66
+ /**
67
+ * Build an MCP resource link — a `type: "resource_link"` block carrying a URI
68
+ * the client can fetch (or subscribe to) on demand. Use a link when the
69
+ * client should retrieve the bytes itself; use {@link embeddedResource} when
70
+ * the content must travel inline with the response.
71
+ */
39
72
  export function resourceLink(link, annotations) {
40
73
  return {
41
74
  type: "resource_link",
@@ -1 +1 @@
1
- {"version":3,"file":"content-helpers.js","sourceRoot":"","sources":["../../src/server/content-helpers.ts"],"names":[],"mappings":"AAcA;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,IAAyB;IACzC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,IAAI,CAClB,KAAa,EACb,WAAgC;IAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,KAAK,CACnB,IAAyB,EACzB,QAAgB,EAChB,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;QACpB,QAAQ;QACR,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,KAAK,CACnB,IAAyB,EACzB,QAAgB,EAChB,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;QACpB,QAAQ;QACR,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,QAEoD,EACpD,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ;QACR,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,IAOC,EACD,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,GAAG,IAAI;QACP,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n AudioContent,\n EmbeddedResource,\n ImageContent,\n ResourceLink,\n TextContent,\n} from \"@modelcontextprotocol/sdk/types.js\";\n\ntype ContentAnnotations = {\n audience?: (\"user\" | \"assistant\")[];\n priority?: number;\n lastModified?: string;\n};\n\n/**\n * Returns a base64-encoded string.\n * - `Uint8Array` input is encoded via `Buffer.toString(\"base64\")`.\n * - `string` input is assumed to be **already base64-encoded** and is returned\n * as-is. Passing raw/unencoded string bytes will produce invalid MCP content.\n */\nfunction toBase64(data: string | Uint8Array): string {\n if (typeof data === \"string\") {\n return data;\n }\n return Buffer.from(data).toString(\"base64\");\n}\n\nexport function text(\n value: string,\n annotations?: ContentAnnotations,\n): TextContent {\n return { type: \"text\", text: value, ...(annotations && { annotations }) };\n}\n\nexport function image(\n data: string | Uint8Array,\n mimeType: string,\n annotations?: ContentAnnotations,\n): ImageContent {\n return {\n type: \"image\",\n data: toBase64(data),\n mimeType,\n ...(annotations && { annotations }),\n };\n}\n\nexport function audio(\n data: string | Uint8Array,\n mimeType: string,\n annotations?: ContentAnnotations,\n): AudioContent {\n return {\n type: \"audio\",\n data: toBase64(data),\n mimeType,\n ...(annotations && { annotations }),\n };\n}\n\nexport function embeddedResource(\n resource:\n | { uri: string; mimeType?: string; text: string }\n | { uri: string; mimeType?: string; blob: string },\n annotations?: ContentAnnotations,\n): EmbeddedResource {\n return {\n type: \"resource\",\n resource,\n ...(annotations && { annotations }),\n };\n}\n\nexport function resourceLink(\n link: {\n uri: string;\n name: string;\n title?: string;\n description?: string;\n mimeType?: string;\n size?: number;\n },\n annotations?: ContentAnnotations,\n): ResourceLink {\n return {\n type: \"resource_link\",\n ...link,\n ...(annotations && { annotations }),\n };\n}\n"]}
1
+ {"version":3,"file":"content-helpers.js","sourceRoot":"","sources":["../../src/server/content-helpers.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,IAAyB;IACzC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,IAAI,CAClB,KAAa,EACb,WAAgC;IAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;AAC5E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CACnB,IAAyB,EACzB,QAAgB,EAChB,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;QACpB,QAAQ;QACR,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CACnB,IAAyB,EACzB,QAAgB,EAChB,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;QACpB,QAAQ;QACR,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAEoD,EACpD,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ;QACR,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,IAOC,EACD,WAAgC;IAEhC,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,GAAG,IAAI;QACP,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n AudioContent,\n EmbeddedResource,\n ImageContent,\n ResourceLink,\n TextContent,\n} from \"@modelcontextprotocol/sdk/types.js\";\n\n/**\n * MCP content annotations applied to any returned block.\n *\n * - `audience` — who is meant to see the content (`\"user\"`, `\"assistant\"`, or both).\n * - `priority` — relative importance hint for the host.\n * - `lastModified` — ISO timestamp for when the content was produced.\n */\ntype ContentAnnotations = {\n audience?: (\"user\" | \"assistant\")[];\n priority?: number;\n lastModified?: string;\n};\n\n/**\n * Returns a base64-encoded string.\n * - `Uint8Array` input is encoded via `Buffer.toString(\"base64\")`.\n * - `string` input is assumed to be **already base64-encoded** and is returned\n * as-is. Passing raw/unencoded string bytes will produce invalid MCP content.\n */\nfunction toBase64(data: string | Uint8Array): string {\n if (typeof data === \"string\") {\n return data;\n }\n return Buffer.from(data).toString(\"base64\");\n}\n\n/**\n * Build an MCP text content block.\n *\n * @example\n * ```ts\n * return { content: [text(\"Found 3 results.\")] };\n * ```\n */\nexport function text(\n value: string,\n annotations?: ContentAnnotations,\n): TextContent {\n return { type: \"text\", text: value, ...(annotations && { annotations }) };\n}\n\n/**\n * Build an MCP image content block.\n *\n * `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is\n * **already base64-encoded**. Passing a raw byte-string will produce invalid\n * content.\n */\nexport function image(\n data: string | Uint8Array,\n mimeType: string,\n annotations?: ContentAnnotations,\n): ImageContent {\n return {\n type: \"image\",\n data: toBase64(data),\n mimeType,\n ...(annotations && { annotations }),\n };\n}\n\n/**\n * Build an MCP audio content block.\n *\n * `data` may be a `Uint8Array` (encoded to base64 for you) or a string that is\n * **already base64-encoded**.\n */\nexport function audio(\n data: string | Uint8Array,\n mimeType: string,\n annotations?: ContentAnnotations,\n): AudioContent {\n return {\n type: \"audio\",\n data: toBase64(data),\n mimeType,\n ...(annotations && { annotations }),\n };\n}\n\n/**\n * Build an MCP embedded resource — the full content travels inline. Use this\n * when the client needs the bytes themselves rather than a link.\n *\n * Pass either `text` (UTF-8 string) or `blob` (base64-encoded bytes).\n */\nexport function embeddedResource(\n resource:\n | { uri: string; mimeType?: string; text: string }\n | { uri: string; mimeType?: string; blob: string },\n annotations?: ContentAnnotations,\n): EmbeddedResource {\n return {\n type: \"resource\",\n resource,\n ...(annotations && { annotations }),\n };\n}\n\n/**\n * Build an MCP resource link — a `type: \"resource_link\"` block carrying a URI\n * the client can fetch (or subscribe to) on demand. Use a link when the\n * client should retrieve the bytes itself; use {@link embeddedResource} when\n * the content must travel inline with the response.\n */\nexport function resourceLink(\n link: {\n uri: string;\n name: string;\n title?: string;\n description?: string;\n mimeType?: string;\n size?: number;\n },\n annotations?: ContentAnnotations,\n): ResourceLink {\n return {\n type: \"resource_link\",\n ...link,\n ...(annotations && { annotations }),\n };\n}\n"]}
@@ -1,8 +1,28 @@
1
1
  import { z } from "zod";
2
+ /**
3
+ * Zod schema for a host-managed file reference passed between tools and views.
4
+ *
5
+ * Use it inside a tool's `inputSchema` or `outputSchema` so the host can
6
+ * recognize the field as a file and surface attach / preview affordances.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * server.registerTool({
11
+ * name: "summarize-document",
12
+ * inputSchema: { document: FileRef },
13
+ * }, async ({ document }) => {
14
+ * const res = await fetch(document.download_url);
15
+ * // …
16
+ * });
17
+ * ```
18
+ *
19
+ * @see https://docs.skybridge.tech/api-reference/file-ref
20
+ */
2
21
  export declare const FileRef: z.ZodObject<{
3
22
  file_id: z.ZodString;
4
23
  download_url: z.ZodString;
5
24
  mime_type: z.ZodOptional<z.ZodString>;
6
25
  file_name: z.ZodOptional<z.ZodString>;
7
26
  }, z.core.$strip>;
27
+ /** Inferred TypeScript type for {@link FileRef}. */
8
28
  export type FileRef = z.infer<typeof FileRef>;
@@ -1,4 +1,23 @@
1
1
  import { z } from "zod";
2
+ /**
3
+ * Zod schema for a host-managed file reference passed between tools and views.
4
+ *
5
+ * Use it inside a tool's `inputSchema` or `outputSchema` so the host can
6
+ * recognize the field as a file and surface attach / preview affordances.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * server.registerTool({
11
+ * name: "summarize-document",
12
+ * inputSchema: { document: FileRef },
13
+ * }, async ({ document }) => {
14
+ * const res = await fetch(document.download_url);
15
+ * // …
16
+ * });
17
+ * ```
18
+ *
19
+ * @see https://docs.skybridge.tech/api-reference/file-ref
20
+ */
2
21
  export const FileRef = z.object({
3
22
  file_id: z.string(),
4
23
  download_url: z.string(),
@@ -1 +1 @@
1
- {"version":3,"file":"file-ref.js","sourceRoot":"","sources":["../../src/server/file-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\n\nexport const FileRef = z.object({\n file_id: z.string(),\n download_url: z.string(),\n mime_type: z.string().optional(),\n file_name: z.string().optional(),\n});\n\nexport type FileRef = z.infer<typeof FileRef>;\n"]}
1
+ {"version":3,"file":"file-ref.js","sourceRoot":"","sources":["../../src/server/file-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\n\n/**\n * Zod schema for a host-managed file reference passed between tools and views.\n *\n * Use it inside a tool's `inputSchema` or `outputSchema` so the host can\n * recognize the field as a file and surface attach / preview affordances.\n *\n * @example\n * ```ts\n * server.registerTool({\n * name: \"summarize-document\",\n * inputSchema: { document: FileRef },\n * }, async ({ document }) => {\n * const res = await fetch(document.download_url);\n * // …\n * });\n * ```\n *\n * @see https://docs.skybridge.tech/api-reference/file-ref\n */\nexport const FileRef = z.object({\n file_id: z.string(),\n download_url: z.string(),\n mime_type: z.string().optional(),\n file_name: z.string().optional(),\n});\n\n/** Inferred TypeScript type for {@link FileRef}. */\nexport type FileRef = z.infer<typeof FileRef>;\n"]}
@@ -1,7 +1,8 @@
1
+ export { type AuthInfo, type AuthMetadataOptions, type BearerAuthMiddlewareOptions, InvalidTokenError, mcpAuthMetadataRouter, optionalBearerAuth, requireBearerAuth, } from "./auth.js";
1
2
  export { audio, embeddedResource, image, resourceLink, text, } from "./content-helpers.js";
2
3
  export { FileRef } from "./file-ref.js";
3
4
  export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
4
5
  export type { McpExtra, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard, } from "./middleware.js";
5
- export type { HandlerContent, KnownToolMeta, McpServerTypes, ToolDef, ToolMeta, ViewConfig, ViewCsp, ViewHostType, ViewName, ViewNameRegistry, } from "./server.js";
6
+ export type { HandlerContent, KnownToolMeta, McpServerTypes, SecurityScheme, ToolDef, ToolMeta, ViewConfig, ViewCsp, ViewHostType, ViewName, ViewNameRegistry, } from "./server.js";
6
7
  export { McpServer, normalizeContent, } from "./server.js";
7
8
  export { viewsDevServer } from "./viewsDevServer.js";
@@ -1,3 +1,4 @@
1
+ export { InvalidTokenError, mcpAuthMetadataRouter, optionalBearerAuth, requireBearerAuth, } from "./auth.js";
1
2
  export { audio, embeddedResource, image, resourceLink, text, } from "./content-helpers.js";
2
3
  export { FileRef } from "./file-ref.js";
3
4
  export { McpServer, normalizeContent, } from "./server.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,KAAK,EACL,YAAY,EACZ,IAAI,GACL,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AA8BxC,OAAO,EACL,SAAS,EACT,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n audio,\n embeddedResource,\n image,\n resourceLink,\n text,\n} from \"./content-helpers.js\";\nexport { FileRef } from \"./file-ref.js\";\nexport type {\n AnyToolRegistry,\n InferTools,\n ToolInput,\n ToolNames,\n ToolOutput,\n ToolResponseMetadata,\n} from \"./inferUtilityTypes.js\";\nexport type {\n McpExtra,\n McpMethodString,\n McpMiddlewareFilter,\n McpMiddlewareFn,\n McpResultFor,\n McpTypedMiddlewareFn,\n McpWildcard,\n} from \"./middleware.js\";\nexport type {\n HandlerContent,\n KnownToolMeta,\n McpServerTypes,\n ToolDef,\n ToolMeta,\n ViewConfig,\n ViewCsp,\n ViewHostType,\n ViewName,\n ViewNameRegistry,\n} from \"./server.js\";\nexport {\n McpServer,\n normalizeContent,\n} from \"./server.js\";\nexport { viewsDevServer } from \"./viewsDevServer.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,KAAK,EACL,YAAY,EACZ,IAAI,GACL,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AA+BxC,OAAO,EACL,SAAS,EACT,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n type AuthInfo,\n type AuthMetadataOptions,\n type BearerAuthMiddlewareOptions,\n InvalidTokenError,\n mcpAuthMetadataRouter,\n optionalBearerAuth,\n requireBearerAuth,\n} from \"./auth.js\";\nexport {\n audio,\n embeddedResource,\n image,\n resourceLink,\n text,\n} from \"./content-helpers.js\";\nexport { FileRef } from \"./file-ref.js\";\nexport type {\n AnyToolRegistry,\n InferTools,\n ToolInput,\n ToolNames,\n ToolOutput,\n ToolResponseMetadata,\n} from \"./inferUtilityTypes.js\";\nexport type {\n McpExtra,\n McpMethodString,\n McpMiddlewareFilter,\n McpMiddlewareFn,\n McpResultFor,\n McpTypedMiddlewareFn,\n McpWildcard,\n} from \"./middleware.js\";\nexport type {\n HandlerContent,\n KnownToolMeta,\n McpServerTypes,\n SecurityScheme,\n ToolDef,\n ToolMeta,\n ViewConfig,\n ViewCsp,\n ViewHostType,\n ViewName,\n ViewNameRegistry,\n} from \"./server.js\";\nexport {\n McpServer,\n normalizeContent,\n} from \"./server.js\";\nexport { viewsDevServer } from \"./viewsDevServer.js\";\n"]}
@@ -19,7 +19,12 @@ export type McpMiddlewareFn = (request: {
19
19
  * MCP methods the server handles (incoming from client).
20
20
  */
21
21
  export type McpMethodString = ClientRequest["method"] | ClientNotification["method"];
22
- /** Extract params type for a specific MCP method from SDK unions. */
22
+ /**
23
+ * Resolve the `params` type for a specific MCP method (request or notification)
24
+ * from the SDK's typed unions. Falls back to `Record<string, unknown>` for
25
+ * unknown methods. Used by {@link McpTypedMiddlewareFn} to narrow the request
26
+ * shape in typed middleware.
27
+ */
23
28
  export type McpRequestParams<M extends string> = Extract<ClientRequest, {
24
29
  method: M;
25
30
  }> extends {
@@ -29,7 +34,11 @@ export type McpRequestParams<M extends string> = Extract<ClientRequest, {
29
34
  }> extends {
30
35
  params: infer P;
31
36
  } ? P : Record<string, unknown>;
32
- /** Resolve extra type: McpExtra for requests, undefined for notifications. */
37
+ /**
38
+ * Resolve the `extra` arg type for a specific MCP method: {@link McpExtra} for
39
+ * request methods, `undefined` for notification methods (the SDK does not
40
+ * pass extra context for notifications).
41
+ */
33
42
  export type McpExtraFor<M extends string> = M extends ClientRequest["method"] ? McpExtra : M extends ClientNotification["method"] ? undefined : McpExtra | undefined;
34
43
  /** Maps each MCP request method to its SDK result type. */
35
44
  interface McpResultMap {
@@ -59,7 +68,11 @@ interface McpResultMap {
59
68
  * For unknown/unmatched methods, falls back to `ServerResult`.
60
69
  */
61
70
  export type McpResultFor<M extends string> = M extends keyof McpResultMap ? McpResultMap[M] : M extends `${infer Prefix}/*` ? [McpResultMap[keyof McpResultMap & `${Prefix}/${string}`]] extends [never] ? M extends ToWildcard<ClientNotification["method"]> ? undefined : ServerResult : McpResultMap[keyof McpResultMap & `${Prefix}/${string}`] : M extends ClientNotification["method"] ? undefined : ServerResult;
62
- /** Typed middleware fn for a specific method — narrows params, extra, and next() result. */
71
+ /**
72
+ * Typed middleware function for a specific method. Narrows `request.params`
73
+ * via {@link McpRequestParams}, `extra` via {@link McpExtraFor}, and the
74
+ * resolved value of `next()` via {@link McpResultFor}.
75
+ */
63
76
  export type McpTypedMiddlewareFn<M extends string> = (request: {
64
77
  method: M;
65
78
  params: McpRequestParams<M>;
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/server/middleware.ts"],"names":[],"mappings":"AAyJA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,MAAM,GAAG,GAAW,MAAM,CAAC;IAE3B,IACE,CAAC,CAAC,kBAAkB,IAAI,GAAG,IAAI,GAAG,CAAC,gBAAgB,YAAY,GAAG,CAAC;QACnE,CAAC,CACC,uBAAuB,IAAI,GAAG,IAAI,GAAG,CAAC,qBAAqB,YAAY,GAAG,CAC3E,EACD,CAAC;QACD,MAAM,IAAI,KAAK,CACb,6FAA6F,CAC9F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ACxB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport type { RequestHandlerExtra } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport type {\n CallToolResult,\n CancelTaskResult,\n ClientNotification,\n ClientRequest,\n CompleteResult,\n EmptyResult,\n GetPromptResult,\n GetTaskPayloadResult,\n GetTaskResult,\n InitializeResult,\n ListPromptsResult,\n ListResourcesResult,\n ListResourceTemplatesResult,\n ListTasksResult,\n ListToolsResult,\n ReadResourceResult,\n ServerNotification,\n ServerRequest,\n ServerResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\n\n/**\n * The `extra` context object provided by the MCP SDK to request handlers.\n */\nexport type McpExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;\n\n/**\n * A single MCP middleware function following the onion model.\n * Call `next()` to invoke the next middleware or the final handler.\n * For notifications, `extra` is `undefined` (SDK does not provide extra context)\n * and `next()` resolves to `undefined`.\n */\nexport type McpMiddlewareFn = (\n request: { method: string; params: Record<string, unknown> },\n extra: McpExtra | undefined,\n next: () => Promise<unknown>,\n) => Promise<unknown> | unknown;\n\n/**\n * MCP methods the server handles (incoming from client).\n */\nexport type McpMethodString =\n | ClientRequest[\"method\"]\n | ClientNotification[\"method\"];\n\n/** Extract params type for a specific MCP method from SDK unions. */\nexport type McpRequestParams<M extends string> =\n Extract<ClientRequest, { method: M }> extends { params: infer P }\n ? P\n : Extract<ClientNotification, { method: M }> extends { params: infer P }\n ? P\n : Record<string, unknown>;\n\n/** Resolve extra type: McpExtra for requests, undefined for notifications. */\nexport type McpExtraFor<M extends string> = M extends ClientRequest[\"method\"]\n ? McpExtra\n : M extends ClientNotification[\"method\"]\n ? undefined\n : McpExtra | undefined;\n\n/** Maps each MCP request method to its SDK result type. */\ninterface McpResultMap {\n ping: EmptyResult;\n initialize: InitializeResult;\n \"tools/list\": ListToolsResult;\n \"tools/call\": CallToolResult;\n \"resources/list\": ListResourcesResult;\n \"resources/templates/list\": ListResourceTemplatesResult;\n \"resources/read\": ReadResourceResult;\n \"resources/subscribe\": EmptyResult;\n \"resources/unsubscribe\": EmptyResult;\n \"prompts/list\": ListPromptsResult;\n \"prompts/get\": GetPromptResult;\n \"completion/complete\": CompleteResult;\n \"logging/setLevel\": EmptyResult;\n \"tasks/get\": GetTaskResult;\n \"tasks/result\": GetTaskPayloadResult;\n \"tasks/list\": ListTasksResult;\n \"tasks/cancel\": CancelTaskResult;\n}\n\n/**\n * Map an MCP method string to its corresponding result type.\n * For request methods, resolves to the specific SDK result type.\n * For wildcard patterns (e.g. `\"tools/*\"`), resolves to the union of matching result types.\n * For notification methods, resolves to `undefined`.\n * For unknown/unmatched methods, falls back to `ServerResult`.\n */\nexport type McpResultFor<M extends string> = M extends keyof McpResultMap\n ? McpResultMap[M]\n : M extends `${infer Prefix}/*`\n ? [McpResultMap[keyof McpResultMap & `${Prefix}/${string}`]] extends [never]\n ? M extends ToWildcard<ClientNotification[\"method\"]>\n ? undefined\n : ServerResult\n : McpResultMap[keyof McpResultMap & `${Prefix}/${string}`]\n : M extends ClientNotification[\"method\"]\n ? undefined\n : ServerResult;\n\n/** Typed middleware fn for a specific method — narrows params, extra, and next() result. */\nexport type McpTypedMiddlewareFn<M extends string> = (\n request: { method: M; params: McpRequestParams<M> },\n extra: McpExtraFor<M>,\n next: () => Promise<McpResultFor<M>>,\n) => Promise<unknown> | unknown;\n\n/** Extracts `\"prefix/*\"` from `\"prefix/anything\"` — distributive over unions. */\ntype ToWildcard<T extends string> = T extends `${infer Prefix}/${string}`\n ? `${Prefix}/*`\n : never;\n\n/** Wildcard prefixes derived from method strings (e.g. `\"tools/*\"` from `\"tools/call\"`). */\nexport type McpWildcard = ToWildcard<McpMethodString>;\n\n/** Category keywords matching all requests or all notifications. */\ntype McpCategory = \"request\" | \"notification\";\n\n/**\n * A single filter pattern for MCP middleware:\n * - Exact method: `\"tools/call\"`\n * - Wildcard: `\"tools/*\"`\n * - Category: `\"request\"` | `\"notification\"`\n * - Escape hatch: arbitrary string via `string & {}`\n */\ntype McpMiddlewareFilterPattern =\n | McpMethodString\n | McpWildcard\n | McpCategory\n | (string & {});\n\n/**\n * Filter determining which MCP methods a middleware applies to.\n * A single pattern or an array of patterns (OR logic).\n */\nexport type McpMiddlewareFilter =\n | McpMiddlewareFilterPattern\n | McpMiddlewareFilterPattern[];\n\n/**\n * Internal entry stored for each registered middleware.\n * `filter: null` means catch-all (matches everything).\n */\nexport type McpMiddlewareEntry = {\n filter: McpMiddlewareFilter | null;\n handler: McpMiddlewareFn;\n};\n\ntype HandlerMap = Map<string, (...args: unknown[]) => Promise<unknown>>;\n\n/**\n * Extract the TS-private `_requestHandlers` and `_notificationHandlers` maps\n * from the SDK's `Server` (extends `Protocol`). These are runtime-accessible\n * but declared `private` in TypeScript.\n *\n * Validates with `instanceof Map` so an incompatible SDK version fails fast\n * instead of silently breaking.\n */\nexport function getHandlerMaps(server: Server) {\n const obj: object = server;\n\n if (\n !(\"_requestHandlers\" in obj && obj._requestHandlers instanceof Map) ||\n !(\n \"_notificationHandlers\" in obj && obj._notificationHandlers instanceof Map\n )\n ) {\n throw new Error(\n \"Incompatible MCP SDK version: expected _requestHandlers and _notificationHandlers on Server\",\n );\n }\n\n return {\n requestHandlers: obj._requestHandlers as HandlerMap,\n notificationHandlers: obj._notificationHandlers as HandlerMap,\n };\n}\n\n/**\n * Check if a single filter pattern matches a given method.\n *\n * - Exact: `\"tools/call\"` matches only `\"tools/call\"`\n * - Wildcard: `\"tools/*\"` matches any method starting with `\"tools/\"`\n * - Category `\"request\"`: matches when `isNotification` is false\n * - Category `\"notification\"`: matches when `isNotification` is true\n */\nexport function matchesFilter(\n method: string,\n filter: string,\n isNotification: boolean,\n): boolean {\n if (filter === \"request\") {\n return !isNotification;\n }\n if (filter === \"notification\") {\n return isNotification;\n }\n if (filter.endsWith(\"/*\")) {\n const prefix = filter.slice(0, -1); // \"tools/*\" → \"tools/\"\n return method.startsWith(prefix);\n }\n return method === filter;\n}\n\nfunction matchesAnyFilter(\n method: string,\n filter: McpMiddlewareFilter | null,\n isNotification: boolean,\n): boolean {\n if (filter === null) {\n return true;\n }\n if (typeof filter === \"string\") {\n return matchesFilter(method, filter, isNotification);\n }\n return filter.some((pattern) =>\n matchesFilter(method, pattern, isNotification),\n );\n}\n\n/**\n * Build an onion-model middleware chain for a specific method.\n *\n * Filters `entries` to those matching `method`, then composes them\n * so the first registered middleware is the outermost layer.\n * `next()` is guarded against multiple calls within a single middleware.\n */\nexport function buildMiddlewareChain(\n method: string,\n isNotification: boolean,\n originalHandler: (...args: unknown[]) => Promise<unknown>,\n entries: McpMiddlewareEntry[],\n) {\n const applicable = entries.filter((entry) =>\n matchesAnyFilter(method, entry.filter, isNotification),\n );\n\n if (applicable.length === 0) {\n return originalHandler;\n }\n\n return (...args: unknown[]) => {\n const rawRequest = args[0] as Record<string, unknown> | undefined;\n // SDK calls request handlers as handler(request, extra) but\n // notification handlers as handler(notification) — no extra arg.\n const extra = isNotification ? undefined : (args[1] as McpExtra);\n const mcpRequest = {\n method,\n params: (rawRequest?.params as Record<string, unknown>) ?? {},\n };\n\n let index = 0;\n\n const executeLayer = (): Promise<unknown> => {\n const entry = applicable[index++];\n if (!entry) {\n if (rawRequest) {\n rawRequest.params = mcpRequest.params;\n }\n return originalHandler(...args);\n }\n\n let nextCalled = false;\n\n const next = (): Promise<unknown> => {\n if (nextCalled) {\n throw new Error(\n `next() called multiple times in middleware for \"${method}\"`,\n );\n }\n nextCalled = true;\n return executeLayer();\n };\n\n return Promise.resolve(entry.handler(mcpRequest, extra, next));\n };\n\n return executeLayer();\n };\n}\n"]}
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/server/middleware.ts"],"names":[],"mappings":"AAsKA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,MAAM,GAAG,GAAW,MAAM,CAAC;IAE3B,IACE,CAAC,CAAC,kBAAkB,IAAI,GAAG,IAAI,G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xB,CAAC,CAAC;YAEF,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC;QAEF,OAAO,YAAY,EAAE,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport type { RequestHandlerExtra } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport type {\n CallToolResult,\n CancelTaskResult,\n ClientNotification,\n ClientRequest,\n CompleteResult,\n EmptyResult,\n GetPromptResult,\n GetTaskPayloadResult,\n GetTaskResult,\n InitializeResult,\n ListPromptsResult,\n ListResourcesResult,\n ListResourceTemplatesResult,\n ListTasksResult,\n ListToolsResult,\n ReadResourceResult,\n ServerNotification,\n ServerRequest,\n ServerResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\n\n/**\n * The `extra` context object provided by the MCP SDK to request handlers.\n */\nexport type McpExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;\n\n/**\n * A single MCP middleware function following the onion model.\n * Call `next()` to invoke the next middleware or the final handler.\n * For notifications, `extra` is `undefined` (SDK does not provide extra context)\n * and `next()` resolves to `undefined`.\n */\nexport type McpMiddlewareFn = (\n request: { method: string; params: Record<string, unknown> },\n extra: McpExtra | undefined,\n next: () => Promise<unknown>,\n) => Promise<unknown> | unknown;\n\n/**\n * MCP methods the server handles (incoming from client).\n */\nexport type McpMethodString =\n | ClientRequest[\"method\"]\n | ClientNotification[\"method\"];\n\n/**\n * Resolve the `params` type for a specific MCP method (request or notification)\n * from the SDK's typed unions. Falls back to `Record<string, unknown>` for\n * unknown methods. Used by {@link McpTypedMiddlewareFn} to narrow the request\n * shape in typed middleware.\n */\nexport type McpRequestParams<M extends string> =\n Extract<ClientRequest, { method: M }> extends { params: infer P }\n ? P\n : Extract<ClientNotification, { method: M }> extends { params: infer P }\n ? P\n : Record<string, unknown>;\n\n/**\n * Resolve the `extra` arg type for a specific MCP method: {@link McpExtra} for\n * request methods, `undefined` for notification methods (the SDK does not\n * pass extra context for notifications).\n */\nexport type McpExtraFor<M extends string> = M extends ClientRequest[\"method\"]\n ? McpExtra\n : M extends ClientNotification[\"method\"]\n ? undefined\n : McpExtra | undefined;\n\n/** Maps each MCP request method to its SDK result type. */\ninterface McpResultMap {\n ping: EmptyResult;\n initialize: InitializeResult;\n \"tools/list\": ListToolsResult;\n \"tools/call\": CallToolResult;\n \"resources/list\": ListResourcesResult;\n \"resources/templates/list\": ListResourceTemplatesResult;\n \"resources/read\": ReadResourceResult;\n \"resources/subscribe\": EmptyResult;\n \"resources/unsubscribe\": EmptyResult;\n \"prompts/list\": ListPromptsResult;\n \"prompts/get\": GetPromptResult;\n \"completion/complete\": CompleteResult;\n \"logging/setLevel\": EmptyResult;\n \"tasks/get\": GetTaskResult;\n \"tasks/result\": GetTaskPayloadResult;\n \"tasks/list\": ListTasksResult;\n \"tasks/cancel\": CancelTaskResult;\n}\n\n/**\n * Map an MCP method string to its corresponding result type.\n * For request methods, resolves to the specific SDK result type.\n * For wildcard patterns (e.g. `\"tools/*\"`), resolves to the union of matching result types.\n * For notification methods, resolves to `undefined`.\n * For unknown/unmatched methods, falls back to `ServerResult`.\n */\nexport type McpResultFor<M extends string> = M extends keyof McpResultMap\n ? McpResultMap[M]\n : M extends `${infer Prefix}/*`\n ? [McpResultMap[keyof McpResultMap & `${Prefix}/${string}`]] extends [never]\n ? M extends ToWildcard<ClientNotification[\"method\"]>\n ? undefined\n : ServerResult\n : McpResultMap[keyof McpResultMap & `${Prefix}/${string}`]\n : M extends ClientNotification[\"method\"]\n ? undefined\n : ServerResult;\n\n/**\n * Typed middleware function for a specific method. Narrows `request.params`\n * via {@link McpRequestParams}, `extra` via {@link McpExtraFor}, and the\n * resolved value of `next()` via {@link McpResultFor}.\n */\nexport type McpTypedMiddlewareFn<M extends string> = (\n request: { method: M; params: McpRequestParams<M> },\n extra: McpExtraFor<M>,\n next: () => Promise<McpResultFor<M>>,\n) => Promise<unknown> | unknown;\n\n/** Extracts `\"prefix/*\"` from `\"prefix/anything\"` — distributive over unions. */\ntype ToWildcard<T extends string> = T extends `${infer Prefix}/${string}`\n ? `${Prefix}/*`\n : never;\n\n/** Wildcard prefixes derived from method strings (e.g. `\"tools/*\"` from `\"tools/call\"`). */\nexport type McpWildcard = ToWildcard<McpMethodString>;\n\n/** Category keywords matching all requests or all notifications. */\ntype McpCategory = \"request\" | \"notification\";\n\n/**\n * A single filter pattern for MCP middleware:\n * - Exact method: `\"tools/call\"`\n * - Wildcard: `\"tools/*\"`\n * - Category: `\"request\"` | `\"notification\"`\n * - Escape hatch: arbitrary string via `string & {}`\n */\ntype McpMiddlewareFilterPattern =\n | McpMethodString\n | McpWildcard\n | McpCategory\n | (string & {});\n\n/**\n * Filter determining which MCP methods a middleware applies to.\n * A single pattern or an array of patterns (OR logic).\n */\nexport type McpMiddlewareFilter =\n | McpMiddlewareFilterPattern\n | McpMiddlewareFilterPattern[];\n\n/**\n * Internal entry stored for each registered middleware.\n * `filter: null` means catch-all (matches everything).\n */\nexport type McpMiddlewareEntry = {\n filter: McpMiddlewareFilter | null;\n handler: McpMiddlewareFn;\n};\n\ntype HandlerMap = Map<string, (...args: unknown[]) => Promise<unknown>>;\n\n/**\n * Extract the TS-private `_requestHandlers` and `_notificationHandlers` maps\n * from the SDK's `Server` (extends `Protocol`). These are runtime-accessible\n * but declared `private` in TypeScript.\n *\n * Validates with `instanceof Map` so an incompatible SDK version fails fast\n * instead of silently breaking.\n */\nexport function getHandlerMaps(server: Server) {\n const obj: object = server;\n\n if (\n !(\"_requestHandlers\" in obj && obj._requestHandlers instanceof Map) ||\n !(\n \"_notificationHandlers\" in obj && obj._notificationHandlers instanceof Map\n )\n ) {\n throw new Error(\n \"Incompatible MCP SDK version: expected _requestHandlers and _notificationHandlers on Server\",\n );\n }\n\n return {\n requestHandlers: obj._requestHandlers as HandlerMap,\n notificationHandlers: obj._notificationHandlers as HandlerMap,\n };\n}\n\n/**\n * Check if a single filter pattern matches a given method.\n *\n * - Exact: `\"tools/call\"` matches only `\"tools/call\"`\n * - Wildcard: `\"tools/*\"` matches any method starting with `\"tools/\"`\n * - Category `\"request\"`: matches when `isNotification` is false\n * - Category `\"notification\"`: matches when `isNotification` is true\n */\nexport function matchesFilter(\n method: string,\n filter: string,\n isNotification: boolean,\n): boolean {\n if (filter === \"request\") {\n return !isNotification;\n }\n if (filter === \"notification\") {\n return isNotification;\n }\n if (filter.endsWith(\"/*\")) {\n const prefix = filter.slice(0, -1); // \"tools/*\" → \"tools/\"\n return method.startsWith(prefix);\n }\n return method === filter;\n}\n\nfunction matchesAnyFilter(\n method: string,\n filter: McpMiddlewareFilter | null,\n isNotification: boolean,\n): boolean {\n if (filter === null) {\n return true;\n }\n if (typeof filter === \"string\") {\n return matchesFilter(method, filter, isNotification);\n }\n return filter.some((pattern) =>\n matchesFilter(method, pattern, isNotification),\n );\n}\n\n/**\n * Build an onion-model middleware chain for a specific method.\n *\n * Filters `entries` to those matching `method`, then composes them\n * so the first registered middleware is the outermost layer.\n * `next()` is guarded against multiple calls within a single middleware.\n */\nexport function buildMiddlewareChain(\n method: string,\n isNotification: boolean,\n originalHandler: (...args: unknown[]) => Promise<unknown>,\n entries: McpMiddlewareEntry[],\n) {\n const applicable = entries.filter((entry) =>\n matchesAnyFilter(method, entry.filter, isNotification),\n );\n\n if (applicable.length === 0) {\n return originalHandler;\n }\n\n return (...args: unknown[]) => {\n const rawRequest = args[0] as Record<string, unknown> | undefined;\n // SDK calls request handlers as handler(request, extra) but\n // notification handlers as handler(notification) — no extra arg.\n const extra = isNotification ? undefined : (args[1] as McpExtra);\n const mcpRequest = {\n method,\n params: (rawRequest?.params as Record<string, unknown>) ?? {},\n };\n\n let index = 0;\n\n const executeLayer = (): Promise<unknown> => {\n const entry = applicable[index++];\n if (!entry) {\n if (rawRequest) {\n rawRequest.params = mcpRequest.params;\n }\n return originalHandler(...args);\n }\n\n let nextCalled = false;\n\n const next = (): Promise<unknown> => {\n if (nextCalled) {\n throw new Error(\n `next() called multiple times in middleware for \"${method}\"`,\n );\n }\n nextCalled = true;\n return executeLayer();\n };\n\n return Promise.resolve(entry.handler(mcpRequest, extra, next));\n };\n\n return executeLayer();\n };\n}\n"]}
@@ -1,16 +1,30 @@
1
+ import type { McpUiToolMeta } from "@modelcontextprotocol/ext-apps";
1
2
  import { type ServerOptions } from "@modelcontextprotocol/sdk/server/index.js";
2
3
  import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
3
4
  import type { AnySchema, SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
4
5
  import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
5
- import type { ContentBlock, Implementation, ServerNotification, ServerRequest, ServerResult, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
6
+ import type { ContentBlock, Implementation, RequestMeta, ServerNotification, ServerRequest, ServerResult, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
6
7
  import { type ErrorRequestHandler, type Express, type RequestHandler } from "express";
7
8
  import type { McpExtra, McpExtraFor, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard } from "./middleware.js";
9
+ /**
10
+ * Type marker for a registered tool — carries its input, output, and response
11
+ * metadata shapes so views can infer types from `typeof server`.
12
+ *
13
+ * You normally never construct this by hand; it is produced by `registerTool`
14
+ * and consumed by helpers like {@link InferTools} and {@link generateHelpers}.
15
+ */
8
16
  export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
9
17
  input: TInput;
10
18
  output: TOutput;
11
19
  responseMetadata: TResponseMetadata;
12
20
  };
21
+ /** Which host runtime a view targets — `"apps-sdk"` (ChatGPT) or `"mcp-app"` (MCP Apps spec). */
13
22
  export type ViewHostType = "apps-sdk" | "mcp-app";
23
+ /**
24
+ * Content Security Policy origins attached to a view's resource. Each list is
25
+ * passed through to the host's CSP for the view iframe; omit a field to inherit
26
+ * the host's default for that directive.
27
+ */
14
28
  export interface ViewCsp {
15
29
  /** Origins for static assets (images, fonts, scripts, styles). */
16
30
  resourceDomains?: string[];
@@ -23,24 +37,67 @@ export interface ViewCsp {
23
37
  /** Origins allowed in `<base href>` tags (mcp-apps only). */
24
38
  baseUriDomains?: string[];
25
39
  }
40
+ /**
41
+ * Registry of view component names. The Skybridge Vite plugin augments this
42
+ * interface in the generated `.skybridge/views.d.ts` with one key per view
43
+ * file, which narrows {@link ViewName} from `string` to the concrete union.
44
+ */
26
45
  export interface ViewNameRegistry {
27
46
  }
47
+ /** Union of valid view component names. Narrowed by {@link ViewNameRegistry}. */
28
48
  export type ViewName = keyof ViewNameRegistry & string;
49
+ /**
50
+ * Pass under `view` in a tool's `registerTool` config to render the tool's
51
+ * result through a Skybridge view instead of a plain text response.
52
+ */
29
53
  export interface ViewConfig {
54
+ /** Filename of the view module (without extension) — matches a file in your `viewsDir`. */
30
55
  component: ViewName;
56
+ /** Human-readable label the host may show alongside the view. */
31
57
  description?: string;
58
+ /** Restrict where the view is rendered. Defaults to all known hosts. */
32
59
  hosts?: ViewHostType[];
60
+ /** Apps SDK only: request a visible border around the widget. */
33
61
  prefersBorder?: boolean;
62
+ /** Apps SDK only: override the iframe's served domain (advanced). */
34
63
  domain?: string;
64
+ /** Per-view CSP overrides — see {@link ViewCsp}. */
35
65
  csp?: ViewCsp;
66
+ /** Free-form metadata forwarded on the view resource's `_meta`. */
36
67
  _meta?: Record<string, unknown>;
37
68
  }
69
+ export type SecurityScheme = {
70
+ type: "noauth";
71
+ } | {
72
+ type: "oauth2";
73
+ scopes?: string[];
74
+ };
75
+ /**
76
+ * Well-known keys recognized by host runtimes when set on a tool's `_meta`.
77
+ * Use {@link ToolMeta} to also pass arbitrary custom metadata alongside these.
78
+ *
79
+ * @see https://developers.openai.com/apps-sdk/reference#tool-descriptor-parameters
80
+ */
38
81
  export interface KnownToolMeta {
82
+ /** Apps SDK: allow the rendered view to call this tool from inside its iframe. */
39
83
  "openai/widgetAccessible"?: boolean;
84
+ /** Apps SDK: status text shown while the tool is running (e.g. `"Searching trips"`). */
40
85
  "openai/toolInvocation/invoking"?: string;
86
+ /** Apps SDK: status text shown once the tool returns (e.g. `"Found 3 trips"`). */
41
87
  "openai/toolInvocation/invoked"?: string;
88
+ /** Apps SDK: input parameters that hold file references — the host attaches uploaded files to them. */
89
+ "openai/fileParams"?: string[];
90
+ /** MCP Apps: control whether the tool is exposed to the model, the app, or both. */
91
+ ui?: Pick<McpUiToolMeta, "visibility">;
92
+ securitySchemes?: SecurityScheme[];
42
93
  }
94
+ /** {@link KnownToolMeta} merged with arbitrary string-keyed metadata for custom flags. */
43
95
  export type ToolMeta = KnownToolMeta & Record<string, unknown>;
96
+ /**
97
+ * Convenient return type for tool handlers — a plain string, a single
98
+ * {@link ContentBlock}, or an array. Skybridge normalizes it to the MCP
99
+ * `content: ContentBlock[]` shape before responding.
100
+ */
44
101
  export type HandlerContent = string | ContentBlock | ContentBlock[];
45
102
  /**
46
103
  * Type-level marker interface for cross-package type inference.
@@ -84,17 +141,92 @@ interface ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> {
84
141
  outputSchema?: ZodRawShapeCompat | AnySchema;
85
142
  annotations?: ToolAnnotations;
86
143
  view?: ViewConfig;
144
+ /**
145
+ * Declares which auth schemes this tool supports (e.g. `noauth`, `oauth2`).
146
+ * Lets clients label tools that require sign-in before calling, and pass
147
+ * the right scopes through the OAuth flow. Listing both `noauth` and
148
+ * `oauth2` signals that the tool works for anonymous callers and gives
149
+ * enhanced behavior to authenticated ones.
150
+ */
151
+ securitySchemes?: SecurityScheme[];
87
152
  _meta?: ToolMeta;
88
153
  }
154
+ /**
155
+ * Optional client-supplied hints attached to `params._meta` on every tool call
156
+ * by the Apps SDK host. Hints only: never use for authorization, and tolerate
157
+ * absence.
158
+ * @see https://developers.openai.com/apps-sdk/reference#_meta-fields-the-client-provides
159
+ */
160
+ export interface ClientHintsMeta {
161
+ /** Requested locale (BCP-47, e.g. `"en-US"`). */
162
+ "openai/locale"?: string;
163
+ /** Browser user-agent */
164
+ "openai/userAgent"?: string;
165
+ /** Coarse user location. May be partially populated. */
166
+ "openai/userLocation"?: {
167
+ city?: string;
168
+ region?: string;
169
+ country?: string;
170
+ timezone?: string;
171
+ longitude?: number;
172
+ latitude?: number;
173
+ };
174
+ /** Anonymized user id. */
175
+ "openai/subject"?: string;
176
+ /** Anonymized conversation id, stable within a ChatGPT session. */
177
+ "openai/session"?: string;
178
+ /** Anonymized organization id, when the user account is part of an organization. */
179
+ "openai/organization"?: string;
180
+ /** Stable id for the currently mounted widget instance. */
181
+ "openai/widgetSessionId"?: string;
182
+ }
183
+ type ToolHandlerExtra = Omit<RequestHandlerExtra<ServerRequest, ServerNotification>, "_meta"> & {
184
+ _meta?: RequestMeta & ClientHintsMeta;
185
+ };
89
186
  type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends {
90
187
  content?: HandlerContent;
91
188
  } = {
92
189
  content?: HandlerContent;
93
- }> = (args: ShapeOutput<TInput>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
190
+ }> = (args: ShapeOutput<TInput>, extra: ToolHandlerExtra) => TReturn | Promise<TReturn>;
191
+ /**
192
+ * Coerce a tool handler's return value into an MCP `content` array. Strings
193
+ * become a single `TextContent`; a single block is wrapped in an array;
194
+ * `undefined` produces `[]`. Mostly used internally — exported so consumers
195
+ * who build content lazily can apply the same normalization.
196
+ */
94
197
  export declare function normalizeContent(content: HandlerContent | undefined): ContentBlock[];
95
198
  interface McpServerBaseOmitted extends Omit<McpServerBase, "registerTool" | "connect"> {
96
199
  }
97
200
  declare const McpServerBaseOmitted: new (...args: ConstructorParameters<typeof McpServerBase>) => McpServerBaseOmitted;
201
+ /**
202
+ * The Skybridge server. Extends the MCP SDK's `McpServer` with a typed tool
203
+ * registry, view resources, an embedded Express app, and protocol-level
204
+ * middleware. Construct it with the same `Implementation` info you would pass
205
+ * to the SDK, chain {@link McpServer.registerTool} calls to declare tools,
206
+ * then call {@link McpServer.run} to start the HTTP server.
207
+ *
208
+ * The `TTools` generic accumulates each registered tool's input/output/meta
209
+ * shape, so `typeof server` carries enough information for view-side helpers
210
+ * like {@link generateHelpers} to produce fully-typed hooks.
211
+ *
212
+ * @typeParam TTools - Accumulated tool registry. Filled in by `registerTool`
213
+ * chaining; you almost never set this manually.
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * const server = new McpServer({ name: "my-app", version: "1.0.0" }, {})
218
+ * .registerTool({
219
+ * name: "search",
220
+ * inputSchema: { query: z.string() },
221
+ * view: { component: "search" },
222
+ * }, async ({ query }) => ({ content: `Results for ${query}` }));
223
+ *
224
+ * await server.run();
225
+ * export type AppType = typeof server;
226
+ * ```
227
+ *
228
+ * @see https://docs.skybridge.tech/api-reference/mcp-server
229
+ */
98
230
  export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBaseOmitted {
99
231
  readonly $types: McpServerTypes<TTools>;
100
232
  /**
@@ -114,12 +246,34 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
114
246
  private mcpMiddlewareEntries;
115
247
  private mcpMiddlewareApplied;
116
248
  private claimedViews;
249
+ private viewMetaBuilders;
117
250
  private viteManifest;
118
251
  private readonly serverInfo;
119
252
  private readonly serverOptions?;
120
253
  constructor(serverInfo: Implementation, options?: ServerOptions);
254
+ /**
255
+ * Register Express middleware on the underlying app. Mirrors `app.use` —
256
+ * pass handlers directly or a path-prefixed handler list. Register before
257
+ * {@link McpServer.run}; ordering matches Express.
258
+ *
259
+ * Note: Alpic Cloud only routes traffic to `/mcp`. Custom paths work
260
+ * locally and on self-hosted deployments.
261
+ */
121
262
  use(...handlers: RequestHandler[]): this;
122
263
  use(path: string, ...handlers: RequestHandler[]): this;
264
+ /**
265
+ * Register Express error-handling middleware to run after the built-in
266
+ * `/mcp` route (or your custom route). Use this to log or transform errors
267
+ * thrown by tool handlers before the default error handler responds.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * server.useOnError((err, _req, _res, next) => {
272
+ * logger.error(err);
273
+ * next(err);
274
+ * });
275
+ * ```
276
+ */
123
277
  useOnError(...handlers: ErrorRequestHandler[]): this;
124
278
  useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;
125
279
  /** Register MCP protocol-level middleware (catch-all). */
@@ -154,6 +308,14 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
154
308
  */
155
309
  mcpMiddleware(filter: McpMiddlewareFilter, handler: McpMiddlewareFn): this;
156
310
  private applyMcpMiddleware;
311
+ /**
312
+ * Connect to an MCP transport (override of the SDK's `connect`). Use this
313
+ * when you're embedding Skybridge in a host that already manages its own
314
+ * transport (e.g. stdio for desktop apps); for HTTP, prefer {@link McpServer.run}
315
+ * which sets the transport up for you. Locks in any middleware registered
316
+ * via {@link McpServer.mcpMiddleware} — further calls to that method will
317
+ * throw afterwards.
318
+ */
157
319
  connect(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
158
320
  /**
159
321
  * Per-request stateless connect. The SDK's `Protocol` only allows one
@@ -166,10 +328,21 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
166
328
  * read side and fails fast on SDK field renames.
167
329
  */
168
330
  connectStatelessTransport(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
331
+ /**
332
+ * Start the HTTP server. Listens on `process.env.__PORT` (default `3000`),
333
+ * mounts the `/mcp` route, applies any custom Express middleware registered
334
+ * via {@link McpServer.use} / {@link McpServer.useOnError}, and locks in
335
+ * any MCP middleware registered via {@link McpServer.mcpMiddleware}.
336
+ *
337
+ * On Cloudflare Workers / workerd, returns an object exposing `fetch` so
338
+ * the runtime can bridge incoming requests to the Node HTTP server. On
339
+ * Node, returns `undefined` once listening.
340
+ */
169
341
  run(): Promise<{
170
342
  fetch: (...args: unknown[]) => unknown;
171
343
  } | undefined>;
172
344
  private enforceOneToolPerView;
345
+ private resolveViewRequestContext;
173
346
  private registerViewResources;
174
347
  private registerViewResource;
175
348
  private wrapHandler;
@@ -186,6 +359,35 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
186
359
  file: string;
187
360
  }>): this;
188
361
  private readManifest;
362
+ /**
363
+ * Register a tool. Pass a `config` describing the tool (name, schemas,
364
+ * optional {@link ViewConfig}, optional {@link ToolMeta}) and a handler that
365
+ * returns the tool's result.
366
+ *
367
+ * Chain calls to build up a server: each call returns a new `McpServer`
368
+ * type that captures the tool's input/output/`_meta` shape so the
369
+ * resulting `typeof server` can drive {@link generateHelpers}.
370
+ *
371
+ * The handler's return shape determines the output types: the
372
+ * `structuredContent` field becomes the tool's typed output, and `_meta`
373
+ * becomes its `responseMetadata`. The `content` field is normalized through
374
+ * {@link normalizeContent}.
375
+ *
376
+ * @example
377
+ * ```ts
378
+ * server.registerTool({
379
+ * name: "search",
380
+ * inputSchema: { query: z.string() },
381
+ * outputSchema: { results: z.array(z.string()) },
382
+ * view: { component: "search" },
383
+ * }, async ({ query }) => ({
384
+ * content: `Found results for ${query}`,
385
+ * structuredContent: { results: [...] },
386
+ * }));
387
+ * ```
388
+ *
389
+ * @see https://docs.skybridge.tech/api-reference/register-tool
390
+ */
189
391
  registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
190
392
  content?: HandlerContent;
191
393
  }>(config: ToolConfig<InputArgs> & {