ChatmcpPrompts.ts20 matches
2* Frontend MCP Prompts Utility
3*
4* Handles fetching prompts from MCP servers directly from the frontend
5* without requiring backend proxy endpoints.
6*/
2324/**
25* Fetch prompts from a single MCP server
26* @param server - MCP server configuration
27* @returns Promise<MCPPrompt[]>
28*/
29async function fetchPromptsFromServer(server: MCPServerConfig): Promise<MCPPrompt[]> {
30if (!server.enabled || !server.url) {
31return [];
47try {
48// First, initialize the connection
49const initResponse = await fetch(server.url, {
50method: "POST",
51headers,
71}
7273// Then fetch prompts
74const promptsResponse = await fetch(server.url, {
75method: "POST",
76headers,
100}
101}
102} catch (fetchError: any) {
103clearTimeout(timeoutId);
104105if (fetchError.name === "AbortError") {
106console.warn(`Timeout fetching prompts from ${server.name}`);
107} else {
108throw fetchError;
109}
110}
112return [];
113} catch (error) {
114console.warn(`Failed to fetch prompts from ${server.name}:`, error);
115return [];
116}
118119/**
120* Fetch prompts from all enabled MCP servers
121* @param servers - Array of MCP server configurations
122* @returns Promise<MCPPromptsResult>
123*/
124export async function fetchMCPPrompts(servers: MCPServerConfig[]): Promise<MCPPromptsResult> {
125try {
126if (!servers || !Array.isArray(servers)) {
141}
142143// Fetch prompts from all enabled servers concurrently
144const promptPromises = enabledServers.map(server => fetchPromptsFromServer(server));
145const promptArrays = await Promise.all(promptPromises);
146175176/**
177* Fetch prompts with caching support
178* @param servers - Array of MCP server configurations
179* @param cacheKey - Optional cache key for localStorage
181* @returns Promise<MCPPromptsResult>
182*/
183export async function fetchMCPPromptsWithCache(
184servers: MCPServerConfig[],
185cacheKey: string = "mcp_prompts_cache",
202}
203204// Fetch fresh data
205const result = await fetchMCPPrompts(servers);
206207// Cache successful results
223try {
224const { data } = JSON.parse(cached);
225console.warn("Using stale cached prompts due to fetch error:", error);
226return {
227success: true,
projectTreemain.ts1 match
22);
2324export default app.fetch;
25
test-yt-transcriptmain.tsx1 match
3let videoId = "https://www.youtube.com/watch?v=5orZtBqftE8";
4console.log("starting...");
5let x = YoutubeTranscript.fetchTranscript(videoId);
6console.log(x);
7};
crm_OBUO_FARMSproducts.ts10 matches
20});
21} catch (error) {
22console.error('Error fetching products:', error);
23return c.json<ApiResponse<null>>({
24success: false,
25error: "Failed to fetch products"
26}, 500);
27}
37});
38} catch (error) {
39console.error('Error fetching low stock products:', error);
40return c.json<ApiResponse<null>>({
41success: false,
42error: "Failed to fetch low stock products"
43}, 500);
44}
69});
70} catch (error) {
71console.error('Error fetching product:', error);
72return c.json<ApiResponse<null>>({
73success: false,
74error: "Failed to fetch product"
75}, 500);
76}
259});
260} catch (error) {
261console.error('Error fetching stock movements:', error);
262return c.json<ApiResponse<null>>({
263success: false,
264error: "Failed to fetch stock movements"
265}, 500);
266}
278});
279} catch (error) {
280console.error('Error fetching all stock movements:', error);
281return c.json<ApiResponse<null>>({
282success: false,
283error: "Failed to fetch stock movements"
284}, 500);
285}
stevensDemosendDailyBrief.ts1 match
135const lastSunday = today.startOf("week").minus({ days: 1 });
136137// Fetch relevant memories using the utility function
138const memories = await getRelevantMemories();
139
stevensDemoNotebookView.tsx12 matches
67const [currentPage, setCurrentPage] = useState(1);
6869const fetchMemories = useCallback(async () => {
70setLoading(true);
71setError(null);
72try {
73const response = await fetch(API_BASE);
74if (!response.ok) {
75throw new Error(`HTTP error! status: ${response.status}`);
78setMemories(data);
79} catch (e) {
80console.error("Failed to fetch memories:", e);
81setError(e.message || "Failed to fetch memories.");
82} finally {
83setLoading(false);
8687useEffect(() => {
88fetchMemories();
89}, [fetchMemories]);
9091const handleAddMemory = async (e: React.FormEvent) => {
100101try {
102const response = await fetch(API_BASE, {
103method: "POST",
104headers: { "Content-Type": "application/json" },
112setNewMemoryTags("");
113setShowAddForm(false);
114await fetchMemories();
115} catch (e) {
116console.error("Failed to add memory:", e);
123124try {
125const response = await fetch(`${API_BASE}/${id}`, {
126method: "DELETE",
127});
129throw new Error(`HTTP error! status: ${response.status}`);
130}
131await fetchMemories();
132} catch (e) {
133console.error("Failed to delete memory:", e);
155156try {
157const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
158method: "PUT",
159headers: { "Content-Type": "application/json" },
164}
165setEditingMemory(null);
166await fetchMemories();
167} catch (e) {
168console.error("Failed to update memory:", e);
stevensDemoindex.ts2 matches
135));
136137// HTTP vals expect an exported "fetch handler"
138export default app.fetch;
stevensDemo.cursorrules5 matches
163```
1641655. **fetchTranspiledJavaScript** - Fetch and transpile TypeScript to JavaScript:
166```ts
167const jsCode = await fetchTranspiledJavaScript("https://esm.town/v/username/project/path/to/file.ts");
168```
169242243// Inject data to avoid extra round-trips
244const initialData = await fetchInitialData();
245const dataScript = `<script>
246window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
3003015. **API Design:**
302- `fetch` handler is the entry point for HTTP vals
303- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
304- Properly handle CORS if needed for external access
stevensDemoApp.tsx17 matches
82const [cookieAndTeaMode, setCookieAndTeaMode] = useState(false);
8384// Fetch images from backend instead of blob storage directly
85useEffect(() => {
86// Set default background color in case image doesn't load
89}
9091// Fetch avatar image
92fetch("/api/images/stevens.jpg")
93.then((response) => {
94if (response.ok) return response.blob();
103});
104105// Fetch wood background
106fetch("/api/images/wood.jpg")
107.then((response) => {
108if (response.ok) return response.blob();
129}, []);
130131const fetchMemories = useCallback(async () => {
132setLoading(true);
133setError(null);
134try {
135const response = await fetch(API_BASE);
136if (!response.ok) {
137throw new Error(`HTTP error! status: ${response.status}`);
154}
155} catch (e) {
156console.error("Failed to fetch memories:", e);
157setError(e.message || "Failed to fetch memories.");
158} finally {
159setLoading(false);
162163useEffect(() => {
164fetchMemories();
165}, [fetchMemories]);
166167const handleAddMemory = async (e: React.FormEvent) => {
176177try {
178const response = await fetch(API_BASE, {
179method: "POST",
180headers: { "Content-Type": "application/json" },
188setNewMemoryTags("");
189setShowAddForm(false);
190await fetchMemories();
191} catch (e) {
192console.error("Failed to add memory:", e);
199200try {
201const response = await fetch(`${API_BASE}/${id}`, {
202method: "DELETE",
203});
205throw new Error(`HTTP error! status: ${response.status}`);
206}
207await fetchMemories();
208} catch (e) {
209console.error("Failed to delete memory:", e);
231232try {
233const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
234method: "PUT",
235headers: { "Content-Type": "application/json" },
240}
241setEditingMemory(null);
242await fetchMemories();
243} catch (e) {
244console.error("Failed to update memory:", e);