Skip to content

Commit e29d611

Browse files
committed
fix: handle mixed relation/entity types in bm_context results
BM MCP returns two types in related_results: - type='relation': has relation_type, from_entity, to_entity (no title) - type='entity': has title, permalink (may have relation_type) Plugin assumed all items had title+permalink+relation_type, causing 'undefined' in output. Now handles both types correctly. Also fixed schema_validate error response handling (from prev commit).
1 parent 4b4d737 commit e29d611

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

bm-client.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ export interface ContextResult {
6767
content: string
6868
}>
6969
related_results: Array<{
70-
title: string
70+
type: "relation" | "entity"
71+
title?: string
7172
permalink: string
72-
relation_type: string
73+
relation_type?: string
74+
from_entity?: string
75+
to_entity?: string
7376
}>
7477
}>
7578
}

tools/context.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ describe("context tool", () => {
7777
],
7878
related_results: [
7979
{
80-
title: "Related Note 1",
80+
type: "entity", title: "Related Note 1",
8181
permalink: "related-note-1",
8282
relation_type: "references",
8383
},
8484
{
85-
title: "Related Note 2",
85+
type: "entity", title: "Related Note 2",
8686
permalink: "related-note-2",
8787
relation_type: "follows_from",
8888
},
@@ -211,7 +211,7 @@ describe("context tool", () => {
211211
observations: [{ category: "note", content: "Single observation" }],
212212
related_results: [
213213
{
214-
title: "Related to Second",
214+
type: "entity", title: "Related to Second",
215215
permalink: "related-to-second",
216216
relation_type: "depends_on",
217217
},
@@ -315,12 +315,12 @@ describe("context tool", () => {
315315
observations: [],
316316
related_results: [
317317
{
318-
title: "Related Note with Long Title",
318+
type: "entity", title: "Related Note with Long Title",
319319
permalink: "related-note-with-long-title",
320320
relation_type: "references",
321321
},
322322
{
323-
title: "Short Note",
323+
type: "entity", title: "Short Note",
324324
permalink: "short",
325325
relation_type: "follows_from",
326326
},

tools/context.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,15 @@ export function registerContextTool(
7676

7777
if (result.related_results?.length > 0) {
7878
const rels = result.related_results
79-
.map(
80-
(r) =>
81-
`- ${r.relation_type} → **${r.title}** (${r.permalink})`,
82-
)
79+
.map((r) => {
80+
if (r.type === "relation") {
81+
return `- ${r.relation_type} → **${r.to_entity}**`
82+
}
83+
const label = r.relation_type
84+
? `${r.relation_type} → **${r.title}**`
85+
: `**${r.title}**`
86+
return r.permalink ? `- ${label} (${r.permalink})` : `- ${label}`
87+
})
8388
.join("\n")
8489
sections.push(`### Related\n${rels}`)
8590
}

0 commit comments

Comments
 (0)