add_edge
Add a relationship between two persons in a mystery case. Provide local IDs of the persons and a label for the relationship.
Instructions
두 인물 사이 관계를 추가합니다. from/to는 인물의 local id. label 예: "친구", "직장 동료", "부부".
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| caseId | Yes | ||
| from | Yes | ||
| to | Yes | ||
| label | No |
Implementation Reference
- src/tools.ts:275-300 (registration)The 'add_edge' tool is defined as an entry in the `tools` array exported from src/tools.ts. It includes name, description, inputSchema, and the handler function.
{ name: 'add_edge', description: '두 인물 사이 관계를 추가합니다. from/to는 인물의 local id. label 예: "친구", "직장 동료", "부부".', inputSchema: z.object({ caseId: z.string().uuid(), from: z.number().int(), to: z.number().int(), label: z.string().optional(), }), handler: async (input: { caseId: string; from: number; to: number; label?: string }) => { const c = await fetchCase(input.caseId); const ids = new Set(c.people.map((p) => p.id)); if (!ids.has(input.from)) throw new Error(`from 인물(${input.from})이 존재하지 않습니다.`); if (!ids.has(input.to)) throw new Error(`to 인물(${input.to})이 존재하지 않습니다.`); const localId = nextLocalId(c.edges); c.edges.push({ id: localId, from: input.from, to: input.to, label: input.label ?? '', }); await saveCase(c); return { localId, url: caseUrl(input.caseId) }; }, }, - src/tools.ts:285-299 (handler)The handler function for 'add_edge': fetches the case data, validates that both 'from' and 'to' person IDs exist, creates a new edge with nextLocalId, pushes it to c.edges, saves the case, and returns the new localId and case URL.
handler: async (input: { caseId: string; from: number; to: number; label?: string }) => { const c = await fetchCase(input.caseId); const ids = new Set(c.people.map((p) => p.id)); if (!ids.has(input.from)) throw new Error(`from 인물(${input.from})이 존재하지 않습니다.`); if (!ids.has(input.to)) throw new Error(`to 인물(${input.to})이 존재하지 않습니다.`); const localId = nextLocalId(c.edges); c.edges.push({ id: localId, from: input.from, to: input.to, label: input.label ?? '', }); await saveCase(c); return { localId, url: caseUrl(input.caseId) }; }, - src/tools.ts:279-284 (schema)Input schema for 'add_edge': requires caseId (UUID string), from (int), to (int), and optional label (string). Validated with Zod.
inputSchema: z.object({ caseId: z.string().uuid(), from: z.number().int(), to: z.number().int(), label: z.string().optional(), }), - src/tools.ts:47-47 (helper)EdgeData type definition: { id: number; from: number; to: number; label: string } used for the edge objects.
type EdgeData = { id: number; from: number; to: number; label: string }; - src/tools.ts:60-62 (helper)nextLocalId helper: computes the next ID by finding the max existing ID + 1.
function nextLocalId(items: { id: number }[]): number { return items.reduce((max, it) => Math.max(max, it.id ?? 0), 0) + 1; }