@mastra/react 1.8.0 → 1.9.0-alpha.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/{accumulator-CsUGDUHk.cjs → accumulator-BQGsraqS.cjs} +2 -2
- package/dist/{accumulator-CsUGDUHk.cjs.map → accumulator-BQGsraqS.cjs.map} +1 -1
- package/dist/{accumulator-B1MuNX3j.js → accumulator-C8kIc450.js} +2 -2
- package/dist/{accumulator-B1MuNX3j.js.map → accumulator-C8kIc450.js.map} +1 -1
- package/dist/chat/index.cjs +1 -1
- package/dist/chat/index.js +1 -1
- package/dist/hooks/capabilities/index.cjs +15 -0
- package/dist/hooks/capabilities/index.cjs.map +1 -1
- package/dist/hooks/capabilities/index.d.ts +1 -0
- package/dist/hooks/capabilities/index.d.ts.map +1 -1
- package/dist/hooks/capabilities/index.js +15 -1
- package/dist/hooks/capabilities/index.js.map +1 -1
- package/dist/hooks/capabilities/use-trace-query-discovery-available.d.ts +10 -0
- package/dist/hooks/capabilities/use-trace-query-discovery-available.d.ts.map +1 -0
- package/dist/hooks/mcps/index.cjs +23 -0
- package/dist/hooks/mcps/index.cjs.map +1 -1
- package/dist/hooks/mcps/index.d.ts +1 -0
- package/dist/hooks/mcps/index.d.ts.map +1 -1
- package/dist/hooks/mcps/index.js +23 -1
- package/dist/hooks/mcps/index.js.map +1 -1
- package/dist/hooks/mcps/use-mcp-app-html.d.ts +17 -0
- package/dist/hooks/mcps/use-mcp-app-html.d.ts.map +1 -0
- package/dist/hooks/metrics/index.cjs +23 -16
- package/dist/hooks/metrics/index.cjs.map +1 -1
- package/dist/hooks/metrics/index.js +23 -16
- package/dist/hooks/metrics/index.js.map +1 -1
- package/dist/hooks/metrics/use-model-usage-cost-metrics.d.ts +1 -0
- package/dist/hooks/metrics/use-model-usage-cost-metrics.d.ts.map +1 -1
- package/dist/hooks/traces/index.cjs +2 -0
- package/dist/hooks/traces/index.cjs.map +1 -1
- package/dist/hooks/traces/index.js +2 -0
- package/dist/hooks/traces/index.js.map +1 -1
- package/dist/hooks/traces/use-trace-metadata-filter-fields.d.ts +6 -0
- package/dist/hooks/traces/use-trace-metadata-filter-fields.d.ts.map +1 -1
- package/dist/hooks/workflows/index.cjs +1 -1
- package/dist/hooks/workflows/index.js +1 -1
- package/dist/{hooks-CjULNHpJ.js → hooks-0L0RNfau.js} +2 -2
- package/dist/{hooks-CjULNHpJ.js.map → hooks-0L0RNfau.js.map} +1 -1
- package/dist/{hooks-CMjizg6y.cjs → hooks-DeaoDYVv.cjs} +2 -2
- package/dist/{hooks-CMjizg6y.cjs.map → hooks-DeaoDYVv.cjs.map} +1 -1
- package/dist/{hooks-DsDYaJ3T.cjs → hooks-_YevKidX.cjs} +2 -2
- package/dist/{hooks-DsDYaJ3T.cjs.map → hooks-_YevKidX.cjs.map} +1 -1
- package/dist/{hooks-BFQK_s4g.js → hooks-s61OBZ5M.js} +2 -2
- package/dist/{hooks-BFQK_s4g.js.map → hooks-s61OBZ5M.js.map} +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.js +3 -3
- package/dist/lib/mastra-db/accumulator.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/chat/index.cjs
CHANGED
package/dist/chat/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useChat } from "../hooks-
|
|
1
|
+
import { t as useChat } from "../hooks-s61OBZ5M.js";
|
|
2
2
|
export { useChat };
|
|
@@ -27,6 +27,20 @@ const useTraceQueryAvailable = () => {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
//#endregion
|
|
30
|
+
//#region src/hooks/capabilities/use-trace-query-discovery-available.ts
|
|
31
|
+
/**
|
|
32
|
+
* Whether the store supports trace query field/value discovery. Callers combine it with
|
|
33
|
+
* `useTraceQueryAvailable` when they also need the trace query API. `enabled` stays false
|
|
34
|
+
* while capabilities load; servers without the capabilities endpoint fall back to `true`.
|
|
35
|
+
*/
|
|
36
|
+
const useTraceQueryDiscoveryAvailable = () => {
|
|
37
|
+
const { data, isLoading } = useObservabilityCapabilities();
|
|
38
|
+
return {
|
|
39
|
+
isLoading,
|
|
40
|
+
enabled: !isLoading && (data?.capabilities.traceQueryDiscovery ?? true)
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
30
44
|
//#region src/hooks/capabilities/use-feedback-available.ts
|
|
31
45
|
/**
|
|
32
46
|
* `enabled` stays false while capabilities load. Servers without the
|
|
@@ -43,5 +57,6 @@ const useFeedbackAvailable = () => {
|
|
|
43
57
|
exports.useFeedbackAvailable = useFeedbackAvailable;
|
|
44
58
|
exports.useObservabilityCapabilities = useObservabilityCapabilities;
|
|
45
59
|
exports.useTraceQueryAvailable = useTraceQueryAvailable;
|
|
60
|
+
exports.useTraceQueryDiscoveryAvailable = useTraceQueryDiscoveryAvailable;
|
|
46
61
|
|
|
47
62
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMastraClient"],"sources":["../../../src/hooks/capabilities/use-observability-capabilities.ts","../../../src/hooks/capabilities/use-trace-query-available.ts","../../../src/hooks/capabilities/use-feedback-available.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nconst OBSERVABILITY_CAPABILITIES_STALE_TIME = 24 * 60 * 60 * 1000;\n\ntype ObservabilityCapabilitiesResponse = Awaited<ReturnType<MastraClient['getObservabilityCapabilities']>>;\n\nexport const useObservabilityCapabilities = <TData = ObservabilityCapabilitiesResponse>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<ObservabilityCapabilitiesResponse, TData> } = {}): UseQueryResult<\n TData,\n Error\n> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['observability-capabilities'],\n queryFn: () => client.getObservabilityCapabilities(),\n retry: false,\n staleTime: OBSERVABILITY_CAPABILITIES_STALE_TIME,\n ...queryOptions,\n });\n};\n","import { useObservabilityCapabilities } from './use-observability-capabilities';\n\n/**\n * `enabled` stays false while capabilities load. Servers without the\n * capabilities endpoint fall back to `true` (trace query was the default before).\n */\nexport const useTraceQueryAvailable = (): { isLoading: boolean; enabled: boolean } => {\n const { data, isLoading } = useObservabilityCapabilities();\n\n return {\n isLoading,\n enabled: !isLoading && (data?.capabilities.traceQuery ?? true),\n };\n};\n","import { useObservabilityCapabilities } from './use-observability-capabilities';\n\n/**\n * `enabled` stays false while capabilities load. Servers without the\n * capabilities endpoint fall back to `true` (feedback was shown by default before).\n */\nexport const useFeedbackAvailable = (): { isLoading: boolean; enabled: boolean } => {\n const { data, isLoading } = useObservabilityCapabilities();\n\n return {\n isLoading,\n enabled: !isLoading && (data?.capabilities.feedback ?? true),\n };\n};\n"],"mappings":";;;;AAMA,MAAM,wCAAwC,OAAU,KAAK;AAI7D,MAAa,gCAA2E,EACtF,iBACmF,CAAC,MAGjF;CACH,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAA,sBAAA,SAAA,CAAgB;EACd,UAAU,CAAC,4BAA4B;EACvC,eAAe,OAAO,6BAA6B;EACnD,OAAO;EACP,WAAW;EACX,GAAG;CACL,CAAC;AACH;;;;;;;ACnBA,MAAa,+BAAyE;CACpF,MAAM,EAAE,MAAM,cAAc,6BAA6B;CAEzD,OAAO;EACL;EACA,SAAS,CAAC,cAAc,MAAM,aAAa,cAAc;CAC3D;AACF;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMastraClient"],"sources":["../../../src/hooks/capabilities/use-observability-capabilities.ts","../../../src/hooks/capabilities/use-trace-query-available.ts","../../../src/hooks/capabilities/use-trace-query-discovery-available.ts","../../../src/hooks/capabilities/use-feedback-available.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nconst OBSERVABILITY_CAPABILITIES_STALE_TIME = 24 * 60 * 60 * 1000;\n\ntype ObservabilityCapabilitiesResponse = Awaited<ReturnType<MastraClient['getObservabilityCapabilities']>>;\n\nexport const useObservabilityCapabilities = <TData = ObservabilityCapabilitiesResponse>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<ObservabilityCapabilitiesResponse, TData> } = {}): UseQueryResult<\n TData,\n Error\n> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['observability-capabilities'],\n queryFn: () => client.getObservabilityCapabilities(),\n retry: false,\n staleTime: OBSERVABILITY_CAPABILITIES_STALE_TIME,\n ...queryOptions,\n });\n};\n","import { useObservabilityCapabilities } from './use-observability-capabilities';\n\n/**\n * `enabled` stays false while capabilities load. Servers without the\n * capabilities endpoint fall back to `true` (trace query was the default before).\n */\nexport const useTraceQueryAvailable = (): { isLoading: boolean; enabled: boolean } => {\n const { data, isLoading } = useObservabilityCapabilities();\n\n return {\n isLoading,\n enabled: !isLoading && (data?.capabilities.traceQuery ?? true),\n };\n};\n","import { useObservabilityCapabilities } from './use-observability-capabilities';\n\n/**\n * Whether the store supports trace query field/value discovery. Callers combine it with\n * `useTraceQueryAvailable` when they also need the trace query API. `enabled` stays false\n * while capabilities load; servers without the capabilities endpoint fall back to `true`.\n */\nexport const useTraceQueryDiscoveryAvailable = (): { isLoading: boolean; enabled: boolean } => {\n const { data, isLoading } = useObservabilityCapabilities();\n\n return {\n isLoading,\n enabled: !isLoading && (data?.capabilities.traceQueryDiscovery ?? true),\n };\n};\n","import { useObservabilityCapabilities } from './use-observability-capabilities';\n\n/**\n * `enabled` stays false while capabilities load. Servers without the\n * capabilities endpoint fall back to `true` (feedback was shown by default before).\n */\nexport const useFeedbackAvailable = (): { isLoading: boolean; enabled: boolean } => {\n const { data, isLoading } = useObservabilityCapabilities();\n\n return {\n isLoading,\n enabled: !isLoading && (data?.capabilities.feedback ?? true),\n };\n};\n"],"mappings":";;;;AAMA,MAAM,wCAAwC,OAAU,KAAK;AAI7D,MAAa,gCAA2E,EACtF,iBACmF,CAAC,MAGjF;CACH,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAA,sBAAA,SAAA,CAAgB;EACd,UAAU,CAAC,4BAA4B;EACvC,eAAe,OAAO,6BAA6B;EACnD,OAAO;EACP,WAAW;EACX,GAAG;CACL,CAAC;AACH;;;;;;;ACnBA,MAAa,+BAAyE;CACpF,MAAM,EAAE,MAAM,cAAc,6BAA6B;CAEzD,OAAO;EACL;EACA,SAAS,CAAC,cAAc,MAAM,aAAa,cAAc;CAC3D;AACF;;;;;;;;ACNA,MAAa,wCAAkF;CAC7F,MAAM,EAAE,MAAM,cAAc,6BAA6B;CAEzD,OAAO;EACL;EACA,SAAS,CAAC,cAAc,MAAM,aAAa,uBAAuB;CACpE;AACF;;;;;;;ACRA,MAAa,6BAAuE;CAClF,MAAM,EAAE,MAAM,cAAc,6BAA6B;CAEzD,OAAO;EACL;EACA,SAAS,CAAC,cAAc,MAAM,aAAa,YAAY;CACzD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/capabilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/capabilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uCAAuC,CAAC;AACtD,cAAc,0BAA0B,CAAC"}
|
|
@@ -26,6 +26,20 @@ const useTraceQueryAvailable = () => {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
//#endregion
|
|
29
|
+
//#region src/hooks/capabilities/use-trace-query-discovery-available.ts
|
|
30
|
+
/**
|
|
31
|
+
* Whether the store supports trace query field/value discovery. Callers combine it with
|
|
32
|
+
* `useTraceQueryAvailable` when they also need the trace query API. `enabled` stays false
|
|
33
|
+
* while capabilities load; servers without the capabilities endpoint fall back to `true`.
|
|
34
|
+
*/
|
|
35
|
+
const useTraceQueryDiscoveryAvailable = () => {
|
|
36
|
+
const { data, isLoading } = useObservabilityCapabilities();
|
|
37
|
+
return {
|
|
38
|
+
isLoading,
|
|
39
|
+
enabled: !isLoading && (data?.capabilities.traceQueryDiscovery ?? true)
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
29
43
|
//#region src/hooks/capabilities/use-feedback-available.ts
|
|
30
44
|
/**
|
|
31
45
|
* `enabled` stays false while capabilities load. Servers without the
|
|
@@ -39,6 +53,6 @@ const useFeedbackAvailable = () => {
|
|
|
39
53
|
};
|
|
40
54
|
};
|
|
41
55
|
//#endregion
|
|
42
|
-
export { useFeedbackAvailable, useObservabilityCapabilities, useTraceQueryAvailable };
|
|
56
|
+
export { useFeedbackAvailable, useObservabilityCapabilities, useTraceQueryAvailable, useTraceQueryDiscoveryAvailable };
|
|
43
57
|
|
|
44
58
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/capabilities/use-observability-capabilities.ts","../../../src/hooks/capabilities/use-trace-query-available.ts","../../../src/hooks/capabilities/use-feedback-available.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nconst OBSERVABILITY_CAPABILITIES_STALE_TIME = 24 * 60 * 60 * 1000;\n\ntype ObservabilityCapabilitiesResponse = Awaited<ReturnType<MastraClient['getObservabilityCapabilities']>>;\n\nexport const useObservabilityCapabilities = <TData = ObservabilityCapabilitiesResponse>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<ObservabilityCapabilitiesResponse, TData> } = {}): UseQueryResult<\n TData,\n Error\n> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['observability-capabilities'],\n queryFn: () => client.getObservabilityCapabilities(),\n retry: false,\n staleTime: OBSERVABILITY_CAPABILITIES_STALE_TIME,\n ...queryOptions,\n });\n};\n","import { useObservabilityCapabilities } from './use-observability-capabilities';\n\n/**\n * `enabled` stays false while capabilities load. Servers without the\n * capabilities endpoint fall back to `true` (trace query was the default before).\n */\nexport const useTraceQueryAvailable = (): { isLoading: boolean; enabled: boolean } => {\n const { data, isLoading } = useObservabilityCapabilities();\n\n return {\n isLoading,\n enabled: !isLoading && (data?.capabilities.traceQuery ?? true),\n };\n};\n","import { useObservabilityCapabilities } from './use-observability-capabilities';\n\n/**\n * `enabled` stays false while capabilities load. Servers without the\n * capabilities endpoint fall back to `true` (feedback was shown by default before).\n */\nexport const useFeedbackAvailable = (): { isLoading: boolean; enabled: boolean } => {\n const { data, isLoading } = useObservabilityCapabilities();\n\n return {\n isLoading,\n enabled: !isLoading && (data?.capabilities.feedback ?? true),\n };\n};\n"],"mappings":";;;AAMA,MAAM,wCAAwC,OAAU,KAAK;AAI7D,MAAa,gCAA2E,EACtF,iBACmF,CAAC,MAGjF;CACH,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,CAAC,4BAA4B;EACvC,eAAe,OAAO,6BAA6B;EACnD,OAAO;EACP,WAAW;EACX,GAAG;CACL,CAAC;AACH;;;;;;;ACnBA,MAAa,+BAAyE;CACpF,MAAM,EAAE,MAAM,cAAc,6BAA6B;CAEzD,OAAO;EACL;EACA,SAAS,CAAC,cAAc,MAAM,aAAa,cAAc;CAC3D;AACF;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/capabilities/use-observability-capabilities.ts","../../../src/hooks/capabilities/use-trace-query-available.ts","../../../src/hooks/capabilities/use-trace-query-discovery-available.ts","../../../src/hooks/capabilities/use-feedback-available.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nconst OBSERVABILITY_CAPABILITIES_STALE_TIME = 24 * 60 * 60 * 1000;\n\ntype ObservabilityCapabilitiesResponse = Awaited<ReturnType<MastraClient['getObservabilityCapabilities']>>;\n\nexport const useObservabilityCapabilities = <TData = ObservabilityCapabilitiesResponse>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<ObservabilityCapabilitiesResponse, TData> } = {}): UseQueryResult<\n TData,\n Error\n> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['observability-capabilities'],\n queryFn: () => client.getObservabilityCapabilities(),\n retry: false,\n staleTime: OBSERVABILITY_CAPABILITIES_STALE_TIME,\n ...queryOptions,\n });\n};\n","import { useObservabilityCapabilities } from './use-observability-capabilities';\n\n/**\n * `enabled` stays false while capabilities load. Servers without the\n * capabilities endpoint fall back to `true` (trace query was the default before).\n */\nexport const useTraceQueryAvailable = (): { isLoading: boolean; enabled: boolean } => {\n const { data, isLoading } = useObservabilityCapabilities();\n\n return {\n isLoading,\n enabled: !isLoading && (data?.capabilities.traceQuery ?? true),\n };\n};\n","import { useObservabilityCapabilities } from './use-observability-capabilities';\n\n/**\n * Whether the store supports trace query field/value discovery. Callers combine it with\n * `useTraceQueryAvailable` when they also need the trace query API. `enabled` stays false\n * while capabilities load; servers without the capabilities endpoint fall back to `true`.\n */\nexport const useTraceQueryDiscoveryAvailable = (): { isLoading: boolean; enabled: boolean } => {\n const { data, isLoading } = useObservabilityCapabilities();\n\n return {\n isLoading,\n enabled: !isLoading && (data?.capabilities.traceQueryDiscovery ?? true),\n };\n};\n","import { useObservabilityCapabilities } from './use-observability-capabilities';\n\n/**\n * `enabled` stays false while capabilities load. Servers without the\n * capabilities endpoint fall back to `true` (feedback was shown by default before).\n */\nexport const useFeedbackAvailable = (): { isLoading: boolean; enabled: boolean } => {\n const { data, isLoading } = useObservabilityCapabilities();\n\n return {\n isLoading,\n enabled: !isLoading && (data?.capabilities.feedback ?? true),\n };\n};\n"],"mappings":";;;AAMA,MAAM,wCAAwC,OAAU,KAAK;AAI7D,MAAa,gCAA2E,EACtF,iBACmF,CAAC,MAGjF;CACH,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,CAAC,4BAA4B;EACvC,eAAe,OAAO,6BAA6B;EACnD,OAAO;EACP,WAAW;EACX,GAAG;CACL,CAAC;AACH;;;;;;;ACnBA,MAAa,+BAAyE;CACpF,MAAM,EAAE,MAAM,cAAc,6BAA6B;CAEzD,OAAO;EACL;EACA,SAAS,CAAC,cAAc,MAAM,aAAa,cAAc;CAC3D;AACF;;;;;;;;ACNA,MAAa,wCAAkF;CAC7F,MAAM,EAAE,MAAM,cAAc,6BAA6B;CAEzD,OAAO;EACL;EACA,SAAS,CAAC,cAAc,MAAM,aAAa,uBAAuB;CACpE;AACF;;;;;;;ACRA,MAAa,6BAAuE;CAClF,MAAM,EAAE,MAAM,cAAc,6BAA6B;CAEzD,OAAO;EACL;EACA,SAAS,CAAC,cAAc,MAAM,aAAa,YAAY;CACzD;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the store supports trace query field/value discovery. Callers combine it with
|
|
3
|
+
* `useTraceQueryAvailable` when they also need the trace query API. `enabled` stays false
|
|
4
|
+
* while capabilities load; servers without the capabilities endpoint fall back to `true`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useTraceQueryDiscoveryAvailable: () => {
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=use-trace-query-discovery-available.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-trace-query-discovery-available.d.ts","sourceRoot":"","sources":["../../../src/hooks/capabilities/use-trace-query-discovery-available.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,QAAO;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAOxF,CAAC"}
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_mastra_client_context = require("../../mastra-client-context-DzX3f0RF.cjs");
|
|
3
3
|
let _tanstack_react_query = require("@tanstack/react-query");
|
|
4
|
+
//#region src/hooks/mcps/use-mcp-app-html.ts
|
|
5
|
+
/**
|
|
6
|
+
* The HTML of an MCP tool's `ui://` app resource (from the tool's `_meta`), for rendering the tool's own UI.
|
|
7
|
+
* Skips the fetch when the tool has no app resource.
|
|
8
|
+
*/
|
|
9
|
+
const useMcpAppHtml = ({ serverId, appResourceUri, queryOptions }) => {
|
|
10
|
+
const client = require_mastra_client_context.useMastraClient();
|
|
11
|
+
return (0, _tanstack_react_query.useQuery)({
|
|
12
|
+
queryKey: [
|
|
13
|
+
"mcp-app-resource",
|
|
14
|
+
serverId,
|
|
15
|
+
appResourceUri
|
|
16
|
+
],
|
|
17
|
+
queryFn: async () => {
|
|
18
|
+
if (!appResourceUri) return null;
|
|
19
|
+
return (await client.readMcpServerResource(serverId, appResourceUri)).contents[0]?.text ?? null;
|
|
20
|
+
},
|
|
21
|
+
enabled: appResourceUri !== void 0,
|
|
22
|
+
...queryOptions
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
4
26
|
//#region src/hooks/mcps/use-mcp-app-tools.ts
|
|
5
27
|
/**
|
|
6
28
|
* Builds a map of tool names → MCP App info for tools across all registered
|
|
@@ -209,6 +231,7 @@ exports.useMCPServerTool = useMCPServerTool;
|
|
|
209
231
|
exports.useMCPServerTools = useMCPServerTools;
|
|
210
232
|
exports.useMCPServerToolsById = useMCPServerToolsById;
|
|
211
233
|
exports.useMCPServers = useMCPServers;
|
|
234
|
+
exports.useMcpAppHtml = useMcpAppHtml;
|
|
212
235
|
exports.useMcpAppTools = useMcpAppTools;
|
|
213
236
|
exports.useTryConnectMcp = useTryConnectMcp;
|
|
214
237
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMastraClient","useMastraClient","useMastraClient","useMastraClient","useMastraClient","useMastraClient"],"sources":["../../../src/hooks/mcps/use-mcp-app-tools.ts","../../../src/hooks/mcps/use-mcp-server-tool.ts","../../../src/hooks/mcps/use-mcp-server-tools.ts","../../../src/hooks/mcps/use-mcp-server-tools-by-id.ts","../../../src/hooks/mcps/use-mcp-servers.ts","../../../src/hooks/mcps/use-try-connect-mcp.ts"],"sourcesContent":["import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport interface McpAppToolInfo {\n serverId: string;\n toolId: string;\n toolName: string;\n resourceUri: string;\n}\n\n/**\n * Builds a map of tool names → MCP App info for tools across all registered\n * MCP servers that have `_meta.ui.resourceUri` (i.e., tools with interactive\n * MCP App UIs).\n *\n * For each app tool, entries are created under both the original tool name\n * and the namespaced name (`${serverId}_${toolName}`) so that agent tools\n * sourced via `MCPClient.listTools()` (which namespaces) can be resolved.\n */\nexport function useMcpAppTools<TData = Record<string, McpAppToolInfo>>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<Record<string, McpAppToolInfo>, TData> } = {}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-tools'],\n queryFn: async () => {\n const map: Record<string, McpAppToolInfo> = {};\n\n const { servers } = await client.getMcpServers();\n if (!servers?.length) return map;\n\n const results = await Promise.allSettled(\n servers.map(async server => {\n const { tools } = await client.getMcpServerTools(server.id);\n return { serverId: server.id, tools };\n }),\n );\n\n for (const result of results) {\n if (result.status !== 'fulfilled') continue;\n const { serverId, tools } = result.value;\n for (const tool of tools) {\n const meta = tool._meta as { ui?: { resourceUri?: string } } | undefined;\n const resourceUri = meta?.ui?.resourceUri;\n if (resourceUri) {\n const toolId = tool.name;\n const info: McpAppToolInfo = { serverId, toolId, toolName: tool.name, resourceUri };\n map[toolId] = info;\n if (tool.name !== toolId) {\n map[tool.name] = info;\n }\n // Also map the namespaced name used by MCPClient.listTools()\n map[`${serverId}_${tool.name}`] = info;\n }\n }\n }\n\n return map;\n },\n staleTime: 60_000,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolDetails = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['details']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerTool = <TData = MCPServerToolDetails>({\n serverId,\n toolId,\n requestContext,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MCPServerToolDetails, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-server-tool', serverId, toolId],\n queryFn: () => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.details(requestContext);\n },\n ...queryOptions,\n });\n};\n\nexport type ExecuteMCPToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['execute']>>;\ntype ExecuteMCPToolVariables = { data: any; requestContext?: Record<string, any> };\n\nexport const useExecuteMCPTool = ({\n serverId,\n toolId,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n queryOptions?: MastraMutationOptions<ExecuteMCPToolResponse, ExecuteMCPToolVariables>;\n}): UseMutationResult<ExecuteMCPToolResponse, Error, ExecuteMCPToolVariables> => {\n const client = useMastraClient();\n\n return useMutation({\n mutationFn: ({ data, requestContext }: ExecuteMCPToolVariables) => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.execute({ data, requestContext: requestContext as RequestContext });\n },\n ...queryOptions,\n });\n};\n","import type { McpToolInfo as SdkMcpToolInfo } from '@mastra/client-js';\nimport type { ServerInfo } from '@mastra/core/mcp';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServerTools = <TData = Record<string, SdkMcpToolInfo>>({\n selectedServer,\n queryOptions,\n}: {\n selectedServer: ServerInfo;\n queryOptions?: MastraQueryOptions<Record<string, SdkMcpToolInfo>, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', selectedServer?.id],\n queryFn: async () => {\n const response = await client.getMcpServerTools(selectedServer?.id);\n const fetchedToolsArray: SdkMcpToolInfo[] = response.tools;\n const transformedTools: Record<string, SdkMcpToolInfo> = {};\n fetchedToolsArray.forEach((sdkToolInfo: SdkMcpToolInfo) => {\n transformedTools[sdkToolInfo.name] = sdkToolInfo;\n });\n\n return transformedTools;\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolsById = Record<string, Awaited<ReturnType<MastraClient['getMcpServerTools']>>['tools'][number]>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerToolsById = <TData = MCPServerToolsById>({\n serverId,\n queryOptions,\n}: {\n serverId: string | null;\n queryOptions?: MastraQueryOptions<MCPServerToolsById, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', serverId],\n queryFn: async (): Promise<MCPServerToolsById> => {\n const response = await client.getMcpServerTools(serverId!);\n return Object.fromEntries(response.tools.map(tool => [tool.name, tool]));\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { McpServerListResponse } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServers = <TData = McpServerListResponse['servers']>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<McpServerListResponse['servers'], TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-servers'],\n queryFn: async () => {\n const mcpServers: McpServerListResponse['servers'] = (await client.getMcpServers(requestContext)).servers;\n return mcpServers;\n },\n ...queryOptions,\n });\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\ninterface McpTool {\n name: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n}\n\nexport interface TryConnectResult {\n tools: McpTool[];\n}\n\nasync function parseResponse(response: Response): Promise<unknown> {\n const contentType = response.headers.get('content-type') ?? '';\n\n if (contentType.includes('text/event-stream')) {\n const text = await response.text();\n const lines = text.split('\\n');\n\n for (const line of lines) {\n if (line.startsWith('data:')) {\n const data = line.slice('data:'.length).trim();\n if (data) {\n return JSON.parse(data);\n }\n }\n }\n\n throw new Error('No data found in SSE response');\n }\n\n return response.json();\n}\n\nasync function connectAndListTools(url: string, clientHeaders?: Record<string, string>): Promise<TryConnectResult> {\n const baseHeaders: Record<string, string> = {\n ...clientHeaders,\n 'Content-Type': 'application/json',\n Accept: 'application/json, text/event-stream',\n };\n\n // Step 1: Initialize\n const initResponse = await fetch(url, {\n method: 'POST',\n headers: baseHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'initialize',\n params: {\n protocolVersion: '2025-03-26',\n capabilities: {},\n clientInfo: { name: 'mastra-playground', version: '1.0.0' },\n },\n }),\n });\n\n if (!initResponse.ok) {\n throw new Error(`Initialize failed: ${initResponse.status} ${initResponse.statusText}`);\n }\n\n const sessionId = initResponse.headers.get('Mcp-Session-Id');\n await parseResponse(initResponse);\n\n const sessionHeaders: Record<string, string> = {\n ...baseHeaders,\n };\n if (sessionId) {\n sessionHeaders['Mcp-Session-Id'] = sessionId;\n }\n\n // Step 2: Send initialized notification\n await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n method: 'notifications/initialized',\n }),\n });\n\n // Step 3: List tools\n const toolsResponse = await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 2,\n method: 'tools/list',\n }),\n });\n\n if (!toolsResponse.ok) {\n throw new Error(`tools/list failed: ${toolsResponse.status} ${toolsResponse.statusText}`);\n }\n\n const toolsResult = (await parseResponse(toolsResponse)) as { result?: { tools?: McpTool[] } };\n\n return {\n tools: toolsResult.result?.tools ?? [],\n };\n}\n\nexport const useTryConnectMcp = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<TryConnectResult, string> } = {}) => {\n const client = useMastraClient();\n const clientHeaders = (client.options?.headers as Record<string, string>) ?? {};\n\n return useMutation({\n mutationFn: (url: string) => connectAndListTools(url, clientHeaders),\n ...queryOptions,\n });\n};\n\nexport type TryConnectMcp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;EACR,SAAS;EACT,aAAa;EACb,MAAM,KAAK,UAAU;GACnB,SAAS;GACT,IAAI;GACJ,QAAQ;EACV,CAAC;CACH,CAAC;CAED,IAAI,CAAC,cAAc,IACjB,MAAM,IAAI,MAAM,sBAAsB,cAAc,OAAO,GAAG,cAAc,YAAY;CAK1F,OAAO,EACL,QAAO,MAHkB,cAAc,aAAa,EAAA,CAGjC,QAAQ,SAAS,CAAC,EACvC;AACF;AAEA,MAAa,oBAAoB,EAC/B,iBACsE,CAAC,MAAM;CAE7E,MAAM,gBADSC,8BAAAA,gBACa,CAAC,CAAC,SAAS,WAAsC,CAAC;CAE9E,QAAA,GAAA,sBAAA,YAAA,CAAmB;EACjB,aAAa,QAAgB,oBAAoB,KAAK,aAAa;EACnE,GAAG;CACL,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMastraClient","useMastraClient","useMastraClient","useMastraClient","useMastraClient","useMastraClient","useMastraClient"],"sources":["../../../src/hooks/mcps/use-mcp-app-html.ts","../../../src/hooks/mcps/use-mcp-app-tools.ts","../../../src/hooks/mcps/use-mcp-server-tool.ts","../../../src/hooks/mcps/use-mcp-server-tools.ts","../../../src/hooks/mcps/use-mcp-server-tools-by-id.ts","../../../src/hooks/mcps/use-mcp-servers.ts","../../../src/hooks/mcps/use-try-connect-mcp.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport { useQuery } from '@tanstack/react-query';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\n/** The app HTML, or `null` when the resource has no text. */\ntype McpAppHtml = string | null;\n\nexport type ReadMcpServerResourceResponse = Awaited<ReturnType<MastraClient['readMcpServerResource']>>;\n\n/**\n * The HTML of an MCP tool's `ui://` app resource (from the tool's `_meta`), for rendering the tool's own UI.\n * Skips the fetch when the tool has no app resource.\n */\nexport const useMcpAppHtml = <TData = McpAppHtml>({\n serverId,\n appResourceUri,\n queryOptions,\n}: {\n serverId: string;\n appResourceUri?: string;\n queryOptions?: MastraQueryOptions<McpAppHtml, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-resource', serverId, appResourceUri],\n queryFn: async () => {\n if (!appResourceUri) return null;\n const response = await client.readMcpServerResource(serverId, appResourceUri);\n return response.contents[0]?.text ?? null;\n },\n enabled: appResourceUri !== undefined,\n ...queryOptions,\n });\n};\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport interface McpAppToolInfo {\n serverId: string;\n toolId: string;\n toolName: string;\n resourceUri: string;\n}\n\n/**\n * Builds a map of tool names → MCP App info for tools across all registered\n * MCP servers that have `_meta.ui.resourceUri` (i.e., tools with interactive\n * MCP App UIs).\n *\n * For each app tool, entries are created under both the original tool name\n * and the namespaced name (`${serverId}_${toolName}`) so that agent tools\n * sourced via `MCPClient.listTools()` (which namespaces) can be resolved.\n */\nexport function useMcpAppTools<TData = Record<string, McpAppToolInfo>>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<Record<string, McpAppToolInfo>, TData> } = {}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-tools'],\n queryFn: async () => {\n const map: Record<string, McpAppToolInfo> = {};\n\n const { servers } = await client.getMcpServers();\n if (!servers?.length) return map;\n\n const results = await Promise.allSettled(\n servers.map(async server => {\n const { tools } = await client.getMcpServerTools(server.id);\n return { serverId: server.id, tools };\n }),\n );\n\n for (const result of results) {\n if (result.status !== 'fulfilled') continue;\n const { serverId, tools } = result.value;\n for (const tool of tools) {\n const meta = tool._meta as { ui?: { resourceUri?: string } } | undefined;\n const resourceUri = meta?.ui?.resourceUri;\n if (resourceUri) {\n const toolId = tool.name;\n const info: McpAppToolInfo = { serverId, toolId, toolName: tool.name, resourceUri };\n map[toolId] = info;\n if (tool.name !== toolId) {\n map[tool.name] = info;\n }\n // Also map the namespaced name used by MCPClient.listTools()\n map[`${serverId}_${tool.name}`] = info;\n }\n }\n }\n\n return map;\n },\n staleTime: 60_000,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolDetails = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['details']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerTool = <TData = MCPServerToolDetails>({\n serverId,\n toolId,\n requestContext,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MCPServerToolDetails, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-server-tool', serverId, toolId],\n queryFn: () => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.details(requestContext);\n },\n ...queryOptions,\n });\n};\n\nexport type ExecuteMCPToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['execute']>>;\ntype ExecuteMCPToolVariables = { data: any; requestContext?: Record<string, any> };\n\nexport const useExecuteMCPTool = ({\n serverId,\n toolId,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n queryOptions?: MastraMutationOptions<ExecuteMCPToolResponse, ExecuteMCPToolVariables>;\n}): UseMutationResult<ExecuteMCPToolResponse, Error, ExecuteMCPToolVariables> => {\n const client = useMastraClient();\n\n return useMutation({\n mutationFn: ({ data, requestContext }: ExecuteMCPToolVariables) => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.execute({ data, requestContext: requestContext as RequestContext });\n },\n ...queryOptions,\n });\n};\n","import type { McpToolInfo as SdkMcpToolInfo } from '@mastra/client-js';\nimport type { ServerInfo } from '@mastra/core/mcp';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServerTools = <TData = Record<string, SdkMcpToolInfo>>({\n selectedServer,\n queryOptions,\n}: {\n selectedServer: ServerInfo;\n queryOptions?: MastraQueryOptions<Record<string, SdkMcpToolInfo>, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', selectedServer?.id],\n queryFn: async () => {\n const response = await client.getMcpServerTools(selectedServer?.id);\n const fetchedToolsArray: SdkMcpToolInfo[] = response.tools;\n const transformedTools: Record<string, SdkMcpToolInfo> = {};\n fetchedToolsArray.forEach((sdkToolInfo: SdkMcpToolInfo) => {\n transformedTools[sdkToolInfo.name] = sdkToolInfo;\n });\n\n return transformedTools;\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolsById = Record<string, Awaited<ReturnType<MastraClient['getMcpServerTools']>>['tools'][number]>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerToolsById = <TData = MCPServerToolsById>({\n serverId,\n queryOptions,\n}: {\n serverId: string | null;\n queryOptions?: MastraQueryOptions<MCPServerToolsById, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', serverId],\n queryFn: async (): Promise<MCPServerToolsById> => {\n const response = await client.getMcpServerTools(serverId!);\n return Object.fromEntries(response.tools.map(tool => [tool.name, tool]));\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { McpServerListResponse } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServers = <TData = McpServerListResponse['servers']>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<McpServerListResponse['servers'], TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-servers'],\n queryFn: async () => {\n const mcpServers: McpServerListResponse['servers'] = (await client.getMcpServers(requestContext)).servers;\n return mcpServers;\n },\n ...queryOptions,\n });\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\ninterface McpTool {\n name: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n}\n\nexport interface TryConnectResult {\n tools: McpTool[];\n}\n\nasync function parseResponse(response: Response): Promise<unknown> {\n const contentType = response.headers.get('content-type') ?? '';\n\n if (contentType.includes('text/event-stream')) {\n const text = await response.text();\n const lines = text.split('\\n');\n\n for (const line of lines) {\n if (line.startsWith('data:')) {\n const data = line.slice('data:'.length).trim();\n if (data) {\n return JSON.parse(data);\n }\n }\n }\n\n throw new Error('No data found in SSE response');\n }\n\n return response.json();\n}\n\nasync function connectAndListTools(url: string, clientHeaders?: Record<string, string>): Promise<TryConnectResult> {\n const baseHeaders: Record<string, string> = {\n ...clientHeaders,\n 'Content-Type': 'application/json',\n Accept: 'application/json, text/event-stream',\n };\n\n // Step 1: Initialize\n const initResponse = await fetch(url, {\n method: 'POST',\n headers: baseHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'initialize',\n params: {\n protocolVersion: '2025-03-26',\n capabilities: {},\n clientInfo: { name: 'mastra-playground', version: '1.0.0' },\n },\n }),\n });\n\n if (!initResponse.ok) {\n throw new Error(`Initialize failed: ${initResponse.status} ${initResponse.statusText}`);\n }\n\n const sessionId = initResponse.headers.get('Mcp-Session-Id');\n await parseResponse(initResponse);\n\n const sessionHeaders: Record<string, string> = {\n ...baseHeaders,\n };\n if (sessionId) {\n sessionHeaders['Mcp-Session-Id'] = sessionId;\n }\n\n // Step 2: Send initialized notification\n await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n method: 'notifications/initialized',\n }),\n });\n\n // Step 3: List tools\n const toolsResponse = await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 2,\n method: 'tools/list',\n }),\n });\n\n if (!toolsResponse.ok) {\n throw new Error(`tools/list failed: ${toolsResponse.status} ${toolsResponse.statusText}`);\n }\n\n const toolsResult = (await parseResponse(toolsResponse)) as { result?: { tools?: McpTool[] } };\n\n return {\n tools: toolsResult.result?.tools ?? [],\n };\n}\n\nexport const useTryConnectMcp = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<TryConnectResult, string> } = {}) => {\n const client = useMastraClient();\n const clientHeaders = (client.options?.headers as Record<string, string>) ?? {};\n\n return useMutation({\n mutationFn: (url: string) => connectAndListTools(url, clientHeaders),\n ...queryOptions,\n });\n};\n\nexport type TryConnectMcpMutation = ReturnType<typeof useTryConnectMcp>;\n"],"mappings":";;;;;;;;AAeA,MAAa,iBAAqC,EAChD,UACA,gBACA,mBAKkC;CAClC,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAA,sBAAA,SAAA,CAAgB;EACd,UAAU;GAAC;GAAoB;GAAU;EAAc;EACvD,SAAS,YAAY;GACnB,IAAI,CAAC,gBAAgB,OAAO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,UAAU;GACnB,SAAS;GACT,QAAQ;EACV,CAAC;CACH,CAAC;CAGD,MAAM,gBAAgB,MAAM,MAAM,KAAK;EACrC,QAAQ;EACR,SAAS;EACT,aAAa;EACb,MAAM,KAAK,UAAU;GACnB,SAAS;GACT,IAAI;GACJ,QAAQ;EACV,CAAC;CACH,CAAC;CAED,IAAI,CAAC,cAAc,IACjB,MAAM,IAAI,MAAM,sBAAsB,cAAc,OAAO,GAAG,cAAc,YAAY;CAK1F,OAAO,EACL,QAAO,MAHkB,cAAc,aAAa,EAAA,CAGjC,QAAQ,SAAS,CAAC,EACvC;AACF;AAEA,MAAa,oBAAoB,EAC/B,iBACsE,CAAC,MAAM;CAE7E,MAAM,gBADSC,8BAAAA,gBACa,CAAC,CAAC,SAAS,WAAsC,CAAC;CAE9E,QAAA,GAAA,sBAAA,YAAA,CAAmB;EACjB,aAAa,QAAgB,oBAAoB,KAAK,aAAa;EACnE,GAAG;CACL,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/mcps/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/mcps/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC"}
|
package/dist/hooks/mcps/index.js
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import { n as useMastraClient } from "../../mastra-client-context-Bx_g84YB.js";
|
|
2
2
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
3
|
+
//#region src/hooks/mcps/use-mcp-app-html.ts
|
|
4
|
+
/**
|
|
5
|
+
* The HTML of an MCP tool's `ui://` app resource (from the tool's `_meta`), for rendering the tool's own UI.
|
|
6
|
+
* Skips the fetch when the tool has no app resource.
|
|
7
|
+
*/
|
|
8
|
+
const useMcpAppHtml = ({ serverId, appResourceUri, queryOptions }) => {
|
|
9
|
+
const client = useMastraClient();
|
|
10
|
+
return useQuery({
|
|
11
|
+
queryKey: [
|
|
12
|
+
"mcp-app-resource",
|
|
13
|
+
serverId,
|
|
14
|
+
appResourceUri
|
|
15
|
+
],
|
|
16
|
+
queryFn: async () => {
|
|
17
|
+
if (!appResourceUri) return null;
|
|
18
|
+
return (await client.readMcpServerResource(serverId, appResourceUri)).contents[0]?.text ?? null;
|
|
19
|
+
},
|
|
20
|
+
enabled: appResourceUri !== void 0,
|
|
21
|
+
...queryOptions
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
3
25
|
//#region src/hooks/mcps/use-mcp-app-tools.ts
|
|
4
26
|
/**
|
|
5
27
|
* Builds a map of tool names → MCP App info for tools across all registered
|
|
@@ -203,6 +225,6 @@ const useTryConnectMcp = ({ queryOptions } = {}) => {
|
|
|
203
225
|
});
|
|
204
226
|
};
|
|
205
227
|
//#endregion
|
|
206
|
-
export { useExecuteMCPTool, useMCPServerTool, useMCPServerTools, useMCPServerToolsById, useMCPServers, useMcpAppTools, useTryConnectMcp };
|
|
228
|
+
export { useExecuteMCPTool, useMCPServerTool, useMCPServerTools, useMCPServerToolsById, useMCPServers, useMcpAppHtml, useMcpAppTools, useTryConnectMcp };
|
|
207
229
|
|
|
208
230
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/mcps/use-mcp-app-tools.ts","../../../src/hooks/mcps/use-mcp-server-tool.ts","../../../src/hooks/mcps/use-mcp-server-tools.ts","../../../src/hooks/mcps/use-mcp-server-tools-by-id.ts","../../../src/hooks/mcps/use-mcp-servers.ts","../../../src/hooks/mcps/use-try-connect-mcp.ts"],"sourcesContent":["import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport interface McpAppToolInfo {\n serverId: string;\n toolId: string;\n toolName: string;\n resourceUri: string;\n}\n\n/**\n * Builds a map of tool names → MCP App info for tools across all registered\n * MCP servers that have `_meta.ui.resourceUri` (i.e., tools with interactive\n * MCP App UIs).\n *\n * For each app tool, entries are created under both the original tool name\n * and the namespaced name (`${serverId}_${toolName}`) so that agent tools\n * sourced via `MCPClient.listTools()` (which namespaces) can be resolved.\n */\nexport function useMcpAppTools<TData = Record<string, McpAppToolInfo>>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<Record<string, McpAppToolInfo>, TData> } = {}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-tools'],\n queryFn: async () => {\n const map: Record<string, McpAppToolInfo> = {};\n\n const { servers } = await client.getMcpServers();\n if (!servers?.length) return map;\n\n const results = await Promise.allSettled(\n servers.map(async server => {\n const { tools } = await client.getMcpServerTools(server.id);\n return { serverId: server.id, tools };\n }),\n );\n\n for (const result of results) {\n if (result.status !== 'fulfilled') continue;\n const { serverId, tools } = result.value;\n for (const tool of tools) {\n const meta = tool._meta as { ui?: { resourceUri?: string } } | undefined;\n const resourceUri = meta?.ui?.resourceUri;\n if (resourceUri) {\n const toolId = tool.name;\n const info: McpAppToolInfo = { serverId, toolId, toolName: tool.name, resourceUri };\n map[toolId] = info;\n if (tool.name !== toolId) {\n map[tool.name] = info;\n }\n // Also map the namespaced name used by MCPClient.listTools()\n map[`${serverId}_${tool.name}`] = info;\n }\n }\n }\n\n return map;\n },\n staleTime: 60_000,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolDetails = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['details']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerTool = <TData = MCPServerToolDetails>({\n serverId,\n toolId,\n requestContext,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MCPServerToolDetails, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-server-tool', serverId, toolId],\n queryFn: () => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.details(requestContext);\n },\n ...queryOptions,\n });\n};\n\nexport type ExecuteMCPToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['execute']>>;\ntype ExecuteMCPToolVariables = { data: any; requestContext?: Record<string, any> };\n\nexport const useExecuteMCPTool = ({\n serverId,\n toolId,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n queryOptions?: MastraMutationOptions<ExecuteMCPToolResponse, ExecuteMCPToolVariables>;\n}): UseMutationResult<ExecuteMCPToolResponse, Error, ExecuteMCPToolVariables> => {\n const client = useMastraClient();\n\n return useMutation({\n mutationFn: ({ data, requestContext }: ExecuteMCPToolVariables) => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.execute({ data, requestContext: requestContext as RequestContext });\n },\n ...queryOptions,\n });\n};\n","import type { McpToolInfo as SdkMcpToolInfo } from '@mastra/client-js';\nimport type { ServerInfo } from '@mastra/core/mcp';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServerTools = <TData = Record<string, SdkMcpToolInfo>>({\n selectedServer,\n queryOptions,\n}: {\n selectedServer: ServerInfo;\n queryOptions?: MastraQueryOptions<Record<string, SdkMcpToolInfo>, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', selectedServer?.id],\n queryFn: async () => {\n const response = await client.getMcpServerTools(selectedServer?.id);\n const fetchedToolsArray: SdkMcpToolInfo[] = response.tools;\n const transformedTools: Record<string, SdkMcpToolInfo> = {};\n fetchedToolsArray.forEach((sdkToolInfo: SdkMcpToolInfo) => {\n transformedTools[sdkToolInfo.name] = sdkToolInfo;\n });\n\n return transformedTools;\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolsById = Record<string, Awaited<ReturnType<MastraClient['getMcpServerTools']>>['tools'][number]>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerToolsById = <TData = MCPServerToolsById>({\n serverId,\n queryOptions,\n}: {\n serverId: string | null;\n queryOptions?: MastraQueryOptions<MCPServerToolsById, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', serverId],\n queryFn: async (): Promise<MCPServerToolsById> => {\n const response = await client.getMcpServerTools(serverId!);\n return Object.fromEntries(response.tools.map(tool => [tool.name, tool]));\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { McpServerListResponse } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServers = <TData = McpServerListResponse['servers']>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<McpServerListResponse['servers'], TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-servers'],\n queryFn: async () => {\n const mcpServers: McpServerListResponse['servers'] = (await client.getMcpServers(requestContext)).servers;\n return mcpServers;\n },\n ...queryOptions,\n });\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\ninterface McpTool {\n name: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n}\n\nexport interface TryConnectResult {\n tools: McpTool[];\n}\n\nasync function parseResponse(response: Response): Promise<unknown> {\n const contentType = response.headers.get('content-type') ?? '';\n\n if (contentType.includes('text/event-stream')) {\n const text = await response.text();\n const lines = text.split('\\n');\n\n for (const line of lines) {\n if (line.startsWith('data:')) {\n const data = line.slice('data:'.length).trim();\n if (data) {\n return JSON.parse(data);\n }\n }\n }\n\n throw new Error('No data found in SSE response');\n }\n\n return response.json();\n}\n\nasync function connectAndListTools(url: string, clientHeaders?: Record<string, string>): Promise<TryConnectResult> {\n const baseHeaders: Record<string, string> = {\n ...clientHeaders,\n 'Content-Type': 'application/json',\n Accept: 'application/json, text/event-stream',\n };\n\n // Step 1: Initialize\n const initResponse = await fetch(url, {\n method: 'POST',\n headers: baseHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'initialize',\n params: {\n protocolVersion: '2025-03-26',\n capabilities: {},\n clientInfo: { name: 'mastra-playground', version: '1.0.0' },\n },\n }),\n });\n\n if (!initResponse.ok) {\n throw new Error(`Initialize failed: ${initResponse.status} ${initResponse.statusText}`);\n }\n\n const sessionId = initResponse.headers.get('Mcp-Session-Id');\n await parseResponse(initResponse);\n\n const sessionHeaders: Record<string, string> = {\n ...baseHeaders,\n };\n if (sessionId) {\n sessionHeaders['Mcp-Session-Id'] = sessionId;\n }\n\n // Step 2: Send initialized notification\n await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n method: 'notifications/initialized',\n }),\n });\n\n // Step 3: List tools\n const toolsResponse = await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 2,\n method: 'tools/list',\n }),\n });\n\n if (!toolsResponse.ok) {\n throw new Error(`tools/list failed: ${toolsResponse.status} ${toolsResponse.statusText}`);\n }\n\n const toolsResult = (await parseResponse(toolsResponse)) as { result?: { tools?: McpTool[] } };\n\n return {\n tools: toolsResult.result?.tools ?? [],\n };\n}\n\nexport const useTryConnectMcp = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<TryConnectResult, string> } = {}) => {\n const client = useMastraClient();\n const clientHeaders = (client.options?.headers as Record<string, string>) ?? {};\n\n return useMutation({\n mutationFn: (url: string) => connectAndListTools(url, clientHeaders),\n ...queryOptions,\n });\n};\n\nexport type TryConnectMcpMutation = ReturnType<typeof useTryConnectMcp>;\n"],"mappings":";;;;;;;;;;;;AAqBA,SAAgB,eAAuD,EACrE,iBACgF,CAAC,GAAiC;CAClH,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,CAAC,eAAe;EAC1B,SAAS,YAAY;GACnB,MAAM,MAAsC,CAAC;GAE7C,MAAM,EAAE,YAAY,MAAM,OAAO,cAAc;GAC/C,IAAI,CAAC,SAAS,QAAQ,OAAO;GAE7B,MAAM,UAAU,MAAM,QAAQ,WAC5B,QAAQ,IAAI,OAAM,WAAU;IAC1B,MAAM,EAAE,UAAU,MAAM,OAAO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AQ;CACV;CAGA,MAAM,eAAe,MAAM,MAAM,KAAK;EACpC,QAAQ;EACR,SAAS;EACT,aAAa;EACb,MAAM,KAAK,UAAU;GACnB,SAAS;GACT,IAAI;GACJ,QAAQ;GACR,QAAQ;IACN,iBAAiB;IACjB,cAAc,CAAC;IACf,YAAY;KAAE,MAAM;KAAqB,SAAS;IAAQ;GAC5D;EACF,CAAC;CACH,CAAC;CAED,IAAI,CAAC,aAAa,IAChB,MAAM,IAAI,MAAM,sBAAsB,aAAa,OAAO,GAAG,aAAa,YAAY;CAGxF,MAAM,YAAY,aAAa,QAAQ,IAAI,gBAAgB;CAC3D,MAAM,cAAc,YAAY;CAEhC,MAAM,iBAAyC,EAC7C,GAAG,YACL;CACA,IAAI,WACF,eAAe,oBAAoB;CAIrC,MAAM,MAAM,KAAK;EACf,QAAQ;EACR,SAAS;EACT,aAAa;EACb,MAAM,KAAK,UAAU;GACnB,SAAS;GACT,QAAQ;EACV,CAAC;CACH,CAAC;CAGD,MAAM,gBAAgB,MAAM,MAAM,KAAK;EACrC,QAAQ;EACR,SAAS;EACT,aAAa;EACb,MAAM,KAAK,UAAU;GACnB,SAAS;GACT,IAAI;GACJ,QAAQ;EACV,CAAC;CACH,CAAC;CAED,IAAI,CAAC,cAAc,IACjB,MAAM,IAAI,MAAM,sBAAsB,cAAc,OAAO,GAAG,cAAc,YAAY;CAK1F,OAAO,EACL,QAAO,MAHkB,cAAc,aAAa,EAAA,CAGjC,QAAQ,SAAS,CAAC,EACvC;AACF;AAEA,MAAa,oBAAoB,EAC/B,iBACsE,CAAC,MAAM;CAE7E,MAAM,gBADS,gBACa,CAAC,CAAC,SAAS,WAAsC,CAAC;CAE9E,OAAO,YAAY;EACjB,aAAa,QAAgB,oBAAoB,KAAK,aAAa;EACnE,GAAG;CACL,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/mcps/use-mcp-app-html.ts","../../../src/hooks/mcps/use-mcp-app-tools.ts","../../../src/hooks/mcps/use-mcp-server-tool.ts","../../../src/hooks/mcps/use-mcp-server-tools.ts","../../../src/hooks/mcps/use-mcp-server-tools-by-id.ts","../../../src/hooks/mcps/use-mcp-servers.ts","../../../src/hooks/mcps/use-try-connect-mcp.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport { useQuery } from '@tanstack/react-query';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\n/** The app HTML, or `null` when the resource has no text. */\ntype McpAppHtml = string | null;\n\nexport type ReadMcpServerResourceResponse = Awaited<ReturnType<MastraClient['readMcpServerResource']>>;\n\n/**\n * The HTML of an MCP tool's `ui://` app resource (from the tool's `_meta`), for rendering the tool's own UI.\n * Skips the fetch when the tool has no app resource.\n */\nexport const useMcpAppHtml = <TData = McpAppHtml>({\n serverId,\n appResourceUri,\n queryOptions,\n}: {\n serverId: string;\n appResourceUri?: string;\n queryOptions?: MastraQueryOptions<McpAppHtml, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-resource', serverId, appResourceUri],\n queryFn: async () => {\n if (!appResourceUri) return null;\n const response = await client.readMcpServerResource(serverId, appResourceUri);\n return response.contents[0]?.text ?? null;\n },\n enabled: appResourceUri !== undefined,\n ...queryOptions,\n });\n};\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport interface McpAppToolInfo {\n serverId: string;\n toolId: string;\n toolName: string;\n resourceUri: string;\n}\n\n/**\n * Builds a map of tool names → MCP App info for tools across all registered\n * MCP servers that have `_meta.ui.resourceUri` (i.e., tools with interactive\n * MCP App UIs).\n *\n * For each app tool, entries are created under both the original tool name\n * and the namespaced name (`${serverId}_${toolName}`) so that agent tools\n * sourced via `MCPClient.listTools()` (which namespaces) can be resolved.\n */\nexport function useMcpAppTools<TData = Record<string, McpAppToolInfo>>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<Record<string, McpAppToolInfo>, TData> } = {}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-tools'],\n queryFn: async () => {\n const map: Record<string, McpAppToolInfo> = {};\n\n const { servers } = await client.getMcpServers();\n if (!servers?.length) return map;\n\n const results = await Promise.allSettled(\n servers.map(async server => {\n const { tools } = await client.getMcpServerTools(server.id);\n return { serverId: server.id, tools };\n }),\n );\n\n for (const result of results) {\n if (result.status !== 'fulfilled') continue;\n const { serverId, tools } = result.value;\n for (const tool of tools) {\n const meta = tool._meta as { ui?: { resourceUri?: string } } | undefined;\n const resourceUri = meta?.ui?.resourceUri;\n if (resourceUri) {\n const toolId = tool.name;\n const info: McpAppToolInfo = { serverId, toolId, toolName: tool.name, resourceUri };\n map[toolId] = info;\n if (tool.name !== toolId) {\n map[tool.name] = info;\n }\n // Also map the namespaced name used by MCPClient.listTools()\n map[`${serverId}_${tool.name}`] = info;\n }\n }\n }\n\n return map;\n },\n staleTime: 60_000,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolDetails = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['details']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerTool = <TData = MCPServerToolDetails>({\n serverId,\n toolId,\n requestContext,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MCPServerToolDetails, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-server-tool', serverId, toolId],\n queryFn: () => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.details(requestContext);\n },\n ...queryOptions,\n });\n};\n\nexport type ExecuteMCPToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['execute']>>;\ntype ExecuteMCPToolVariables = { data: any; requestContext?: Record<string, any> };\n\nexport const useExecuteMCPTool = ({\n serverId,\n toolId,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n queryOptions?: MastraMutationOptions<ExecuteMCPToolResponse, ExecuteMCPToolVariables>;\n}): UseMutationResult<ExecuteMCPToolResponse, Error, ExecuteMCPToolVariables> => {\n const client = useMastraClient();\n\n return useMutation({\n mutationFn: ({ data, requestContext }: ExecuteMCPToolVariables) => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.execute({ data, requestContext: requestContext as RequestContext });\n },\n ...queryOptions,\n });\n};\n","import type { McpToolInfo as SdkMcpToolInfo } from '@mastra/client-js';\nimport type { ServerInfo } from '@mastra/core/mcp';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServerTools = <TData = Record<string, SdkMcpToolInfo>>({\n selectedServer,\n queryOptions,\n}: {\n selectedServer: ServerInfo;\n queryOptions?: MastraQueryOptions<Record<string, SdkMcpToolInfo>, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', selectedServer?.id],\n queryFn: async () => {\n const response = await client.getMcpServerTools(selectedServer?.id);\n const fetchedToolsArray: SdkMcpToolInfo[] = response.tools;\n const transformedTools: Record<string, SdkMcpToolInfo> = {};\n fetchedToolsArray.forEach((sdkToolInfo: SdkMcpToolInfo) => {\n transformedTools[sdkToolInfo.name] = sdkToolInfo;\n });\n\n return transformedTools;\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolsById = Record<string, Awaited<ReturnType<MastraClient['getMcpServerTools']>>['tools'][number]>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerToolsById = <TData = MCPServerToolsById>({\n serverId,\n queryOptions,\n}: {\n serverId: string | null;\n queryOptions?: MastraQueryOptions<MCPServerToolsById, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', serverId],\n queryFn: async (): Promise<MCPServerToolsById> => {\n const response = await client.getMcpServerTools(serverId!);\n return Object.fromEntries(response.tools.map(tool => [tool.name, tool]));\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { McpServerListResponse } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const useMCPServers = <TData = McpServerListResponse['servers']>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<McpServerListResponse['servers'], TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-servers'],\n queryFn: async () => {\n const mcpServers: McpServerListResponse['servers'] = (await client.getMcpServers(requestContext)).servers;\n return mcpServers;\n },\n ...queryOptions,\n });\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\ninterface McpTool {\n name: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n}\n\nexport interface TryConnectResult {\n tools: McpTool[];\n}\n\nasync function parseResponse(response: Response): Promise<unknown> {\n const contentType = response.headers.get('content-type') ?? '';\n\n if (contentType.includes('text/event-stream')) {\n const text = await response.text();\n const lines = text.split('\\n');\n\n for (const line of lines) {\n if (line.startsWith('data:')) {\n const data = line.slice('data:'.length).trim();\n if (data) {\n return JSON.parse(data);\n }\n }\n }\n\n throw new Error('No data found in SSE response');\n }\n\n return response.json();\n}\n\nasync function connectAndListTools(url: string, clientHeaders?: Record<string, string>): Promise<TryConnectResult> {\n const baseHeaders: Record<string, string> = {\n ...clientHeaders,\n 'Content-Type': 'application/json',\n Accept: 'application/json, text/event-stream',\n };\n\n // Step 1: Initialize\n const initResponse = await fetch(url, {\n method: 'POST',\n headers: baseHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'initialize',\n params: {\n protocolVersion: '2025-03-26',\n capabilities: {},\n clientInfo: { name: 'mastra-playground', version: '1.0.0' },\n },\n }),\n });\n\n if (!initResponse.ok) {\n throw new Error(`Initialize failed: ${initResponse.status} ${initResponse.statusText}`);\n }\n\n const sessionId = initResponse.headers.get('Mcp-Session-Id');\n await parseResponse(initResponse);\n\n const sessionHeaders: Record<string, string> = {\n ...baseHeaders,\n };\n if (sessionId) {\n sessionHeaders['Mcp-Session-Id'] = sessionId;\n }\n\n // Step 2: Send initialized notification\n await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n method: 'notifications/initialized',\n }),\n });\n\n // Step 3: List tools\n const toolsResponse = await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 2,\n method: 'tools/list',\n }),\n });\n\n if (!toolsResponse.ok) {\n throw new Error(`tools/list failed: ${toolsResponse.status} ${toolsResponse.statusText}`);\n }\n\n const toolsResult = (await parseResponse(toolsResponse)) as { result?: { tools?: McpTool[] } };\n\n return {\n tools: toolsResult.result?.tools ?? [],\n };\n}\n\nexport const useTryConnectMcp = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<TryConnectResult, string> } = {}) => {\n const client = useMastraClient();\n const clientHeaders = (client.options?.headers as Record<string, string>) ?? {};\n\n return useMutation({\n mutationFn: (url: string) => connectAndListTools(url, clientHeaders),\n ...queryOptions,\n });\n};\n\nexport type TryConnectMcpMutation = ReturnType<typeof useTryConnectMcp>;\n"],"mappings":";;;;;;;AAeA,MAAa,iBAAqC,EAChD,UACA,gBACA,mBAKkC;CAClC,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU;GAAC;GAAoB;GAAU;EAAc;EACvD,SAAS,YAAY;GACnB,IAAI,CAAC,gBAAgB,OAAO;GAE5B,QAAO,MADgB,OAAO,sBAAsB,UAAU,cAAc,EAAA,CAC5D,SAAS,EAAE,EAAE,QAAQ;EACvC;EACA,SAAS,mBAAmB,KAAA;EAC5B,GAAG;CACL,CAAC;AACH;;;;;;;;;;;;ACfA,SAAgB,eAAuD,EACrE,iBACgF,CAAC,GAAiC;CAClH,MAAM,SAAS,gBAAgB;CAE/B,OAAO,SAAS;EACd,UAAU,CAAC,eAAe;EAC1B,SAAS,YAAY;GACnB,MAAM,MAAsC,CAAC;GAE7C,MAAM,EAAE,YAAY,MAAM,OAAO,cAAc;GAC/C,IAAI,CAAC,SAAS,QAAQ,OAAO;GAE7B,MAAM,UAAU,MAAM,QAAQ,WAC5B,QAAQ,IAAI,OAAM,WAAU;IAC1B,MAAM,EAAE,UAAU,MAAM,OAAO,kBAAkB,OAAO,EAAE;IAC1D,OAAO;KAAE,UAAU,OAAO;KAAI;IAAM;GACtC,CAAC,CACH;GAEA,KAAK,MAAM,UAAU,SAAS;IAC5B,IAAI,OAAO,WAAW,aAAa;IACnC,MAAM,EAAE,UAAU,UAAU,OAAO;IACnC,KAAK,M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;KAAE,MAAM;KAAqB,SAAS;IAAQ;GAC5D;EACF,CAAC;CACH,CAAC;CAED,IAAI,CAAC,aAAa,IAChB,MAAM,IAAI,MAAM,sBAAsB,aAAa,OAAO,GAAG,aAAa,YAAY;CAGxF,MAAM,YAAY,aAAa,QAAQ,IAAI,gBAAgB;CAC3D,MAAM,cAAc,YAAY;CAEhC,MAAM,iBAAyC,EAC7C,GAAG,YACL;CACA,IAAI,WACF,eAAe,oBAAoB;CAIrC,MAAM,MAAM,KAAK;EACf,QAAQ;EACR,SAAS;EACT,aAAa;EACb,MAAM,KAAK,UAAU;GACnB,SAAS;GACT,QAAQ;EACV,CAAC;CACH,CAAC;CAGD,MAAM,gBAAgB,MAAM,MAAM,KAAK;EACrC,QAAQ;EACR,SAAS;EACT,aAAa;EACb,MAAM,KAAK,UAAU;GACnB,SAAS;GACT,IAAI;GACJ,QAAQ;EACV,CAAC;CACH,CAAC;CAED,IAAI,CAAC,cAAc,IACjB,MAAM,IAAI,MAAM,sBAAsB,cAAc,OAAO,GAAG,cAAc,YAAY;CAK1F,OAAO,EACL,QAAO,MAHkB,cAAc,aAAa,EAAA,CAGjC,QAAQ,SAAS,CAAC,EACvC;AACF;AAEA,MAAa,oBAAoB,EAC/B,iBACsE,CAAC,MAAM;CAE7E,MAAM,gBADS,gBACa,CAAC,CAAC,SAAS,WAAsC,CAAC;CAE9E,OAAO,YAAY;EACjB,aAAa,QAAgB,oBAAoB,KAAK,aAAa;EACnE,GAAG;CACL,CAAC;AACH"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MastraClient } from '@mastra/client-js';
|
|
2
|
+
import type { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { MastraQueryOptions } from '../shared/query-options.js';
|
|
4
|
+
/** The app HTML, or `null` when the resource has no text. */
|
|
5
|
+
type McpAppHtml = string | null;
|
|
6
|
+
export type ReadMcpServerResourceResponse = Awaited<ReturnType<MastraClient['readMcpServerResource']>>;
|
|
7
|
+
/**
|
|
8
|
+
* The HTML of an MCP tool's `ui://` app resource (from the tool's `_meta`), for rendering the tool's own UI.
|
|
9
|
+
* Skips the fetch when the tool has no app resource.
|
|
10
|
+
*/
|
|
11
|
+
export declare const useMcpAppHtml: <TData = McpAppHtml>({ serverId, appResourceUri, queryOptions, }: {
|
|
12
|
+
serverId: string;
|
|
13
|
+
appResourceUri?: string;
|
|
14
|
+
queryOptions?: MastraQueryOptions<McpAppHtml, TData>;
|
|
15
|
+
}) => UseQueryResult<TData, Error>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=use-mcp-app-html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-mcp-app-html.d.ts","sourceRoot":"","sources":["../../../src/hooks/mcps/use-mcp-app-html.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,6DAA6D;AAC7D,KAAK,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC;AAEhC,MAAM,MAAM,6BAA6B,GAAG,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;AAEvG;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,GAAG,UAAU,+CAI7C;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;CACtD,KAAG,cAAc,CAAC,KAAK,EAAE,KAAK,CAa9B,CAAC"}
|
|
@@ -445,21 +445,27 @@ function useModelUsageCostMetrics(params) {
|
|
|
445
445
|
"mastra_model_input_cache_write_tokens"
|
|
446
446
|
].map((name) => client.getMetricBreakdown({
|
|
447
447
|
name: [name],
|
|
448
|
-
groupBy: ["model"],
|
|
448
|
+
groupBy: ["model", "provider"],
|
|
449
449
|
aggregation: "sum",
|
|
450
450
|
orderDirection: "DESC",
|
|
451
451
|
filters
|
|
452
452
|
})));
|
|
453
453
|
if (!inputRes || !outputRes || !cacheReadRes || !cacheWriteRes) return [];
|
|
454
454
|
const modelMap = /* @__PURE__ */ new Map();
|
|
455
|
-
const ensureModel = (
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
455
|
+
const ensureModel = (dimensions) => {
|
|
456
|
+
const model = dimensions.model ?? "unknown";
|
|
457
|
+
const provider = dimensions.provider ?? void 0;
|
|
458
|
+
return require_map.getOrCreate(modelMap, `${model}\u0000${provider ?? ""}`, () => ({
|
|
459
|
+
model,
|
|
460
|
+
provider,
|
|
461
|
+
input: 0,
|
|
462
|
+
output: 0,
|
|
463
|
+
cacheRead: 0,
|
|
464
|
+
cacheWrite: 0,
|
|
465
|
+
cost: null,
|
|
466
|
+
costUnit: null
|
|
467
|
+
}));
|
|
468
|
+
};
|
|
463
469
|
const addCost = (entry, group) => {
|
|
464
470
|
if (group.estimatedCost != null) {
|
|
465
471
|
entry.cost = (entry.cost ?? 0) + group.estimatedCost;
|
|
@@ -467,32 +473,33 @@ function useModelUsageCostMetrics(params) {
|
|
|
467
473
|
}
|
|
468
474
|
};
|
|
469
475
|
for (const group of inputRes.groups) {
|
|
470
|
-
const entry = ensureModel(group.dimensions
|
|
476
|
+
const entry = ensureModel(group.dimensions);
|
|
471
477
|
entry.input = group.value;
|
|
472
478
|
addCost(entry, group);
|
|
473
479
|
}
|
|
474
480
|
for (const group of outputRes.groups) {
|
|
475
|
-
const entry = ensureModel(group.dimensions
|
|
481
|
+
const entry = ensureModel(group.dimensions);
|
|
476
482
|
entry.output = group.value;
|
|
477
483
|
addCost(entry, group);
|
|
478
484
|
}
|
|
479
485
|
for (const group of cacheReadRes.groups) {
|
|
480
|
-
const entry = ensureModel(group.dimensions
|
|
486
|
+
const entry = ensureModel(group.dimensions);
|
|
481
487
|
entry.cacheRead = group.value;
|
|
482
488
|
}
|
|
483
489
|
for (const group of cacheWriteRes.groups) {
|
|
484
|
-
const entry = ensureModel(group.dimensions
|
|
490
|
+
const entry = ensureModel(group.dimensions);
|
|
485
491
|
entry.cacheWrite = group.value;
|
|
486
492
|
}
|
|
487
|
-
return Array.from(modelMap.
|
|
488
|
-
model,
|
|
493
|
+
return Array.from(modelMap.values()).map((vals) => ({
|
|
494
|
+
model: vals.model,
|
|
495
|
+
...vals.provider ? { provider: vals.provider } : {},
|
|
489
496
|
input: formatCompactNumber(vals.input),
|
|
490
497
|
output: formatCompactNumber(vals.output),
|
|
491
498
|
cacheRead: formatCompactNumber(vals.cacheRead),
|
|
492
499
|
cacheWrite: formatCompactNumber(vals.cacheWrite),
|
|
493
500
|
cost: vals.cost,
|
|
494
501
|
costUnit: vals.costUnit
|
|
495
|
-
})).sort((a, b) => a.model.localeCompare(b.model));
|
|
502
|
+
})).sort((a, b) => a.model.localeCompare(b.model) || (a.provider ?? "").localeCompare(b.provider ?? ""));
|
|
496
503
|
},
|
|
497
504
|
...queryOptions
|
|
498
505
|
});
|