@cognistore/mcp-server 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +50 -74
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1601,88 +1601,64 @@ function createServer(sdk) {
|
|
|
1601
1601
|
version: "1.0.0"
|
|
1602
1602
|
});
|
|
1603
1603
|
let lastSearchResultIds = [];
|
|
1604
|
-
|
|
1605
|
-
"
|
|
1606
|
-
"
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
await sdk.addPlanRelation(params.planId, result.id, "output");
|
|
1635
|
-
linked = true;
|
|
1636
|
-
} catch (e) {
|
|
1637
|
-
linkWarning = e instanceof Error ? e.message : "Unknown linking error";
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
const response = { entry: result };
|
|
1641
|
-
if (params.planId) {
|
|
1642
|
-
response.linked = linked;
|
|
1643
|
-
response.planId = params.planId;
|
|
1644
|
-
if (linkWarning) response.linkWarning = linkWarning;
|
|
1604
|
+
const knowledgeEntrySchema = z2.object({
|
|
1605
|
+
title: z2.string().describe("Short descriptive title"),
|
|
1606
|
+
content: z2.string().describe("The knowledge content text"),
|
|
1607
|
+
tags: z2.array(z2.string()).describe("Categorical tags for filtering"),
|
|
1608
|
+
type: z2.enum(knowledgeTypeValues).describe("Type: decision, pattern, fix, constraint, or gotcha"),
|
|
1609
|
+
scope: z2.string().describe('Scope: "global" or "workspace:<project-name>"'),
|
|
1610
|
+
source: z2.string().describe("Source of the knowledge"),
|
|
1611
|
+
confidenceScore: z2.number().min(0).max(1).optional().describe("Confidence score 0-1"),
|
|
1612
|
+
agentId: z2.string().optional().describe("ID of the agent that created this"),
|
|
1613
|
+
planId: z2.string().optional().describe("Plan ID to auto-link this knowledge as output. ALWAYS pass this if you have an active plan.")
|
|
1614
|
+
});
|
|
1615
|
+
async function createEntry(params) {
|
|
1616
|
+
const entry = await sdk.addKnowledge({
|
|
1617
|
+
title: params.title,
|
|
1618
|
+
content: params.content,
|
|
1619
|
+
tags: params.tags,
|
|
1620
|
+
type: params.type,
|
|
1621
|
+
scope: params.scope,
|
|
1622
|
+
source: params.source,
|
|
1623
|
+
confidenceScore: params.confidenceScore,
|
|
1624
|
+
agentId: params.agentId
|
|
1625
|
+
});
|
|
1626
|
+
let linked = false;
|
|
1627
|
+
let linkWarning = "";
|
|
1628
|
+
if (params.planId && entry.type !== "system") {
|
|
1629
|
+
try {
|
|
1630
|
+
await sdk.addPlanRelation(params.planId, entry.id, "output");
|
|
1631
|
+
linked = true;
|
|
1632
|
+
} catch (e) {
|
|
1633
|
+
linkWarning = e instanceof Error ? e.message : "Unknown linking error";
|
|
1645
1634
|
}
|
|
1646
|
-
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
1647
1635
|
}
|
|
1648
|
-
|
|
1636
|
+
const result = { entry };
|
|
1637
|
+
if (params.planId) {
|
|
1638
|
+
result.linked = linked;
|
|
1639
|
+
result.planId = params.planId;
|
|
1640
|
+
if (linkWarning) result.linkWarning = linkWarning;
|
|
1641
|
+
}
|
|
1642
|
+
return result;
|
|
1643
|
+
}
|
|
1649
1644
|
server.tool(
|
|
1650
|
-
"
|
|
1651
|
-
"
|
|
1645
|
+
"addKnowledge",
|
|
1646
|
+
"Store one or multiple knowledge entries. Pass a single object or an array. If you have an active plan, ALWAYS pass planId to auto-link as output.",
|
|
1652
1647
|
{
|
|
1653
|
-
entries: z2.
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
type: z2.enum(knowledgeTypeValues),
|
|
1658
|
-
scope: z2.string(),
|
|
1659
|
-
source: z2.string(),
|
|
1660
|
-
planId: z2.string().optional()
|
|
1661
|
-
})).describe("Array of knowledge entries to create")
|
|
1648
|
+
entries: z2.union([
|
|
1649
|
+
knowledgeEntrySchema,
|
|
1650
|
+
z2.array(knowledgeEntrySchema)
|
|
1651
|
+
]).describe("A single knowledge entry object, or an array of entries")
|
|
1662
1652
|
},
|
|
1663
1653
|
WRITE,
|
|
1664
1654
|
async (params) => {
|
|
1655
|
+
const items = Array.isArray(params.entries) ? params.entries : [params.entries];
|
|
1665
1656
|
const results = [];
|
|
1666
|
-
for (const
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
type: e.type,
|
|
1672
|
-
scope: e.scope,
|
|
1673
|
-
source: e.source
|
|
1674
|
-
});
|
|
1675
|
-
let linked = false;
|
|
1676
|
-
let linkWarning = "";
|
|
1677
|
-
if (e.planId && entry.type !== "system") {
|
|
1678
|
-
try {
|
|
1679
|
-
await sdk.addPlanRelation(e.planId, entry.id, "output");
|
|
1680
|
-
linked = true;
|
|
1681
|
-
} catch (err) {
|
|
1682
|
-
linkWarning = err instanceof Error ? err.message : "Unknown linking error";
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
results.push({ entry, linked, ...e.planId ? { planId: e.planId } : {}, ...linkWarning ? { linkWarning } : {} });
|
|
1657
|
+
for (const item of items) {
|
|
1658
|
+
results.push(await createEntry(item));
|
|
1659
|
+
}
|
|
1660
|
+
if (results.length === 1) {
|
|
1661
|
+
return { content: [{ type: "text", text: JSON.stringify(results[0], null, 2) }] };
|
|
1686
1662
|
}
|
|
1687
1663
|
return { content: [{ type: "text", text: JSON.stringify({ created: results.length, entries: results }, null, 2) }] };
|
|
1688
1664
|
}
|