Skip to content

feat(mcp): rewrite API URLs as get_api_reference refs with member-level lookups#1698

Open
dkalinovInfra wants to merge 5 commits into
masterfrom
dkalinov/link-ref
Open

feat(mcp): rewrite API URLs as get_api_reference refs with member-level lookups#1698
dkalinovInfra wants to merge 5 commits into
masterfrom
dkalinov/link-ref

Conversation

@dkalinovInfra
Copy link
Copy Markdown
Contributor

Description

Adds deterministic mcp:get_api_reference?... references for API documentation links in the MCP server's compiled docs, and extends get_api_reference to resolve those references at call time.

Two coordinated changes:

  1. Member-aware get_api_reference — the tool gains an optional member parameter that returns only one property/method/event line instead of the full component entry. section (properties / methods / events) is now functional too — it walks the bullet list and emits only matching bullets, classified by syntax (method = signature, event = EventEmitter<T> or EventCallback<T>, otherwise property). The handler also tolerates Component#member shorthand defensively. Response-size impact on a real Angular grid entry: full 4.6 KB → section=methods 2.3 KB (−50%) → member=data 113 B (−97%).

  2. Deterministic URL → MCP-ref rewriter — new scripts/rewrite-api-links.ts runs between inject and diff in each platform pipeline. It rewrites https://www.infragistics.com/.../classes/<name>.html#<member> URLs to mcp:get_api_reference?platform=<p>&component=<C>&member=<m>. Pure regex match per platform — no LLM in the loop. Handles all four URL shapes (bare /docs/, /api/docs/ with package prefixes, Blazor FQN form, Web Components dock-manager subpath), decodes Blazor docfx synthetic anchors (#IgniteUI_Blazor_Controls_IgbGrid_Sortmember=Sort), and recovers PascalCase canonical names from lowercased URL segments via the existing ApiDocLoader index. Compression prompts updated to preserve mcp: URIs verbatim.

End-to-end smoke test against 270 Blazor doc files: 5,683 URLs rewritten across 241 files, 0 unknown-component skips, 0 mis-rewrites.

Related Issue

Closes #

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring / code cleanup
  • Build / CI configuration change

Affected Packages

  • igniteui-cli (packages/cli)
  • @igniteui/cli-core (packages/core)
  • @igniteui/angular-templates (packages/igx-templates)
  • @igniteui/angular-schematics (packages/ng-schematics)
  • @igniteui/mcp-server (packages/igniteui-mcp)

Checklist

  • I have tested my changes locally (npm run test) — 173/173 passing
  • I have built the project successfully (npm run build)
  • I have run the linter (npm run lint) — root-level lint has pre-existing parser errors in submodule files under webcomponents/igniteui-webcomponents/** that are unrelated to this PR; no new errors introduced by these changes
  • I have added/updated tests as needed — +33 new tests covering member lookup, section inference, URL rewriter regexes, and Blazor EventCallback classification
  • My changes do not introduce new warnings or errors

Additional Context

Sample rewrite (dist/docs_prepeared/blazor/grid-advanced-filtering.md):

- [`Filterable`](https://www.infragistics.com/blazor/docs/api/api/IgniteUI.Blazor.Controls.IgbColumn.html#IgniteUI_Blazor_Controls_IgbColumn_Filterable)
+ [`Filterable`](mcp:get_api_reference?platform=blazor&component=IgbColumn&member=Filterable)

Real-world get_api_reference probe (scripts/test-get-api-reference.ts) — 27 scenarios across all four platforms, every code path passing. Response-size impact on a real IgbGrid entry:

Scenario Response size
Full entry 6,333 B
section=properties 1,975 B (−69%)
section=methods 3,966 B (−37%)
section=events 314 B (−95%)
member=Data 45 B (−99%)

Section parameter was previously a no-opextractSection walked for ## Properties / ## Methods / ## Events headings, but no real llms-full.txt file has those headings (they're flat bullet lists under ### [Component]). The new bullet-inference fallback makes the parameter actually do what its description always claimed.

Pipeline ordering: clear → (build:xplat) → export → inject → rewrite-api-urls → diff → compress → update-baseline → build:db. Rewrite runs pre-compress so the LLM sees and preserves the final mcp: URIs.

- Introduced new scripts for rewriting API URLs for Angular, Blazor, React, and Web Components in package.json.
- Updated compression scripts to preserve specific API reference links verbatim.
- Implemented a new script (rewrite-api-links.ts) to convert existing API documentation URLs to a standardized format.
- Enhanced the extractMember function to support member-targeted lookups in API documentation.
- Updated API reference handler to prioritize member lookups over section requests.
- Added validation for member names in schemas, ensuring they are trimmed and within character limits.
- Improved test coverage for member extraction and API reference handling.
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 87.455%. remained the same — dkalinov/link-ref into master

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the @igniteui/mcp-server documentation pipeline by (1) extending get_api_reference to support member-level lookups (and making section filtering work on real llms-full.txt shapes), and (2) adding a deterministic, non-LLM rewrite step that converts infragistics.com API links in prepared markdown into mcp:get_api_reference?... references resolved at tool-call time.

Changes:

  • Extend get_api_reference with optional member support (plus defensive Component#member parsing) and implement bullet-syntax inference so section=properties|methods|events works even without ## headings.
  • Add scripts/rewrite-api-links.ts + tests, and wire it into all platform pipelines (inject → rewrite-api-urls → diff → compress ...).
  • Update compression prompts and developer docs to preserve mcp:get_api_reference?... URIs verbatim and document the new pipeline step/tool behavior.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/igniteui-mcp/igniteui-doc-mcp/src/tools/schemas.ts Adds member param to get_api_reference schema and clarifies section precedence.
packages/igniteui-mcp/igniteui-doc-mcp/src/tools/handlers.ts Implements member lookup, Component#member parsing, and precedence over section.
packages/igniteui-mcp/igniteui-doc-mcp/src/tools/constants.ts Updates tool description to document member usage and error behavior.
packages/igniteui-mcp/igniteui-doc-mcp/src/lib/api-doc-search.ts Adds extractMember and implements flat-bullet inference fallback for extractSection.
packages/igniteui-mcp/igniteui-doc-mcp/src/tests/tools/schemas.test.ts Updates schema tests for Blazor platform support and new member field.
packages/igniteui-mcp/igniteui-doc-mcp/src/tests/tools/handlers.test.ts Adds coverage for member-targeted lookup and Component#member parsing.
packages/igniteui-mcp/igniteui-doc-mcp/src/tests/scripts/rewrite-api-links.test.ts New tests for per-platform URL rewrite patterns and skip behavior.
packages/igniteui-mcp/igniteui-doc-mcp/src/tests/lib/api-doc-search.test.ts Adds tests for bullet inference in extractSection and for extractMember.
packages/igniteui-mcp/igniteui-doc-mcp/scripts/rewrite-api-links.ts New deterministic link rewriter script + canonical-name index builder.
packages/igniteui-mcp/igniteui-doc-mcp/scripts/compress-*-docs.ts Updates prompts to require preserving mcp:get_api_reference?... URLs verbatim.
packages/igniteui-mcp/igniteui-doc-mcp/package.json Adds rewrite scripts and inserts them into incremental/full pipelines.
packages/igniteui-mcp/igniteui-doc-mcp/DEVELOPMENT.md Documents new rewrite step and new get_api_reference parameters/behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +62 to +67
// Member-targeted lookup takes precedence over section.
if (member) {
const match = extractMember(content, member);
if (match) {
const text = `${entry.component}.${member} (${match.section}):\n${match.line}`;
return { content: [{ type: "text", text }] };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0197c68. Added a name field to MemberMatch that captures the actual member name as found in the markdown, and extractMember now returns it alongside section and line. The response header in handlers.ts now uses match.name instead of the user-supplied member, so it always reflects the canonical casing from the API docs regardless of how the user typed the member name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants