Skip to main content
Glama

AttachRelation

Create relationships between records in RushDB by connecting a source record to single or multiple targets with specified type and direction.

Instructions

Create a relationship between records (single or multiple targets)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceIdYesID of the source record
targetIdNoID of one target record (deprecated if targetIds provided)
targetIdsNoIDs of multiple target records
relationTypeNoType of the relationship
directionNoDirection of the relationshipoutgoing
transactionIdNoOptional transaction ID for atomic relation creation

Implementation Reference

  • The core handler function that implements the AttachRelation tool. It attaches relationships from a source record to one or more target records using the database API, with options for relation type and direction.
    export async function AttachRelation(params: {
      sourceId: string
      targetId?: string
      targetIds?: string[]
      relationType?: string
      direction?: 'outgoing' | 'incoming' | 'bidirectional'
      transactionId?: string
    }) {
      const { sourceId, targetId, targetIds, relationType, direction = 'outgoing', transactionId } = params
    
      const options: any = {}
      if (relationType) {
        options.type = relationType
      }
      if (direction) {
        options.direction = direction
      }
    
      const targets: string[] =
        targetIds && targetIds.length > 0 ? targetIds
        : targetId ? [targetId]
        : []
      if (targets.length === 0) {
        return { success: false, message: 'No targetId(s) provided' }
      }
    
      await db.records.attach({ source: sourceId, target: targets, options }, transactionId)
    
      return {
        success: true,
        message: `Relationship attached from '${sourceId}' to ${targets.length} target record(s)`
      }
    }
  • The JSON schema definition for the AttachRelation tool input parameters, part of the tools array used for MCP tool listing and validation.
    {
      name: 'AttachRelation',
      description: 'Create a relationship between records (single or multiple targets)',
      inputSchema: {
        type: 'object',
        properties: {
          sourceId: { type: 'string', description: 'ID of the source record' },
          targetId: {
            type: 'string',
            description: 'ID of one target record (deprecated if targetIds provided)'
          },
          targetIds: {
            type: 'array',
            items: { type: 'string' },
            description: 'IDs of multiple target records'
          },
          relationType: { type: 'string', description: 'Type of the relationship' },
          direction: {
            type: 'string',
            enum: ['outgoing', 'incoming', 'bidirectional'],
            description: 'Direction of the relationship',
            default: 'outgoing'
          },
          transactionId: { type: 'string', description: 'Optional transaction ID for atomic relation creation' }
        },
        required: ['sourceId']
      }
    },
  • index.ts:72-76 (registration)
    Registration of the tools list handler, which returns the array of all tool definitions including AttachRelation schema.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools
      }
    })
  • index.ts:221-237 (registration)
    The dispatch case in the CallToolRequest handler that invokes the AttachRelation function with parsed arguments.
    case 'AttachRelation':
      const attachResult = await AttachRelation({
        sourceId: args.sourceId as string,
        targetId: args.targetId as string | undefined,
        targetIds: args.targetIds as string[] | undefined,
        relationType: args.relationType as string | undefined,
        direction: args.direction as 'outgoing' | 'incoming' | 'bidirectional' | undefined,
        transactionId: args.transactionId as string | undefined
      })
      return {
        content: [
          {
            type: 'text',
            text: attachResult.message
          }
        ]
      }
  • index.ts:32-32 (registration)
    Import statement bringing the AttachRelation handler into the main index.ts for use in tool dispatch.
    import { AttachRelation } from './tools/AttachRelation.js'
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 offers minimal behavioral insight. It mentions creating relationships but doesn't disclose permissions needed, whether it's idempotent, error handling, or what happens if relationships already exist. For a mutation tool with 6 parameters, this is inadequate.

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 part earns its place by clarifying scope (single or multiple targets).

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 6 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain the relationship types, direction implications, transaction usage, or what the tool returns. Given the complexity and lack of structured data, more context is needed.

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 no additional parameter semantics beyond implying support for multiple targets, which is already covered in the schema's 'targetIds' description. Baseline 3 is appropriate when schema does the heavy lifting.

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 ('Create a relationship') and resource ('between records'), specifying it can handle single or multiple targets. However, it doesn't differentiate from sibling tools like 'DetachRelation' or explain what types of relationships exist beyond the basic concept.

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 guidance is provided on when to use this tool versus alternatives like 'DetachRelation' for removing relationships, or how it relates to other record operations in the sibling list. The description only states what it does, not when it's appropriate.

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/rush-db/RushDB'

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