Skip to content

Commit a806506

Browse files
authored
Merge pull request #1694 from IgniteUI/ipetrov/fix-1620-enforce-library-boundaries
Fix [MCP] Enforce library boundaries in search_api and server instructions
2 parents d44baaa + 5b70603 commit a806506

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

packages/igniteui-mcp/igniteui-doc-mcp/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ const server = new McpServer(
7070
"React → Igr prefix (IgrGrid), package 'igniteui-react', .tsx files. " +
7171
"Blazor → Igb prefix (IgbGrid), package 'IgniteUI.Blazor', .razor files. " +
7272
"Web Components → Igc prefix + Component suffix (IgcGridComponent), package 'igniteui-webcomponents', .ts+.html with custom elements. " +
73-
"If the framework is unclear from context, ask the user.",
73+
"If the framework is unclear from context, ask the user. " +
74+
"LIBRARY BOUNDARY RULE: Once the target framework is identified, always pass it as the 'framework' or 'platform' parameter to every tool call. " +
75+
"Never apply component APIs, event names, binding syntax, prop names, or state patterns from one framework to code in another framework. " +
76+
"Angular (Igx), React (Igr), Blazor (Igb), and Web Components (Igc) each have distinct APIs — they are not interchangeable.",
7477
}
7578
);
7679

packages/igniteui-mcp/igniteui-doc-mcp/src/tools/constants.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Use this as the discovery step when the exact component name is unknown — e.g.
6363
6464
Each result includes: exact component name, framework tag, API type (class/interface/directive/enum), match count, keyword list, and a content excerpt. Pass the component name and framework from a result to get_api_reference for full details. To reduce response size, use section="properties", "methods", or "events" instead of the default "all".
6565
66-
Omit framework to search all frameworks at once. Maximum query length is 256 characters.
66+
Always specify \`platform\` when your target framework is known — this prevents cross-framework API contamination. Omit only when you explicitly need to compare or search across all frameworks at once. Maximum query length is 256 characters.
6767
`
6868
};
6969

@@ -132,6 +132,15 @@ Most tools require a \`framework\` parameter. Determine the framework from the u
132132
4. **User's explicit statement** — "I'm using Angular", "Blazor project", etc.
133133
5. **Ask the user** if none of the above apply
134134
135+
## Library Boundary Rules
136+
137+
> **These rules are mandatory. Violating them produces code that looks valid but fails at runtime.**
138+
139+
- **Always pass \`framework\` / \`platform\` to every tool call once the target framework is known.** Do not omit it.
140+
- **Never mix APIs across frameworks.** Angular (\`Igx\`), React (\`Igr\`), Blazor (\`Igb\`), and Web Components (\`Igc\`) each have distinct component names, event shapes, prop names, binding syntax, and state models. They are not interchangeable.
141+
- **Do not apply Angular patterns to React code** (or any other cross-framework combination). For example: Angular template bindings (\`(cellEditDone)\`), directive imports (\`IGX_GRID_DIRECTIVES\`), and signal-based \`viewChild\` are Angular-only. React uses callback props, hook-based state, and \`useRef\`.
142+
- **When \`search_api\` returns results from multiple frameworks, only use entries that match your target framework.**
143+
135144
## Documentation Tools
136145
137146
- **\`search_docs\`** — full-text search when user asks "how do I..." or describes a feature need

packages/igniteui-mcp/igniteui-doc-mcp/src/tools/handlers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ export function createSearchApiHandler(docLoader: ApiDocLoader) {
8585
return `**${h.entry.component}** ${platformTag} ${typeTag} (${h.matches} matches)${kwTag}\n${h.excerpt}`;
8686
});
8787

88-
return { content: [{ type: "text", text: lines.join("\n\n") }] };
88+
const frameworks = new Set(hits.map(h => h.entry.platform));
89+
const crossPlatformWarning = !platform && frameworks.size > 1
90+
? `⚠ Results span multiple frameworks (${[...frameworks].join(', ')}). Only use entries that match your target framework — never apply APIs, events, or binding syntax from one framework to another.\n\n`
91+
: '';
92+
93+
return { content: [{ type: "text", text: crossPlatformWarning + lines.join("\n\n") }] };
8994
};
9095
}

0 commit comments

Comments
 (0)