Skip to main content
Glama
PSPDFKit

Nutrient Document Engine MCP Server

by PSPDFKit
Thread.tsx1.96 kB
import { validate } from "uuid"; import { getApiKey } from "@/lib/api-key"; import { Thread } from "@langchain/langgraph-sdk"; import { useQueryState } from "nuqs"; import { createContext, useContext, ReactNode, useCallback, useState, Dispatch, SetStateAction, } from "react"; import { createClient } from "./client"; interface ThreadContextType { getThreads: () => Promise<Thread[]>; threads: Thread[]; setThreads: Dispatch<SetStateAction<Thread[]>>; threadsLoading: boolean; setThreadsLoading: Dispatch<SetStateAction<boolean>>; } const ThreadContext = createContext<ThreadContextType | undefined>(undefined); function getThreadSearchMetadata( assistantId: string, ): { graph_id: string } | { assistant_id: string } { if (validate(assistantId)) { return { assistant_id: assistantId }; } else { return { graph_id: assistantId }; } } export function ThreadProvider({ children }: { children: ReactNode }) { const [apiUrl] = useQueryState("apiUrl"); const [assistantId] = useQueryState("assistantId"); const [threads, setThreads] = useState<Thread[]>([]); const [threadsLoading, setThreadsLoading] = useState(false); const getThreads = useCallback(async (): Promise<Thread[]> => { if (!apiUrl || !assistantId) return []; const client = createClient(apiUrl, getApiKey() ?? undefined); const threads = await client.threads.search({ metadata: { ...getThreadSearchMetadata(assistantId), }, limit: 100, }); return threads; }, [apiUrl, assistantId]); const value = { getThreads, threads, setThreads, threadsLoading, setThreadsLoading, }; return ( <ThreadContext.Provider value={value}>{children}</ThreadContext.Provider> ); } export function useThreads() { const context = useContext(ThreadContext); if (context === undefined) { throw new Error("useThreads must be used within a ThreadProvider"); } return context; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PSPDFKit/nutrient-document-engine-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server