Skip to main content
Glama

retrieve_relevant_thoughts

Identifies and retrieves related thoughts from long-term storage based on shared tags with a specified thought, aiding in structured idea exploration and analysis.

Instructions

Finds thoughts from long-term storage that share tags with the specified thought.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
thought_idYesThe ID of the thought to find related thoughts for

Implementation Reference

  • Main handler method for the 'retrieve_relevant_thoughts' tool. It retrieves the specified thought by ID, calls the memory manager to find related thoughts based on shared tags, and returns a formatted JSON response with the results.
    retrieveRelevantThoughts(input: { thought_id: number }): any { try { // Find the thought const thought = this.findThoughtById(input.thought_id); if (!thought) { throw new Error(`Thought with ID ${input.thought_id} not found`); } // Get related thoughts const relatedThoughts = this.memoryManager.retrieveRelevantThoughts(thought); return { content: [{ type: "text", text: JSON.stringify({ status: "success", retrieval: { thoughtNumber: thought.thoughtNumber, relatedThoughtsCount: relatedThoughts.length, relatedThoughts: relatedThoughts.map(t => ({ thoughtNumber: t.thoughtNumber, stage: t.stage, tags: t.tags })) } }, null, 2) }] }; } catch (e) { return this.handleError(e); } }
  • Core helper function in MemoryManager class that implements the logic to retrieve relevant thoughts by finding those that share any tags with the input thought from long-term storage.
    retrieveRelevantThoughts(currentThought: ThoughtData): ThoughtData[] { const relevant: ThoughtData[] = []; for (const thoughts of Object.values(this.longTermStorage)) { for (const thought of thoughts) { if (thought.tags.some(tag => currentThought.tags.includes(tag))) { relevant.push(thought); } } } return relevant; }
  • Zod schema defining the input parameters for the tool: a positive integer thought_id.
    export const retrieveRelevantThoughtsSchema = z.object({ thought_id: z.number().int().positive().describe("The ID of the thought to find related thoughts for") });
  • src/tools.ts:59-64 (registration)
    Tool registration object defining the name, description, parameters schema, and input schema for MCP tool listing.
    export const retrieveRelevantThoughtsTool: Tool = { name: "retrieve_relevant_thoughts", description: "Finds thoughts from long-term storage that share tags with the specified thought.", parameters: retrieveRelevantThoughtsSchema, inputSchema: zodToInputSchema(retrieveRelevantThoughtsSchema) };
  • index.ts:120-137 (registration)
    Dispatch handler in the MCP callTool request that validates input, extracts thought_id, and invokes the server handler method.
    case "retrieve_relevant_thoughts": { if (!params.arguments) { console.error("ERROR: params.arguments object is undefined in retrieve_relevant_thoughts request"); return { content: [{ type: "text", text: JSON.stringify({ error: "Invalid request: params.arguments object is undefined", status: "failed" }) }], isError: true }; } const { thought_id } = params.arguments as { thought_id: number }; return thinkingServer.retrieveRelevantThoughts({ thought_id }); }

Other Tools

Related Tools

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/Promptly-Technologies-LLC/mcp-structured-thinking'

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