@macroforge/mcp-server 0.1.33 → 0.1.35

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.
Files changed (50) hide show
  1. package/README.md +68 -0
  2. package/dist/index.d.ts +32 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +46 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/tools/docs-loader.d.ts +133 -5
  7. package/dist/tools/docs-loader.d.ts.map +1 -1
  8. package/dist/tools/docs-loader.js +131 -15
  9. package/dist/tools/docs-loader.js.map +1 -1
  10. package/dist/tools/index.d.ts +48 -1
  11. package/dist/tools/index.d.ts.map +1 -1
  12. package/dist/tools/index.js +163 -14
  13. package/dist/tools/index.js.map +1 -1
  14. package/docs/api/api-overview.md +24 -46
  15. package/docs/api/expand-sync.md +24 -51
  16. package/docs/api/native-plugin.md +24 -56
  17. package/docs/api/position-mapper.md +34 -76
  18. package/docs/api/transform-sync.md +27 -59
  19. package/docs/builtin-macros/clone.md +45 -104
  20. package/docs/builtin-macros/debug.md +33 -104
  21. package/docs/builtin-macros/default.md +78 -114
  22. package/docs/builtin-macros/deserialize.md +93 -273
  23. package/docs/builtin-macros/hash.md +58 -100
  24. package/docs/builtin-macros/macros-overview.md +42 -103
  25. package/docs/builtin-macros/ord.md +65 -133
  26. package/docs/builtin-macros/partial-eq.md +53 -179
  27. package/docs/builtin-macros/partial-ord.md +67 -159
  28. package/docs/builtin-macros/serialize.md +64 -194
  29. package/docs/concepts/architecture.md +40 -99
  30. package/docs/concepts/derive-system.md +129 -125
  31. package/docs/concepts/how-macros-work.md +52 -84
  32. package/docs/custom-macros/custom-overview.md +17 -39
  33. package/docs/custom-macros/rust-setup.md +22 -55
  34. package/docs/custom-macros/ts-macro-derive.md +43 -107
  35. package/docs/custom-macros/ts-quote.md +177 -507
  36. package/docs/getting-started/first-macro.md +108 -33
  37. package/docs/getting-started/installation.md +32 -73
  38. package/docs/integration/cli.md +70 -156
  39. package/docs/integration/configuration.md +32 -75
  40. package/docs/integration/integration-overview.md +16 -55
  41. package/docs/integration/mcp-server.md +30 -69
  42. package/docs/integration/svelte-preprocessor.md +60 -83
  43. package/docs/integration/typescript-plugin.md +32 -74
  44. package/docs/integration/vite-plugin.md +30 -79
  45. package/docs/language-servers/ls-overview.md +22 -46
  46. package/docs/language-servers/svelte.md +30 -69
  47. package/docs/language-servers/zed.md +34 -72
  48. package/docs/roadmap/roadmap.md +54 -130
  49. package/docs/sections.json +3 -262
  50. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @macroforge/mcp-server
2
+
3
+ MCP server for Macroforge documentation and code analysis
4
+
5
+ [![npm version](https://badge.fury.io/js/%40macroforge%2Fmcp-server.svg)](https://www.npmjs.com/package/@macroforge/mcp-server)
6
+
7
+ ## Overview
8
+
9
+ @macroforge/mcp-server
10
+
11
+ Macroforge MCP (Model Context Protocol) Server
12
+
13
+ This module provides the main entry point for the Macroforge MCP server,
14
+ which enables AI assistants and other MCP clients to access Macroforge
15
+ documentation, validate code with @derive decorators, and expand macros.
16
+
17
+ The server communicates over stdio transport and exposes the following tools:
18
+ - `list-sections` - List available documentation sections
19
+ - `get-documentation` - Retrieve documentation content
20
+ - `macroforge-autofixer` - Validate TypeScript code with @derive decorators
21
+ - `expand-code` - Expand Macroforge macros and show generated code
22
+ - `get-macro-info` - Get documentation for macros and decorators
23
+
24
+ @example
25
+ ```bash
26
+ # Run the server directly
27
+ npx @macroforge/mcp-server
28
+
29
+ # Or configure in your MCP client settings
30
+ {
31
+ "mcpServers": {
32
+ "macroforge": {
33
+ "command": "npx",
34
+ "args": ["@macroforge/mcp-server"]
35
+ }
36
+ }
37
+ }
38
+ ```
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ npm install @macroforge/mcp-server
44
+ ```
45
+
46
+ ## Examples
47
+
48
+ ```typescript
49
+ # Run the server directly
50
+ npx @macroforge/mcp-server
51
+ # Or configure in your MCP client settings
52
+ {
53
+ "mcpServers": {
54
+ "macroforge": {
55
+ "command": "npx",
56
+ "args": ["@macroforge/mcp-server"]
57
+ }
58
+ }
59
+ }
60
+ ```
61
+
62
+ ## Documentation
63
+
64
+ See the [full documentation](https://macroforge.dev/docs/api/reference/typescript/mcp-server) on the Macroforge website.
65
+
66
+ ## License
67
+
68
+ MIT
package/dist/index.d.ts CHANGED
@@ -1,3 +1,35 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * @module @macroforge/mcp-server
4
+ *
5
+ * Macroforge MCP (Model Context Protocol) Server
6
+ *
7
+ * This module provides the main entry point for the Macroforge MCP server,
8
+ * which enables AI assistants and other MCP clients to access Macroforge
9
+ * documentation, validate code with @derive decorators, and expand macros.
10
+ *
11
+ * The server communicates over stdio transport and exposes the following tools:
12
+ * - `list-sections` - List available documentation sections
13
+ * - `get-documentation` - Retrieve documentation content
14
+ * - `macroforge-autofixer` - Validate TypeScript code with @derive decorators
15
+ * - `expand-code` - Expand Macroforge macros and show generated code
16
+ * - `get-macro-info` - Get documentation for macros and decorators
17
+ *
18
+ * @example
19
+ * ```bash
20
+ * # Run the server directly
21
+ * npx @macroforge/mcp-server
22
+ *
23
+ * # Or configure in your MCP client settings
24
+ * {
25
+ * "mcpServers": {
26
+ * "macroforge": {
27
+ * "command": "npx",
28
+ * "args": ["@macroforge/mcp-server"]
29
+ * }
30
+ * }
31
+ * }
32
+ * ```
33
+ */
2
34
  export {};
3
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG"}
package/dist/index.js CHANGED
@@ -1,4 +1,36 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * @module @macroforge/mcp-server
4
+ *
5
+ * Macroforge MCP (Model Context Protocol) Server
6
+ *
7
+ * This module provides the main entry point for the Macroforge MCP server,
8
+ * which enables AI assistants and other MCP clients to access Macroforge
9
+ * documentation, validate code with @derive decorators, and expand macros.
10
+ *
11
+ * The server communicates over stdio transport and exposes the following tools:
12
+ * - `list-sections` - List available documentation sections
13
+ * - `get-documentation` - Retrieve documentation content
14
+ * - `macroforge-autofixer` - Validate TypeScript code with @derive decorators
15
+ * - `expand-code` - Expand Macroforge macros and show generated code
16
+ * - `get-macro-info` - Get documentation for macros and decorators
17
+ *
18
+ * @example
19
+ * ```bash
20
+ * # Run the server directly
21
+ * npx @macroforge/mcp-server
22
+ *
23
+ * # Or configure in your MCP client settings
24
+ * {
25
+ * "mcpServers": {
26
+ * "macroforge": {
27
+ * "command": "npx",
28
+ * "args": ["@macroforge/mcp-server"]
29
+ * }
30
+ * }
31
+ * }
32
+ * ```
33
+ */
2
34
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
35
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
36
  import { readFileSync } from 'node:fs';
@@ -11,7 +43,20 @@ const __dirname = dirname(__filename);
11
43
  const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'));
12
44
  const { name, version } = pkg;
13
45
  /**
14
- * Main function to start the MCP server
46
+ * Initializes and starts the Macroforge MCP server.
47
+ *
48
+ * This function performs the following setup:
49
+ * 1. Creates an MCP Server instance with name and version from package.json
50
+ * 2. Registers all Macroforge tools (documentation, validation, expansion)
51
+ * 3. Sets up error handling for server errors
52
+ * 4. Configures graceful shutdown on SIGINT (Ctrl+C)
53
+ * 5. Connects to stdio transport for client communication
54
+ *
55
+ * The server runs until terminated and logs status to stderr
56
+ * (stdout is reserved for MCP protocol communication).
57
+ *
58
+ * @returns A promise that resolves when the server is connected
59
+ * @throws Will exit the process with code 1 if server initialization fails
15
60
  */
16
61
  async function main() {
17
62
  // Create server instance with metadata
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"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;;;;;;;;;;;GAeG;AACH,KAAK,UAAU,IAAI;IACjB,uCAAuC;IACvC,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB;QACE,IAAI;QACJ,OAAO;KACR,EACD;QACE,YAAY,EAAE;YACZ,KAAK,EAAE,EAAE;SACV;KACF,CACF,CAAC;IAEF,qBAAqB;IACrB,aAAa,CAAC,MAAM,CAAC,CAAC;IAEtB,wBAAwB;IACxB,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,EAAE;QACzB,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC,CAAC;IAEF,6BAA6B;IAC7B,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;QAC9B,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,uBAAuB;IACvB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAC1D,CAAC;AAED,iBAAiB;AACjB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;IACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -1,3 +1,45 @@
1
+ /**
2
+ * @module docs-loader
3
+ *
4
+ * Documentation Loading and Search Utilities
5
+ *
6
+ * This module provides functionality for loading, searching, and retrieving
7
+ * Macroforge documentation sections. Documentation is stored as markdown files
8
+ * with metadata in `docs/sections.json`.
9
+ *
10
+ * Key features:
11
+ * - Loads documentation sections from disk with lazy content loading
12
+ * - Supports multiple search strategies (exact, partial, fuzzy, category)
13
+ * - Handles chunked documentation for large sections
14
+ * - Provides type-safe interfaces for documentation structure
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { loadSections, getSection, searchSections } from './docs-loader.js';
19
+ *
20
+ * const sections = loadSections();
21
+ * const debug = getSection(sections, 'debug');
22
+ * const matches = searchSections(sections, 'serialization');
23
+ * ```
24
+ */
25
+ /**
26
+ * Represents a documentation section with metadata and optional content.
27
+ *
28
+ * Sections can be standalone or part of a chunked hierarchy for large documents.
29
+ * Chunked sections have a parent entry with `is_chunked: true` and child entries
30
+ * with `parent_id` pointing to the parent.
31
+ *
32
+ * @property id - Unique identifier for the section (e.g., "debug", "serde-validators")
33
+ * @property title - Human-readable title displayed to users
34
+ * @property category - Category slug for grouping (e.g., "macros", "guides")
35
+ * @property category_title - Human-readable category name
36
+ * @property path - Relative path to the markdown content file from docs directory
37
+ * @property use_cases - Comma-separated keywords describing when this doc is useful
38
+ * @property content - The actual markdown content (loaded lazily, undefined for chunked parents)
39
+ * @property is_chunked - True if this section is split into multiple sub-chunks
40
+ * @property parent_id - For sub-chunks, the ID of the parent section
41
+ * @property chunk_ids - For chunked parents, ordered list of child chunk IDs
42
+ */
1
43
  export interface Section {
2
44
  id: string;
3
45
  title: string;
@@ -11,23 +53,109 @@ export interface Section {
11
53
  chunk_ids?: string[];
12
54
  }
13
55
  /**
14
- * Load all documentation sections from the docs directory
56
+ * Loads all documentation sections from the docs directory.
57
+ *
58
+ * This function reads `docs/sections.json` for metadata and loads the markdown
59
+ * content for each section from disk. Chunked parent sections do not have their
60
+ * content loaded directly - their content is accessed through child chunks.
61
+ *
62
+ * @returns Array of Section objects with content loaded. Returns empty array if
63
+ * sections.json is not found (with a warning logged to stderr).
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const sections = loadSections();
68
+ * console.log(`Loaded ${sections.length} sections`);
69
+ * ```
15
70
  */
16
71
  export declare function loadSections(): Section[];
17
72
  /**
18
- * Get a section by ID or title (case-insensitive)
73
+ * Finds a section by ID or title using progressive matching strategies.
74
+ *
75
+ * The function attempts to match in the following order (stopping at first match):
76
+ * 1. Exact ID match (case-insensitive)
77
+ * 2. Exact title match (case-insensitive)
78
+ * 3. Partial ID match (query is substring of ID)
79
+ * 4. Partial title match (query is substring of title)
80
+ *
81
+ * @param sections - Array of sections to search through
82
+ * @param query - Search query (ID or title to find)
83
+ * @returns The first matching Section, or undefined if no match found
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const debug = getSection(sections, 'debug'); // Exact ID match
88
+ * const serde = getSection(sections, 'Serialize'); // Exact title match
89
+ * const partial = getSection(sections, 'valid'); // Partial match on "validators"
90
+ * ```
19
91
  */
20
92
  export declare function getSection(sections: Section[], query: string): Section | undefined;
21
93
  /**
22
- * Get multiple sections by IDs or titles
94
+ * Retrieves multiple sections by their IDs or titles.
95
+ *
96
+ * Uses {@link getSection} for each query, deduplicating results if the same
97
+ * section matches multiple queries.
98
+ *
99
+ * @param sections - Array of sections to search through
100
+ * @param queries - Array of search queries (IDs or titles)
101
+ * @returns Array of unique matching Sections in the order they were found
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const docs = getSections(sections, ['debug', 'serialize', 'clone']);
106
+ * // Returns all three sections if found
107
+ * ```
23
108
  */
24
109
  export declare function getSections(sections: Section[], queries: string[]): Section[];
25
110
  /**
26
- * Search sections by use_cases or content
111
+ * Performs a fuzzy search across sections using a weighted scoring algorithm.
112
+ *
113
+ * The search splits the query into keywords and scores each section based on
114
+ * where matches are found. Results are sorted by relevance score (highest first).
115
+ *
116
+ * ## Scoring Algorithm
117
+ *
118
+ * Each section is scored based on matches in different fields:
119
+ * - **ID match** (+10): Full query found in section ID
120
+ * - **Title match** (+10): Full query found in section title
121
+ * - **Use cases match** (+5 per keyword): Each query keyword found in use_cases
122
+ * - **Content match** (+1 per keyword): Each query keyword found in content
123
+ *
124
+ * The higher weights for ID/title ensure exact matches rank above content matches.
125
+ * Use cases are weighted moderately as they indicate intended use.
126
+ *
127
+ * @param sections - Array of sections to search through
128
+ * @param query - Search query (can contain multiple space-separated keywords)
129
+ * @returns Array of matching Sections sorted by relevance score (highest first)
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * // Single keyword search
134
+ * const results = searchSections(sections, 'validation');
135
+ *
136
+ * // Multi-keyword search (scores sections matching more keywords higher)
137
+ * const results = searchSections(sections, 'email url length');
138
+ * ```
27
139
  */
28
140
  export declare function searchSections(sections: Section[], query: string): Section[];
29
141
  /**
30
- * Get all sections in a category
142
+ * Filters sections by category slug or category title.
143
+ *
144
+ * Matches against both `category` (slug) and `category_title` (display name)
145
+ * to support flexible lookups.
146
+ *
147
+ * @param sections - Array of sections to filter
148
+ * @param category - Category slug or title to filter by (case-insensitive)
149
+ * @returns Array of Sections belonging to the specified category
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * // Filter by category slug
154
+ * const macros = getSectionsByCategory(sections, 'macros');
155
+ *
156
+ * // Filter by category title
157
+ * const guides = getSectionsByCategory(sections, 'Getting Started');
158
+ * ```
31
159
  */
32
160
  export declare function getSectionsByCategory(sections: Section[], category: string): Section[];
33
161
  //# sourceMappingURL=docs-loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"docs-loader.d.ts","sourceRoot":"","sources":["../../src/tools/docs-loader.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,OAAO,EAAE,CA0BxC;AAED;;G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AAC,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAY7E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,CA4C5E;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,EAAE,CAOtF"}
@@ -1,11 +1,51 @@
1
+ /**
2
+ * @module docs-loader
3
+ *
4
+ * Documentation Loading and Search Utilities
5
+ *
6
+ * This module provides functionality for loading, searching, and retrieving
7
+ * Macroforge documentation sections. Documentation is stored as markdown files
8
+ * with metadata in `docs/sections.json`.
9
+ *
10
+ * Key features:
11
+ * - Loads documentation sections from disk with lazy content loading
12
+ * - Supports multiple search strategies (exact, partial, fuzzy, category)
13
+ * - Handles chunked documentation for large sections
14
+ * - Provides type-safe interfaces for documentation structure
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { loadSections, getSection, searchSections } from './docs-loader.js';
19
+ *
20
+ * const sections = loadSections();
21
+ * const debug = getSection(sections, 'debug');
22
+ * const matches = searchSections(sections, 'serialization');
23
+ * ```
24
+ */
1
25
  import { readFileSync, existsSync } from 'node:fs';
2
26
  import { dirname, join } from 'node:path';
3
27
  import { fileURLToPath } from 'node:url';
28
+ /** Current file path for ESM module resolution */
4
29
  const __filename = fileURLToPath(import.meta.url);
30
+ /** Current directory path for ESM module resolution */
5
31
  const __dirname = dirname(__filename);
32
+ /** Path to the docs directory containing sections.json and markdown files */
6
33
  const docsDir = join(__dirname, '..', '..', 'docs');
7
34
  /**
8
- * Load all documentation sections from the docs directory
35
+ * Loads all documentation sections from the docs directory.
36
+ *
37
+ * This function reads `docs/sections.json` for metadata and loads the markdown
38
+ * content for each section from disk. Chunked parent sections do not have their
39
+ * content loaded directly - their content is accessed through child chunks.
40
+ *
41
+ * @returns Array of Section objects with content loaded. Returns empty array if
42
+ * sections.json is not found (with a warning logged to stderr).
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const sections = loadSections();
47
+ * console.log(`Loaded ${sections.length} sections`);
48
+ * ```
9
49
  */
10
50
  export function loadSections() {
11
51
  const sectionsPath = join(docsDir, 'sections.json');
@@ -14,9 +54,9 @@ export function loadSections() {
14
54
  return [];
15
55
  }
16
56
  const sectionsData = JSON.parse(readFileSync(sectionsPath, 'utf-8'));
17
- // Load content for each section
57
+ // Load content for each non-chunked section from its markdown file
18
58
  for (const section of sectionsData) {
19
- // For chunked parent sections, we don't load content - it will be handled specially
59
+ // Chunked parent sections don't have direct content - content is in child chunks
20
60
  if (section.is_chunked) {
21
61
  continue;
22
62
  }
@@ -31,35 +71,66 @@ export function loadSections() {
31
71
  return sectionsData;
32
72
  }
33
73
  /**
34
- * Get a section by ID or title (case-insensitive)
74
+ * Finds a section by ID or title using progressive matching strategies.
75
+ *
76
+ * The function attempts to match in the following order (stopping at first match):
77
+ * 1. Exact ID match (case-insensitive)
78
+ * 2. Exact title match (case-insensitive)
79
+ * 3. Partial ID match (query is substring of ID)
80
+ * 4. Partial title match (query is substring of title)
81
+ *
82
+ * @param sections - Array of sections to search through
83
+ * @param query - Search query (ID or title to find)
84
+ * @returns The first matching Section, or undefined if no match found
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const debug = getSection(sections, 'debug'); // Exact ID match
89
+ * const serde = getSection(sections, 'Serialize'); // Exact title match
90
+ * const partial = getSection(sections, 'valid'); // Partial match on "validators"
91
+ * ```
35
92
  */
36
93
  export function getSection(sections, query) {
37
94
  const normalizedQuery = query.toLowerCase().trim();
38
- // Try exact ID match first
95
+ // Priority 1: Exact ID match (most specific)
39
96
  let match = sections.find((s) => s.id.toLowerCase() === normalizedQuery);
40
97
  if (match)
41
98
  return match;
42
- // Try exact title match
99
+ // Priority 2: Exact title match
43
100
  match = sections.find((s) => s.title.toLowerCase() === normalizedQuery);
44
101
  if (match)
45
102
  return match;
46
- // Try partial ID match
103
+ // Priority 3: Partial ID match (query is substring of ID)
47
104
  match = sections.find((s) => s.id.toLowerCase().includes(normalizedQuery));
48
105
  if (match)
49
106
  return match;
50
- // Try partial title match
107
+ // Priority 4: Partial title match (query is substring of title)
51
108
  match = sections.find((s) => s.title.toLowerCase().includes(normalizedQuery));
52
109
  if (match)
53
110
  return match;
54
111
  return undefined;
55
112
  }
56
113
  /**
57
- * Get multiple sections by IDs or titles
114
+ * Retrieves multiple sections by their IDs or titles.
115
+ *
116
+ * Uses {@link getSection} for each query, deduplicating results if the same
117
+ * section matches multiple queries.
118
+ *
119
+ * @param sections - Array of sections to search through
120
+ * @param queries - Array of search queries (IDs or titles)
121
+ * @returns Array of unique matching Sections in the order they were found
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const docs = getSections(sections, ['debug', 'serialize', 'clone']);
126
+ * // Returns all three sections if found
127
+ * ```
58
128
  */
59
129
  export function getSections(sections, queries) {
60
130
  const results = [];
61
131
  for (const query of queries) {
62
132
  const section = getSection(sections, query);
133
+ // Deduplicate: only add if not already in results
63
134
  if (section && !results.includes(section)) {
64
135
  results.push(section);
65
136
  }
@@ -67,29 +138,57 @@ export function getSections(sections, queries) {
67
138
  return results;
68
139
  }
69
140
  /**
70
- * Search sections by use_cases or content
141
+ * Performs a fuzzy search across sections using a weighted scoring algorithm.
142
+ *
143
+ * The search splits the query into keywords and scores each section based on
144
+ * where matches are found. Results are sorted by relevance score (highest first).
145
+ *
146
+ * ## Scoring Algorithm
147
+ *
148
+ * Each section is scored based on matches in different fields:
149
+ * - **ID match** (+10): Full query found in section ID
150
+ * - **Title match** (+10): Full query found in section title
151
+ * - **Use cases match** (+5 per keyword): Each query keyword found in use_cases
152
+ * - **Content match** (+1 per keyword): Each query keyword found in content
153
+ *
154
+ * The higher weights for ID/title ensure exact matches rank above content matches.
155
+ * Use cases are weighted moderately as they indicate intended use.
156
+ *
157
+ * @param sections - Array of sections to search through
158
+ * @param query - Search query (can contain multiple space-separated keywords)
159
+ * @returns Array of matching Sections sorted by relevance score (highest first)
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * // Single keyword search
164
+ * const results = searchSections(sections, 'validation');
165
+ *
166
+ * // Multi-keyword search (scores sections matching more keywords higher)
167
+ * const results = searchSections(sections, 'email url length');
168
+ * ```
71
169
  */
72
170
  export function searchSections(sections, query) {
73
171
  const normalizedQuery = query.toLowerCase().trim();
74
172
  const keywords = normalizedQuery.split(/\s+/);
173
+ // Score each section based on where query/keywords match
75
174
  const scored = sections.map((section) => {
76
175
  let score = 0;
77
- // Check ID
176
+ // High priority: ID contains full query (+10)
78
177
  if (section.id.toLowerCase().includes(normalizedQuery)) {
79
178
  score += 10;
80
179
  }
81
- // Check title
180
+ // High priority: Title contains full query (+10)
82
181
  if (section.title.toLowerCase().includes(normalizedQuery)) {
83
182
  score += 10;
84
183
  }
85
- // Check use_cases
184
+ // Medium priority: Each keyword in use_cases (+5 each)
86
185
  const useCases = section.use_cases.toLowerCase();
87
186
  for (const keyword of keywords) {
88
187
  if (useCases.includes(keyword)) {
89
188
  score += 5;
90
189
  }
91
190
  }
92
- // Check content (lower weight)
191
+ // Low priority: Each keyword in content (+1 each)
93
192
  if (section.content) {
94
193
  const content = section.content.toLowerCase();
95
194
  for (const keyword of keywords) {
@@ -100,13 +199,30 @@ export function searchSections(sections, query) {
100
199
  }
101
200
  return { section, score };
102
201
  });
202
+ // Return matching sections sorted by score (highest first)
103
203
  return scored
104
204
  .filter((s) => s.score > 0)
105
205
  .sort((a, b) => b.score - a.score)
106
206
  .map((s) => s.section);
107
207
  }
108
208
  /**
109
- * Get all sections in a category
209
+ * Filters sections by category slug or category title.
210
+ *
211
+ * Matches against both `category` (slug) and `category_title` (display name)
212
+ * to support flexible lookups.
213
+ *
214
+ * @param sections - Array of sections to filter
215
+ * @param category - Category slug or title to filter by (case-insensitive)
216
+ * @returns Array of Sections belonging to the specified category
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * // Filter by category slug
221
+ * const macros = getSectionsByCategory(sections, 'macros');
222
+ *
223
+ * // Filter by category title
224
+ * const guides = getSectionsByCategory(sections, 'Getting Started');
225
+ * ```
110
226
  */
111
227
  export function getSectionsByCategory(sections, category) {
112
228
  const normalizedCategory = category.toLowerCase().trim();
@@ -1 +1 @@
1
- {"version":3,"file":"docs-loader.js","sourceRoot":"","sources":["../../src/tools/docs-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACtC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAepD;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAEpD,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9B,OAAO,CAAC,KAAK,CAAC,uFAAuF,CAAC,CAAC;QACvG,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAc,CAAC;IAElF,gCAAgC;IAChC,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;QACnC,oFAAoF;QACpF,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,SAAS;QACX,CAAC;QAED,MAAM,WAAW,G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O,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YAC9C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAC/B,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC9B,KAAK,IAAI,CAAC,CAAC;gBACb,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,2DAA2D;IAC3D,OAAO,MAAM;SACV,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;SAC1B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;SACjC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAmB,EAAE,QAAgB;IACzE,MAAM,kBAAkB,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;IACzD,OAAO,QAAQ,CAAC,MAAM,CACpB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,kBAAkB;QAC/C,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,KAAK,kBAAkB,CACxD,CAAC;AACJ,CAAC"}
@@ -1,6 +1,53 @@
1
+ /**
2
+ * @module tools
3
+ *
4
+ * MCP Tool Registry and Request Handlers
5
+ *
6
+ * This module registers and implements all MCP tools exposed by the Macroforge server.
7
+ * It serves as the main business logic layer, handling tool requests from MCP clients.
8
+ *
9
+ * ## Registered Tools
10
+ *
11
+ * | Tool | Purpose |
12
+ * |------|---------|
13
+ * | `list-sections` | List all documentation sections with metadata |
14
+ * | `get-documentation` | Retrieve full content for specific sections |
15
+ * | `macroforge-autofixer` | Validate TypeScript code with @derive decorators |
16
+ * | `expand-code` | Expand macros and show generated code |
17
+ * | `get-macro-info` | Get documentation for macros and decorators |
18
+ *
19
+ * ## Architecture
20
+ *
21
+ * The module uses:
22
+ * - `docs-loader.js` for documentation loading and search
23
+ * - `@macroforge/core` (optional) for native code validation and expansion
24
+ *
25
+ * Native bindings are loaded dynamically and gracefully degrade if unavailable.
26
+ *
27
+ * @see {@link registerTools} for the main entry point
28
+ */
1
29
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
30
  /**
3
- * Register all Macroforge MCP tools with the server
31
+ * Registers all Macroforge MCP tools with the server instance.
32
+ *
33
+ * This function:
34
+ * 1. Loads documentation sections from disk
35
+ * 2. Registers a `tools/list` handler returning all available tools
36
+ * 3. Registers a `tools/call` handler routing requests to appropriate handlers
37
+ *
38
+ * The tools registered provide documentation access and code analysis capabilities
39
+ * for AI assistants working with Macroforge.
40
+ *
41
+ * @param server - The MCP Server instance to register tools with
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * import { Server } from '@modelcontextprotocol/sdk/server/index.js';
46
+ * import { registerTools } from './tools/index.js';
47
+ *
48
+ * const server = new Server({ name: 'macroforge', version: '1.0.0' }, { capabilities: { tools: {} } });
49
+ * registerTools(server);
50
+ * ```
4
51
  */
5
52
  export declare function registerTools(server: Server): void;
6
53
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAWnE;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAwKlD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAYnE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAwKlD"}