skybridge 0.0.0-dev.8ead776 → 0.0.0-dev.8ec5383

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.
@@ -16,7 +16,7 @@ export { FileRef } from "./file-ref.js";
16
16
  export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
17
17
  export type { McpExtra, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard, } from "./middleware.js";
18
18
  export { getToolError } from "./middleware.js";
19
- export type { HandlerContent, JsonOptions, KnownToolMeta, McpServerTypes, OpenAIDisplayMode, OpenAIEntrypoint, OpenAIFileViewerConfig, OpenAIMentionsConfig, OpenAIQuickAction, OpenAIToolConfig, SecurityScheme, SkybridgeServerOptions, ToolDef, ToolMeta, ViewConfig, ViewCsp, ViewName, ViewNameRegistry, } from "./server.js";
19
+ export type { HandlerContent, JsonOptions, KnownToolMeta, McpServerTypes, OpenAIDisplayMode, OpenAIEntrypoint, OpenAIMentionsConfig, OpenAIQuickAction, OpenAIToolConfig, SecurityScheme, SkybridgeServerOptions, ToolDef, ToolMeta, ViewConfig, ViewCsp, ViewName, ViewNameRegistry, } from "./server.js";
20
20
  export { __setBuildManifest, __setSkillsManifest, McpServer, normalizeContent, } from "./server.js";
21
21
  export { discoverSkills, type Skill, type SkillsManifest, } from "./skills.js";
22
22
  export { viewsDevServer } from "./viewsDevServer.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,8BAA8B,CAAC;AAMtC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAoB,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAoB,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAEL,eAAe,GAChB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAqB,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAqB,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EACL,kBAAkB,GAEnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAKL,qBAAqB,EACrB,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,iBAAiB,GAElB,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;AAkBxC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAqB/C,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,GAGf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n inputRequired,\n ProtocolError,\n ProtocolErrorCode,\n ResourceTemplate,\n type StandardSchemaWithJSON,\n} from \"@modelcontextprotocol/server\";\nexport type {\n SkybridgeConfig,\n SkybridgeHandler,\n SkybridgeOAuthInput,\n} from \"./app.js\";\nexport { Skybridge } from \"./app.js\";\nexport type { OAuthConfig, OAuthProvider } from \"./auth/index.js\";\nexport { type Auth0Claims, auth0Provider } from \"./auth/providers/auth0.js\";\nexport { authplaneProvider } from \"./auth/providers/authplane.js\";\nexport { type ClerkClaims, clerkProvider } from \"./auth/providers/clerk.js\";\nexport { customProvider } from \"./auth/providers/custom.js\";\nexport {\n type DescopeClaims,\n descopeProvider,\n} from \"./auth/providers/descope.js\";\nexport { type StytchClaims, stytchProvider } from \"./auth/providers/stytch.js\";\nexport { type WorkosClaims, workosProvider } from \"./auth/providers/workos.js\";\nexport {\n createJwksVerifier,\n type JwksVerifyConfig,\n} from \"./auth/verify.js\";\nexport {\n type AuthInfo,\n type AuthMetadataOptions,\n type BearerAuthMiddlewareOptions,\n type ExtraClaims,\n mcpAuthMetadataRouter,\n OAuthError,\n OAuthErrorCode,\n optionalBearerAuth,\n requireBearerAuth,\n type TokenVerifier,\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 { getToolError } from \"./middleware.js\";\nexport type {\n HandlerContent,\n JsonOptions,\n KnownToolMeta,\n McpServerTypes,\n OpenAIDisplayMode,\n OpenAIEntrypoint,\n OpenAIFileViewerConfig,\n OpenAIMentionsConfig,\n OpenAIQuickAction,\n OpenAIToolConfig,\n SecurityScheme,\n SkybridgeServerOptions,\n ToolDef,\n ToolMeta,\n ViewConfig,\n ViewCsp,\n ViewName,\n ViewNameRegistry,\n} from \"./server.js\";\nexport {\n __setBuildManifest,\n __setSkillsManifest,\n McpServer,\n normalizeContent,\n} from \"./server.js\";\nexport {\n discoverSkills,\n type Skill,\n type SkillsManifest,\n} from \"./skills.js\";\nexport { viewsDevServer } from \"./viewsDevServer.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,8BAA8B,CAAC;AAMtC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAoB,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAoB,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAEL,eAAe,GAChB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAqB,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAqB,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EACL,kBAAkB,GAEnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAKL,qBAAqB,EACrB,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,iBAAiB,GAElB,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;AAkBxC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAoB/C,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,GAGf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n inputRequired,\n ProtocolError,\n ProtocolErrorCode,\n ResourceTemplate,\n type StandardSchemaWithJSON,\n} from \"@modelcontextprotocol/server\";\nexport type {\n SkybridgeConfig,\n SkybridgeHandler,\n SkybridgeOAuthInput,\n} from \"./app.js\";\nexport { Skybridge } from \"./app.js\";\nexport type { OAuthConfig, OAuthProvider } from \"./auth/index.js\";\nexport { type Auth0Claims, auth0Provider } from \"./auth/providers/auth0.js\";\nexport { authplaneProvider } from \"./auth/providers/authplane.js\";\nexport { type ClerkClaims, clerkProvider } from \"./auth/providers/clerk.js\";\nexport { customProvider } from \"./auth/providers/custom.js\";\nexport {\n type DescopeClaims,\n descopeProvider,\n} from \"./auth/providers/descope.js\";\nexport { type StytchClaims, stytchProvider } from \"./auth/providers/stytch.js\";\nexport { type WorkosClaims, workosProvider } from \"./auth/providers/workos.js\";\nexport {\n createJwksVerifier,\n type JwksVerifyConfig,\n} from \"./auth/verify.js\";\nexport {\n type AuthInfo,\n type AuthMetadataOptions,\n type BearerAuthMiddlewareOptions,\n type ExtraClaims,\n mcpAuthMetadataRouter,\n OAuthError,\n OAuthErrorCode,\n optionalBearerAuth,\n requireBearerAuth,\n type TokenVerifier,\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 { getToolError } from \"./middleware.js\";\nexport type {\n HandlerContent,\n JsonOptions,\n KnownToolMeta,\n McpServerTypes,\n OpenAIDisplayMode,\n OpenAIEntrypoint,\n OpenAIMentionsConfig,\n OpenAIQuickAction,\n OpenAIToolConfig,\n SecurityScheme,\n SkybridgeServerOptions,\n ToolDef,\n ToolMeta,\n ViewConfig,\n ViewCsp,\n ViewName,\n ViewNameRegistry,\n} from \"./server.js\";\nexport {\n __setBuildManifest,\n __setSkillsManifest,\n McpServer,\n normalizeContent,\n} from \"./server.js\";\nexport {\n discoverSkills,\n type Skill,\n type SkillsManifest,\n} from \"./skills.js\";\nexport { viewsDevServer } from \"./viewsDevServer.js\";\n"]}
@@ -106,28 +106,5 @@ describe("registerTool handler invocation", () => {
106
106
  await client.close();
107
107
  await instance.close();
108
108
  });
109
- it("registers a file viewer with the file input and a file entrypoint", async () => {
110
- const app = new Skybridge({
111
- name: "test",
112
- version: "1.0.0",
113
- handler: (server) => server.registerFileViewer({
114
- name: "part-viewer",
115
- extensions: [".stl"],
116
- view: { component: "widget" },
117
- }, async ({ file }) => ({ content: file.name })),
118
- });
119
- const instance = await app.createServerInstance();
120
- const client = new Client({ name: "client", version: "1.0.0" });
121
- const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
122
- await instance.connect(serverTransport);
123
- await client.connect(clientTransport);
124
- const { tools } = await client.listTools();
125
- expect(tools[0]?._meta?.["openai/ui"]).toEqual({
126
- entrypoints: [{ type: "file", extensions: [".stl"] }],
127
- });
128
- expect(tools[0]?.inputSchema.required).toEqual(["file"]);
129
- await client.close();
130
- await instance.close();
131
- });
132
109
  });
133
110
  //# sourceMappingURL=register-tool.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"register-tool.test.js","sourceRoot":"","sources":["../../src/server/register-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,QAAQ,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAC/C,EAAE,CAAC,oEAAoE,EAAE,KAAK,IAAI,EAAE;QAClF,IAAI,QAAuD,CAAC;QAC5D,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC;YACxB,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,OAAO;YAChB,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE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CAAC;SACtD,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;QAEzD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { Client, InMemoryTransport } from \"@modelcontextprotocol/client\";\nimport { describe, expect, it } from \"vitest\";\nimport { z } from \"zod\";\nimport { Skybridge } from \"./app.js\";\n\ndescribe(\"registerTool handler invocation\", () => {\n it(\"passes empty args and a usable extra to a schema-less tool handler\", async () => {\n let received: { args: unknown; extra: unknown } | undefined;\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n handler: (server) =>\n server.registerTool(\n { name: \"no-input\", description: \"no-input\" },\n async (args, extra) => {\n received = { args, extra };\n return { content: [{ type: \"text\", text: \"ok\" }] };\n },\n ),\n });\n const instance = await app.createServerInstance();\n\n const client = new Client({ name: \"client\", version: \"1.0.0\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await instance.connect(serverTransport);\n await client.connect(clientTransport);\n\n await client.callTool({ name: \"no-input\" });\n\n expect(received?.args).toEqual({});\n expect(received?.extra).toHaveProperty(\"mcpReq.send\");\n\n await client.close();\n await instance.close();\n });\n\n it(\"emits openai options as openai/ui metadata on the tool and its view\", async () => {\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n handler: (server) =>\n server.registerTool(\n {\n name: \"library\",\n description: \"library\",\n view: { component: \"widget\" },\n openai: {\n entrypoints: [\n { type: \"global\" },\n { type: \"file\", extensions: [\".stl\"] },\n ],\n availableDisplayModes: [\"inline\", \"fullscreen\"],\n preferredDisplayMode: \"fullscreen\",\n },\n },\n async () => ({ content: \"ok\" }),\n ),\n });\n const instance = await app.createServerInstance();\n const client = new Client({ name: \"client\", version: \"1.0.0\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await instance.connect(serverTransport);\n await client.connect(clientTransport);\n\n const { tools } = await client.listTools();\n const { resources } = await client.listResources();\n\n expect(tools[0]?._meta?.[\"openai/ui\"]).toEqual({\n entrypoints: [{ type: \"global\" }, { type: \"file\", extensions: [\".stl\"] }],\n });\n expect(resources[0]?._meta?.[\"openai/ui\"]).toEqual({\n availableDisplayModes: [\"inline\", \"fullscreen\"],\n preferredDisplayMode: \"fullscreen\",\n });\n\n await client.close();\n await instance.close();\n });\n\n it(\"rejects a global entrypoint on a tool that requires input\", async () => {\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n handler: (server) =>\n server.registerTool(\n {\n name: \"search\",\n description: \"search\",\n inputSchema: { query: z.string() },\n view: { component: \"widget\" },\n openai: { entrypoints: [{ type: \"global\" }] },\n },\n async () => ({ content: \"ok\" }),\n ),\n });\n\n await expect(app.createServerInstance()).rejects.toThrow(/rejects `\\{\\}`/);\n });\n\n it(\"registers mention search as an app-only tool advertising the extension\", async () => {\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n handler: (server) =>\n server.registerMentions({\n name: \"search_parts\",\n handler: async ({ query }) => ({\n items: [\n { type: \"resource_link\", uri: `parts://${query}`, name: query },\n ],\n }),\n }),\n });\n const instance = await app.createServerInstance();\n const client = new Client({ name: \"client\", version: \"1.0.0\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await instance.connect(serverTransport);\n await client.connect(clientTransport);\n\n const { tools } = await client.listTools();\n expect(tools[0]?._meta).toMatchObject({\n \"openai/extensions\": { \"mentions/search\": {} },\n ui: { visibility: [\"app\"] },\n });\n const result = await client.callTool({\n name: \"search_parts\",\n arguments: { query: \"bolt\" },\n });\n expect(result.structuredContent).toEqual({\n items: [{ type: \"resource_link\", uri: \"parts://bolt\", name: \"bolt\" }],\n });\n\n await client.close();\n await instance.close();\n });\n\n it(\"registers a file viewer with the file input and a file entrypoint\", async () => {\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n handler: (server) =>\n server.registerFileViewer(\n {\n name: \"part-viewer\",\n extensions: [\".stl\"],\n view: { component: \"widget\" },\n },\n async ({ file }) => ({ content: file.name }),\n ),\n });\n const instance = await app.createServerInstance();\n const client = new Client({ name: \"client\", version: \"1.0.0\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await instance.connect(serverTransport);\n await client.connect(clientTransport);\n\n const { tools } = await client.listTools();\n expect(tools[0]?._meta?.[\"openai/ui\"]).toEqual({\n entrypoints: [{ type: \"file\", extensions: [\".stl\"] }],\n });\n expect(tools[0]?.inputSchema.required).toEqual([\"file\"]);\n\n await client.close();\n await instance.close();\n });\n});\n"]}
1
+ {"version":3,"file":"register-tool.test.js","sourceRoot":"","sources":["../../src/server/register-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,QAAQ,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAC/C,EAAE,CAAC,oEAAoE,EAAE,KAAK,IAAI,EAAE;QAClF,IAAI,QAAuD,CAAC;QAC5D,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC;YACxB,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,OAAO;YAChB,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAClB,MAAM,CAAC,YAAY,CACjB,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,EAC7C,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;gBACpB,QAAQ,GAAG,EAAE,IAAI,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Client, InMemoryTransport } from \"@modelcontextprotocol/client\";\nimport { describe, expect, it } from \"vitest\";\nimport { z } from \"zod\";\nimport { Skybridge } from \"./app.js\";\n\ndescribe(\"registerTool handler invocation\", () => {\n it(\"passes empty args and a usable extra to a schema-less tool handler\", async () => {\n let received: { args: unknown; extra: unknown } | undefined;\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n handler: (server) =>\n server.registerTool(\n { name: \"no-input\", description: \"no-input\" },\n async (args, extra) => {\n received = { args, extra };\n return { content: [{ type: \"text\", text: \"ok\" }] };\n },\n ),\n });\n const instance = await app.createServerInstance();\n\n const client = new Client({ name: \"client\", version: \"1.0.0\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await instance.connect(serverTransport);\n await client.connect(clientTransport);\n\n await client.callTool({ name: \"no-input\" });\n\n expect(received?.args).toEqual({});\n expect(received?.extra).toHaveProperty(\"mcpReq.send\");\n\n await client.close();\n await instance.close();\n });\n\n it(\"emits openai options as openai/ui metadata on the tool and its view\", async () => {\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n handler: (server) =>\n server.registerTool(\n {\n name: \"library\",\n description: \"library\",\n view: { component: \"widget\" },\n openai: {\n entrypoints: [\n { type: \"global\" },\n { type: \"file\", extensions: [\".stl\"] },\n ],\n availableDisplayModes: [\"inline\", \"fullscreen\"],\n preferredDisplayMode: \"fullscreen\",\n },\n },\n async () => ({ content: \"ok\" }),\n ),\n });\n const instance = await app.createServerInstance();\n const client = new Client({ name: \"client\", version: \"1.0.0\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await instance.connect(serverTransport);\n await client.connect(clientTransport);\n\n const { tools } = await client.listTools();\n const { resources } = await client.listResources();\n\n expect(tools[0]?._meta?.[\"openai/ui\"]).toEqual({\n entrypoints: [{ type: \"global\" }, { type: \"file\", extensions: [\".stl\"] }],\n });\n expect(resources[0]?._meta?.[\"openai/ui\"]).toEqual({\n availableDisplayModes: [\"inline\", \"fullscreen\"],\n preferredDisplayMode: \"fullscreen\",\n });\n\n await client.close();\n await instance.close();\n });\n\n it(\"rejects a global entrypoint on a tool that requires input\", async () => {\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n handler: (server) =>\n server.registerTool(\n {\n name: \"search\",\n description: \"search\",\n inputSchema: { query: z.string() },\n view: { component: \"widget\" },\n openai: { entrypoints: [{ type: \"global\" }] },\n },\n async () => ({ content: \"ok\" }),\n ),\n });\n\n await expect(app.createServerInstance()).rejects.toThrow(/rejects `\\{\\}`/);\n });\n\n it(\"registers mention search as an app-only tool advertising the extension\", async () => {\n const app = new Skybridge({\n name: \"test\",\n version: \"1.0.0\",\n handler: (server) =>\n server.registerMentions({\n name: \"search_parts\",\n handler: async ({ query }) => ({\n items: [\n { type: \"resource_link\", uri: `parts://${query}`, name: query },\n ],\n }),\n }),\n });\n const instance = await app.createServerInstance();\n const client = new Client({ name: \"client\", version: \"1.0.0\" });\n const [clientTransport, serverTransport] =\n InMemoryTransport.createLinkedPair();\n await instance.connect(serverTransport);\n await client.connect(clientTransport);\n\n const { tools } = await client.listTools();\n expect(tools[0]?._meta).toMatchObject({\n \"openai/extensions\": { \"mentions/search\": {} },\n ui: { visibility: [\"app\"] },\n });\n const result = await client.callTool({\n name: \"search_parts\",\n arguments: { query: \"bolt\" },\n });\n expect(result.structuredContent).toEqual({\n items: [{ type: \"resource_link\", uri: \"parts://bolt\", name: \"bolt\" }],\n });\n\n await client.close();\n await instance.close();\n });\n});\n"]}
@@ -10,16 +10,34 @@ export function resolveServerOrigin(header) {
10
10
  const firstHop = (value) => value?.split(",")[0]?.trim();
11
11
  const forwardedHost = firstHop(header("x-forwarded-host"));
12
12
  if (forwardedHost) {
13
- const proto = firstHop(header("x-forwarded-proto")) || "https";
13
+ const proto = firstHop(header("x-forwarded-proto")) ||
14
+ (isLoopbackHost(forwardedHost) ? "http" : "https");
14
15
  return `${proto}://${forwardedHost}`;
15
16
  }
16
17
  const host = header("host");
17
18
  if (host) {
18
- const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
19
- ? "http"
20
- : "https";
19
+ const proto = isLoopbackHost(host) ? "http" : "https";
21
20
  return `${proto}://${host}`;
22
21
  }
23
22
  return `http://localhost:${process.env.__PORT || "3000"}`;
24
23
  }
24
+ /**
25
+ * Loopback names that are served over HTTP in local development.
26
+ * Includes bare `localhost` and any name ending in `.localhost` (RFC 6761 §6.3).
27
+ */
28
+ function isLoopbackHost(host) {
29
+ let hostname;
30
+ try {
31
+ hostname = new URL(`http://${host}`).hostname;
32
+ }
33
+ catch {
34
+ return false;
35
+ }
36
+ // Node's URL parser keeps the brackets on an IPv6 hostname (`[::1]`).
37
+ return (hostname === "localhost" ||
38
+ hostname.endsWith(".localhost") ||
39
+ hostname === "127.0.0.1" ||
40
+ hostname === "::1" ||
41
+ hostname === "[::1]");
42
+ }
25
43
  //# sourceMappingURL=requestOrigin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestOrigin.js","sourceRoot":"","sources":["../../src/server/requestOrigin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA2C;IAE3C,+EAA+E;IAC/E,0BAA0B;IAC1B,MAAM,QAAQ,GAAG,CAAC,KAAyB,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;IAC7E,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC3D,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,IAAI,OAAO,CAAC;QAC/D,OAAO,GAAG,KAAK,MAAM,aAAa,EAAE,CAAC;IACvC,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,KAAK,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACxE,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,OAAO,CAAC;QACZ,OAAO,GAAG,KAAK,MAAM,IAAI,EAAE,CAAC;IAC9B,CAAC;IACD,OAAO,oBAAoB,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,MAAM,EAAE,CAAC;AAC5D,CAAC","sourcesContent":["/**\n * Resolves this server's public origin from request headers, in precedence\n * `x-forwarded-host` → `host` → localhost dev fallback. Shared by view serving\n * and OAuth metadata so the two can't drift. `Origin` is deliberately ignored:\n * it carries the *caller's* site, not this server's.\n */\nexport function resolveServerOrigin(\n header: (key: string) => string | undefined,\n): string {\n // Proxies may send X-Forwarded-* as a comma-separated chain; the client-facing\n // hop is the first entry.\n const firstHop = (value: string | undefined) => value?.split(\",\")[0]?.trim();\n const forwardedHost = firstHop(header(\"x-forwarded-host\"));\n if (forwardedHost) {\n const proto = firstHop(header(\"x-forwarded-proto\")) || \"https\";\n return `${proto}://${forwardedHost}`;\n }\n const host = header(\"host\");\n if (host) {\n const proto = [\"127.0.0.1:\", \"localhost:\"].some((p) => host.startsWith(p))\n ? \"http\"\n : \"https\";\n return `${proto}://${host}`;\n }\n return `http://localhost:${process.env.__PORT || \"3000\"}`;\n}\n"]}
1
+ {"version":3,"file":"requestOrigin.js","sourceRoot":"","sources":["../../src/server/requestOrigin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA2C;IAE3C,+EAA+E;IAC/E,0BAA0B;IAC1B,MAAM,QAAQ,GAAG,CAAC,KAAyB,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;IAC7E,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC3D,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,KAAK,GACT,QAAQ,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;YACrC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACrD,OAAO,GAAG,KAAK,MAAM,aAAa,EAAE,CAAC;IACvC,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QACtD,OAAO,GAAG,KAAK,MAAM,IAAI,EAAE,CAAC;IAC9B,CAAC;IACD,OAAO,oBAAoB,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,MAAM,EAAE,CAAC;AAC5D,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,IAAY;IAClC,IAAI,QAAgB,CAAC;IACrB,IAAI,CAAC;QACH,QAAQ,GAAG,IAAI,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC;IAChD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IACD,sEAAsE;IACtE,OAAO,CACL,QAAQ,KAAK,WAAW;QACxB,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC;QAC/B,QAAQ,KAAK,WAAW;QACxB,QAAQ,KAAK,KAAK;QAClB,QAAQ,KAAK,OAAO,CACrB,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Resolves this server's public origin from request headers, in precedence\n * `x-forwarded-host` → `host` → localhost dev fallback. Shared by view serving\n * and OAuth metadata so the two can't drift. `Origin` is deliberately ignored:\n * it carries the *caller's* site, not this server's.\n */\nexport function resolveServerOrigin(\n header: (key: string) => string | undefined,\n): string {\n // Proxies may send X-Forwarded-* as a comma-separated chain; the client-facing\n // hop is the first entry.\n const firstHop = (value: string | undefined) => value?.split(\",\")[0]?.trim();\n const forwardedHost = firstHop(header(\"x-forwarded-host\"));\n if (forwardedHost) {\n const proto =\n firstHop(header(\"x-forwarded-proto\")) ||\n (isLoopbackHost(forwardedHost) ? \"http\" : \"https\");\n return `${proto}://${forwardedHost}`;\n }\n const host = header(\"host\");\n if (host) {\n const proto = isLoopbackHost(host) ? \"http\" : \"https\";\n return `${proto}://${host}`;\n }\n return `http://localhost:${process.env.__PORT || \"3000\"}`;\n}\n\n/**\n * Loopback names that are served over HTTP in local development.\n * Includes bare `localhost` and any name ending in `.localhost` (RFC 6761 §6.3).\n */\nfunction isLoopbackHost(host: string): boolean {\n let hostname: string;\n try {\n hostname = new URL(`http://${host}`).hostname;\n } catch {\n return false;\n }\n // Node's URL parser keeps the brackets on an IPv6 hostname (`[::1]`).\n return (\n hostname === \"localhost\" ||\n hostname.endsWith(\".localhost\") ||\n hostname === \"127.0.0.1\" ||\n hostname === \"::1\" ||\n hostname === \"[::1]\"\n );\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { resolveServerOrigin } from "./requestOrigin.js";
3
+ const headers = (map) => (key) => map[key];
4
+ describe("resolveServerOrigin", () => {
5
+ it("uses http for loopback hosts, including *.localhost", () => {
6
+ expect(resolveServerOrigin(headers({ host: "localhost:3000" }))).toBe("http://localhost:3000");
7
+ expect(resolveServerOrigin(headers({ host: "127.0.0.1:3000" }))).toBe("http://127.0.0.1:3000");
8
+ expect(resolveServerOrigin(headers({ host: "[::1]:3000" }))).toBe("http://[::1]:3000");
9
+ expect(resolveServerOrigin(headers({ host: "chift.localhost:4000" }))).toBe("http://chift.localhost:4000");
10
+ });
11
+ it("uses https for public hosts", () => {
12
+ expect(resolveServerOrigin(headers({ host: "app.example.com" }))).toBe("https://app.example.com");
13
+ expect(resolveServerOrigin(headers({ host: "localhost.example.com:3000" }))).toBe("https://localhost.example.com:3000");
14
+ });
15
+ it("defaults a forwarded loopback host to http when proto is absent", () => {
16
+ expect(resolveServerOrigin(headers({ "x-forwarded-host": "chift.localhost:4000" }))).toBe("http://chift.localhost:4000");
17
+ });
18
+ it("keeps an explicit forwarded proto", () => {
19
+ expect(resolveServerOrigin(headers({
20
+ "x-forwarded-host": "chift.localhost:4000",
21
+ "x-forwarded-proto": "https",
22
+ }))).toBe("https://chift.localhost:4000");
23
+ });
24
+ it("falls back to the local dev origin when no host is present", () => {
25
+ expect(resolveServerOrigin(headers({}))).toBe("http://localhost:3000");
26
+ });
27
+ });
28
+ //# sourceMappingURL=requestOrigin.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestOrigin.test.js","sourceRoot":"","sources":["../../src/server/requestOrigin.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,MAAM,OAAO,GACX,CAAC,GAA2B,EAAE,EAAE,CAChC,CAAC,GAAW,EAAsB,EAAE,CAClC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEb,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CACnE,uBAAuB,CACxB,CAAC;QACF,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CACnE,uBAAuB,CACxB,CAAC;QACF,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,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./requestOrigin.js\";\n\nconst headers =\n (map: Record<string, string>) =>\n (key: string): string | undefined =>\n map[key];\n\ndescribe(\"resolveServerOrigin\", () => {\n it(\"uses http for loopback hosts, including *.localhost\", () => {\n expect(resolveServerOrigin(headers({ host: \"localhost:3000\" }))).toBe(\n \"http://localhost:3000\",\n );\n expect(resolveServerOrigin(headers({ host: \"127.0.0.1:3000\" }))).toBe(\n \"http://127.0.0.1:3000\",\n );\n expect(resolveServerOrigin(headers({ host: \"[::1]:3000\" }))).toBe(\n \"http://[::1]:3000\",\n );\n expect(resolveServerOrigin(headers({ host: \"chift.localhost:4000\" }))).toBe(\n \"http://chift.localhost:4000\",\n );\n });\n\n it(\"uses https for public hosts\", () => {\n expect(resolveServerOrigin(headers({ host: \"app.example.com\" }))).toBe(\n \"https://app.example.com\",\n );\n expect(\n resolveServerOrigin(headers({ host: \"localhost.example.com:3000\" })),\n ).toBe(\"https://localhost.example.com:3000\");\n });\n\n it(\"defaults a forwarded loopback host to http when proto is absent\", () => {\n expect(\n resolveServerOrigin(\n headers({ \"x-forwarded-host\": \"chift.localhost:4000\" }),\n ),\n ).toBe(\"http://chift.localhost:4000\");\n });\n\n it(\"keeps an explicit forwarded proto\", () => {\n expect(\n resolveServerOrigin(\n headers({\n \"x-forwarded-host\": \"chift.localhost:4000\",\n \"x-forwarded-proto\": \"https\",\n }),\n ),\n ).toBe(\"https://chift.localhost:4000\");\n });\n\n it(\"falls back to the local dev origin when no host is present\", () => {\n expect(resolveServerOrigin(headers({}))).toBe(\"http://localhost:3000\");\n });\n});\n"]}
@@ -1,7 +1,6 @@
1
1
  import type { McpUiToolMeta } from "@modelcontextprotocol/ext-apps";
2
2
  import { type ContentBlock, type Icon, type Implementation, McpServer as McpServerBase, type RequestMeta, type ResourceLink, type ServerOptions, type ServerResult, type StandardSchemaV1, type StandardSchemaWithJSON, type ToolAnnotations } from "@modelcontextprotocol/server";
3
3
  import type express from "express";
4
- import { z } from "zod/v4";
5
4
  import type { ResourceMetadataUrlResolver } from "./auth/setup.js";
6
5
  import type { ExtraClaims } from "./auth.js";
7
6
  import type { McpExtra, McpExtraFor, McpMethodString, McpMiddlewareEntry, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard } from "./middleware.js";
@@ -265,22 +264,6 @@ type ToolAuthConfig = {
265
264
  securitySchemes?: SecurityScheme[];
266
265
  };
267
266
  type ToolConfig<TInput extends Record<string, StandardSchemaWithJSON> | StandardSchemaWithJSON> = ToolConfigBase<TInput> & ToolAuthConfig;
268
- declare const fileEntrypointInput: {
269
- file: z.ZodObject<{
270
- name: z.ZodString;
271
- resourceUri: z.ZodString;
272
- }, z.core.$strip>;
273
- };
274
- type FileEntrypointInput = typeof fileEntrypointInput;
275
- /** A ChatGPT file viewer, registered with `server.registerFileViewer`. */
276
- export type OpenAIFileViewerConfig<TName extends string = string> = Omit<ToolConfigBase<FileEntrypointInput>, "inputSchema" | "openai" | "view"> & ToolAuthConfig & {
277
- name: TName;
278
- /** File extensions the viewer opens, each starting with `.`. */
279
- extensions: string[];
280
- view: ViewConfig;
281
- /** Display modes. The file entrypoint is set from `extensions`. */
282
- openai?: Omit<OpenAIToolConfig, "entrypoints">;
283
- };
284
267
  /**
285
268
  * Optional client-supplied hints attached to `params._meta` on every tool call
286
269
  * by the ChatGPT host. Hints only: never use for authorization, and tolerate
@@ -486,30 +469,6 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
486
469
  file: string;
487
470
  }>): this;
488
471
  private readManifest;
489
- /**
490
- * Register a ChatGPT file viewer, from the OpenAI MCP extensions: a tool
491
- * with a file entrypoint for `extensions` and a view. ChatGPT desktop calls
492
- * it with the file the user opened, as `{ file: { name, resourceUri } }`.
493
- * Read and save the file from the view with `useFileResource`.
494
- *
495
- * @example
496
- * ```ts
497
- * server.registerFileViewer(
498
- * {
499
- * name: "part-viewer",
500
- * title: "Part Viewer",
501
- * extensions: [".stl", ".step"],
502
- * view: { component: "part-viewer" },
503
- * },
504
- * async ({ file }) => ({ structuredContent: { name: file.name } }),
505
- * );
506
- * ```
507
- *
508
- * @see https://docs.skybridge.tech/api-reference/register-file-viewer
509
- */
510
- registerFileViewer<TName extends string, TReturn extends {
511
- content?: HandlerContent;
512
- }>(config: OpenAIFileViewerConfig<TName>, cb: ToolHandler<FileEntrypointInput, TReturn, TAuthExtra>): AddTool<TTools, TName, FileEntrypointInput, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>, TAuthExtra>;
513
472
  /**
514
473
  * Register the composer at-mention search for ChatGPT, from the OpenAI MCP
515
474
  * extensions. When the user types `@` and your app name, ChatGPT calls
@@ -40,9 +40,6 @@ function normalizeForwardedPrefix(raw) {
40
40
  }
41
41
  return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
42
42
  }
43
- const fileEntrypointInput = {
44
- file: z.object({ name: z.string(), resourceUri: z.string() }),
45
- };
46
43
  /**
47
44
  * Drop the query string from a `ui://` view URI, leaving the bare path. The
48
45
  * `?v=` cache key is the only query we append, so a plain split is enough and
@@ -525,35 +522,6 @@ export class McpServer extends McpServerBaseOmitted {
525
522
  cachedDiskManifest ??= JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
526
523
  return cachedDiskManifest ?? {};
527
524
  }
528
- /**
529
- * Register a ChatGPT file viewer, from the OpenAI MCP extensions: a tool
530
- * with a file entrypoint for `extensions` and a view. ChatGPT desktop calls
531
- * it with the file the user opened, as `{ file: { name, resourceUri } }`.
532
- * Read and save the file from the view with `useFileResource`.
533
- *
534
- * @example
535
- * ```ts
536
- * server.registerFileViewer(
537
- * {
538
- * name: "part-viewer",
539
- * title: "Part Viewer",
540
- * extensions: [".stl", ".step"],
541
- * view: { component: "part-viewer" },
542
- * },
543
- * async ({ file }) => ({ structuredContent: { name: file.name } }),
544
- * );
545
- * ```
546
- *
547
- * @see https://docs.skybridge.tech/api-reference/register-file-viewer
548
- */
549
- registerFileViewer(config, cb) {
550
- const { extensions, openai, ...toolConfig } = config;
551
- return this.registerTool({
552
- ...toolConfig,
553
- inputSchema: fileEntrypointInput,
554
- openai: { ...openai, entrypoints: [{ type: "file", extensions }] },
555
- }, cb);
556
- }
557
525
  /**
558
526
  * Register the composer at-mention search for ChatGPT, from the OpenAI MCP
559
527
  * extensions. When the user types `@` and your app name, ChatGPT calls