mcp-use 1.2.2-canary.0 → 1.2.2-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-VPPILX7B.js → chunk-3RJENWH4.js} +15 -6
- package/dist/{chunk-UVUM35MV.js → chunk-7UX634PO.js} +307 -112
- package/dist/{chunk-CPV4QNHD.js → chunk-KLIBVJ3Z.js} +145 -79
- package/dist/{chunk-EYAIJPBH.js → chunk-MZLETWQQ.js} +55 -17
- package/dist/{chunk-C3SRZK7H.js → chunk-RSGKBEHH.js} +144 -72
- package/dist/index.cjs +719 -300
- package/dist/index.d.ts +24 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +86 -28
- package/dist/{langfuse-MO3AMDBE.js → langfuse-LCJ6VJEP.js} +2 -2
- package/dist/src/adapters/base.d.ts +2 -2
- package/dist/src/adapters/base.d.ts.map +1 -1
- package/dist/src/adapters/index.d.ts +2 -2
- package/dist/src/adapters/index.d.ts.map +1 -1
- package/dist/src/adapters/langchain_adapter.d.ts +4 -4
- package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
- package/dist/src/agents/base.d.ts +1 -1
- package/dist/src/agents/base.d.ts.map +1 -1
- package/dist/src/agents/index.d.ts +3 -3
- package/dist/src/agents/index.d.ts.map +1 -1
- package/dist/src/agents/mcp_agent.d.ts +12 -12
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/agents/prompts/system_prompt_builder.d.ts +2 -2
- package/dist/src/agents/prompts/system_prompt_builder.d.ts.map +1 -1
- package/dist/src/agents/prompts/templates.d.ts.map +1 -1
- package/dist/src/agents/remote.d.ts +2 -2
- package/dist/src/agents/remote.d.ts.map +1 -1
- package/dist/src/agents/types.d.ts +1 -1
- package/dist/src/agents/types.d.ts.map +1 -1
- package/dist/src/agents/utils/ai_sdk.d.ts +1 -1
- package/dist/src/agents/utils/ai_sdk.d.ts.map +1 -1
- package/dist/src/agents/utils/index.d.ts +1 -1
- package/dist/src/agents/utils/index.d.ts.map +1 -1
- package/dist/src/auth/browser-provider.d.ts +2 -2
- package/dist/src/auth/browser-provider.d.ts.map +1 -1
- package/dist/src/auth/callback.d.ts.map +1 -1
- package/dist/src/auth/index.d.ts +3 -3
- package/dist/src/auth/index.d.ts.map +1 -1
- package/dist/src/auth/types.d.ts +1 -1
- package/dist/src/auth/types.d.ts.map +1 -1
- package/dist/src/browser.cjs +508 -201
- package/dist/src/browser.d.ts +17 -17
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +11 -5
- package/dist/src/client/base.d.ts +2 -2
- package/dist/src/client/base.d.ts.map +1 -1
- package/dist/src/client/browser.d.ts +2 -2
- package/dist/src/client/browser.d.ts.map +1 -1
- package/dist/src/client.d.ts +2 -2
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/config.d.ts +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/connectors/base.d.ts +5 -5
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/connectors/http.d.ts +3 -3
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/connectors/index.d.ts +4 -4
- package/dist/src/connectors/index.d.ts.map +1 -1
- package/dist/src/connectors/stdio.d.ts +3 -3
- package/dist/src/connectors/stdio.d.ts.map +1 -1
- package/dist/src/connectors/websocket.d.ts +3 -3
- package/dist/src/connectors/websocket.d.ts.map +1 -1
- package/dist/src/logging.d.ts +4 -4
- package/dist/src/logging.d.ts.map +1 -1
- package/dist/src/managers/index.d.ts +2 -2
- package/dist/src/managers/index.d.ts.map +1 -1
- package/dist/src/managers/server_manager.d.ts +4 -4
- package/dist/src/managers/server_manager.d.ts.map +1 -1
- package/dist/src/managers/tools/acquire_active_mcp_server.d.ts +3 -3
- package/dist/src/managers/tools/acquire_active_mcp_server.d.ts.map +1 -1
- package/dist/src/managers/tools/add_server_from_config.d.ts +3 -3
- package/dist/src/managers/tools/add_server_from_config.d.ts.map +1 -1
- package/dist/src/managers/tools/base.d.ts +6 -6
- package/dist/src/managers/tools/base.d.ts.map +1 -1
- package/dist/src/managers/tools/connect_mcp_server.d.ts +4 -4
- package/dist/src/managers/tools/connect_mcp_server.d.ts.map +1 -1
- package/dist/src/managers/tools/index.d.ts +5 -5
- package/dist/src/managers/tools/index.d.ts.map +1 -1
- package/dist/src/managers/tools/list_mcp_servers.d.ts +3 -3
- package/dist/src/managers/tools/list_mcp_servers.d.ts.map +1 -1
- package/dist/src/managers/tools/release_mcp_server_connection.d.ts +3 -3
- package/dist/src/managers/tools/release_mcp_server_connection.d.ts.map +1 -1
- package/dist/src/managers/types.d.ts +3 -3
- package/dist/src/managers/types.d.ts.map +1 -1
- package/dist/src/oauth-helper.d.ts.map +1 -1
- package/dist/src/observability/index.d.ts +3 -3
- package/dist/src/observability/index.d.ts.map +1 -1
- package/dist/src/observability/langfuse.d.ts +1 -1
- package/dist/src/observability/langfuse.d.ts.map +1 -1
- package/dist/src/observability/manager.d.ts +1 -1
- package/dist/src/observability/manager.d.ts.map +1 -1
- package/dist/src/observability/types.d.ts +1 -1
- package/dist/src/observability/types.d.ts.map +1 -1
- package/dist/src/react/index.cjs +295 -154
- package/dist/src/react/index.d.ts +6 -6
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/index.js +3 -3
- package/dist/src/react/types.d.ts +6 -6
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/useMcp.d.ts +1 -1
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/react/useWidget.d.ts +5 -2
- package/dist/src/react/useWidget.d.ts.map +1 -1
- package/dist/src/react/widget-types.d.ts +3 -3
- package/dist/src/react/widget-types.d.ts.map +1 -1
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts +3 -3
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts.map +1 -1
- package/dist/src/server/index.cjs +170 -50
- package/dist/src/server/index.d.ts +4 -4
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +174 -51
- package/dist/src/server/logging.d.ts +1 -1
- package/dist/src/server/logging.d.ts.map +1 -1
- package/dist/src/server/mcp-server.d.ts +29 -29
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/types/common.d.ts +2 -2
- package/dist/src/server/types/common.d.ts.map +1 -1
- package/dist/src/server/types/index.d.ts +4 -4
- package/dist/src/server/types/index.d.ts.map +1 -1
- package/dist/src/server/types/prompt.d.ts +2 -2
- package/dist/src/server/types/prompt.d.ts.map +1 -1
- package/dist/src/server/types/resource.d.ts +24 -24
- package/dist/src/server/types/resource.d.ts.map +1 -1
- package/dist/src/server/types/tool.d.ts +3 -3
- package/dist/src/server/types/tool.d.ts.map +1 -1
- package/dist/src/server/types/widget.d.ts +1 -1
- package/dist/src/server/types.d.ts +1 -1
- package/dist/src/server/types.d.ts.map +1 -1
- package/dist/src/session.d.ts +1 -1
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/task_managers/base.d.ts.map +1 -1
- package/dist/src/task_managers/index.d.ts +5 -5
- package/dist/src/task_managers/index.d.ts.map +1 -1
- package/dist/src/task_managers/sse.d.ts +3 -3
- package/dist/src/task_managers/sse.d.ts.map +1 -1
- package/dist/src/task_managers/stdio.d.ts +4 -4
- package/dist/src/task_managers/stdio.d.ts.map +1 -1
- package/dist/src/task_managers/streamable_http.d.ts +3 -3
- package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
- package/dist/src/task_managers/websocket.d.ts +2 -2
- package/dist/src/task_managers/websocket.d.ts.map +1 -1
- package/dist/src/telemetry/events.d.ts.map +1 -1
- package/dist/src/telemetry/index.d.ts +4 -4
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/src/telemetry/telemetry.d.ts +1 -1
- package/dist/src/telemetry/telemetry.d.ts.map +1 -1
- package/dist/src/telemetry/utils.d.ts +1 -1
- package/dist/src/telemetry/utils.d.ts.map +1 -1
- package/dist/tsup.config.d.ts.map +1 -1
- package/dist/vitest.config.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Entry point for the React integration.
|
|
3
3
|
* Provides the useMcp hook and related types.
|
|
4
4
|
*/
|
|
5
|
-
export { useMcp } from
|
|
6
|
-
export type { UseMcpOptions, UseMcpResult } from
|
|
7
|
-
export { onMcpAuthorization } from
|
|
8
|
-
export type { Tool, Resource, ResourceTemplate, Prompt } from
|
|
9
|
-
export { useWidget, useWidgetProps, useWidgetTheme, useWidgetState } from
|
|
10
|
-
export type { UseWidgetResult, OpenAiGlobals, API, Theme, DisplayMode, DeviceType, SafeArea, SafeAreaInsets, UserAgent, CallToolResponse, UnknownObject, } from
|
|
5
|
+
export { useMcp } from "./useMcp.js";
|
|
6
|
+
export type { UseMcpOptions, UseMcpResult } from "./types.js";
|
|
7
|
+
export { onMcpAuthorization } from "../auth/callback.js";
|
|
8
|
+
export type { Tool, Resource, ResourceTemplate, Prompt, } from "@modelcontextprotocol/sdk/types.js";
|
|
9
|
+
export { useWidget, useWidgetProps, useWidgetTheme, useWidgetState, } from "./useWidget.js";
|
|
10
|
+
export type { UseWidgetResult, OpenAiGlobals, API, Theme, DisplayMode, DeviceType, SafeArea, SafeAreaInsets, UserAgent, CallToolResponse, UnknownObject, } from "./widget-types.js";
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGzD,YAAY,EACV,IAAI,EACJ,QAAQ,EACR,gBAAgB,EAChB,MAAM,GACP,MAAM,oCAAoC,CAAC;AAG5C,OAAO,EACL,SAAS,EACT,cAAc,EACd,cAAc,EACd,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,eAAe,EACf,aAAa,EACb,GAAG,EACH,KAAK,EACL,WAAW,EACX,UAAU,EACV,QAAQ,EACR,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,aAAa,GACd,MAAM,mBAAmB,CAAC"}
|
package/dist/src/react/index.js
CHANGED
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
useWidgetProps,
|
|
5
5
|
useWidgetState,
|
|
6
6
|
useWidgetTheme
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-KLIBVJ3Z.js";
|
|
8
8
|
import {
|
|
9
9
|
onMcpAuthorization
|
|
10
|
-
} from "../../chunk-
|
|
11
|
-
import "../../chunk-
|
|
10
|
+
} from "../../chunk-RSGKBEHH.js";
|
|
11
|
+
import "../../chunk-3RJENWH4.js";
|
|
12
12
|
import "../../chunk-SHUYVCID.js";
|
|
13
13
|
export {
|
|
14
14
|
onMcpAuthorization,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Prompt, Resource, ResourceTemplate, Tool } from
|
|
2
|
-
import type { BrowserMCPClient } from
|
|
1
|
+
import type { Prompt, Resource, ResourceTemplate, Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import type { BrowserMCPClient } from "../client/browser.js";
|
|
3
3
|
export type UseMcpOptions = {
|
|
4
4
|
/** The /sse URL of your remote MCP server */
|
|
5
5
|
url?: string;
|
|
@@ -29,7 +29,7 @@ export type UseMcpOptions = {
|
|
|
29
29
|
/** Popup window features string (dimensions and behavior) for OAuth */
|
|
30
30
|
popupFeatures?: string;
|
|
31
31
|
/** Transport type preference: 'auto' (HTTP with SSE fallback), 'http' (HTTP only), 'sse' (SSE only) */
|
|
32
|
-
transportType?:
|
|
32
|
+
transportType?: "auto" | "http" | "sse";
|
|
33
33
|
/** Prevent automatic authentication popup on initial connection (default: false) */
|
|
34
34
|
preventAutoAuth?: boolean;
|
|
35
35
|
/**
|
|
@@ -62,7 +62,7 @@ export type UseMcpResult = {
|
|
|
62
62
|
* - 'ready': Connected and ready for tool calls.
|
|
63
63
|
* - 'failed': Connection or authentication failed. Check the `error` property.
|
|
64
64
|
*/
|
|
65
|
-
state:
|
|
65
|
+
state: "discovering" | "pending_auth" | "authenticating" | "connecting" | "loading" | "ready" | "failed";
|
|
66
66
|
/** If the state is 'failed', this provides the error message */
|
|
67
67
|
error?: string;
|
|
68
68
|
/**
|
|
@@ -72,7 +72,7 @@ export type UseMcpResult = {
|
|
|
72
72
|
authUrl?: string;
|
|
73
73
|
/** Array of internal log messages (useful for debugging) */
|
|
74
74
|
log: {
|
|
75
|
-
level:
|
|
75
|
+
level: "debug" | "info" | "warn" | "error";
|
|
76
76
|
message: string;
|
|
77
77
|
timestamp: number;
|
|
78
78
|
}[];
|
|
@@ -119,7 +119,7 @@ export type UseMcpResult = {
|
|
|
119
119
|
*/
|
|
120
120
|
getPrompt: (name: string, args?: Record<string, string>) => Promise<{
|
|
121
121
|
messages: Array<{
|
|
122
|
-
role:
|
|
122
|
+
role: "user" | "assistant";
|
|
123
123
|
content: {
|
|
124
124
|
type: string;
|
|
125
125
|
text?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/react/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/react/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,IAAI,EACL,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,C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CAAC,MAAM,EAAE,MAAM,CAAC,KAC1B,OAAO,CAAC;QACX,QAAQ,EAAE,KAAK,CAAC;YACd,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;YAC3B,OAAO,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAC;gBAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;aAAE,CAAC;SAC9D,CAAC,CAAC;KACJ,CAAC,CAAC;IACH,+DAA+D;IAC/D,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,kDAAkD;IAClD,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB;;;;;OAKG;IACH,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,+GAA+G;IAC/G,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMcp.d.ts","sourceRoot":"","sources":["../../../src/react/useMcp.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAS9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"useMcp.d.ts","sourceRoot":"","sources":["../../../src/react/useMcp.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAS9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CA+yB3D"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* React hook for OpenAI Apps SDK widget development
|
|
3
3
|
* Wraps window.openai API and adapts MCP UI props to toolInput
|
|
4
4
|
*/
|
|
5
|
-
import type { Theme, UnknownObject, UseWidgetResult } from
|
|
5
|
+
import type { Theme, UnknownObject, UseWidgetResult } from "./widget-types.js";
|
|
6
6
|
/**
|
|
7
7
|
* React hook for building OpenAI Apps SDK widgets with MCP-use
|
|
8
8
|
*
|
|
@@ -50,5 +50,8 @@ export declare function useWidgetTheme(): Theme;
|
|
|
50
50
|
* const [favorites, setFavorites] = useWidgetState<string[]>([]);
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
|
-
export declare function useWidgetState<TState extends UnknownObject>(defaultState?: TState): readonly [
|
|
53
|
+
export declare function useWidgetState<TState extends UnknownObject>(defaultState?: TState): readonly [
|
|
54
|
+
TState | null,
|
|
55
|
+
(state: TState | ((prev: TState | null) => TState)) => Promise<void>
|
|
56
|
+
];
|
|
54
57
|
//# sourceMappingURL=useWidget.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWidget.d.ts","sourceRoot":"","sources":["../../../src/react/useWidget.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"useWidget.d.ts","sourceRoot":"","sources":["../../../src/react/useWidget.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,KAAK,EAKV,KAAK,EACL,aAAa,EAEb,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAsC3B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,SAAS,CACvB,MAAM,SAAS,aAAa,GAAG,aAAa,EAC5C,OAAO,SAAS,aAAa,GAAG,aAAa,EAC7C,SAAS,SAAS,aAAa,GAAG,aAAa,EAC/C,MAAM,SAAS,aAAa,GAAG,aAAa,EAC5C,YAAY,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAuJ5E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa,EACzE,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAGR;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,IAAI,KAAK,CAGtC;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,SAAS,aAAa,EACzD,YAAY,CAAC,EAAE,MAAM,GACpB,SAAS;IACV,MAAM,GAAG,IAAI;IACb,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC;CACrE,CAoBA"}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Based on: https://developers.openai.com/apps-sdk/build/custom-ux
|
|
4
4
|
*/
|
|
5
5
|
export type UnknownObject = Record<string, unknown>;
|
|
6
|
-
export type Theme =
|
|
7
|
-
export type DisplayMode =
|
|
8
|
-
export type DeviceType =
|
|
6
|
+
export type Theme = "light" | "dark";
|
|
7
|
+
export type DisplayMode = "pip" | "inline" | "fullscreen";
|
|
8
|
+
export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
|
|
9
9
|
export type SafeAreaInsets = {
|
|
10
10
|
top: number;
|
|
11
11
|
bottom: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-types.d.ts","sourceRoot":"","sources":["../../../src/react/widget-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"widget-types.d.ts","sourceRoot":"","sources":["../../../src/react/widget-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG,KAAK,GA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CAAA;KAAE,CAAC,CAAC;IAE1E,0CAA0C;IAC1C,WAAW,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* Apps SDK: https://mcpui.dev/guide/apps-sdk
|
|
9
9
|
* Official Apps SDK Docs: https://developers.openai.com/apps-sdk/build/mcp-server
|
|
10
10
|
*/
|
|
11
|
-
import { type AdaptersConfig } from
|
|
12
|
-
import type { UIResourceContent, UIResourceDefinition, UIEncoding, AppsSdkMetadata } from
|
|
11
|
+
import { type AdaptersConfig } from "@mcp-ui/server";
|
|
12
|
+
import type { UIResourceContent, UIResourceDefinition, UIEncoding, AppsSdkMetadata } from "../types/resource.js";
|
|
13
13
|
/**
|
|
14
14
|
* Configuration for building widget URLs
|
|
15
15
|
*/
|
|
@@ -59,7 +59,7 @@ export declare function createRawHtmlResource(uri: string, htmlString: string, e
|
|
|
59
59
|
* @param metadata - Additional metadata for the resource
|
|
60
60
|
* @returns UIResourceContent object
|
|
61
61
|
*/
|
|
62
|
-
export declare function createRemoteDomResource(uri: string, script: string, framework?:
|
|
62
|
+
export declare function createRemoteDomResource(uri: string, script: string, framework?: "react" | "webcomponents", encoding?: UIEncoding, adapters?: AdaptersConfig, metadata?: AppsSdkMetadata): UIResourceContent;
|
|
63
63
|
/**
|
|
64
64
|
* Create a UIResource for OpenAI Apps SDK
|
|
65
65
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-ui-adapter.d.ts","sourceRoot":"","sources":["../../../../src/server/adapters/mcp-ui-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"mcp-ui-adapter.d.ts","sourceRoot":"","sources":["../../../../src/server/adapters/mcp-ui-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,gBAAg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ACH,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,oBAAoB,EAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,MAAM,EAAE,SAAS,GAChB,iBAAiB,CAwDnB"}
|
|
@@ -221,11 +221,21 @@ var McpServer = class {
|
|
|
221
221
|
});
|
|
222
222
|
this.app = (0, import_express.default)();
|
|
223
223
|
this.app.use(import_express.default.json());
|
|
224
|
-
this.app.use(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
224
|
+
this.app.use(
|
|
225
|
+
(0, import_cors.default)({
|
|
226
|
+
origin: "*",
|
|
227
|
+
methods: ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
228
|
+
allowedHeaders: [
|
|
229
|
+
"Content-Type",
|
|
230
|
+
"Accept",
|
|
231
|
+
"Authorization",
|
|
232
|
+
"mcp-protocol-version",
|
|
233
|
+
"mcp-session-id",
|
|
234
|
+
"X-Proxy-Token",
|
|
235
|
+
"X-Target-URL"
|
|
236
|
+
]
|
|
237
|
+
})
|
|
238
|
+
);
|
|
229
239
|
this.app.use(requestLogger);
|
|
230
240
|
return new Proxy(this, {
|
|
231
241
|
get(target, prop) {
|
|
@@ -498,7 +508,7 @@ var McpServer = class {
|
|
|
498
508
|
* ```typescript
|
|
499
509
|
* // Simple usage - auto-loads from generated schema
|
|
500
510
|
* server.uiResource('display-weather')
|
|
501
|
-
*
|
|
511
|
+
*
|
|
502
512
|
* // Legacy MCP-UI widget
|
|
503
513
|
* server.uiResource({
|
|
504
514
|
* type: 'externalUrl',
|
|
@@ -559,7 +569,9 @@ var McpServer = class {
|
|
|
559
569
|
mimeType = "text/html+skybridge";
|
|
560
570
|
break;
|
|
561
571
|
default:
|
|
562
|
-
throw new Error(
|
|
572
|
+
throw new Error(
|
|
573
|
+
`Unsupported UI resource type. Must be one of: externalUrl, rawHtml, remoteDom, appsSdk`
|
|
574
|
+
);
|
|
563
575
|
}
|
|
564
576
|
this.resource({
|
|
565
577
|
name: definition.name,
|
|
@@ -624,7 +636,10 @@ var McpServer = class {
|
|
|
624
636
|
if (definition.type === "appsSdk") {
|
|
625
637
|
const randomId = Math.random().toString(36).substring(2, 15);
|
|
626
638
|
const uniqueUri = `ui://widget/${definition.name}-${randomId}.html`;
|
|
627
|
-
const uniqueToolMetadata = {
|
|
639
|
+
const uniqueToolMetadata = {
|
|
640
|
+
...toolMetadata,
|
|
641
|
+
"openai/outputTemplate": uniqueUri
|
|
642
|
+
};
|
|
628
643
|
return {
|
|
629
644
|
_meta: uniqueToolMetadata,
|
|
630
645
|
content: [
|
|
@@ -752,7 +767,7 @@ var McpServer = class {
|
|
|
752
767
|
}
|
|
753
768
|
/**
|
|
754
769
|
* Check if server is running in production mode
|
|
755
|
-
*
|
|
770
|
+
*
|
|
756
771
|
* @private
|
|
757
772
|
* @returns true if in production mode, false otherwise
|
|
758
773
|
*/
|
|
@@ -761,13 +776,17 @@ var McpServer = class {
|
|
|
761
776
|
}
|
|
762
777
|
/**
|
|
763
778
|
* Read build manifest file
|
|
764
|
-
*
|
|
779
|
+
*
|
|
765
780
|
* @private
|
|
766
781
|
* @returns Build manifest or null if not found
|
|
767
782
|
*/
|
|
768
783
|
readBuildManifest() {
|
|
769
784
|
try {
|
|
770
|
-
const manifestPath = (0, import_node_path.join)(
|
|
785
|
+
const manifestPath = (0, import_node_path.join)(
|
|
786
|
+
process.cwd(),
|
|
787
|
+
"dist",
|
|
788
|
+
".mcp-use-manifest.json"
|
|
789
|
+
);
|
|
771
790
|
const content = (0, import_node_fs2.readFileSync)(manifestPath, "utf8");
|
|
772
791
|
return JSON.parse(content);
|
|
773
792
|
} catch {
|
|
@@ -813,7 +832,9 @@ var McpServer = class {
|
|
|
813
832
|
try {
|
|
814
833
|
await fs.access(srcDir);
|
|
815
834
|
} catch (error) {
|
|
816
|
-
console.log(
|
|
835
|
+
console.log(
|
|
836
|
+
`[WIDGETS] No ${resourcesDir}/ directory found - skipping widget serving`
|
|
837
|
+
);
|
|
817
838
|
return;
|
|
818
839
|
}
|
|
819
840
|
let entries = [];
|
|
@@ -848,7 +869,10 @@ var McpServer = class {
|
|
|
848
869
|
await fs.mkdir(widgetTempDir, { recursive: true });
|
|
849
870
|
const resourcesPath = (0, import_node_path.join)(process.cwd(), resourcesDir);
|
|
850
871
|
const { relative } = await import("path");
|
|
851
|
-
const relativeResourcesPath = relative(
|
|
872
|
+
const relativeResourcesPath = relative(
|
|
873
|
+
widgetTempDir,
|
|
874
|
+
resourcesPath
|
|
875
|
+
).replace(/\\/g, "/");
|
|
852
876
|
const cssContent = `@import "tailwindcss";
|
|
853
877
|
|
|
854
878
|
/* Configure Tailwind to scan the resources directory */
|
|
@@ -878,11 +902,21 @@ if (container && Component) {
|
|
|
878
902
|
<script type="module" src="${baseRoute}/${widget.name}/entry.tsx"></script>
|
|
879
903
|
</body>
|
|
880
904
|
</html>`;
|
|
881
|
-
await fs.writeFile(
|
|
882
|
-
|
|
905
|
+
await fs.writeFile(
|
|
906
|
+
(0, import_node_path.join)(widgetTempDir, "entry.tsx"),
|
|
907
|
+
entryContent,
|
|
908
|
+
"utf8"
|
|
909
|
+
);
|
|
910
|
+
await fs.writeFile(
|
|
911
|
+
(0, import_node_path.join)(widgetTempDir, "index.html"),
|
|
912
|
+
htmlContent,
|
|
913
|
+
"utf8"
|
|
914
|
+
);
|
|
883
915
|
}
|
|
884
916
|
const serverOrigin = this.serverBaseUrl || `http://${this.serverHost}:${this.serverPort}`;
|
|
885
|
-
console.log(
|
|
917
|
+
console.log(
|
|
918
|
+
`[WIDGETS] Serving ${entries.length} widget(s) with shared Vite dev server and HMR`
|
|
919
|
+
);
|
|
886
920
|
const viteServer = await (0, import_vite.createServer)({
|
|
887
921
|
root: tempDir,
|
|
888
922
|
base: baseRoute + "/",
|
|
@@ -914,7 +948,9 @@ if (container && Component) {
|
|
|
914
948
|
});
|
|
915
949
|
this.app.use(baseRoute, viteServer.middlewares);
|
|
916
950
|
widgets.forEach((widget) => {
|
|
917
|
-
console.log(
|
|
951
|
+
console.log(
|
|
952
|
+
`[WIDGET] ${widget.name} mounted at ${baseRoute}/${widget.name}`
|
|
953
|
+
);
|
|
918
954
|
});
|
|
919
955
|
for (const widget of widgets) {
|
|
920
956
|
const type = "appsSdk";
|
|
@@ -930,12 +966,18 @@ if (container && Component) {
|
|
|
930
966
|
try {
|
|
931
967
|
props = metadata.inputs.shape || {};
|
|
932
968
|
} catch (error) {
|
|
933
|
-
console.warn(
|
|
969
|
+
console.warn(
|
|
970
|
+
`[WIDGET] Failed to extract props schema for ${widget.name}:`,
|
|
971
|
+
error
|
|
972
|
+
);
|
|
934
973
|
}
|
|
935
974
|
}
|
|
936
975
|
}
|
|
937
976
|
} catch (error) {
|
|
938
|
-
console.warn(
|
|
977
|
+
console.warn(
|
|
978
|
+
`[WIDGET] Failed to load metadata for ${widget.name}:`,
|
|
979
|
+
error
|
|
980
|
+
);
|
|
939
981
|
}
|
|
940
982
|
console.log("[WIDGET dev] Metadata:", metadata);
|
|
941
983
|
let html = "";
|
|
@@ -948,22 +990,40 @@ if (container && Component) {
|
|
|
948
990
|
if (baseTagRegex.test(htmlWithoutComments)) {
|
|
949
991
|
const actualBaseTagMatch = html.match(/<base\s+[^>]*\/?>/i);
|
|
950
992
|
if (actualBaseTagMatch) {
|
|
951
|
-
html = html.replace(
|
|
993
|
+
html = html.replace(
|
|
994
|
+
actualBaseTagMatch[0],
|
|
995
|
+
`<base href="${mcpUrl}" />`
|
|
996
|
+
);
|
|
952
997
|
}
|
|
953
998
|
} else {
|
|
954
999
|
const headTagRegex = /<head[^>]*>/i;
|
|
955
1000
|
if (headTagRegex.test(html)) {
|
|
956
|
-
html = html.replace(
|
|
957
|
-
|
|
1001
|
+
html = html.replace(
|
|
1002
|
+
headTagRegex,
|
|
1003
|
+
(match) => `${match}
|
|
1004
|
+
<base href="${mcpUrl}" />`
|
|
1005
|
+
);
|
|
958
1006
|
}
|
|
959
1007
|
}
|
|
960
1008
|
}
|
|
961
|
-
html = html.replace(
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1009
|
+
html = html.replace(
|
|
1010
|
+
/src="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
1011
|
+
`src="${this.serverBaseUrl}/mcp-use/widgets/$1"`
|
|
1012
|
+
);
|
|
1013
|
+
html = html.replace(
|
|
1014
|
+
/href="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
1015
|
+
`href="${this.serverBaseUrl}/mcp-use/widgets/$1"`
|
|
1016
|
+
);
|
|
1017
|
+
html = html.replace(
|
|
1018
|
+
/<head[^>]*>/i,
|
|
1019
|
+
`<head>
|
|
1020
|
+
<script>window.__getFile = (filename) => { return "${this.serverBaseUrl}/mcp-use/widgets/${widget.name}/"+filename }</script>`
|
|
1021
|
+
);
|
|
965
1022
|
} catch (error) {
|
|
966
|
-
console.error(
|
|
1023
|
+
console.error(
|
|
1024
|
+
`Failed to read html template for widget ${widget.name}`,
|
|
1025
|
+
error
|
|
1026
|
+
);
|
|
967
1027
|
}
|
|
968
1028
|
this.uiResource({
|
|
969
1029
|
name: widget.name,
|
|
@@ -1025,7 +1085,9 @@ if (container && Component) {
|
|
|
1025
1085
|
const baseRoute = options?.baseRoute || "/mcp-use/widgets";
|
|
1026
1086
|
const widgetsDir = (0, import_node_path.join)(process.cwd(), "dist", "resources", "widgets");
|
|
1027
1087
|
if (!(0, import_node_fs.existsSync)(widgetsDir)) {
|
|
1028
|
-
console.log(
|
|
1088
|
+
console.log(
|
|
1089
|
+
"[WIDGETS] No dist/resources/widgets/ directory found - skipping widget serving"
|
|
1090
|
+
);
|
|
1029
1091
|
return;
|
|
1030
1092
|
}
|
|
1031
1093
|
this.setupWidgetRoutes();
|
|
@@ -1035,10 +1097,14 @@ if (container && Component) {
|
|
|
1035
1097
|
return (0, import_node_fs.existsSync)(indexPath);
|
|
1036
1098
|
});
|
|
1037
1099
|
if (widgets.length === 0) {
|
|
1038
|
-
console.log(
|
|
1100
|
+
console.log(
|
|
1101
|
+
"[WIDGETS] No built widgets found in dist/resources/widgets/"
|
|
1102
|
+
);
|
|
1039
1103
|
return;
|
|
1040
1104
|
}
|
|
1041
|
-
console.log(
|
|
1105
|
+
console.log(
|
|
1106
|
+
`[WIDGETS] Serving ${widgets.length} pre-built widget(s) from dist/resources/widgets/`
|
|
1107
|
+
);
|
|
1042
1108
|
for (const widgetName of widgets) {
|
|
1043
1109
|
const widgetPath = (0, import_node_path.join)(widgetsDir, widgetName);
|
|
1044
1110
|
const indexPath = (0, import_node_path.join)(widgetPath, "index.html");
|
|
@@ -1053,22 +1119,40 @@ if (container && Component) {
|
|
|
1053
1119
|
if (baseTagRegex.test(htmlWithoutComments)) {
|
|
1054
1120
|
const actualBaseTagMatch = html.match(/<base\s+[^>]*\/?>/i);
|
|
1055
1121
|
if (actualBaseTagMatch) {
|
|
1056
|
-
html = html.replace(
|
|
1122
|
+
html = html.replace(
|
|
1123
|
+
actualBaseTagMatch[0],
|
|
1124
|
+
`<base href="${mcpUrl}" />`
|
|
1125
|
+
);
|
|
1057
1126
|
}
|
|
1058
1127
|
} else {
|
|
1059
1128
|
const headTagRegex = /<head[^>]*>/i;
|
|
1060
1129
|
if (headTagRegex.test(html)) {
|
|
1061
|
-
html = html.replace(
|
|
1062
|
-
|
|
1130
|
+
html = html.replace(
|
|
1131
|
+
headTagRegex,
|
|
1132
|
+
(match) => `${match}
|
|
1133
|
+
<base href="${mcpUrl}" />`
|
|
1134
|
+
);
|
|
1063
1135
|
}
|
|
1064
1136
|
}
|
|
1065
|
-
html = html.replace(
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1137
|
+
html = html.replace(
|
|
1138
|
+
/src="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
1139
|
+
`src="${this.serverBaseUrl}/mcp-use/widgets/$1"`
|
|
1140
|
+
);
|
|
1141
|
+
html = html.replace(
|
|
1142
|
+
/href="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
1143
|
+
`href="${this.serverBaseUrl}/mcp-use/widgets/$1"`
|
|
1144
|
+
);
|
|
1145
|
+
html = html.replace(
|
|
1146
|
+
/<head[^>]*>/i,
|
|
1147
|
+
`<head>
|
|
1148
|
+
<script>window.__getFile = (filename) => { return "${this.serverBaseUrl}/mcp-use/widgets/${widgetName}/"+filename }</script>`
|
|
1149
|
+
);
|
|
1069
1150
|
}
|
|
1070
1151
|
} catch (error) {
|
|
1071
|
-
console.error(
|
|
1152
|
+
console.error(
|
|
1153
|
+
`[WIDGET] Failed to read ${widgetName}/index.html:`,
|
|
1154
|
+
error
|
|
1155
|
+
);
|
|
1072
1156
|
continue;
|
|
1073
1157
|
}
|
|
1074
1158
|
let metadata = {};
|
|
@@ -1084,7 +1168,9 @@ if (container && Component) {
|
|
|
1084
1168
|
props = metadata.inputs;
|
|
1085
1169
|
}
|
|
1086
1170
|
} catch (error) {
|
|
1087
|
-
console.log(
|
|
1171
|
+
console.log(
|
|
1172
|
+
`[WIDGET] No metadata found for ${widgetName}, using defaults`
|
|
1173
|
+
);
|
|
1088
1174
|
}
|
|
1089
1175
|
this.uiResource({
|
|
1090
1176
|
name: widgetName,
|
|
@@ -1127,7 +1213,9 @@ if (container && Component) {
|
|
|
1127
1213
|
}
|
|
1128
1214
|
}
|
|
1129
1215
|
});
|
|
1130
|
-
console.log(
|
|
1216
|
+
console.log(
|
|
1217
|
+
`[WIDGET] ${widgetName} mounted at ${baseRoute}/${widgetName}`
|
|
1218
|
+
);
|
|
1131
1219
|
}
|
|
1132
1220
|
}
|
|
1133
1221
|
/**
|
|
@@ -1223,8 +1311,12 @@ if (container && Component) {
|
|
|
1223
1311
|
await this.mountMcp();
|
|
1224
1312
|
this.mountInspector();
|
|
1225
1313
|
this.app.listen(this.serverPort, () => {
|
|
1226
|
-
console.log(
|
|
1227
|
-
|
|
1314
|
+
console.log(
|
|
1315
|
+
`[SERVER] Listening on http://${this.serverHost}:${this.serverPort}`
|
|
1316
|
+
);
|
|
1317
|
+
console.log(
|
|
1318
|
+
`[MCP] Endpoints: http://${this.serverHost}:${this.serverPort}/mcp`
|
|
1319
|
+
);
|
|
1228
1320
|
});
|
|
1229
1321
|
}
|
|
1230
1322
|
/**
|
|
@@ -1254,14 +1346,18 @@ if (container && Component) {
|
|
|
1254
1346
|
if (this.isProductionMode()) {
|
|
1255
1347
|
const manifest = this.readBuildManifest();
|
|
1256
1348
|
if (!manifest?.includeInspector) {
|
|
1257
|
-
console.log(
|
|
1349
|
+
console.log(
|
|
1350
|
+
"[INSPECTOR] Skipped in production (use --with-inspector flag during build)"
|
|
1351
|
+
);
|
|
1258
1352
|
return;
|
|
1259
1353
|
}
|
|
1260
1354
|
}
|
|
1261
1355
|
import("@mcp-use/inspector").then(({ mountInspector }) => {
|
|
1262
1356
|
mountInspector(this.app);
|
|
1263
1357
|
this.inspectorMounted = true;
|
|
1264
|
-
console.log(
|
|
1358
|
+
console.log(
|
|
1359
|
+
`[INSPECTOR] UI available at http://${this.serverHost}:${this.serverPort}/inspector`
|
|
1360
|
+
);
|
|
1265
1361
|
}).catch(() => {
|
|
1266
1362
|
});
|
|
1267
1363
|
}
|
|
@@ -1290,7 +1386,15 @@ if (container && Component) {
|
|
|
1290
1386
|
this.app.get("/mcp-use/widgets/:widget/assets/*", (req, res, next) => {
|
|
1291
1387
|
const widget = req.params.widget;
|
|
1292
1388
|
const assetFile = req.params[0];
|
|
1293
|
-
const assetPath = (0, import_node_path.join)(
|
|
1389
|
+
const assetPath = (0, import_node_path.join)(
|
|
1390
|
+
process.cwd(),
|
|
1391
|
+
"dist",
|
|
1392
|
+
"resources",
|
|
1393
|
+
"widgets",
|
|
1394
|
+
widget,
|
|
1395
|
+
"assets",
|
|
1396
|
+
assetFile
|
|
1397
|
+
);
|
|
1294
1398
|
res.sendFile(assetPath, (err) => err ? next() : void 0);
|
|
1295
1399
|
});
|
|
1296
1400
|
this.app.get("/mcp-use/widgets/assets/*", (req, res, next) => {
|
|
@@ -1310,12 +1414,28 @@ if (container && Component) {
|
|
|
1310
1414
|
}
|
|
1311
1415
|
});
|
|
1312
1416
|
this.app.get("/mcp-use/widgets/:widget", (req, res, next) => {
|
|
1313
|
-
const filePath = (0, import_node_path.join)(
|
|
1417
|
+
const filePath = (0, import_node_path.join)(
|
|
1418
|
+
process.cwd(),
|
|
1419
|
+
"dist",
|
|
1420
|
+
"resources",
|
|
1421
|
+
"widgets",
|
|
1422
|
+
req.params.widget,
|
|
1423
|
+
"index.html"
|
|
1424
|
+
);
|
|
1314
1425
|
let html = (0, import_node_fs2.readFileSync)(filePath, "utf8");
|
|
1315
|
-
html = html.replace(
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1426
|
+
html = html.replace(
|
|
1427
|
+
/src="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
1428
|
+
`src="${this.serverBaseUrl}/mcp-use/widgets/$1"`
|
|
1429
|
+
);
|
|
1430
|
+
html = html.replace(
|
|
1431
|
+
/href="\/mcp-use\/widgets\/([^"]+)"/g,
|
|
1432
|
+
`href="${this.serverBaseUrl}/mcp-use/widgets/$1"`
|
|
1433
|
+
);
|
|
1434
|
+
html = html.replace(
|
|
1435
|
+
/<head[^>]*>/i,
|
|
1436
|
+
`<head>
|
|
1437
|
+
<script>window.__getFile = (filename) => { return "${this.serverBaseUrl}/mcp-use/widgets/${req.params.widget}/"+filename }</script>`
|
|
1438
|
+
);
|
|
1319
1439
|
res.send(html);
|
|
1320
1440
|
});
|
|
1321
1441
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { createMCPServer, type McpServerInstance } from
|
|
2
|
-
export * from
|
|
3
|
-
export { buildWidgetUrl, createExternalUrlResource, createRawHtmlResource, createRemoteDomResource, createUIResourceFromDefinition, type UrlConfig } from
|
|
4
|
-
export type { InputDefinition, PromptDefinition, PromptCallback, ResourceDefinition, ReadResourceCallback, ReadResourceTemplateCallback, ServerConfig, ToolDefinition, ToolCallback, UIResourceDefinition, ExternalUrlUIResource, RawHtmlUIResource, RemoteDomUIResource, WidgetProps, WidgetConfig, WidgetManifest, DiscoverWidgetsOptions, } from
|
|
1
|
+
export { createMCPServer, type McpServerInstance } from "./mcp-server.js";
|
|
2
|
+
export * from "./types/index.js";
|
|
3
|
+
export { buildWidgetUrl, createExternalUrlResource, createRawHtmlResource, createRemoteDomResource, createUIResourceFromDefinition, type UrlConfig, } from "./adapters/mcp-ui-adapter.js";
|
|
4
|
+
export type { InputDefinition, PromptDefinition, PromptCallback, ResourceDefinition, ReadResourceCallback, ReadResourceTemplateCallback, ServerConfig, ToolDefinition, ToolCallback, UIResourceDefinition, ExternalUrlUIResource, RawHtmlUIResource, RemoteDomUIResource, WidgetProps, WidgetConfig, WidgetManifest, DiscoverWidgetsOptions, } from "./types/index.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,qBAAqB,EACrB,uBAAuB,EACvB,8BAA8B,EAC9B,KAAK,SAAS,GACf,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,YAAY,EACZ,cAAc,EACd,YAAY,EAEZ,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,sBAAsB,GACvB,MAAM,kBAAkB,CAAC"}
|