Skip to main content
Glama

K8s MCP

by rahul007-bit
chatStore.js2.85 kB
import { create } from 'zustand' import { v4 as uuidv4 } from 'uuid' export const useChatStore = create((set) => ({ messages: [], toolCalls: [], conversationId: null, loading: false, currentMessageId: null, // Track which message is being responded to initConversation: () => set({ conversationId: uuidv4() }), addMessage: (message) => set((state) => { // If it's a streamed message, append to the last assistant message if (message.stream && state.messages.length > 0) { const lastMessage = state.messages[state.messages.length - 1] if (lastMessage.role === 'assistant') { console.log(`[Store] Streaming: appending to message ${lastMessage.messageId}`) // Just update the content, keep everything else const updated = [ ...state.messages.slice(0, -1), { ...lastMessage, content: (lastMessage.content || '') + (message.content || '') } ] return { messages: updated } } } // Add new message with unique ID const messageId = uuidv4() console.log(`[Store] addMessage: role=${message.role}, messageId=${messageId}`) const newState = { messages: [...state.messages, { ...message, messageId, toolCalls: [] }] } // Set currentMessageId for assistant messages so tool calls get associated if (message.role === 'assistant') { newState.currentMessageId = messageId console.log(`[Store] Set currentMessageId: ${messageId}`) } return newState }), addToolCall: (toolCall) => set((state) => { console.log(`[Store] addToolCall: ${toolCall.tool_name}, currentMessageId=${state.currentMessageId}`) // Add to global tool calls list const newToolCall = { ...toolCall, id: uuidv4(), timestamp: new Date().toISOString() } const updatedToolCalls = [...state.toolCalls, newToolCall] // If we have a current message, add tool call to it if (state.currentMessageId) { console.log(`[Store] Linking tool to message ${state.currentMessageId}`) const updatedMessages = state.messages.map(msg => { if (msg.messageId === state.currentMessageId) { console.log(`[Store] ✓ Added tool to message`) return { ...msg, toolCalls: [...(msg.toolCalls || []), newToolCall] } } return msg }) return { toolCalls: updatedToolCalls, messages: updatedMessages } } // If no current message, just add to global list console.log(`[Store] ✗ No currentMessageId, tool only added to global list`) return { toolCalls: updatedToolCalls } }), clearHistory: () => set({ messages: [], toolCalls: [], conversationId: uuidv4(), currentMessageId: null }) }))

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/rahul007-bit/k8s-mcp'

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