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
| Name | Required | Description | Default |
|---|---|---|---|
| sourceId | Yes | ID of the source record | |
| targetId | No | ID of one target record (deprecated if targetIds provided) | |
| targetIds | No | IDs of multiple target records | |
| relationType | No | Type of the relationship | |
| direction | No | Direction of the relationship | outgoing |
| transactionId | No | Optional transaction ID for atomic relation creation |
Implementation Reference
- tools/AttachRelation.ts:17-49 (handler)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)` } }
- tools.ts:183-210 (schema)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'