Skip to main content
Glama
DollhouseMCP

DollhouseMCP

Official

get_element_relationships

Analyze connections between elements in DollhouseMCP, including semantic similarities, verb-based links, and cross-element references for personas, skills, templates, agents, memories, and ensembles.

Instructions

Get all relationships for a specific element, including semantic similarities, verb-based connections, and cross-element references.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
element_nameYesName of the element to get relationships for
element_typeNoType of the element. If not specified, searches all types.
relationship_typesNoFilter by specific relationship types. If not specified, returns all types.

Implementation Reference

  • Main execution logic for the get_element_relationships tool. Validates input, normalizes unicode, fetches relationships from EnhancedIndexManager, filters by type, formats markdown response with icons and strengths.
    async getElementRelationships(options: {
      elementName: string;
      elementType?: string;
      relationshipTypes?: string[];
    }) {
      try {
        // FIX: DMCP-SEC-004 - Normalize Unicode in user input
        const normalized = UnicodeValidator.normalize(options.elementName);
        if (!normalized.isValid) {
          throw new Error(`Invalid element name: ${normalized.detectedIssues?.join(', ')}`);
        }
        options.elementName = normalized.normalizedContent;
    
        if (options.elementType) {
          const normalizedType = UnicodeValidator.normalize(options.elementType);
          if (!normalizedType.isValid) {
            throw new Error(`Invalid element type: ${normalizedType.detectedIssues?.join(', ')}`);
          }
          options.elementType = normalizedType.normalizedContent;
        }
    
        // Get the index with error handling
        await this.enhancedIndexManager.getIndex().catch(async (error) => {
          logger.error('Failed to get Enhanced Index, attempting rebuild', error);
          return this.enhancedIndexManager.getIndex({ forceRebuild: true });
        });
    
        // FIX: DMCP-SEC-006 - Add security audit logging
        SecurityMonitor.logSecurityEvent({
          type: 'ELEMENT_CREATED',
          severity: 'LOW',
          source: 'EnhancedIndexHandler.getElementRelationships',
          details: `Relationship query performed for element: ${options.elementName}`,
          additionalData: {
            elementType: options.elementType,
            relationshipTypes: options.relationshipTypes
          }
        });
    
        // FIX: Use centralized element ID formatting
        // If no element type provided, use full element name as-is (may already include type)
        const elementId = options.elementType ?
          formatElementId(options.elementType, options.elementName) :
          options.elementName;
    
        const relationships = await this.enhancedIndexManager.getElementRelationships(elementId);
    
        // Filter by type if requested
        let filteredRelationships = relationships;
        if (options.relationshipTypes && options.relationshipTypes.length > 0) {
          filteredRelationships = {};
          for (const type of options.relationshipTypes) {
            if (relationships[type]) {
              filteredRelationships[type] = relationships[type];
            }
          }
        }
    
        // Format results
        let text = `${this.personaIndicator}🔗 **Element Relationships**\n\n`;
        text += `**Element**: ${options.elementName}\n`;
        if (options.elementType) {
          text += `**Type**: ${options.elementType}\n`;
        }
        text += '\n';
    
        const relationshipCount = Object.values(filteredRelationships)
          .reduce((sum, rels) => sum + (Array.isArray(rels) ? rels.length : 0), 0);
    
        if (relationshipCount === 0) {
          text += `No relationships found for this element.\n`;
        } else {
          for (const [relType, relations] of Object.entries(filteredRelationships)) {
            if (Array.isArray(relations) && relations.length > 0) {
              text += `**${relType.charAt(0).toUpperCase() + relType.slice(1)} (${relations.length})**\n`;
              for (const rel of relations) {
                // FIX: Use type-safe relationship parsing
                const parsedRel = parseRelationship(rel);
                if (isParsedRelationship(parsedRel)) {
                  const icon = this.getElementIcon(parsedRel.targetType);
                  text += `  ${icon} ${parsedRel.targetName}`;
                  if (parsedRel.strength) {
                    text += ` (strength: ${(parsedRel.strength * 100).toFixed(0)}%)`;
                  }
                  text += '\n';
                } else {
                  // Fallback for invalid relationships
                  const parsed = parseElementIdWithFallback(rel.element);
                  const icon = this.getElementIcon(parsed.type);
                  text += `  ${icon} ${parsed.name} ⚠️\n`;
                }
              }
              text += '\n';
            }
          }
        }
    
        return {
          content: [{
            type: "text",
            text
          }]
        };
      } catch (error: any) {
        ErrorHandler.logError('EnhancedIndexHandler.getElementRelationships', error, options);
        return {
          content: [{
            type: "text",
            text: `${this.personaIndicator}❌ Failed to get relationships: ${SecureErrorHandler.sanitizeError(error).message}`
          }]
        };
      }
    }
  • Tool registration in getEnhancedIndexTools() array. Defines name, description, inputSchema, and handler that maps args to server.getElementRelationships call.
    {
      tool: {
        name: "get_element_relationships",
        description: "Get all relationships for a specific element, including semantic similarities, verb-based connections, and cross-element references.",
        inputSchema: {
          type: "object",
          properties: {
            element_name: {
              type: "string",
              description: "Name of the element to get relationships for",
            },
            element_type: {
              type: "string",
              enum: ["personas", "skills", "templates", "agents", "memories", "ensembles"],
              description: "Type of the element. If not specified, searches all types.",
            },
            relationship_types: {
              type: "array",
              items: {
                type: "string",
                enum: ["similar", "uses", "extends", "requires", "complements", "verb-based"]
              },
              description: "Filter by specific relationship types. If not specified, returns all types.",
            },
          },
          required: ["element_name"],
        },
      },
      handler: (args: GetElementRelationshipsArgs) => server.getElementRelationships({
        elementName: args.element_name,
        elementType: args.element_type,
        relationshipTypes: args.relationship_types
      })
    },
  • TypeScript interface defining the input arguments for the get_element_relationships tool handler.
    interface GetElementRelationshipsArgs {
      element_name: string;
      element_type?: string;
      relationship_types?: string[];
    }
  • JSON schema for input validation of the get_element_relationships tool, defining properties, types, enums, and required fields.
    inputSchema: {
      type: "object",
      properties: {
        element_name: {
          type: "string",
          description: "Name of the element to get relationships for",
        },
        element_type: {
          type: "string",
          enum: ["personas", "skills", "templates", "agents", "memories", "ensembles"],
          description: "Type of the element. If not specified, searches all types.",
        },
        relationship_types: {
          type: "array",
          items: {
            type: "string",
            enum: ["similar", "uses", "extends", "requires", "complements", "verb-based"]
          },
          description: "Filter by specific relationship types. If not specified, returns all types.",
        },
      },
      required: ["element_name"],
    },
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what the tool does, not how it behaves. It lacks disclosure about permissions, rate limits, pagination, error handling, or whether it's read-only/destructive. The description doesn't contradict annotations, but provides minimal behavioral context.

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

Conciseness4/5

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

Single sentence is appropriately concise and front-loaded with the core purpose. No wasted words, though it could be slightly more structured with bullet points for relationship types.

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 read operation with 3 parameters and no output schema, the description is incomplete. It doesn't explain return format, pagination, error cases, or relationship structure. With no annotations and missing output schema, more behavioral context is needed for adequate completeness.

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%, so parameters are well-documented in the schema. The description adds marginal value by mentioning relationship types (similarities, verb-based connections, references) that align with schema enums, but doesn't provide additional syntax, format, or usage details beyond what's in the schema.

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 verb ('Get') and resource ('relationships for a specific element'), with specific types of relationships listed (semantic similarities, verb-based connections, cross-element references). It distinguishes from general search tools but doesn't explicitly differentiate from sibling 'get_element_details' or 'find_similar_elements'.

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?

No explicit guidance on when to use this tool versus alternatives like 'find_similar_elements' or 'get_element_details'. The description implies usage for relationship retrieval but lacks context about prerequisites, timing, or exclusions.

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

Install Server

Other 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/DollhouseMCP/mcp-server'

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