Skip to main content
Glama

get_cluster_insights

Analyze memory cluster performance and structure to identify patterns, optimize storage, and track data relationships in AI systems.

Instructions

Get detailed analytics for a memory cluster

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cluster_idYesUUID of the cluster

Implementation Reference

  • Main handler implementation that retrieves detailed analytics for a memory cluster. Performs a complex SQL query with joins across memory_clusters, memory_cluster_members, and memories tables to aggregate statistics including total memories, average importance, last memory access, recent memories count, average membership strength, and memory types distribution.
    async getClusterInsights(clusterId) {
      try {
        const insights = await this.db
          .select({
            id: schema.memoryClusters.id,
            name: schema.memoryClusters.name,
            clusterType: schema.memoryClusters.clusterType,
            description: schema.memoryClusters.description,
            importanceScore: schema.memoryClusters.importanceScore,
            totalMemories: sql`COUNT(${schema.memoryClusterMembers.memoryId})`.as('total_memories'),
            avgImportance: sql`AVG(${schema.memories.importance})`.as('avg_importance'),
            lastMemoryAccess: sql`MAX(${schema.memories.lastAccessed})`.as('last_memory_access'),
            recentMemories: sql`COUNT(CASE WHEN ${schema.memories.createdAt} > CURRENT_TIMESTAMP - INTERVAL '7 days' THEN 1 END)`.as('recent_memories'),
            avgMembershipStrength: sql`AVG(${schema.memoryClusterMembers.membershipStrength})`.as('avg_membership_strength'),
            memoryTypes: sql`array_agg(DISTINCT ${schema.memories.type})`.as('memory_types')
          })
          .from(schema.memoryClusters)
          .leftJoin(
            schema.memoryClusterMembers,
            eq(schema.memoryClusters.id, schema.memoryClusterMembers.clusterId)
          )
          .leftJoin(
            schema.memories,
            and(
              eq(schema.memoryClusterMembers.memoryId, schema.memories.id),
              eq(schema.memories.status, 'active')
            )
          )
          .where(eq(schema.memoryClusters.id, clusterId))
          .groupBy(schema.memoryClusters.id)
          .limit(1);
    
        return insights[0] || null;
      } catch (error) {
        console.warn('Cluster insights query failed:', error.message);
        return null;
      }
    }
  • Tool schema definition specifying the input validation. Requires a cluster_id parameter (UUID string) and provides description for getting detailed analytics for a memory cluster.
      name: "get_cluster_insights",
      description: "Get detailed analytics for a memory cluster",
      inputSchema: {
        type: "object",
        properties: {
          cluster_id: {
            type: "string",
            description: "UUID of the cluster"
          }
        },
        required: ["cluster_id"]
      }
    },
  • mcp.js:374-386 (registration)
    MCP tool registration in the tools list, defining the tool name, description, and input schema for the get_cluster_insights tool.
      name: "get_cluster_insights",
      description: "Get detailed analytics for a memory cluster",
      inputSchema: {
        type: "object",
        properties: {
          cluster_id: {
            type: "string",
            description: "UUID of the cluster"
          }
        },
        required: ["cluster_id"]
      }
    },
  • mcp.js:645-647 (registration)
    Tool routing handler in the switch statement that calls memoryManager.getClusterInsights() with the cluster_id argument and returns JSON-serialized results.
    case "get_cluster_insights":
      const clusterInsights = await memoryManager.getClusterInsights(args.cluster_id);
      return { content: [{ type: "text", text: JSON.stringify(clusterInsights, null, 2) }] };
  • Database schema definition for memory_clusters table that stores cluster metadata including id, name, clusterType, description, importanceScore, and other fields used by the insights query.
    export const memoryClusters = pgTable("memory_clusters", {
    	id: uuid().defaultRandom().primaryKey().notNull(),
    	createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
    	updatedAt: timestamp("updated_at", { withTimezone: true, mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
    	clusterType: clusterType("cluster_type").notNull(),
    	name: text().notNull(),
    	description: text(),
    	centroidEmbedding: vector("centroid_embedding", { dimensions: 1536 }),
    	emotionalSignature: jsonb("emotional_signature"),
    	keywords: text().array(),
    	importanceScore: doublePrecision("importance_score").default(0),
    	coherenceScore: doublePrecision("coherence_score"),
    	lastActivated: timestamp("last_activated", { withTimezone: true, mode: 'string' }),
    	activationCount: integer("activation_count").default(0),
    	worldviewAlignment: doublePrecision("worldview_alignment"),
    }, (table) => [
    	index("memory_clusters_centroid_embedding_idx").using("ivfflat", table.centroidEmbedding.asc().nullsLast().op("vector_cosine_ops")),
    	index("memory_clusters_cluster_type_importance_score_idx").using("btree", table.clusterType.asc().nullsLast().op("enum_ops"), table.importanceScore.desc().nullsFirst().op("float8_ops")),
    	index("memory_clusters_last_activated_idx").using("btree", table.lastActivated.desc().nullsFirst().op("timestamptz_ops")),
    ]);

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It implies a read-only operation ('Get') but doesn't specify whether it requires authentication, has rate limits, returns structured data, or involves side effects. For a tool that presumably returns analytics data, this lack of behavioral context is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary words. Every word earns its place: 'Get' (action), 'detailed analytics' (output type), 'for a memory cluster' (target). There's no redundancy or fluff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations, no output schema, and a single parameter, the description is incomplete. It doesn't explain what 'detailed analytics' includes (e.g., metrics, timestamps, visualizations), how results are structured, or error conditions. Given the complexity implied by 'analytics' and lack of structured fields, more context is needed for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the single parameter 'cluster_id' documented as a UUID. The description adds no additional parameter semantics beyond what the schema provides—it doesn't clarify format examples, valid UUID ranges, or how to obtain cluster IDs. Given the high schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get detailed analytics') and target resource ('for a memory cluster'), making the purpose immediately understandable. It distinguishes from siblings like 'get_memory_clusters' (which likely lists clusters) and 'get_memory_health' (which might provide health metrics rather than analytics). However, it doesn't specify what 'detailed analytics' includes, leaving some ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'get_memory_clusters' or 'get_memory_health'. It doesn't mention prerequisites (e.g., needing an existing cluster) or contextual cues (e.g., use when analyzing cluster performance). The agent must infer usage from the name and sibling tools alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.