@tambo-ai/react 0.73.0 → 0.73.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/mcp/mcp-hooks.d.ts +4 -0
- package/dist/mcp/mcp-hooks.d.ts.map +1 -1
- package/dist/mcp/mcp-hooks.js +4 -0
- package/dist/mcp/mcp-hooks.js.map +1 -1
- package/dist/providers/tambo-provider.d.ts +3 -0
- package/dist/providers/tambo-provider.d.ts.map +1 -1
- package/dist/providers/tambo-provider.js +3 -0
- package/dist/providers/tambo-provider.js.map +1 -1
- package/dist/util/resource-content-resolver.d.ts.map +1 -1
- package/dist/util/resource-content-resolver.js +2 -0
- package/dist/util/resource-content-resolver.js.map +1 -1
- package/esm/mcp/mcp-hooks.d.ts +4 -0
- package/esm/mcp/mcp-hooks.d.ts.map +1 -1
- package/esm/mcp/mcp-hooks.js +4 -0
- package/esm/mcp/mcp-hooks.js.map +1 -1
- package/esm/providers/tambo-provider.d.ts +3 -0
- package/esm/providers/tambo-provider.d.ts.map +1 -1
- package/esm/providers/tambo-provider.js +3 -0
- package/esm/providers/tambo-provider.js.map +1 -1
- package/esm/util/resource-content-resolver.d.ts.map +1 -1
- package/esm/util/resource-content-resolver.js +2 -0
- package/esm/util/resource-content-resolver.js.map +1 -1
- package/package.json +1 -1
package/dist/mcp/mcp-hooks.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface McpResourceEntry {
|
|
|
29
29
|
export type ListResourceEntry = RegistryResourceEntry | McpResourceEntry;
|
|
30
30
|
/**
|
|
31
31
|
* Type guard for narrowing a `ListResourceEntry` to an MCP-backed resource.
|
|
32
|
+
* @param entry - The resource entry to check
|
|
33
|
+
* @returns True if the entry is from an MCP server, false if it's from the registry
|
|
32
34
|
*/
|
|
33
35
|
export declare function isMcpResourceEntry(entry: ListResourceEntry): entry is McpResourceEntry;
|
|
34
36
|
/**
|
|
@@ -73,6 +75,8 @@ export declare function useTamboMcpPromptList(search?: string): {
|
|
|
73
75
|
/**
|
|
74
76
|
* Type guard for narrowing McpServer to ConnectedMcpServer.
|
|
75
77
|
* A connected server has a non-null client.
|
|
78
|
+
* @param server - The MCP server to check
|
|
79
|
+
* @returns True if the server is connected, false otherwise
|
|
76
80
|
*/
|
|
77
81
|
export declare function isConnectedMcpServer(server: McpServer): server is ConnectedMcpServer;
|
|
78
82
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-hooks.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EAEzB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAKvD,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,SAAS,EAEf,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAClE,MAAM,WAAW,eAAe;IAE9B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,IAAI,CAAC;IACb,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,qBAAqB,GAAG,gBAAgB,CAAC;AAoBzE
|
|
1
|
+
{"version":3,"file":"mcp-hooks.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,E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GAKG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0ClC;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,CAAC,EAAE,MAAM;;WArH9C,KAAK,GAAG,IAAI;YACX,KAAK,EAAE;eACJ,OAAO;eACP,OAAO;aACT,OAAO;cACN,OAAO;kBACH,OAAO;gBACT,OAAO;eACR,OAAO;aACT,MAAM,OAAO,CAAC,IAAI,CAAC;EAwO7B;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;;;;;;;;;;;;;;;;;;;;;;;;iBAoElE"}
|
package/dist/mcp/mcp-hooks.js
CHANGED
|
@@ -53,6 +53,8 @@ function toPublicResourceEntry(entry) {
|
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Type guard for narrowing a `ListResourceEntry` to an MCP-backed resource.
|
|
56
|
+
* @param entry - The resource entry to check
|
|
57
|
+
* @returns True if the entry is from an MCP server, false if it's from the registry
|
|
56
58
|
*/
|
|
57
59
|
function isMcpResourceEntry(entry) {
|
|
58
60
|
return entry.server !== null && isConnectedMcpServer(entry.server);
|
|
@@ -146,6 +148,8 @@ function combineArrayResults(results) {
|
|
|
146
148
|
/**
|
|
147
149
|
* Type guard for narrowing McpServer to ConnectedMcpServer.
|
|
148
150
|
* A connected server has a non-null client.
|
|
151
|
+
* @param server - The MCP server to check
|
|
152
|
+
* @returns True if the server is connected, false otherwise
|
|
149
153
|
*/
|
|
150
154
|
function isConnectedMcpServer(server) {
|
|
151
155
|
return "client" in server && server.client != null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-hoo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AAC,mBAAmB,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,oDAAoD;YACpD,IAAI,cAAc,IAAI,CAAC,kBAAkB,IAAI,iBAAiB,CAAC,EAAE,CAAC;gBAChE,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;gBACrE,OAAO,MAAM,IAAI,IAAI,CAAC;YACxB,CAAC;YAED,+BAA+B;YAC/B,IAAI,SAAS,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;gBACjD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;oBACxD,GAAG,EAAE,mBAAmB;iBACzB,CAAC,CAAC;gBACH,OAAO,MAAM,IAAI,IAAI,CAAC;YACxB,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n GetPromptResult,\n type ListPromptsResult,\n type ListResourcesResult,\n type ReadResourceResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { UseQueryResult } from \"@tanstack/react-query\";\nimport * as React from \"react\";\nimport { useTamboQueries, useTamboQuery } from \"../hooks\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { REGISTRY_SERVER_KEY } from \"./mcp-constants\";\nimport {\n type ConnectedMcpServer,\n type McpServer,\n useTamboMcpServers,\n} from \"./tambo-mcp-provider\";\n\nexport type ListPromptItem = ListPromptsResult[\"prompts\"][number];\nexport interface ListPromptEntry {\n // Only connected servers produce prompt entries, so expose the connected type\n server: ConnectedMcpServer;\n prompt: ListPromptItem;\n}\n\nexport type ListResourceItem = ListResourcesResult[\"resources\"][number];\n\n/**\n * Registry resource entry - resources from the local registry (not MCP servers).\n *\n * These entries always have `server === null`.\n */\nexport interface RegistryResourceEntry {\n server: null;\n resource: ListResourceItem;\n}\n\n/**\n * MCP server resource entry - resources from connected MCP servers.\n */\nexport interface McpResourceEntry {\n server: ConnectedMcpServer;\n resource: ListResourceItem;\n}\n\n/**\n * Union type for all resource entries returned by `useTamboMcpResourceList`.\n */\nexport type ListResourceEntry = RegistryResourceEntry | McpResourceEntry;\n\ntype InternalRegistryResourceEntry = RegistryResourceEntry & {\n isDynamic: boolean;\n};\n\ntype InternalListResourceEntry =\n | McpResourceEntry\n | InternalRegistryResourceEntry;\n\nfunction toPublicResourceEntry(\n entry: InternalListResourceEntry,\n): ListResourceEntry {\n if (entry.server === null) {\n const { isDynamic: _isDynamic, ...publicEntry } = entry;\n return publicEntry;\n }\n return entry;\n}\n\n/**\n * Type guard for narrowing a `ListResourceEntry` to an MCP-backed resource.\n */\nexport function isMcpResourceEntry(\n entry: ListResourceEntry,\n): entry is McpResourceEntry {\n return entry.server !== null && isConnectedMcpServer(entry.server);\n}\n\n/**\n * Hook to get the prompts for all the registered MCP servers.\n * @param search - Optional search string to filter prompts by name (case-insensitive).\n * @returns The prompts for the MCP servers, including the server that the prompt was found on.\n */\nexport function useTamboMcpPromptList(search?: string) {\n const mcpServers = useTamboMcpServers();\n\n const queries = useTamboQueries({\n queries: mcpServers.map((mcpServer) => ({\n // search is NOT in queryKey - we filter locally after fetching\n queryKey: [\"mcp-prompts\", mcpServer.key],\n // Only run for connected servers that have a client\n enabled: isConnectedMcpServer(mcpServer),\n queryFn: async (): Promise<ListPromptEntry[]> => {\n // Fast path: if this server doesn't have a client, skip work\n if (!isConnectedMcpServer(mcpServer)) return [];\n\n const result = await mcpServer.client.client.listPrompts();\n const prompts: ListPromptItem[] = result?.prompts ?? [];\n // Return prompts without prefixes - we'll apply prefixing in combine\n const promptsEntries = prompts.map((prompt) => ({\n server: mcpServer,\n prompt,\n }));\n return promptsEntries;\n },\n })),\n combine: (results) => {\n const combined = combineArrayResults(results);\n\n // Always apply serverKey prefix to MCP prompts (breaking change for consistency with resources)\n // This ensures clear separation between local and remote prompts\n return {\n ...combined,\n data: combined.data.map((entry) => ({\n ...entry,\n prompt: {\n ...entry.prompt,\n name: `${entry.server.serverKey}:${entry.prompt.name}`,\n },\n })),\n };\n },\n });\n\n // Filter results by search string - runs on every search change (not just query completion)\n const filteredData = React.useMemo(() => {\n if (!search) return queries.data;\n\n const normalizedSearch = search.toLowerCase();\n return queries.data.filter((entry) => {\n const name = entry.prompt.name?.toLowerCase() ?? \"\";\n return name.includes(normalizedSearch);\n });\n }, [queries.data, search]);\n\n return {\n ...queries,\n data: filteredData,\n };\n}\n// TODO: find a more general place for this\nfunction combineArrayResults<T>(results: UseQueryResult<T[]>[]): {\n data: T[];\n error: Error | null;\n errors: Error[];\n isPending: boolean;\n isSuccess: boolean;\n isError: boolean;\n isPaused: boolean;\n isRefetching: boolean;\n isFetching: boolean;\n isLoading: boolean;\n refetch: () => Promise<void>;\n} {\n const errors = results\n .filter((result) => result.isError)\n .map((result) => result.error);\n\n // Treat queries that are idle (disabled) as non-blocking for aggregate status\n const enabledish = results.filter(\n (r) => r.fetchStatus !== \"idle\" || r.isSuccess || r.isError,\n );\n\n return {\n // Prefer flatMap to avoid extra intermediate arrays\n data: results.flatMap((result) =>\n result.isSuccess && Array.isArray(result.data) ? result.data : [],\n ),\n // Preserve a single error for compatibility and expose the full list for diagnostics\n error: errors[0] ?? null,\n errors,\n isPending: enabledish.some((result) => result.isPending),\n isSuccess:\n enabledish.length > 0 && enabledish.every((result) => result.isSuccess),\n isError: errors.length > 0,\n isPaused: enabledish.some((result) => result.isPaused),\n isRefetching: enabledish.some((result) => result.isRefetching),\n isFetching: enabledish.some((result) => result.isFetching),\n isLoading: enabledish.some((result) => result.isLoading),\n // Aggregate refetch to trigger all underlying queries\n refetch: async () => {\n await Promise.all(\n results.map(async (r) => {\n await r.refetch();\n }),\n );\n },\n };\n}\n\n/**\n * Type guard for narrowing McpServer to ConnectedMcpServer.\n * A connected server has a non-null client.\n */\nexport function isConnectedMcpServer(\n server: McpServer,\n): server is ConnectedMcpServer {\n return \"client\" in server && server.client != null;\n}\n\n/**\n * Hook to get the prompt for the specified name.\n * @param promptName - The name of the prompt to get. Can be prefixed with serverKey (e.g., \"linear:issue\") or unprefixed.\n * @param args - The arguments to pass to the prompt.\n * @returns The prompt for the specified name.\n */\nexport function useTamboMcpPrompt(\n promptName: string | undefined,\n args: Record<string, string> = {},\n) {\n // figure out which server has the prompt\n const { data: promptEntries } = useTamboMcpPromptList();\n const promptEntry = promptEntries?.find(\n (prompt) => prompt.prompt.name === promptName,\n );\n // Use the stable server key (and the server instance itself) instead of brittle\n // name/url/transport matching.\n const mcpServer = promptEntry?.server;\n\n // Strip the prefix to get the original prompt name for the MCP server call\n const originalPromptName = promptName?.includes(\":\")\n ? promptName.split(\":\").slice(1).join(\":\")\n : promptName;\n\n // Canonicalize args to avoid unstable cache keys from object identity/order\n const sortedArgsEntries = Object.keys(args)\n .sort()\n .map((k) => [k, args[k]] as const);\n return useTamboQuery({\n // Include server identity and sorted args to prevent stale cache hits\n queryKey: [\"mcp-prompt\", promptName, mcpServer?.key, sortedArgsEntries],\n // Only run when we have a prompt name and a connected server\n enabled: Boolean(\n promptName && mcpServer && isConnectedMcpServer(mcpServer),\n ),\n queryFn: async (): Promise<GetPromptResult | null> => {\n if (\n !originalPromptName ||\n !mcpServer ||\n !isConnectedMcpServer(mcpServer)\n ) {\n return null;\n }\n const result = await mcpServer.client.client.getPrompt({\n name: originalPromptName,\n arguments: args,\n });\n return result ?? null; // return null because react-query doesn't like undefined results\n },\n });\n}\n\n/**\n * Hook to get the resources for all the registered MCP servers and registry.\n * @param search - Optional search string. For MCP servers, results are filtered locally after fetching.\n * For registry dynamic sources, the search is passed to listResources(search) for dynamic generation.\n * @returns The resources from MCP servers and the local registry, including the server that the resource was found on (null for registry resources).\n */\nexport function useTamboMcpResourceList(search?: string) {\n const mcpServers = useTamboMcpServers();\n const { resources: staticResources, resourceSource } = useTamboRegistry();\n\n // Build list of queries: MCP servers + optional dynamic resource source\n const queriesToRun = [\n // MCP server queries - search is NOT in queryKey so queries don't re-run on search change\n ...mcpServers.map((mcpServer) => ({\n queryKey: [\"mcp-resources\", mcpServer.key],\n // Only run for connected servers that have a client\n enabled: isConnectedMcpServer(mcpServer),\n queryFn: async (): Promise<McpResourceEntry[]> => {\n // Fast path: if this server doesn't have a client, skip work\n if (!isConnectedMcpServer(mcpServer)) return [];\n\n const result = await mcpServer.client.client.listResources();\n const resources: ListResourceItem[] = result?.resources ?? [];\n // Return resources without prefixes - we'll apply prefixing in combine\n const resourceEntries: McpResourceEntry[] = resources.map(\n (resource) => ({\n server: mcpServer,\n resource,\n }),\n );\n return resourceEntries;\n },\n })),\n // Dynamic resource source query (if exists) - search IS in queryKey to allow dynamic generation\n ...(resourceSource\n ? [\n {\n queryKey: [\"registry-resources\", \"dynamic\", search],\n enabled: true,\n queryFn: async (): Promise<InternalRegistryResourceEntry[]> => {\n if (!resourceSource) return [];\n const resources = await resourceSource.listResources(search);\n return resources.map((resource) => ({\n server: null,\n resource,\n isDynamic: true,\n }));\n },\n },\n ]\n : []),\n ];\n\n const queries = useTamboQueries({\n queries: queriesToRun,\n combine: (results) => {\n // Type assertion needed because queries can return different entry types\n const combined = combineArrayResults(\n results as UseQueryResult<InternalListResourceEntry[]>[],\n );\n\n // Add static registry resources (no query needed)\n const staticEntries: InternalRegistryResourceEntry[] =\n staticResources.map((resource) => ({\n server: null,\n resource,\n isDynamic: false,\n }));\n\n // Merge static resources with query results (registry resources first)\n const allData = [...staticEntries, ...combined.data];\n\n // Apply serverKey prefix to ALL resources for unified @serverKey:uri format\n // Registry resources get REGISTRY_SERVER_KEY prefix, MCP resources get their serverKey\n const prefixedData = allData.map((entry) => {\n if (entry.server === null) {\n // Registry resource - prefix with REGISTRY_SERVER_KEY\n return {\n ...entry,\n resource: {\n ...entry.resource,\n uri: `${REGISTRY_SERVER_KEY}:${entry.resource.uri}`,\n },\n };\n }\n // MCP resource - always prefix with serverKey\n return {\n ...entry,\n resource: {\n ...entry.resource,\n uri: `${entry.server.serverKey}:${entry.resource.uri}`,\n },\n };\n });\n\n return {\n ...combined,\n data: prefixedData,\n };\n },\n });\n\n // Filter results by search string - runs on every search change (not just query completion)\n // - MCP resources are filtered locally\n // - Static registry resources are filtered locally\n // - Dynamic registry resources are already filtered by listResources(search)\n const filteredData = React.useMemo((): InternalListResourceEntry[] => {\n if (!search) return queries.data;\n\n const normalizedSearch = search.toLowerCase();\n return queries.data.filter((entry) => {\n if (entry.server === null && entry.isDynamic) {\n return true;\n }\n\n const name = entry.resource.name?.toLowerCase() ?? \"\";\n const uri = entry.resource.uri.toLowerCase();\n return name.includes(normalizedSearch) || uri.includes(normalizedSearch);\n });\n }, [queries.data, search]);\n\n const publicData = React.useMemo(\n () => filteredData.map(toPublicResourceEntry),\n [filteredData],\n );\n\n return {\n ...queries,\n data: publicData,\n };\n}\n\n/**\n * Hook to get the resource for the specified URI.\n * @param resourceUri - The URI of the resource to get. Must be prefixed:\n * - MCP resources: prefixed with serverKey (e.g., \"linear:file://foo\")\n * - Registry resources: prefixed with \"registry:\" (e.g., \"registry:file://bar\")\n * @returns The resource for the specified URI.\n */\nexport function useTamboMcpResource(resourceUri: string | undefined) {\n const { resourceSource } = useTamboRegistry();\n const { data: resourceEntries } = useTamboMcpResourceList();\n\n // Find which server/source has the resource\n const resourceEntry = resourceEntries?.find(\n (entry) => entry.resource.uri === resourceUri,\n );\n\n // Determine if this is a registry resource or MCP resource\n const isRegistryResource = resourceEntry?.server === null;\n const mcpServer = resourceEntry?.server ?? null;\n\n // Check if the URI has the registry prefix\n const hasRegistryPrefix = Boolean(\n resourceUri?.startsWith(`${REGISTRY_SERVER_KEY}:`),\n );\n\n // Strip the prefix to get the original resource URI for fetching\n let originalResourceUri: string | undefined;\n if (isRegistryResource || hasRegistryPrefix) {\n const prefixLen = REGISTRY_SERVER_KEY.length + 1; // +1 for the colon\n originalResourceUri = resourceUri?.slice(prefixLen);\n } else if (mcpServer) {\n const prefixLen = mcpServer.serverKey.length + 1; // +1 for the colon\n originalResourceUri = resourceUri?.slice(prefixLen);\n }\n\n // Check if we can fetch this resource\n const hasRegistrySource = resourceSource != null;\n const hasConnectedMcpServer =\n mcpServer != null && isConnectedMcpServer(mcpServer);\n const canFetchFromRegistry =\n hasRegistrySource && (isRegistryResource || hasRegistryPrefix);\n const canFetchResource = Boolean(\n resourceUri && (canFetchFromRegistry || hasConnectedMcpServer),\n );\n\n const locationKey =\n isRegistryResource || hasRegistryPrefix\n ? REGISTRY_SERVER_KEY\n : mcpServer?.key;\n\n return useTamboQuery({\n queryKey: [\"resource\", resourceUri, locationKey],\n enabled: canFetchResource,\n queryFn: async (): Promise<ReadResourceResult | null> => {\n if (!originalResourceUri) {\n return null;\n }\n\n // Registry resource: use resourceSource.getResource\n if (resourceSource && (isRegistryResource || hasRegistryPrefix)) {\n const result = await resourceSource.getResource(originalResourceUri);\n return result ?? null;\n }\n\n // MCP resource: use MCP client\n if (mcpServer && isConnectedMcpServer(mcpServer)) {\n const result = await mcpServer.client.client.readResource({\n uri: originalResourceUri,\n });\n return result ?? null;\n }\n\n return null;\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mcp-hooks.js","sourceRoot":"","sources":["../../src/mcp/mcp-hooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,gDAIC;AAOD,sDAwDC;AAyDD,oDAIC;AAQD,8CA4CC;AAQD,0DA4HC;AASD,kDAoEC;AAtcD,6CAA+B;AAC/B,oCAA0D;AAC1D,kFAAwE;AACxE,mDAAsD;AACtD,6DAI8B;AA0C9B,SAAS,qBAAqB,CAC5B,KAAgC;IAEhC,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAC1B,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,WAAW,EAAE,GAAG,KAAK,CAAC;QACxD,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAChC,KAAwB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;QACd,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n GetPromptResult,\n type ListPromptsResult,\n type ListResourcesResult,\n type ReadResourceResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { UseQueryResult } from \"@tanstack/react-query\";\nimport * as React from \"react\";\nimport { useTamboQueries, useTamboQuery } from \"../hooks\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { REGISTRY_SERVER_KEY } from \"./mcp-constants\";\nimport {\n type ConnectedMcpServer,\n type McpServer,\n useTamboMcpServers,\n} from \"./tambo-mcp-provider\";\n\nexport type ListPromptItem = ListPromptsResult[\"prompts\"][number];\nexport interface ListPromptEntry {\n // Only connected servers produce prompt entries, so expose the connected type\n server: ConnectedMcpServer;\n prompt: ListPromptItem;\n}\n\nexport type ListResourceItem = ListResourcesResult[\"resources\"][number];\n\n/**\n * Registry resource entry - resources from the local registry (not MCP servers).\n *\n * These entries always have `server === null`.\n */\nexport interface RegistryResourceEntry {\n server: null;\n resource: ListResourceItem;\n}\n\n/**\n * MCP server resource entry - resources from connected MCP servers.\n */\nexport interface McpResourceEntry {\n server: ConnectedMcpServer;\n resource: ListResourceItem;\n}\n\n/**\n * Union type for all resource entries returned by `useTamboMcpResourceList`.\n */\nexport type ListResourceEntry = RegistryResourceEntry | McpResourceEntry;\n\ntype InternalRegistryResourceEntry = RegistryResourceEntry & {\n isDynamic: boolean;\n};\n\ntype InternalListResourceEntry =\n | McpResourceEntry\n | InternalRegistryResourceEntry;\n\nfunction toPublicResourceEntry(\n entry: InternalListResourceEntry,\n): ListResourceEntry {\n if (entry.server === null) {\n const { isDynamic: _isDynamic, ...publicEntry } = entry;\n return publicEntry;\n }\n return entry;\n}\n\n/**\n * Type guard for narrowing a `ListResourceEntry` to an MCP-backed resource.\n * @param entry - The resource entry to check\n * @returns True if the entry is from an MCP server, false if it's from the registry\n */\nexport function isMcpResourceEntry(\n entry: ListResourceEntry,\n): entry is McpResourceEntry {\n return entry.server !== null && isConnectedMcpServer(entry.server);\n}\n\n/**\n * Hook to get the prompts for all the registered MCP servers.\n * @param search - Optional search string to filter prompts by name (case-insensitive).\n * @returns The prompts for the MCP servers, including the server that the prompt was found on.\n */\nexport function useTamboMcpPromptList(search?: string) {\n const mcpServers = useTamboMcpServers();\n\n const queries = useTamboQueries({\n queries: mcpServers.map((mcpServer) => ({\n // search is NOT in queryKey - we filter locally after fetching\n queryKey: [\"mcp-prompts\", mcpServer.key],\n // Only run for connected servers that have a client\n enabled: isConnectedMcpServer(mcpServer),\n queryFn: async (): Promise<ListPromptEntry[]> => {\n // Fast path: if this server doesn't have a client, skip work\n if (!isConnectedMcpServer(mcpServer)) return [];\n\n const result = await mcpServer.client.client.listPrompts();\n const prompts: ListPromptItem[] = result?.prompts ?? [];\n // Return prompts without prefixes - we'll apply prefixing in combine\n const promptsEntries = prompts.map((prompt) => ({\n server: mcpServer,\n prompt,\n }));\n return promptsEntries;\n },\n })),\n combine: (results) => {\n const combined = combineArrayResults(results);\n\n // Always apply serverKey prefix to MCP prompts (breaking change for consistency with resources)\n // This ensures clear separation between local and remote prompts\n return {\n ...combined,\n data: combined.data.map((entry) => ({\n ...entry,\n prompt: {\n ...entry.prompt,\n name: `${entry.server.serverKey}:${entry.prompt.name}`,\n },\n })),\n };\n },\n });\n\n // Filter results by search string - runs on every search change (not just query completion)\n const filteredData = React.useMemo(() => {\n if (!search) return queries.data;\n\n const normalizedSearch = search.toLowerCase();\n return queries.data.filter((entry) => {\n const name = entry.prompt.name?.toLowerCase() ?? \"\";\n return name.includes(normalizedSearch);\n });\n }, [queries.data, search]);\n\n return {\n ...queries,\n data: filteredData,\n };\n}\n// TODO: find a more general place for this\nfunction combineArrayResults<T>(results: UseQueryResult<T[]>[]): {\n data: T[];\n error: Error | null;\n errors: Error[];\n isPending: boolean;\n isSuccess: boolean;\n isError: boolean;\n isPaused: boolean;\n isRefetching: boolean;\n isFetching: boolean;\n isLoading: boolean;\n refetch: () => Promise<void>;\n} {\n const errors = results\n .filter((result) => result.isError)\n .map((result) => result.error);\n\n // Treat queries that are idle (disabled) as non-blocking for aggregate status\n const enabledish = results.filter(\n (r) => r.fetchStatus !== \"idle\" || r.isSuccess || r.isError,\n );\n\n return {\n // Prefer flatMap to avoid extra intermediate arrays\n data: results.flatMap((result) =>\n result.isSuccess && Array.isArray(result.data) ? result.data : [],\n ),\n // Preserve a single error for compatibility and expose the full list for diagnostics\n error: errors[0] ?? null,\n errors,\n isPending: enabledish.some((result) => result.isPending),\n isSuccess:\n enabledish.length > 0 && enabledish.every((result) => result.isSuccess),\n isError: errors.length > 0,\n isPaused: enabledish.some((result) => result.isPaused),\n isRefetching: enabledish.some((result) => result.isRefetching),\n isFetching: enabledish.some((result) => result.isFetching),\n isLoading: enabledish.some((result) => result.isLoading),\n // Aggregate refetch to trigger all underlying queries\n refetch: async () => {\n await Promise.all(\n results.map(async (r) => {\n await r.refetch();\n }),\n );\n },\n };\n}\n\n/**\n * Type guard for narrowing McpServer to ConnectedMcpServer.\n * A connected server has a non-null client.\n * @param server - The MCP server to check\n * @returns True if the server is connected, false otherwise\n */\nexport function isConnectedMcpServer(\n server: McpServer,\n): server is ConnectedMcpServer {\n return \"client\" in server && server.client != null;\n}\n\n/**\n * Hook to get the prompt for the specified name.\n * @param promptName - The name of the prompt to get. Can be prefixed with serverKey (e.g., \"linear:issue\") or unprefixed.\n * @param args - The arguments to pass to the prompt.\n * @returns The prompt for the specified name.\n */\nexport function useTamboMcpPrompt(\n promptName: string | undefined,\n args: Record<string, string> = {},\n) {\n // figure out which server has the prompt\n const { data: promptEntries } = useTamboMcpPromptList();\n const promptEntry = promptEntries?.find(\n (prompt) => prompt.prompt.name === promptName,\n );\n // Use the stable server key (and the server instance itself) instead of brittle\n // name/url/transport matching.\n const mcpServer = promptEntry?.server;\n\n // Strip the prefix to get the original prompt name for the MCP server call\n const originalPromptName = promptName?.includes(\":\")\n ? promptName.split(\":\").slice(1).join(\":\")\n : promptName;\n\n // Canonicalize args to avoid unstable cache keys from object identity/order\n const sortedArgsEntries = Object.keys(args)\n .sort()\n .map((k) => [k, args[k]] as const);\n return useTamboQuery({\n // Include server identity and sorted args to prevent stale cache hits\n queryKey: [\"mcp-prompt\", promptName, mcpServer?.key, sortedArgsEntries],\n // Only run when we have a prompt name and a connected server\n enabled: Boolean(\n promptName && mcpServer && isConnectedMcpServer(mcpServer),\n ),\n queryFn: async (): Promise<GetPromptResult | null> => {\n if (\n !originalPromptName ||\n !mcpServer ||\n !isConnectedMcpServer(mcpServer)\n ) {\n return null;\n }\n const result = await mcpServer.client.client.getPrompt({\n name: originalPromptName,\n arguments: args,\n });\n return result ?? null; // return null because react-query doesn't like undefined results\n },\n });\n}\n\n/**\n * Hook to get the resources for all the registered MCP servers and registry.\n * @param search - Optional search string. For MCP servers, results are filtered locally after fetching.\n * For registry dynamic sources, the search is passed to listResources(search) for dynamic generation.\n * @returns The resources from MCP servers and the local registry, including the server that the resource was found on (null for registry resources).\n */\nexport function useTamboMcpResourceList(search?: string) {\n const mcpServers = useTamboMcpServers();\n const { resources: staticResources, resourceSource } = useTamboRegistry();\n\n // Build list of queries: MCP servers + optional dynamic resource source\n const queriesToRun = [\n // MCP server queries - search is NOT in queryKey so queries don't re-run on search change\n ...mcpServers.map((mcpServer) => ({\n queryKey: [\"mcp-resources\", mcpServer.key],\n // Only run for connected servers that have a client\n enabled: isConnectedMcpServer(mcpServer),\n queryFn: async (): Promise<McpResourceEntry[]> => {\n // Fast path: if this server doesn't have a client, skip work\n if (!isConnectedMcpServer(mcpServer)) return [];\n\n const result = await mcpServer.client.client.listResources();\n const resources: ListResourceItem[] = result?.resources ?? [];\n // Return resources without prefixes - we'll apply prefixing in combine\n const resourceEntries: McpResourceEntry[] = resources.map(\n (resource) => ({\n server: mcpServer,\n resource,\n }),\n );\n return resourceEntries;\n },\n })),\n // Dynamic resource source query (if exists) - search IS in queryKey to allow dynamic generation\n ...(resourceSource\n ? [\n {\n queryKey: [\"registry-resources\", \"dynamic\", search],\n enabled: true,\n queryFn: async (): Promise<InternalRegistryResourceEntry[]> => {\n if (!resourceSource) return [];\n const resources = await resourceSource.listResources(search);\n return resources.map((resource) => ({\n server: null,\n resource,\n isDynamic: true,\n }));\n },\n },\n ]\n : []),\n ];\n\n const queries = useTamboQueries({\n queries: queriesToRun,\n combine: (results) => {\n // Type assertion needed because queries can return different entry types\n const combined = combineArrayResults(\n results as UseQueryResult<InternalListResourceEntry[]>[],\n );\n\n // Add static registry resources (no query needed)\n const staticEntries: InternalRegistryResourceEntry[] =\n staticResources.map((resource) => ({\n server: null,\n resource,\n isDynamic: false,\n }));\n\n // Merge static resources with query results (registry resources first)\n const allData = [...staticEntries, ...combined.data];\n\n // Apply serverKey prefix to ALL resources for unified @serverKey:uri format\n // Registry resources get REGISTRY_SERVER_KEY prefix, MCP resources get their serverKey\n const prefixedData = allData.map((entry) => {\n if (entry.server === null) {\n // Registry resource - prefix with REGISTRY_SERVER_KEY\n return {\n ...entry,\n resource: {\n ...entry.resource,\n uri: `${REGISTRY_SERVER_KEY}:${entry.resource.uri}`,\n },\n };\n }\n // MCP resource - always prefix with serverKey\n return {\n ...entry,\n resource: {\n ...entry.resource,\n uri: `${entry.server.serverKey}:${entry.resource.uri}`,\n },\n };\n });\n\n return {\n ...combined,\n data: prefixedData,\n };\n },\n });\n\n // Filter results by search string - runs on every search change (not just query completion)\n // - MCP resources are filtered locally\n // - Static registry resources are filtered locally\n // - Dynamic registry resources are already filtered by listResources(search)\n const filteredData = React.useMemo((): InternalListResourceEntry[] => {\n if (!search) return queries.data;\n\n const normalizedSearch = search.toLowerCase();\n return queries.data.filter((entry) => {\n if (entry.server === null && entry.isDynamic) {\n return true;\n }\n\n const name = entry.resource.name?.toLowerCase() ?? \"\";\n const uri = entry.resource.uri.toLowerCase();\n return name.includes(normalizedSearch) || uri.includes(normalizedSearch);\n });\n }, [queries.data, search]);\n\n const publicData = React.useMemo(\n () => filteredData.map(toPublicResourceEntry),\n [filteredData],\n );\n\n return {\n ...queries,\n data: publicData,\n };\n}\n\n/**\n * Hook to get the resource for the specified URI.\n * @param resourceUri - The URI of the resource to get. Must be prefixed:\n * - MCP resources: prefixed with serverKey (e.g., \"linear:file://foo\")\n * - Registry resources: prefixed with \"registry:\" (e.g., \"registry:file://bar\")\n * @returns The resource for the specified URI.\n */\nexport function useTamboMcpResource(resourceUri: string | undefined) {\n const { resourceSource } = useTamboRegistry();\n const { data: resourceEntries } = useTamboMcpResourceList();\n\n // Find which server/source has the resource\n const resourceEntry = resourceEntries?.find(\n (entry) => entry.resource.uri === resourceUri,\n );\n\n // Determine if this is a registry resource or MCP resource\n const isRegistryResource = resourceEntry?.server === null;\n const mcpServer = resourceEntry?.server ?? null;\n\n // Check if the URI has the registry prefix\n const hasRegistryPrefix = Boolean(\n resourceUri?.startsWith(`${REGISTRY_SERVER_KEY}:`),\n );\n\n // Strip the prefix to get the original resource URI for fetching\n let originalResourceUri: string | undefined;\n if (isRegistryResource || hasRegistryPrefix) {\n const prefixLen = REGISTRY_SERVER_KEY.length + 1; // +1 for the colon\n originalResourceUri = resourceUri?.slice(prefixLen);\n } else if (mcpServer) {\n const prefixLen = mcpServer.serverKey.length + 1; // +1 for the colon\n originalResourceUri = resourceUri?.slice(prefixLen);\n }\n\n // Check if we can fetch this resource\n const hasRegistrySource = resourceSource != null;\n const hasConnectedMcpServer =\n mcpServer != null && isConnectedMcpServer(mcpServer);\n const canFetchFromRegistry =\n hasRegistrySource && (isRegistryResource || hasRegistryPrefix);\n const canFetchResource = Boolean(\n resourceUri && (canFetchFromRegistry || hasConnectedMcpServer),\n );\n\n const locationKey =\n isRegistryResource || hasRegistryPrefix\n ? REGISTRY_SERVER_KEY\n : mcpServer?.key;\n\n return useTamboQuery({\n queryKey: [\"resource\", resourceUri, locationKey],\n enabled: canFetchResource,\n queryFn: async (): Promise<ReadResourceResult | null> => {\n if (!originalResourceUri) {\n return null;\n }\n\n // Registry resource: use resourceSource.getResource\n if (resourceSource && (isRegistryResource || hasRegistryPrefix)) {\n const result = await resourceSource.getResource(originalResourceUri);\n return result ?? null;\n }\n\n // MCP resource: use MCP client\n if (mcpServer && isConnectedMcpServer(mcpServer)) {\n const result = await mcpServer.client.client.readResource({\n uri: originalResourceUri,\n });\n return result ?? null;\n }\n\n return null;\n },\n });\n}\n"]}
|
|
@@ -25,6 +25,9 @@ import { TamboGenerationStageContextProps, TamboThreadContextProps, TamboThreadP
|
|
|
25
25
|
* @param props.contextKey - Optional context key passed to thread input provider for scoping threads
|
|
26
26
|
* @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called
|
|
27
27
|
* @param props.initialMessages - Initial messages to be included in new threads
|
|
28
|
+
* @param props.getResource - Optional getResource function for registry resources
|
|
29
|
+
* @param props.listResources - Optional listResources function for registry resources
|
|
30
|
+
* @param props.resources - Optional static resources for the registry
|
|
28
31
|
* @returns The TamboProvider component
|
|
29
32
|
*/
|
|
30
33
|
export declare const TamboProvider: React.FC<PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps & TamboThreadProviderProps & TamboContextHelpersProviderProps>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAEL,uBAAuB,EAEvB,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,sBAAsB,EAGvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,+BAA+B,EAE/B,gCAAgC,EAEjC,MAAM,kCAAkC,CAAC;AAM1C,OAAO,EAEL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,gCAAgC,EAChC,uBAAuB,EAEvB,wBAAwB,EAEzB,MAAM,yBAAyB,CAAC;AAEjC
|
|
1
|
+
{"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAEL,uBAAuB,EAEvB,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,sBAAsB,EAGvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,+BAA+B,EAE/B,gCAAgC,EAEjC,MAAM,kCAAkC,CAAC;AAM1C,OAAO,EAEL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,gCAAgC,EAChC,uBAAuB,EAEvB,wBAAwB,EAEzB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAClC,iBAAiB,CACf,wBAAwB,GACtB,0BAA0B,GAC1B,wBAAwB,GACxB,gCAAgC,CACnC,CAiEF,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,GACrD,uBAAuB,GACvB,gCAAgC,GAChC,0BAA0B,GAC1B,wBAAwB,GACxB,+BAA+B,GAC/B,sBAAsB,CAAC;AAEzB,eAAO,MAAM,YAAY,kCAExB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAgC9D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,yBAEpB,CAAC"}
|
|
@@ -65,6 +65,9 @@ const tambo_thread_provider_1 = require("./tambo-thread-provider");
|
|
|
65
65
|
* @param props.contextKey - Optional context key passed to thread input provider for scoping threads
|
|
66
66
|
* @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called
|
|
67
67
|
* @param props.initialMessages - Initial messages to be included in new threads
|
|
68
|
+
* @param props.getResource - Optional getResource function for registry resources
|
|
69
|
+
* @param props.listResources - Optional listResources function for registry resources
|
|
70
|
+
* @param props.resources - Optional static resources for the registry
|
|
68
71
|
* @returns The TamboProvider component
|
|
69
72
|
*/
|
|
70
73
|
const TamboProvider = ({ children, tamboUrl, apiKey, userToken, components, environment, tools, mcpServers, streaming, autoGenerateThreadName, autoGenerateNameThreshold, contextHelpers, contextKey, initialMessages, onCallUnregisteredTool, getResource, listResources, resources, }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA4E;AAC5E,kEAA6D;AAE7D,mEAKiC;AACjC,yEAIoC;AACpC,2FAI6C;AAC7C,qFAK0C;AAC1C,+EAGuC;AACvC,yEAAmE;AACnE,uEAGmC;AACnC,+EAAyE;AACzE,mEAMiC;AAEjC
|
|
1
|
+
{"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,+CAA4E;AAC5E,kEAA6D;AAE7D,mEAKiC;AACjC,yEAIoC;AACpC,2FAI6C;AAC7C,qFAK0C;AAC1C,+EAGuC;AACvC,yEAAmE;AACnE,uEAGmC;AACnC,+EAAyE;AACzE,mEAMiC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,aAAa,GAOtB,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,UAAU,EACV,WAAW,EACX,KAAK,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CAAC,CAAC;IACrD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,kEAAkE,CACnE,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,EAAE,GAAG,aAAa,CAAC;IAC/D,MAAM,iBAAiB,GAAG,IAAA,4CAAiB,GAAE,CAAC;IAC9C,MAAM,sBAAsB,GAAG,IAAA,kDAAoB,GAAE,CAAC;IACtD,MAAM,cAAc,GAAG,IAAA,uDAAsB,GAAE,CAAC;IAChD,MAAM,iBAAiB,GAAG,IAAA,6DAAyB,GAAE,CAAC;IAEtD,OAAO,CACL,8BAAC,oBAAY,CAAC,QAAQ,IACpB,KAAK,EAAE;YACL,MAAM;YACN,WAAW;YACX,eAAe;YACf,GAAG,iBAAiB;YACpB,GAAG,OAAO;YACV,GAAG,sBAAsB;YACzB,GAAG,cAAc;YACjB,GAAG,iBAAiB;SACrB,IAEA,QAAQ,CACa,CACzB,CAAC;AACJ,CAAC,CAAC;AAhCW,QAAA,sBAAsB,0BAgCjC;AAEF;;;;;;;GAOG;AACI,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,IAAA,kBAAU,EAAC,oBAAY,CAAC,CAAC;AAClC,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport { TamboMcpProvider } from \"../mcp/tambo-mcp-provider\";\nimport { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContext,\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n ContextAttachmentState,\n TamboContextAttachmentProvider,\n useTamboContextAttachment,\n} from \"./tambo-context-attachment-provider\";\nimport {\n TamboContextHelpersContextProps,\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboInteractableProvider,\n useTamboInteractable,\n} from \"./tambo-interactable-provider\";\nimport { TamboMcpTokenProvider } from \"./tambo-mcp-token-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport { TamboThreadInputProvider } from \"./tambo-thread-input-provider\";\nimport {\n TamboGenerationStageContextProps,\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, the current thread context, and interactable components.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @param props.tools - The tools to register\n * @param props.mcpServers - The MCP servers to register (metadata only - use TamboMcpProvider for connections)\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @param props.autoGenerateThreadName - Whether to automatically generate thread names. Defaults to true.\n * @param props.autoGenerateNameThreshold - The message count threshold at which the thread name will be auto-generated. Defaults to 3.\n * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled\n * @param props.userToken - The user's OAuth token (access or ID) used to identify the user and exchange for a Tambo session token\n * @param props.contextKey - Optional context key passed to thread input provider for scoping threads\n * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called\n * @param props.initialMessages - Initial messages to be included in new threads\n * @param props.getResource - Optional getResource function for registry resources\n * @param props.listResources - Optional listResources function for registry resources\n * @param props.resources - Optional static resources for the registry\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n mcpServers,\n streaming,\n autoGenerateThreadName,\n autoGenerateNameThreshold,\n contextHelpers,\n contextKey,\n initialMessages,\n onCallUnregisteredTool,\n getResource,\n listResources,\n resources,\n}) => {\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n userToken={userToken}\n >\n <TamboRegistryProvider\n components={components}\n tools={tools}\n mcpServers={mcpServers}\n onCallUnregisteredTool={onCallUnregisteredTool}\n getResource={getResource}\n listResources={listResources}\n resources={resources}\n >\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider\n contextKey={contextKey}\n streaming={streaming}\n autoGenerateThreadName={autoGenerateThreadName}\n autoGenerateNameThreshold={autoGenerateNameThreshold}\n initialMessages={initialMessages}\n >\n <TamboMcpTokenProvider>\n <TamboMcpProvider contextKey={contextKey}>\n <TamboContextAttachmentProvider>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboThreadInputProvider>\n <TamboCompositeProvider>\n {children}\n </TamboCompositeProvider>\n </TamboThreadInputProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboContextAttachmentProvider>\n </TamboMcpProvider>\n </TamboMcpTokenProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboGenerationStageContextProps &\n TamboComponentContextProps &\n TamboInteractableContext &\n TamboContextHelpersContextProps &\n ContextAttachmentState;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, TamboComponent, and TamboInteractable providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const clientContext = useContext(TamboClientContext);\n if (!clientContext) {\n throw new Error(\n \"TamboCompositeProvider must be used within a TamboClientProvider\",\n );\n }\n const { client, queryClient, isUpdatingToken } = clientContext;\n const componentRegistry = useTamboComponent();\n const interactableComponents = useTamboInteractable();\n const contextHelpers = useTamboContextHelpers();\n const contextAttachment = useTamboContextAttachment();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n isUpdatingToken,\n ...componentRegistry,\n ...threads,\n ...interactableComponents,\n ...contextHelpers,\n ...contextAttachment,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, the current thread context,\n * and interactable component management.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-content-resolver.d.ts","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E,OAAO,KAAK,EAAsB,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"resource-content-resolver.d.ts","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E,OAAO,KAAK,EAAsB,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAY7D;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAC3C,YAAY,EAAE,MAAM,EAAE,EACtB,UAAU,EAAE,SAAS,EAAE,EACvB,cAAc,EAAE,cAAc,GAAG,SAAS,GACzC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAyE1C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAI1D"}
|
|
@@ -6,6 +6,8 @@ const mcp_constants_1 = require("../mcp/mcp-constants");
|
|
|
6
6
|
/**
|
|
7
7
|
* Type guard for narrowing McpServer to a connected server.
|
|
8
8
|
* A connected server has a non-null client.
|
|
9
|
+
* @param server - The MCP server to check
|
|
10
|
+
* @returns True if the server is connected, false otherwise
|
|
9
11
|
*/
|
|
10
12
|
function isConnectedMcpServer(server) {
|
|
11
13
|
return "client" in server && server.client != null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-content-resolver.js","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"resource-content-resolver.js","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings":";;AAwBA,0DA6EC;AAOD,kDAIC;AA/GD,wDAAuE;AAIvE;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,MAAiB;IAC7C,OAAO,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC;AACrD,CAAC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,uBAAuB,CAC3C,YAAsB,EACtB,UAAuB,EACvB,cAA0C;IAE1C,MAAM,OAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;IAEtD,MAAM,aAAa,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;QAC3D,mCAAmC;QACnC,sFAAsF;QACtF,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5C,IAAI,UAAU,KAAK,CAAC,CAAC;YAAE,OAAO;QAE9B,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC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D,GAAG,EAAE,WAAW;qBACjB,CAAC,CAA8B,CAAC;oBACjC,IAAI,UAAU,EAAE,CAAC;wBACf,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;oBACvC,CAAC;oBACD,OAAO;gBACT,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,+DAA+D;YAC/D,OAAO,CAAC,IAAI,CACV,wCAAwC,WAAW,GAAG,EACtD,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,MAAM,OAAO,GAAG,yBAAyB,CAAC;IAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACnD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import type { ReadResourceResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport { REGISTRY_SERVER_KEY, ServerType } from \"../mcp/mcp-constants\";\nimport type { ConnectedMcpServer, McpServer } from \"../mcp/tambo-mcp-provider\";\nimport type { ResourceSource } from \"../model/resource-info\";\n\n/**\n * Type guard for narrowing McpServer to a connected server.\n * A connected server has a non-null client.\n * @param server - The MCP server to check\n * @returns True if the server is connected, false otherwise\n */\nfunction isConnectedMcpServer(server: McpServer): server is ConnectedMcpServer {\n return \"client\" in server && server.client != null;\n}\n\n/**\n * Resolves content for client-side resources (MCP and registry).\n * Server-side (internal Tambo) resources are skipped - the backend can resolve them.\n * @param resourceUris - Prefixed URIs (e.g., \"linear:file://foo\", \"registry:file://bar\", \"tambo-abc:test://resource\")\n * @param mcpServers - Active MCP servers including virtual registry server\n * @param resourceSource - Registry resource source (listResources/getResource)\n * @returns Map of prefixedUri -> ReadResourceResult for resolved resources.\n * Resources that failed to fetch or are internal server resources won't be in the map.\n */\nexport async function resolveResourceContents(\n resourceUris: string[],\n mcpServers: McpServer[],\n resourceSource: ResourceSource | undefined,\n): Promise<Map<string, ReadResourceResult>> {\n const results = new Map<string, ReadResourceResult>();\n\n const fetchPromises = resourceUris.map(async (prefixedUri) => {\n // Parse serverKey and original URI\n // Format: serverKey:originalUri (e.g., \"linear:file://foo\", \"registry:docs://readme\")\n const colonIndex = prefixedUri.indexOf(\":\");\n if (colonIndex === -1) return;\n\n const serverKey = prefixedUri.slice(0, colonIndex);\n const originalUri = prefixedUri.slice(colonIndex + 1);\n\n try {\n // Handle registry resources directly - no server lookup needed\n // Registry resources are local to the browser and resolved via resourceSource\n if (serverKey === REGISTRY_SERVER_KEY) {\n if (!resourceSource) {\n console.warn(\n `No resource source available to resolve registry resource: ${prefixedUri}`,\n );\n return;\n }\n const registryContent = await resourceSource.getResource(originalUri);\n if (registryContent) {\n results.set(prefixedUri, registryContent);\n }\n return;\n }\n\n // For non-registry resources, find the server by serverKey\n const server = mcpServers.find((s) => s.serverKey === serverKey);\n if (!server) {\n console.warn(`No server found for resource: ${prefixedUri}`);\n return;\n }\n\n switch (server.serverType) {\n case ServerType.TAMBO_INTERNAL:\n // Skip internal server resources - backend can resolve these\n return;\n\n case ServerType.TAMBO_REGISTRY:\n // Should not reach here since we handle registry above, but keep for safety\n return;\n\n case ServerType.BROWSER_SIDE: {\n // Client-side MCP resource\n if (!isConnectedMcpServer(server)) {\n console.warn(\n `MCP server not connected for resource: ${prefixedUri}`,\n );\n return;\n }\n const mcpContent = (await server.client.client.readResource({\n uri: originalUri,\n })) as ReadResourceResult | null;\n if (mcpContent) {\n results.set(prefixedUri, mcpContent);\n }\n return;\n }\n }\n } catch (error) {\n // Graceful fallback - log warning and continue without content\n console.warn(\n `Failed to fetch resource content for ${prefixedUri}:`,\n error,\n );\n }\n });\n\n await Promise.all(fetchPromises);\n return results;\n}\n\n/**\n * Extracts resource URIs from text using the `@serverKey:uri` pattern.\n * @param text - Text potentially containing resource references\n * @returns Array of prefixed resource URIs (e.g., [\"linear:file://foo\", \"registry:file://bar\"])\n */\nexport function extractResourceUris(text: string): string[] {\n const pattern = /@([a-zA-Z0-9-]+):(\\S+)/g;\n const matches = Array.from(text.matchAll(pattern));\n return matches.map(([, serverKey, uri]) => `${serverKey}:${uri}`);\n}\n"]}
|
package/esm/mcp/mcp-hooks.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface McpResourceEntry {
|
|
|
29
29
|
export type ListResourceEntry = RegistryResourceEntry | McpResourceEntry;
|
|
30
30
|
/**
|
|
31
31
|
* Type guard for narrowing a `ListResourceEntry` to an MCP-backed resource.
|
|
32
|
+
* @param entry - The resource entry to check
|
|
33
|
+
* @returns True if the entry is from an MCP server, false if it's from the registry
|
|
32
34
|
*/
|
|
33
35
|
export declare function isMcpResourceEntry(entry: ListResourceEntry): entry is McpResourceEntry;
|
|
34
36
|
/**
|
|
@@ -73,6 +75,8 @@ export declare function useTamboMcpPromptList(search?: string): {
|
|
|
73
75
|
/**
|
|
74
76
|
* Type guard for narrowing McpServer to ConnectedMcpServer.
|
|
75
77
|
* A connected server has a non-null client.
|
|
78
|
+
* @param server - The MCP server to check
|
|
79
|
+
* @returns True if the server is connected, false otherwise
|
|
76
80
|
*/
|
|
77
81
|
export declare function isConnectedMcpServer(server: McpServer): server is ConnectedMcpServer;
|
|
78
82
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-hooks.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EAEzB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,cAAc,E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,CAAC;EAwO7B;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;;;;;;;;;;;;;;;;;;;;;;;;iBAoElE"}
|
package/esm/mcp/mcp-hooks.js
CHANGED
|
@@ -12,6 +12,8 @@ function toPublicResourceEntry(entry) {
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Type guard for narrowing a `ListResourceEntry` to an MCP-backed resource.
|
|
15
|
+
* @param entry - The resource entry to check
|
|
16
|
+
* @returns True if the entry is from an MCP server, false if it's from the registry
|
|
15
17
|
*/
|
|
16
18
|
export function isMcpResourceEntry(entry) {
|
|
17
19
|
return entry.server !== null && isConnectedMcpServer(entry.server);
|
|
@@ -105,6 +107,8 @@ function combineArrayResults(results) {
|
|
|
105
107
|
/**
|
|
106
108
|
* Type guard for narrowing McpServer to ConnectedMcpServer.
|
|
107
109
|
* A connected server has a non-null client.
|
|
110
|
+
* @param server - The MCP server to check
|
|
111
|
+
* @returns True if the server is connected, false otherwise
|
|
108
112
|
*/
|
|
109
113
|
export function isConnectedMcpServer(server) {
|
|
110
114
|
return "client" in server && server.client != null;
|
package/esm/mcp/mcp-hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-hooks.js","sourceRoot":"","sources":["../../src/mcp/mcp-hooks.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAGL,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AA0C9B,SAAS,qBAAqB,CAC5B,KAAgC;IAEhC,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAC1B,MAAM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C,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;oBACxD,GAAG,EAAE,mBAAmB;iBACzB,CAAC,CAAC;gBACH,OAAO,MAAM,IAAI,IAAI,CAAC;YACxB,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n GetPromptResult,\n type ListPromptsResult,\n type ListResourcesResult,\n type ReadResourceResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { UseQueryResult } from \"@tanstack/react-query\";\nimport * as React from \"react\";\nimport { useTamboQueries, useTamboQuery } from \"../hooks\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { REGISTRY_SERVER_KEY } from \"./mcp-constants\";\nimport {\n type ConnectedMcpServer,\n type McpServer,\n useTamboMcpServers,\n} from \"./tambo-mcp-provider\";\n\nexport type ListPromptItem = ListPromptsResult[\"prompts\"][number];\nexport interface ListPromptEntry {\n // Only connected servers produce prompt entries, so expose the connected type\n server: ConnectedMcpServer;\n prompt: ListPromptItem;\n}\n\nexport type ListResourceItem = ListResourcesResult[\"resources\"][number];\n\n/**\n * Registry resource entry - resources from the local registry (not MCP servers).\n *\n * These entries always have `server === null`.\n */\nexport interface RegistryResourceEntry {\n server: null;\n resource: ListResourceItem;\n}\n\n/**\n * MCP server resource entry - resources from connected MCP servers.\n */\nexport interface McpResourceEntry {\n server: ConnectedMcpServer;\n resource: ListResourceItem;\n}\n\n/**\n * Union type for all resource entries returned by `useTamboMcpResourceList`.\n */\nexport type ListResourceEntry = RegistryResourceEntry | McpResourceEntry;\n\ntype InternalRegistryResourceEntry = RegistryResourceEntry & {\n isDynamic: boolean;\n};\n\ntype InternalListResourceEntry =\n | McpResourceEntry\n | InternalRegistryResourceEntry;\n\nfunction toPublicResourceEntry(\n entry: InternalListResourceEntry,\n): ListResourceEntry {\n if (entry.server === null) {\n const { isDynamic: _isDynamic, ...publicEntry } = entry;\n return publicEntry;\n }\n return entry;\n}\n\n/**\n * Type guard for narrowing a `ListResourceEntry` to an MCP-backed resource.\n */\nexport function isMcpResourceEntry(\n entry: ListResourceEntry,\n): entry is McpResourceEntry {\n return entry.server !== null && isConnectedMcpServer(entry.server);\n}\n\n/**\n * Hook to get the prompts for all the registered MCP servers.\n * @param search - Optional search string to filter prompts by name (case-insensitive).\n * @returns The prompts for the MCP servers, including the server that the prompt was found on.\n */\nexport function useTamboMcpPromptList(search?: string) {\n const mcpServers = useTamboMcpServers();\n\n const queries = useTamboQueries({\n queries: mcpServers.map((mcpServer) => ({\n // search is NOT in queryKey - we filter locally after fetching\n queryKey: [\"mcp-prompts\", mcpServer.key],\n // Only run for connected servers that have a client\n enabled: isConnectedMcpServer(mcpServer),\n queryFn: async (): Promise<ListPromptEntry[]> => {\n // Fast path: if this server doesn't have a client, skip work\n if (!isConnectedMcpServer(mcpServer)) return [];\n\n const result = await mcpServer.client.client.listPrompts();\n const prompts: ListPromptItem[] = result?.prompts ?? [];\n // Return prompts without prefixes - we'll apply prefixing in combine\n const promptsEntries = prompts.map((prompt) => ({\n server: mcpServer,\n prompt,\n }));\n return promptsEntries;\n },\n })),\n combine: (results) => {\n const combined = combineArrayResults(results);\n\n // Always apply serverKey prefix to MCP prompts (breaking change for consistency with resources)\n // This ensures clear separation between local and remote prompts\n return {\n ...combined,\n data: combined.data.map((entry) => ({\n ...entry,\n prompt: {\n ...entry.prompt,\n name: `${entry.server.serverKey}:${entry.prompt.name}`,\n },\n })),\n };\n },\n });\n\n // Filter results by search string - runs on every search change (not just query completion)\n const filteredData = React.useMemo(() => {\n if (!search) return queries.data;\n\n const normalizedSearch = search.toLowerCase();\n return queries.data.filter((entry) => {\n const name = entry.prompt.name?.toLowerCase() ?? \"\";\n return name.includes(normalizedSearch);\n });\n }, [queries.data, search]);\n\n return {\n ...queries,\n data: filteredData,\n };\n}\n// TODO: find a more general place for this\nfunction combineArrayResults<T>(results: UseQueryResult<T[]>[]): {\n data: T[];\n error: Error | null;\n errors: Error[];\n isPending: boolean;\n isSuccess: boolean;\n isError: boolean;\n isPaused: boolean;\n isRefetching: boolean;\n isFetching: boolean;\n isLoading: boolean;\n refetch: () => Promise<void>;\n} {\n const errors = results\n .filter((result) => result.isError)\n .map((result) => result.error);\n\n // Treat queries that are idle (disabled) as non-blocking for aggregate status\n const enabledish = results.filter(\n (r) => r.fetchStatus !== \"idle\" || r.isSuccess || r.isError,\n );\n\n return {\n // Prefer flatMap to avoid extra intermediate arrays\n data: results.flatMap((result) =>\n result.isSuccess && Array.isArray(result.data) ? result.data : [],\n ),\n // Preserve a single error for compatibility and expose the full list for diagnostics\n error: errors[0] ?? null,\n errors,\n isPending: enabledish.some((result) => result.isPending),\n isSuccess:\n enabledish.length > 0 && enabledish.every((result) => result.isSuccess),\n isError: errors.length > 0,\n isPaused: enabledish.some((result) => result.isPaused),\n isRefetching: enabledish.some((result) => result.isRefetching),\n isFetching: enabledish.some((result) => result.isFetching),\n isLoading: enabledish.some((result) => result.isLoading),\n // Aggregate refetch to trigger all underlying queries\n refetch: async () => {\n await Promise.all(\n results.map(async (r) => {\n await r.refetch();\n }),\n );\n },\n };\n}\n\n/**\n * Type guard for narrowing McpServer to ConnectedMcpServer.\n * A connected server has a non-null client.\n */\nexport function isConnectedMcpServer(\n server: McpServer,\n): server is ConnectedMcpServer {\n return \"client\" in server && server.client != null;\n}\n\n/**\n * Hook to get the prompt for the specified name.\n * @param promptName - The name of the prompt to get. Can be prefixed with serverKey (e.g., \"linear:issue\") or unprefixed.\n * @param args - The arguments to pass to the prompt.\n * @returns The prompt for the specified name.\n */\nexport function useTamboMcpPrompt(\n promptName: string | undefined,\n args: Record<string, string> = {},\n) {\n // figure out which server has the prompt\n const { data: promptEntries } = useTamboMcpPromptList();\n const promptEntry = promptEntries?.find(\n (prompt) => prompt.prompt.name === promptName,\n );\n // Use the stable server key (and the server instance itself) instead of brittle\n // name/url/transport matching.\n const mcpServer = promptEntry?.server;\n\n // Strip the prefix to get the original prompt name for the MCP server call\n const originalPromptName = promptName?.includes(\":\")\n ? promptName.split(\":\").slice(1).join(\":\")\n : promptName;\n\n // Canonicalize args to avoid unstable cache keys from object identity/order\n const sortedArgsEntries = Object.keys(args)\n .sort()\n .map((k) => [k, args[k]] as const);\n return useTamboQuery({\n // Include server identity and sorted args to prevent stale cache hits\n queryKey: [\"mcp-prompt\", promptName, mcpServer?.key, sortedArgsEntries],\n // Only run when we have a prompt name and a connected server\n enabled: Boolean(\n promptName && mcpServer && isConnectedMcpServer(mcpServer),\n ),\n queryFn: async (): Promise<GetPromptResult | null> => {\n if (\n !originalPromptName ||\n !mcpServer ||\n !isConnectedMcpServer(mcpServer)\n ) {\n return null;\n }\n const result = await mcpServer.client.client.getPrompt({\n name: originalPromptName,\n arguments: args,\n });\n return result ?? null; // return null because react-query doesn't like undefined results\n },\n });\n}\n\n/**\n * Hook to get the resources for all the registered MCP servers and registry.\n * @param search - Optional search string. For MCP servers, results are filtered locally after fetching.\n * For registry dynamic sources, the search is passed to listResources(search) for dynamic generation.\n * @returns The resources from MCP servers and the local registry, including the server that the resource was found on (null for registry resources).\n */\nexport function useTamboMcpResourceList(search?: string) {\n const mcpServers = useTamboMcpServers();\n const { resources: staticResources, resourceSource } = useTamboRegistry();\n\n // Build list of queries: MCP servers + optional dynamic resource source\n const queriesToRun = [\n // MCP server queries - search is NOT in queryKey so queries don't re-run on search change\n ...mcpServers.map((mcpServer) => ({\n queryKey: [\"mcp-resources\", mcpServer.key],\n // Only run for connected servers that have a client\n enabled: isConnectedMcpServer(mcpServer),\n queryFn: async (): Promise<McpResourceEntry[]> => {\n // Fast path: if this server doesn't have a client, skip work\n if (!isConnectedMcpServer(mcpServer)) return [];\n\n const result = await mcpServer.client.client.listResources();\n const resources: ListResourceItem[] = result?.resources ?? [];\n // Return resources without prefixes - we'll apply prefixing in combine\n const resourceEntries: McpResourceEntry[] = resources.map(\n (resource) => ({\n server: mcpServer,\n resource,\n }),\n );\n return resourceEntries;\n },\n })),\n // Dynamic resource source query (if exists) - search IS in queryKey to allow dynamic generation\n ...(resourceSource\n ? [\n {\n queryKey: [\"registry-resources\", \"dynamic\", search],\n enabled: true,\n queryFn: async (): Promise<InternalRegistryResourceEntry[]> => {\n if (!resourceSource) return [];\n const resources = await resourceSource.listResources(search);\n return resources.map((resource) => ({\n server: null,\n resource,\n isDynamic: true,\n }));\n },\n },\n ]\n : []),\n ];\n\n const queries = useTamboQueries({\n queries: queriesToRun,\n combine: (results) => {\n // Type assertion needed because queries can return different entry types\n const combined = combineArrayResults(\n results as UseQueryResult<InternalListResourceEntry[]>[],\n );\n\n // Add static registry resources (no query needed)\n const staticEntries: InternalRegistryResourceEntry[] =\n staticResources.map((resource) => ({\n server: null,\n resource,\n isDynamic: false,\n }));\n\n // Merge static resources with query results (registry resources first)\n const allData = [...staticEntries, ...combined.data];\n\n // Apply serverKey prefix to ALL resources for unified @serverKey:uri format\n // Registry resources get REGISTRY_SERVER_KEY prefix, MCP resources get their serverKey\n const prefixedData = allData.map((entry) => {\n if (entry.server === null) {\n // Registry resource - prefix with REGISTRY_SERVER_KEY\n return {\n ...entry,\n resource: {\n ...entry.resource,\n uri: `${REGISTRY_SERVER_KEY}:${entry.resource.uri}`,\n },\n };\n }\n // MCP resource - always prefix with serverKey\n return {\n ...entry,\n resource: {\n ...entry.resource,\n uri: `${entry.server.serverKey}:${entry.resource.uri}`,\n },\n };\n });\n\n return {\n ...combined,\n data: prefixedData,\n };\n },\n });\n\n // Filter results by search string - runs on every search change (not just query completion)\n // - MCP resources are filtered locally\n // - Static registry resources are filtered locally\n // - Dynamic registry resources are already filtered by listResources(search)\n const filteredData = React.useMemo((): InternalListResourceEntry[] => {\n if (!search) return queries.data;\n\n const normalizedSearch = search.toLowerCase();\n return queries.data.filter((entry) => {\n if (entry.server === null && entry.isDynamic) {\n return true;\n }\n\n const name = entry.resource.name?.toLowerCase() ?? \"\";\n const uri = entry.resource.uri.toLowerCase();\n return name.includes(normalizedSearch) || uri.includes(normalizedSearch);\n });\n }, [queries.data, search]);\n\n const publicData = React.useMemo(\n () => filteredData.map(toPublicResourceEntry),\n [filteredData],\n );\n\n return {\n ...queries,\n data: publicData,\n };\n}\n\n/**\n * Hook to get the resource for the specified URI.\n * @param resourceUri - The URI of the resource to get. Must be prefixed:\n * - MCP resources: prefixed with serverKey (e.g., \"linear:file://foo\")\n * - Registry resources: prefixed with \"registry:\" (e.g., \"registry:file://bar\")\n * @returns The resource for the specified URI.\n */\nexport function useTamboMcpResource(resourceUri: string | undefined) {\n const { resourceSource } = useTamboRegistry();\n const { data: resourceEntries } = useTamboMcpResourceList();\n\n // Find which server/source has the resource\n const resourceEntry = resourceEntries?.find(\n (entry) => entry.resource.uri === resourceUri,\n );\n\n // Determine if this is a registry resource or MCP resource\n const isRegistryResource = resourceEntry?.server === null;\n const mcpServer = resourceEntry?.server ?? null;\n\n // Check if the URI has the registry prefix\n const hasRegistryPrefix = Boolean(\n resourceUri?.startsWith(`${REGISTRY_SERVER_KEY}:`),\n );\n\n // Strip the prefix to get the original resource URI for fetching\n let originalResourceUri: string | undefined;\n if (isRegistryResource || hasRegistryPrefix) {\n const prefixLen = REGISTRY_SERVER_KEY.length + 1; // +1 for the colon\n originalResourceUri = resourceUri?.slice(prefixLen);\n } else if (mcpServer) {\n const prefixLen = mcpServer.serverKey.length + 1; // +1 for the colon\n originalResourceUri = resourceUri?.slice(prefixLen);\n }\n\n // Check if we can fetch this resource\n const hasRegistrySource = resourceSource != null;\n const hasConnectedMcpServer =\n mcpServer != null && isConnectedMcpServer(mcpServer);\n const canFetchFromRegistry =\n hasRegistrySource && (isRegistryResource || hasRegistryPrefix);\n const canFetchResource = Boolean(\n resourceUri && (canFetchFromRegistry || hasConnectedMcpServer),\n );\n\n const locationKey =\n isRegistryResource || hasRegistryPrefix\n ? REGISTRY_SERVER_KEY\n : mcpServer?.key;\n\n return useTamboQuery({\n queryKey: [\"resource\", resourceUri, locationKey],\n enabled: canFetchResource,\n queryFn: async (): Promise<ReadResourceResult | null> => {\n if (!originalResourceUri) {\n return null;\n }\n\n // Registry resource: use resourceSource.getResource\n if (resourceSource && (isRegistryResource || hasRegistryPrefix)) {\n const result = await resourceSource.getResource(originalResourceUri);\n return result ?? null;\n }\n\n // MCP resource: use MCP client\n if (mcpServer && isConnectedMcpServer(mcpServer)) {\n const result = await mcpServer.client.client.readResource({\n uri: originalResourceUri,\n });\n return result ?? null;\n }\n\n return null;\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mcp-hooks.js","sourceRoot":"","sources":["../../src/mcp/mcp-hooks.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAGL,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AA0C9B,SAAS,qBAAqB,CAC5B,KAAgC;IAEhC,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAC1B,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,WAAW,EAAE,GAAG,KAAK,CAAC;QACxD,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAwB;IAExB,OAAO,KAAK,CAAC,MAAM,KAAK,IAAI,IAAI,oBAAoB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACrE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAe;IACnD,MAAM,UAAU,GAAG,kBAAkB,EAAE,CAAC;IAExC,MAAM,OAAO,GAAG,eAAe,CAAC;QAC9B,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;YACtC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WAAW,IAAI,CAAC,oBAAoB,IAAI,qBAAqB,CAAC,CAC/D,CAAC;IAEF,MAAM,WAAW,GACf,kBAAkB,IAAI,iBAAiB;QACrC,CAAC,CAAC,mBAAmB;QACrB,CAAC,CAAC,SAAS,EAAE,GAAG,CAAC;IAErB,OAAO,aAAa,CAAC;QACnB,QAAQ,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,WAAW,CAAC;QAChD,OAAO,EAAE,gBAAgB;QACzB,OAAO,EAAE,KAAK,IAAwC,EAAE;YACtD,IAAI,CAAC,mBAAmB,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,oDAAoD;YACpD,IAAI,cAAc,IAAI,CAAC,kBAAkB,IAAI,iBAAiB,CAAC,EAAE,CAAC;gBAChE,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;gBACrE,OAAO,MAAM,IAAI,IAAI,CAAC;YACxB,CAAC;YAED,+BAA+B;YAC/B,IAAI,SAAS,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;gBACjD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;oBACxD,GAAG,EAAE,mBAAmB;iBACzB,CAAC,CAAC;gBACH,OAAO,MAAM,IAAI,IAAI,CAAC;YACxB,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n GetPromptResult,\n type ListPromptsResult,\n type ListResourcesResult,\n type ReadResourceResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { UseQueryResult } from \"@tanstack/react-query\";\nimport * as React from \"react\";\nimport { useTamboQueries, useTamboQuery } from \"../hooks\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { REGISTRY_SERVER_KEY } from \"./mcp-constants\";\nimport {\n type ConnectedMcpServer,\n type McpServer,\n useTamboMcpServers,\n} from \"./tambo-mcp-provider\";\n\nexport type ListPromptItem = ListPromptsResult[\"prompts\"][number];\nexport interface ListPromptEntry {\n // Only connected servers produce prompt entries, so expose the connected type\n server: ConnectedMcpServer;\n prompt: ListPromptItem;\n}\n\nexport type ListResourceItem = ListResourcesResult[\"resources\"][number];\n\n/**\n * Registry resource entry - resources from the local registry (not MCP servers).\n *\n * These entries always have `server === null`.\n */\nexport interface RegistryResourceEntry {\n server: null;\n resource: ListResourceItem;\n}\n\n/**\n * MCP server resource entry - resources from connected MCP servers.\n */\nexport interface McpResourceEntry {\n server: ConnectedMcpServer;\n resource: ListResourceItem;\n}\n\n/**\n * Union type for all resource entries returned by `useTamboMcpResourceList`.\n */\nexport type ListResourceEntry = RegistryResourceEntry | McpResourceEntry;\n\ntype InternalRegistryResourceEntry = RegistryResourceEntry & {\n isDynamic: boolean;\n};\n\ntype InternalListResourceEntry =\n | McpResourceEntry\n | InternalRegistryResourceEntry;\n\nfunction toPublicResourceEntry(\n entry: InternalListResourceEntry,\n): ListResourceEntry {\n if (entry.server === null) {\n const { isDynamic: _isDynamic, ...publicEntry } = entry;\n return publicEntry;\n }\n return entry;\n}\n\n/**\n * Type guard for narrowing a `ListResourceEntry` to an MCP-backed resource.\n * @param entry - The resource entry to check\n * @returns True if the entry is from an MCP server, false if it's from the registry\n */\nexport function isMcpResourceEntry(\n entry: ListResourceEntry,\n): entry is McpResourceEntry {\n return entry.server !== null && isConnectedMcpServer(entry.server);\n}\n\n/**\n * Hook to get the prompts for all the registered MCP servers.\n * @param search - Optional search string to filter prompts by name (case-insensitive).\n * @returns The prompts for the MCP servers, including the server that the prompt was found on.\n */\nexport function useTamboMcpPromptList(search?: string) {\n const mcpServers = useTamboMcpServers();\n\n const queries = useTamboQueries({\n queries: mcpServers.map((mcpServer) => ({\n // search is NOT in queryKey - we filter locally after fetching\n queryKey: [\"mcp-prompts\", mcpServer.key],\n // Only run for connected servers that have a client\n enabled: isConnectedMcpServer(mcpServer),\n queryFn: async (): Promise<ListPromptEntry[]> => {\n // Fast path: if this server doesn't have a client, skip work\n if (!isConnectedMcpServer(mcpServer)) return [];\n\n const result = await mcpServer.client.client.listPrompts();\n const prompts: ListPromptItem[] = result?.prompts ?? [];\n // Return prompts without prefixes - we'll apply prefixing in combine\n const promptsEntries = prompts.map((prompt) => ({\n server: mcpServer,\n prompt,\n }));\n return promptsEntries;\n },\n })),\n combine: (results) => {\n const combined = combineArrayResults(results);\n\n // Always apply serverKey prefix to MCP prompts (breaking change for consistency with resources)\n // This ensures clear separation between local and remote prompts\n return {\n ...combined,\n data: combined.data.map((entry) => ({\n ...entry,\n prompt: {\n ...entry.prompt,\n name: `${entry.server.serverKey}:${entry.prompt.name}`,\n },\n })),\n };\n },\n });\n\n // Filter results by search string - runs on every search change (not just query completion)\n const filteredData = React.useMemo(() => {\n if (!search) return queries.data;\n\n const normalizedSearch = search.toLowerCase();\n return queries.data.filter((entry) => {\n const name = entry.prompt.name?.toLowerCase() ?? \"\";\n return name.includes(normalizedSearch);\n });\n }, [queries.data, search]);\n\n return {\n ...queries,\n data: filteredData,\n };\n}\n// TODO: find a more general place for this\nfunction combineArrayResults<T>(results: UseQueryResult<T[]>[]): {\n data: T[];\n error: Error | null;\n errors: Error[];\n isPending: boolean;\n isSuccess: boolean;\n isError: boolean;\n isPaused: boolean;\n isRefetching: boolean;\n isFetching: boolean;\n isLoading: boolean;\n refetch: () => Promise<void>;\n} {\n const errors = results\n .filter((result) => result.isError)\n .map((result) => result.error);\n\n // Treat queries that are idle (disabled) as non-blocking for aggregate status\n const enabledish = results.filter(\n (r) => r.fetchStatus !== \"idle\" || r.isSuccess || r.isError,\n );\n\n return {\n // Prefer flatMap to avoid extra intermediate arrays\n data: results.flatMap((result) =>\n result.isSuccess && Array.isArray(result.data) ? result.data : [],\n ),\n // Preserve a single error for compatibility and expose the full list for diagnostics\n error: errors[0] ?? null,\n errors,\n isPending: enabledish.some((result) => result.isPending),\n isSuccess:\n enabledish.length > 0 && enabledish.every((result) => result.isSuccess),\n isError: errors.length > 0,\n isPaused: enabledish.some((result) => result.isPaused),\n isRefetching: enabledish.some((result) => result.isRefetching),\n isFetching: enabledish.some((result) => result.isFetching),\n isLoading: enabledish.some((result) => result.isLoading),\n // Aggregate refetch to trigger all underlying queries\n refetch: async () => {\n await Promise.all(\n results.map(async (r) => {\n await r.refetch();\n }),\n );\n },\n };\n}\n\n/**\n * Type guard for narrowing McpServer to ConnectedMcpServer.\n * A connected server has a non-null client.\n * @param server - The MCP server to check\n * @returns True if the server is connected, false otherwise\n */\nexport function isConnectedMcpServer(\n server: McpServer,\n): server is ConnectedMcpServer {\n return \"client\" in server && server.client != null;\n}\n\n/**\n * Hook to get the prompt for the specified name.\n * @param promptName - The name of the prompt to get. Can be prefixed with serverKey (e.g., \"linear:issue\") or unprefixed.\n * @param args - The arguments to pass to the prompt.\n * @returns The prompt for the specified name.\n */\nexport function useTamboMcpPrompt(\n promptName: string | undefined,\n args: Record<string, string> = {},\n) {\n // figure out which server has the prompt\n const { data: promptEntries } = useTamboMcpPromptList();\n const promptEntry = promptEntries?.find(\n (prompt) => prompt.prompt.name === promptName,\n );\n // Use the stable server key (and the server instance itself) instead of brittle\n // name/url/transport matching.\n const mcpServer = promptEntry?.server;\n\n // Strip the prefix to get the original prompt name for the MCP server call\n const originalPromptName = promptName?.includes(\":\")\n ? promptName.split(\":\").slice(1).join(\":\")\n : promptName;\n\n // Canonicalize args to avoid unstable cache keys from object identity/order\n const sortedArgsEntries = Object.keys(args)\n .sort()\n .map((k) => [k, args[k]] as const);\n return useTamboQuery({\n // Include server identity and sorted args to prevent stale cache hits\n queryKey: [\"mcp-prompt\", promptName, mcpServer?.key, sortedArgsEntries],\n // Only run when we have a prompt name and a connected server\n enabled: Boolean(\n promptName && mcpServer && isConnectedMcpServer(mcpServer),\n ),\n queryFn: async (): Promise<GetPromptResult | null> => {\n if (\n !originalPromptName ||\n !mcpServer ||\n !isConnectedMcpServer(mcpServer)\n ) {\n return null;\n }\n const result = await mcpServer.client.client.getPrompt({\n name: originalPromptName,\n arguments: args,\n });\n return result ?? null; // return null because react-query doesn't like undefined results\n },\n });\n}\n\n/**\n * Hook to get the resources for all the registered MCP servers and registry.\n * @param search - Optional search string. For MCP servers, results are filtered locally after fetching.\n * For registry dynamic sources, the search is passed to listResources(search) for dynamic generation.\n * @returns The resources from MCP servers and the local registry, including the server that the resource was found on (null for registry resources).\n */\nexport function useTamboMcpResourceList(search?: string) {\n const mcpServers = useTamboMcpServers();\n const { resources: staticResources, resourceSource } = useTamboRegistry();\n\n // Build list of queries: MCP servers + optional dynamic resource source\n const queriesToRun = [\n // MCP server queries - search is NOT in queryKey so queries don't re-run on search change\n ...mcpServers.map((mcpServer) => ({\n queryKey: [\"mcp-resources\", mcpServer.key],\n // Only run for connected servers that have a client\n enabled: isConnectedMcpServer(mcpServer),\n queryFn: async (): Promise<McpResourceEntry[]> => {\n // Fast path: if this server doesn't have a client, skip work\n if (!isConnectedMcpServer(mcpServer)) return [];\n\n const result = await mcpServer.client.client.listResources();\n const resources: ListResourceItem[] = result?.resources ?? [];\n // Return resources without prefixes - we'll apply prefixing in combine\n const resourceEntries: McpResourceEntry[] = resources.map(\n (resource) => ({\n server: mcpServer,\n resource,\n }),\n );\n return resourceEntries;\n },\n })),\n // Dynamic resource source query (if exists) - search IS in queryKey to allow dynamic generation\n ...(resourceSource\n ? [\n {\n queryKey: [\"registry-resources\", \"dynamic\", search],\n enabled: true,\n queryFn: async (): Promise<InternalRegistryResourceEntry[]> => {\n if (!resourceSource) return [];\n const resources = await resourceSource.listResources(search);\n return resources.map((resource) => ({\n server: null,\n resource,\n isDynamic: true,\n }));\n },\n },\n ]\n : []),\n ];\n\n const queries = useTamboQueries({\n queries: queriesToRun,\n combine: (results) => {\n // Type assertion needed because queries can return different entry types\n const combined = combineArrayResults(\n results as UseQueryResult<InternalListResourceEntry[]>[],\n );\n\n // Add static registry resources (no query needed)\n const staticEntries: InternalRegistryResourceEntry[] =\n staticResources.map((resource) => ({\n server: null,\n resource,\n isDynamic: false,\n }));\n\n // Merge static resources with query results (registry resources first)\n const allData = [...staticEntries, ...combined.data];\n\n // Apply serverKey prefix to ALL resources for unified @serverKey:uri format\n // Registry resources get REGISTRY_SERVER_KEY prefix, MCP resources get their serverKey\n const prefixedData = allData.map((entry) => {\n if (entry.server === null) {\n // Registry resource - prefix with REGISTRY_SERVER_KEY\n return {\n ...entry,\n resource: {\n ...entry.resource,\n uri: `${REGISTRY_SERVER_KEY}:${entry.resource.uri}`,\n },\n };\n }\n // MCP resource - always prefix with serverKey\n return {\n ...entry,\n resource: {\n ...entry.resource,\n uri: `${entry.server.serverKey}:${entry.resource.uri}`,\n },\n };\n });\n\n return {\n ...combined,\n data: prefixedData,\n };\n },\n });\n\n // Filter results by search string - runs on every search change (not just query completion)\n // - MCP resources are filtered locally\n // - Static registry resources are filtered locally\n // - Dynamic registry resources are already filtered by listResources(search)\n const filteredData = React.useMemo((): InternalListResourceEntry[] => {\n if (!search) return queries.data;\n\n const normalizedSearch = search.toLowerCase();\n return queries.data.filter((entry) => {\n if (entry.server === null && entry.isDynamic) {\n return true;\n }\n\n const name = entry.resource.name?.toLowerCase() ?? \"\";\n const uri = entry.resource.uri.toLowerCase();\n return name.includes(normalizedSearch) || uri.includes(normalizedSearch);\n });\n }, [queries.data, search]);\n\n const publicData = React.useMemo(\n () => filteredData.map(toPublicResourceEntry),\n [filteredData],\n );\n\n return {\n ...queries,\n data: publicData,\n };\n}\n\n/**\n * Hook to get the resource for the specified URI.\n * @param resourceUri - The URI of the resource to get. Must be prefixed:\n * - MCP resources: prefixed with serverKey (e.g., \"linear:file://foo\")\n * - Registry resources: prefixed with \"registry:\" (e.g., \"registry:file://bar\")\n * @returns The resource for the specified URI.\n */\nexport function useTamboMcpResource(resourceUri: string | undefined) {\n const { resourceSource } = useTamboRegistry();\n const { data: resourceEntries } = useTamboMcpResourceList();\n\n // Find which server/source has the resource\n const resourceEntry = resourceEntries?.find(\n (entry) => entry.resource.uri === resourceUri,\n );\n\n // Determine if this is a registry resource or MCP resource\n const isRegistryResource = resourceEntry?.server === null;\n const mcpServer = resourceEntry?.server ?? null;\n\n // Check if the URI has the registry prefix\n const hasRegistryPrefix = Boolean(\n resourceUri?.startsWith(`${REGISTRY_SERVER_KEY}:`),\n );\n\n // Strip the prefix to get the original resource URI for fetching\n let originalResourceUri: string | undefined;\n if (isRegistryResource || hasRegistryPrefix) {\n const prefixLen = REGISTRY_SERVER_KEY.length + 1; // +1 for the colon\n originalResourceUri = resourceUri?.slice(prefixLen);\n } else if (mcpServer) {\n const prefixLen = mcpServer.serverKey.length + 1; // +1 for the colon\n originalResourceUri = resourceUri?.slice(prefixLen);\n }\n\n // Check if we can fetch this resource\n const hasRegistrySource = resourceSource != null;\n const hasConnectedMcpServer =\n mcpServer != null && isConnectedMcpServer(mcpServer);\n const canFetchFromRegistry =\n hasRegistrySource && (isRegistryResource || hasRegistryPrefix);\n const canFetchResource = Boolean(\n resourceUri && (canFetchFromRegistry || hasConnectedMcpServer),\n );\n\n const locationKey =\n isRegistryResource || hasRegistryPrefix\n ? REGISTRY_SERVER_KEY\n : mcpServer?.key;\n\n return useTamboQuery({\n queryKey: [\"resource\", resourceUri, locationKey],\n enabled: canFetchResource,\n queryFn: async (): Promise<ReadResourceResult | null> => {\n if (!originalResourceUri) {\n return null;\n }\n\n // Registry resource: use resourceSource.getResource\n if (resourceSource && (isRegistryResource || hasRegistryPrefix)) {\n const result = await resourceSource.getResource(originalResourceUri);\n return result ?? null;\n }\n\n // MCP resource: use MCP client\n if (mcpServer && isConnectedMcpServer(mcpServer)) {\n const result = await mcpServer.client.client.readResource({\n uri: originalResourceUri,\n });\n return result ?? null;\n }\n\n return null;\n },\n });\n}\n"]}
|
|
@@ -25,6 +25,9 @@ import { TamboGenerationStageContextProps, TamboThreadContextProps, TamboThreadP
|
|
|
25
25
|
* @param props.contextKey - Optional context key passed to thread input provider for scoping threads
|
|
26
26
|
* @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called
|
|
27
27
|
* @param props.initialMessages - Initial messages to be included in new threads
|
|
28
|
+
* @param props.getResource - Optional getResource function for registry resources
|
|
29
|
+
* @param props.listResources - Optional listResources function for registry resources
|
|
30
|
+
* @param props.resources - Optional static resources for the registry
|
|
28
31
|
* @returns The TamboProvider component
|
|
29
32
|
*/
|
|
30
33
|
export declare const TamboProvider: React.FC<PropsWithChildren<TamboClientProviderProps & TamboRegistryProviderProps & TamboThreadProviderProps & TamboContextHelpersProviderProps>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAEL,uBAAuB,EAEvB,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,sBAAsB,EAGvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,+BAA+B,EAE/B,gCAAgC,EAEjC,MAAM,kCAAkC,CAAC;AAM1C,OAAO,EAEL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,gCAAgC,EAChC,uBAAuB,EAEvB,wBAAwB,EAEzB,MAAM,yBAAyB,CAAC;AAEjC
|
|
1
|
+
{"version":3,"file":"tambo-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAA6B,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAEL,uBAAuB,EAEvB,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAG3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,sBAAsB,EAGvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,+BAA+B,EAE/B,gCAAgC,EAEjC,MAAM,kCAAkC,CAAC;AAM1C,OAAO,EAEL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,gCAAgC,EAChC,uBAAuB,EAEvB,wBAAwB,EAEzB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAClC,iBAAiB,CACf,wBAAwB,GACtB,0BAA0B,GAC1B,wBAAwB,GACxB,gCAAgC,CACnC,CAiEF,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,GACrD,uBAAuB,GACvB,gCAAgC,GAChC,0BAA0B,GAC1B,wBAAwB,GACxB,+BAA+B,GAC/B,sBAAsB,CAAC;AAEzB,eAAO,MAAM,YAAY,kCAExB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAgC9D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,yBAEpB,CAAC"}
|
|
@@ -29,6 +29,9 @@ import { TamboThreadProvider, useTamboThread, } from "./tambo-thread-provider";
|
|
|
29
29
|
* @param props.contextKey - Optional context key passed to thread input provider for scoping threads
|
|
30
30
|
* @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called
|
|
31
31
|
* @param props.initialMessages - Initial messages to be included in new threads
|
|
32
|
+
* @param props.getResource - Optional getResource function for registry resources
|
|
33
|
+
* @param props.listResources - Optional listResources function for registry resources
|
|
34
|
+
* @param props.resources - Optional static resources for the registry
|
|
32
35
|
* @returns The TamboProvider component
|
|
33
36
|
*/
|
|
34
37
|
export const TamboProvider = ({ children, tamboUrl, apiKey, userToken, components, environment, tools, mcpServers, streaming, autoGenerateThreadName, autoGenerateNameThreshold, contextHelpers, contextKey, initialMessages, onCallUnregisteredTool, getResource, listResources, resources, }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAqB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EACL,kBAAkB,EAElB,mBAAmB,GAEpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,8BAA8B,EAC9B,yBAAyB,GAC1B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAEL,2BAA2B,EAE3B,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EACL,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAGL,mBAAmB,EAEnB,cAAc,GACf,MAAM,yBAAyB,CAAC;AAEjC
|
|
1
|
+
{"version":3,"file":"tambo-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,EAAE,EAAqB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EACL,kBAAkB,EAElB,mBAAmB,GAEpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,E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;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,UAAU,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["\"use client\";\nimport React, { PropsWithChildren, createContext, useContext } from \"react\";\nimport { TamboMcpProvider } from \"../mcp/tambo-mcp-provider\";\nimport { TamboInteractableContext } from \"../model/tambo-interactable\";\nimport {\n TamboClientContext,\n TamboClientContextProps,\n TamboClientProvider,\n TamboClientProviderProps,\n} from \"./tambo-client-provider\";\nimport {\n TamboComponentContextProps,\n TamboComponentProvider,\n useTamboComponent,\n} from \"./tambo-component-provider\";\nimport {\n ContextAttachmentState,\n TamboContextAttachmentProvider,\n useTamboContextAttachment,\n} from \"./tambo-context-attachment-provider\";\nimport {\n TamboContextHelpersContextProps,\n TamboContextHelpersProvider,\n TamboContextHelpersProviderProps,\n useTamboContextHelpers,\n} from \"./tambo-context-helpers-provider\";\nimport {\n TamboInteractableProvider,\n useTamboInteractable,\n} from \"./tambo-interactable-provider\";\nimport { TamboMcpTokenProvider } from \"./tambo-mcp-token-provider\";\nimport {\n TamboRegistryProvider,\n TamboRegistryProviderProps,\n} from \"./tambo-registry-provider\";\nimport { TamboThreadInputProvider } from \"./tambo-thread-input-provider\";\nimport {\n TamboGenerationStageContextProps,\n TamboThreadContextProps,\n TamboThreadProvider,\n TamboThreadProviderProps,\n useTamboThread,\n} from \"./tambo-thread-provider\";\n\n/**\n * The TamboProvider gives full access to the whole Tambo API. This includes the\n * TamboAI client, the component registry, the current thread context, and interactable components.\n * @param props - The props for the TamboProvider\n * @param props.children - The children to wrap\n * @param props.tamboUrl - The URL of the Tambo API\n * @param props.apiKey - The API key for the Tambo API\n * @param props.components - The components to register\n * @param props.environment - The environment to use for the Tambo API\n * @param props.tools - The tools to register\n * @param props.mcpServers - The MCP servers to register (metadata only - use TamboMcpProvider for connections)\n * @param props.streaming - Whether to stream the response by default. Defaults to true.\n * @param props.autoGenerateThreadName - Whether to automatically generate thread names. Defaults to true.\n * @param props.autoGenerateNameThreshold - The message count threshold at which the thread name will be auto-generated. Defaults to 3.\n * @param props.contextHelpers - Configuration for which context helpers are enabled/disabled\n * @param props.userToken - The user's OAuth token (access or ID) used to identify the user and exchange for a Tambo session token\n * @param props.contextKey - Optional context key passed to thread input provider for scoping threads\n * @param props.onCallUnregisteredTool - Callback function called when an unregistered tool is called\n * @param props.initialMessages - Initial messages to be included in new threads\n * @param props.getResource - Optional getResource function for registry resources\n * @param props.listResources - Optional listResources function for registry resources\n * @param props.resources - Optional static resources for the registry\n * @returns The TamboProvider component\n */\nexport const TamboProvider: React.FC<\n PropsWithChildren<\n TamboClientProviderProps &\n TamboRegistryProviderProps &\n TamboThreadProviderProps &\n TamboContextHelpersProviderProps\n >\n> = ({\n children,\n tamboUrl,\n apiKey,\n userToken,\n components,\n environment,\n tools,\n mcpServers,\n streaming,\n autoGenerateThreadName,\n autoGenerateNameThreshold,\n contextHelpers,\n contextKey,\n initialMessages,\n onCallUnregisteredTool,\n getResource,\n listResources,\n resources,\n}) => {\n return (\n <TamboClientProvider\n tamboUrl={tamboUrl}\n apiKey={apiKey}\n environment={environment}\n userToken={userToken}\n >\n <TamboRegistryProvider\n components={components}\n tools={tools}\n mcpServers={mcpServers}\n onCallUnregisteredTool={onCallUnregisteredTool}\n getResource={getResource}\n listResources={listResources}\n resources={resources}\n >\n <TamboContextHelpersProvider contextHelpers={contextHelpers}>\n <TamboThreadProvider\n contextKey={contextKey}\n streaming={streaming}\n autoGenerateThreadName={autoGenerateThreadName}\n autoGenerateNameThreshold={autoGenerateNameThreshold}\n initialMessages={initialMessages}\n >\n <TamboMcpTokenProvider>\n <TamboMcpProvider contextKey={contextKey}>\n <TamboContextAttachmentProvider>\n <TamboComponentProvider>\n <TamboInteractableProvider>\n <TamboThreadInputProvider>\n <TamboCompositeProvider>\n {children}\n </TamboCompositeProvider>\n </TamboThreadInputProvider>\n </TamboInteractableProvider>\n </TamboComponentProvider>\n </TamboContextAttachmentProvider>\n </TamboMcpProvider>\n </TamboMcpTokenProvider>\n </TamboThreadProvider>\n </TamboContextHelpersProvider>\n </TamboRegistryProvider>\n </TamboClientProvider>\n );\n};\n\nexport type TamboContextProps = TamboClientContextProps &\n TamboThreadContextProps &\n TamboGenerationStageContextProps &\n TamboComponentContextProps &\n TamboInteractableContext &\n TamboContextHelpersContextProps &\n ContextAttachmentState;\n\nexport const TamboContext = createContext<TamboContextProps>(\n {} as TamboContextProps,\n);\n\n/**\n * TamboCompositeProvider is a provider that combines the TamboClient,\n * TamboThread, TamboComponent, and TamboInteractable providers\n * @param props - The props for the TamboCompositeProvider\n * @param props.children - The children to wrap\n * @returns The wrapped component\n */\nexport const TamboCompositeProvider: React.FC<PropsWithChildren> = ({\n children,\n}) => {\n const threads = useTamboThread();\n const clientContext = useContext(TamboClientContext);\n if (!clientContext) {\n throw new Error(\n \"TamboCompositeProvider must be used within a TamboClientProvider\",\n );\n }\n const { client, queryClient, isUpdatingToken } = clientContext;\n const componentRegistry = useTamboComponent();\n const interactableComponents = useTamboInteractable();\n const contextHelpers = useTamboContextHelpers();\n const contextAttachment = useTamboContextAttachment();\n\n return (\n <TamboContext.Provider\n value={{\n client,\n queryClient,\n isUpdatingToken,\n ...componentRegistry,\n ...threads,\n ...interactableComponents,\n ...contextHelpers,\n ...contextAttachment,\n }}\n >\n {children}\n </TamboContext.Provider>\n );\n};\n\n/**\n * The useTambo hook provides access to the Tambo API. This is the primary entrypoint\n * for the Tambo React SDK.\n *\n * This includes the TamboAI client, the component registry, the current thread context,\n * and interactable component management.\n * @returns The Tambo API\n */\nexport const useTambo = () => {\n return useContext(TamboContext);\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-content-resolver.d.ts","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E,OAAO,KAAK,EAAsB,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"resource-content-resolver.d.ts","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E,OAAO,KAAK,EAAsB,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAY7D;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAC3C,YAAY,EAAE,MAAM,EAAE,EACtB,UAAU,EAAE,SAAS,EAAE,EACvB,cAAc,EAAE,cAAc,GAAG,SAAS,GACzC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAyE1C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAI1D"}
|
|
@@ -2,6 +2,8 @@ import { REGISTRY_SERVER_KEY, ServerType } from "../mcp/mcp-constants";
|
|
|
2
2
|
/**
|
|
3
3
|
* Type guard for narrowing McpServer to a connected server.
|
|
4
4
|
* A connected server has a non-null client.
|
|
5
|
+
* @param server - The MCP server to check
|
|
6
|
+
* @returns True if the server is connected, false otherwise
|
|
5
7
|
*/
|
|
6
8
|
function isConnectedMcpServer(server) {
|
|
7
9
|
return "client" in server && server.client != null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-content-resolver.js","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvE
|
|
1
|
+
{"version":3,"file":"resource-content-resolver.js","sourceRoot":"","sources":["../../src/util/resource-content-resolver.ts"],"names":[],"mappings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AAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACnD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,IAAI,GAAG,EAAE,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import type { ReadResourceResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport { REGISTRY_SERVER_KEY, ServerType } from \"../mcp/mcp-constants\";\nimport type { ConnectedMcpServer, McpServer } from \"../mcp/tambo-mcp-provider\";\nimport type { ResourceSource } from \"../model/resource-info\";\n\n/**\n * Type guard for narrowing McpServer to a connected server.\n * A connected server has a non-null client.\n * @param server - The MCP server to check\n * @returns True if the server is connected, false otherwise\n */\nfunction isConnectedMcpServer(server: McpServer): server is ConnectedMcpServer {\n return \"client\" in server && server.client != null;\n}\n\n/**\n * Resolves content for client-side resources (MCP and registry).\n * Server-side (internal Tambo) resources are skipped - the backend can resolve them.\n * @param resourceUris - Prefixed URIs (e.g., \"linear:file://foo\", \"registry:file://bar\", \"tambo-abc:test://resource\")\n * @param mcpServers - Active MCP servers including virtual registry server\n * @param resourceSource - Registry resource source (listResources/getResource)\n * @returns Map of prefixedUri -> ReadResourceResult for resolved resources.\n * Resources that failed to fetch or are internal server resources won't be in the map.\n */\nexport async function resolveResourceContents(\n resourceUris: string[],\n mcpServers: McpServer[],\n resourceSource: ResourceSource | undefined,\n): Promise<Map<string, ReadResourceResult>> {\n const results = new Map<string, ReadResourceResult>();\n\n const fetchPromises = resourceUris.map(async (prefixedUri) => {\n // Parse serverKey and original URI\n // Format: serverKey:originalUri (e.g., \"linear:file://foo\", \"registry:docs://readme\")\n const colonIndex = prefixedUri.indexOf(\":\");\n if (colonIndex === -1) return;\n\n const serverKey = prefixedUri.slice(0, colonIndex);\n const originalUri = prefixedUri.slice(colonIndex + 1);\n\n try {\n // Handle registry resources directly - no server lookup needed\n // Registry resources are local to the browser and resolved via resourceSource\n if (serverKey === REGISTRY_SERVER_KEY) {\n if (!resourceSource) {\n console.warn(\n `No resource source available to resolve registry resource: ${prefixedUri}`,\n );\n return;\n }\n const registryContent = await resourceSource.getResource(originalUri);\n if (registryContent) {\n results.set(prefixedUri, registryContent);\n }\n return;\n }\n\n // For non-registry resources, find the server by serverKey\n const server = mcpServers.find((s) => s.serverKey === serverKey);\n if (!server) {\n console.warn(`No server found for resource: ${prefixedUri}`);\n return;\n }\n\n switch (server.serverType) {\n case ServerType.TAMBO_INTERNAL:\n // Skip internal server resources - backend can resolve these\n return;\n\n case ServerType.TAMBO_REGISTRY:\n // Should not reach here since we handle registry above, but keep for safety\n return;\n\n case ServerType.BROWSER_SIDE: {\n // Client-side MCP resource\n if (!isConnectedMcpServer(server)) {\n console.warn(\n `MCP server not connected for resource: ${prefixedUri}`,\n );\n return;\n }\n const mcpContent = (await server.client.client.readResource({\n uri: originalUri,\n })) as ReadResourceResult | null;\n if (mcpContent) {\n results.set(prefixedUri, mcpContent);\n }\n return;\n }\n }\n } catch (error) {\n // Graceful fallback - log warning and continue without content\n console.warn(\n `Failed to fetch resource content for ${prefixedUri}:`,\n error,\n );\n }\n });\n\n await Promise.all(fetchPromises);\n return results;\n}\n\n/**\n * Extracts resource URIs from text using the `@serverKey:uri` pattern.\n * @param text - Text potentially containing resource references\n * @returns Array of prefixed resource URIs (e.g., [\"linear:file://foo\", \"registry:file://bar\"])\n */\nexport function extractResourceUris(text: string): string[] {\n const pattern = /@([a-zA-Z0-9-]+):(\\S+)/g;\n const matches = Array.from(text.matchAll(pattern));\n return matches.map(([, serverKey, uri]) => `${serverKey}:${uri}`);\n}\n"]}
|