@macroforge/mcp-server 0.1.17
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.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/docs-loader.d.ts +30 -0
- package/dist/tools/docs-loader.d.ts.map +1 -0
- package/dist/tools/docs-loader.js +112 -0
- package/dist/tools/docs-loader.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +348 -0
- package/dist/tools/index.js.map +1 -0
- package/docs/api/api-overview.md +75 -0
- package/docs/api/expand-sync.md +121 -0
- package/docs/api/native-plugin.md +106 -0
- package/docs/api/position-mapper.md +127 -0
- package/docs/api/transform-sync.md +98 -0
- package/docs/builtin-macros/clone.md +180 -0
- package/docs/builtin-macros/debug.md +222 -0
- package/docs/builtin-macros/default.md +192 -0
- package/docs/builtin-macros/deserialize.md +662 -0
- package/docs/builtin-macros/hash.md +205 -0
- package/docs/builtin-macros/macros-overview.md +169 -0
- package/docs/builtin-macros/ord.md +258 -0
- package/docs/builtin-macros/partial-eq.md +306 -0
- package/docs/builtin-macros/partial-ord.md +268 -0
- package/docs/builtin-macros/serialize.md +321 -0
- package/docs/concepts/architecture.md +139 -0
- package/docs/concepts/derive-system.md +173 -0
- package/docs/concepts/how-macros-work.md +124 -0
- package/docs/custom-macros/custom-overview.md +84 -0
- package/docs/custom-macros/rust-setup.md +146 -0
- package/docs/custom-macros/ts-macro-derive.md +307 -0
- package/docs/custom-macros/ts-quote.md +696 -0
- package/docs/getting-started/first-macro.md +120 -0
- package/docs/getting-started/installation.md +110 -0
- package/docs/integration/cli.md +207 -0
- package/docs/integration/configuration.md +116 -0
- package/docs/integration/integration-overview.md +51 -0
- package/docs/integration/typescript-plugin.md +96 -0
- package/docs/integration/vite-plugin.md +126 -0
- package/docs/language-servers/ls-overview.md +47 -0
- package/docs/language-servers/svelte-ls.md +80 -0
- package/docs/language-servers/zed-extensions.md +84 -0
- package/docs/sections.json +258 -0
- package/package.json +48 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { registerTools } from './tools/index.js';
|
|
8
|
+
// Get package info for server metadata
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = dirname(__filename);
|
|
11
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'));
|
|
12
|
+
const { name, version } = pkg;
|
|
13
|
+
/**
|
|
14
|
+
* Main function to start the MCP server
|
|
15
|
+
*/
|
|
16
|
+
async function main() {
|
|
17
|
+
// Create server instance with metadata
|
|
18
|
+
const server = new Server({
|
|
19
|
+
name,
|
|
20
|
+
version,
|
|
21
|
+
}, {
|
|
22
|
+
capabilities: {
|
|
23
|
+
tools: {},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
// Register all tools
|
|
27
|
+
registerTools(server);
|
|
28
|
+
// Set up error handling
|
|
29
|
+
server.onerror = (error) => {
|
|
30
|
+
console.error('[MCP Error]', error);
|
|
31
|
+
};
|
|
32
|
+
// Handle process termination
|
|
33
|
+
process.on('SIGINT', async () => {
|
|
34
|
+
await server.close();
|
|
35
|
+
process.exit(0);
|
|
36
|
+
});
|
|
37
|
+
// Connect to transport
|
|
38
|
+
const transport = new StdioServerTransport();
|
|
39
|
+
await server.connect(transport);
|
|
40
|
+
console.error('Macroforge MCP server running on stdio');
|
|
41
|
+
}
|
|
42
|
+
// Run the server
|
|
43
|
+
main().catch((error) => {
|
|
44
|
+
console.error('Failed to start MCP server:', error);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,uCAAuC;AACvC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACtC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACpF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;AAE9B;;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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface Section {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
category: string;
|
|
5
|
+
category_title: string;
|
|
6
|
+
path: string;
|
|
7
|
+
use_cases: string;
|
|
8
|
+
content?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Load all documentation sections from the docs directory
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadSections(): Section[];
|
|
14
|
+
/**
|
|
15
|
+
* Get a section by ID or title (case-insensitive)
|
|
16
|
+
*/
|
|
17
|
+
export declare function getSection(sections: Section[], query: string): Section | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Get multiple sections by IDs or titles
|
|
20
|
+
*/
|
|
21
|
+
export declare function getSections(sections: Section[], queries: string[]): Section[];
|
|
22
|
+
/**
|
|
23
|
+
* Search sections by use_cases or content
|
|
24
|
+
*/
|
|
25
|
+
export declare function searchSections(sections: Section[], query: string): Section[];
|
|
26
|
+
/**
|
|
27
|
+
* Get all sections in a category
|
|
28
|
+
*/
|
|
29
|
+
export declare function getSectionsByCategory(sections: Section[], category: string): Section[];
|
|
30
|
+
//# sourceMappingURL=docs-loader.d.ts.map
|
|
@@ -0,0 +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;CAClB;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,OAAO,EAAE,CAqBxC;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAoBlF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAW7E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,CA0C5E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,EAAE,CAOtF"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = dirname(__filename);
|
|
6
|
+
const docsDir = join(__dirname, '..', '..', 'docs');
|
|
7
|
+
/**
|
|
8
|
+
* Load all documentation sections from the docs directory
|
|
9
|
+
*/
|
|
10
|
+
export function loadSections() {
|
|
11
|
+
const sectionsPath = join(docsDir, 'sections.json');
|
|
12
|
+
if (!existsSync(sectionsPath)) {
|
|
13
|
+
console.error('Warning: sections.json not found. Run "npm run build:docs" to generate documentation.');
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const sectionsData = JSON.parse(readFileSync(sectionsPath, 'utf-8'));
|
|
17
|
+
// Load content for each section
|
|
18
|
+
for (const section of sectionsData) {
|
|
19
|
+
const contentPath = join(docsDir, section.path);
|
|
20
|
+
if (existsSync(contentPath)) {
|
|
21
|
+
section.content = readFileSync(contentPath, 'utf-8');
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
section.content = `Documentation file not found: ${section.path}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return sectionsData;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get a section by ID or title (case-insensitive)
|
|
31
|
+
*/
|
|
32
|
+
export function getSection(sections, query) {
|
|
33
|
+
const normalizedQuery = query.toLowerCase().trim();
|
|
34
|
+
// Try exact ID match first
|
|
35
|
+
let match = sections.find((s) => s.id.toLowerCase() === normalizedQuery);
|
|
36
|
+
if (match)
|
|
37
|
+
return match;
|
|
38
|
+
// Try exact title match
|
|
39
|
+
match = sections.find((s) => s.title.toLowerCase() === normalizedQuery);
|
|
40
|
+
if (match)
|
|
41
|
+
return match;
|
|
42
|
+
// Try partial ID match
|
|
43
|
+
match = sections.find((s) => s.id.toLowerCase().includes(normalizedQuery));
|
|
44
|
+
if (match)
|
|
45
|
+
return match;
|
|
46
|
+
// Try partial title match
|
|
47
|
+
match = sections.find((s) => s.title.toLowerCase().includes(normalizedQuery));
|
|
48
|
+
if (match)
|
|
49
|
+
return match;
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get multiple sections by IDs or titles
|
|
54
|
+
*/
|
|
55
|
+
export function getSections(sections, queries) {
|
|
56
|
+
const results = [];
|
|
57
|
+
for (const query of queries) {
|
|
58
|
+
const section = getSection(sections, query);
|
|
59
|
+
if (section && !results.includes(section)) {
|
|
60
|
+
results.push(section);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Search sections by use_cases or content
|
|
67
|
+
*/
|
|
68
|
+
export function searchSections(sections, query) {
|
|
69
|
+
const normalizedQuery = query.toLowerCase().trim();
|
|
70
|
+
const keywords = normalizedQuery.split(/\s+/);
|
|
71
|
+
const scored = sections.map((section) => {
|
|
72
|
+
let score = 0;
|
|
73
|
+
// Check ID
|
|
74
|
+
if (section.id.toLowerCase().includes(normalizedQuery)) {
|
|
75
|
+
score += 10;
|
|
76
|
+
}
|
|
77
|
+
// Check title
|
|
78
|
+
if (section.title.toLowerCase().includes(normalizedQuery)) {
|
|
79
|
+
score += 10;
|
|
80
|
+
}
|
|
81
|
+
// Check use_cases
|
|
82
|
+
const useCases = section.use_cases.toLowerCase();
|
|
83
|
+
for (const keyword of keywords) {
|
|
84
|
+
if (useCases.includes(keyword)) {
|
|
85
|
+
score += 5;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Check content (lower weight)
|
|
89
|
+
if (section.content) {
|
|
90
|
+
const content = section.content.toLowerCase();
|
|
91
|
+
for (const keyword of keywords) {
|
|
92
|
+
if (content.includes(keyword)) {
|
|
93
|
+
score += 1;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { section, score };
|
|
98
|
+
});
|
|
99
|
+
return scored
|
|
100
|
+
.filter((s) => s.score > 0)
|
|
101
|
+
.sort((a, b) => b.score - a.score)
|
|
102
|
+
.map((s) => s.section);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get all sections in a category
|
|
106
|
+
*/
|
|
107
|
+
export function getSectionsByCategory(sections, category) {
|
|
108
|
+
const normalizedCategory = category.toLowerCase().trim();
|
|
109
|
+
return sections.filter((s) => s.category.toLowerCase() === normalizedCategory ||
|
|
110
|
+
s.category_title.toLowerCase() === normalizedCategory);
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=docs-loader.js.map
|
|
@@ -0,0 +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;AAYpD;;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,MAAM,WA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,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAWnE;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAgJlD"}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { loadSections, getSection, searchSections } from './docs-loader.js';
|
|
3
|
+
let sections = [];
|
|
4
|
+
/**
|
|
5
|
+
* Register all Macroforge MCP tools with the server
|
|
6
|
+
*/
|
|
7
|
+
export function registerTools(server) {
|
|
8
|
+
// Load documentation sections
|
|
9
|
+
sections = loadSections();
|
|
10
|
+
// Register tool listing
|
|
11
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
12
|
+
return {
|
|
13
|
+
tools: [
|
|
14
|
+
{
|
|
15
|
+
name: 'list-sections',
|
|
16
|
+
description: `Lists all Macroforge documentation sections.
|
|
17
|
+
|
|
18
|
+
Returns sections with:
|
|
19
|
+
- title: Section name
|
|
20
|
+
- use_cases: When this doc is useful (comma-separated keywords)
|
|
21
|
+
- path: File path
|
|
22
|
+
- category: Category name
|
|
23
|
+
|
|
24
|
+
WORKFLOW:
|
|
25
|
+
1. Call list-sections FIRST for any Macroforge-related task
|
|
26
|
+
2. Analyze use_cases to find relevant sections
|
|
27
|
+
3. Call get-documentation with ALL relevant section names
|
|
28
|
+
|
|
29
|
+
Example use_cases: "setup, install", "serialization, json", "validation, email"`,
|
|
30
|
+
inputSchema: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'get-documentation',
|
|
37
|
+
description: `Retrieves full documentation content for Macroforge sections.
|
|
38
|
+
|
|
39
|
+
Supports flexible search by:
|
|
40
|
+
- Title (e.g., "Debug", "Vite Plugin")
|
|
41
|
+
- ID (e.g., "debug", "vite-plugin")
|
|
42
|
+
- Partial matches
|
|
43
|
+
|
|
44
|
+
Can accept a single section name or an array of sections.
|
|
45
|
+
After calling list-sections, analyze the use_cases and fetch ALL relevant sections at once.`,
|
|
46
|
+
inputSchema: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
section: {
|
|
50
|
+
anyOf: [
|
|
51
|
+
{ type: 'string' },
|
|
52
|
+
{ type: 'array', items: { type: 'string' } },
|
|
53
|
+
],
|
|
54
|
+
description: 'Section name(s) to retrieve. Supports single string or array of strings.',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
required: ['section'],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'macroforge-autofixer',
|
|
62
|
+
description: `Validates TypeScript code with @derive decorators using Macroforge's native validation.
|
|
63
|
+
|
|
64
|
+
Returns structured JSON diagnostics with:
|
|
65
|
+
- level: error | warning | info
|
|
66
|
+
- message: What's wrong
|
|
67
|
+
- location: Line and column number (when available)
|
|
68
|
+
- help: Suggested fix (when available)
|
|
69
|
+
- notes: Additional context (when available)
|
|
70
|
+
- summary: Count of errors, warnings, and info messages
|
|
71
|
+
|
|
72
|
+
This tool MUST be used before sending Macroforge code to the user.
|
|
73
|
+
If require_another_tool_call_after_fixing is true, fix the issues and validate again.
|
|
74
|
+
|
|
75
|
+
Detects:
|
|
76
|
+
- Invalid/unknown macro names
|
|
77
|
+
- Malformed @derive decorators
|
|
78
|
+
- @serde validator issues (email, url, length, etc.)
|
|
79
|
+
- Macro expansion failures
|
|
80
|
+
- Syntax errors in generated code`,
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
code: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
description: 'TypeScript code with @derive decorators to validate',
|
|
87
|
+
},
|
|
88
|
+
filename: {
|
|
89
|
+
type: 'string',
|
|
90
|
+
description: 'Filename for the code (default: input.ts)',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
required: ['code'],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'expand-code',
|
|
98
|
+
description: `Expands Macroforge macros in TypeScript code and returns the transformed result.
|
|
99
|
+
|
|
100
|
+
Shows:
|
|
101
|
+
- The fully expanded TypeScript code with all generated methods
|
|
102
|
+
- Any diagnostics (errors, warnings, info) with line/column locations
|
|
103
|
+
- Help text for fixing issues (when available)
|
|
104
|
+
|
|
105
|
+
Useful for:
|
|
106
|
+
- Seeing what code the macros generate
|
|
107
|
+
- Understanding how @derive decorators transform your classes
|
|
108
|
+
- Debugging macro expansion issues`,
|
|
109
|
+
inputSchema: {
|
|
110
|
+
type: 'object',
|
|
111
|
+
properties: {
|
|
112
|
+
code: {
|
|
113
|
+
type: 'string',
|
|
114
|
+
description: 'TypeScript code with @derive decorators to expand',
|
|
115
|
+
},
|
|
116
|
+
filename: {
|
|
117
|
+
type: 'string',
|
|
118
|
+
description: 'Filename for the code (default: input.ts)',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
required: ['code'],
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
// Register tool call handler
|
|
128
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
129
|
+
const { name, arguments: args } = request.params;
|
|
130
|
+
switch (name) {
|
|
131
|
+
case 'list-sections':
|
|
132
|
+
return handleListSections();
|
|
133
|
+
case 'get-documentation':
|
|
134
|
+
return handleGetDocumentation(args);
|
|
135
|
+
case 'macroforge-autofixer':
|
|
136
|
+
return handleAutofixer(args);
|
|
137
|
+
case 'expand-code':
|
|
138
|
+
return handleExpandCode(args);
|
|
139
|
+
default:
|
|
140
|
+
throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Handle list-sections tool call
|
|
146
|
+
*/
|
|
147
|
+
function handleListSections() {
|
|
148
|
+
const formatted = sections
|
|
149
|
+
.map((s) => `* title: [${s.title}], use_cases: [${s.use_cases}], path: [${s.path}], category: [${s.category_title}]`)
|
|
150
|
+
.join('\n');
|
|
151
|
+
return {
|
|
152
|
+
content: [
|
|
153
|
+
{
|
|
154
|
+
type: 'text',
|
|
155
|
+
text: `Available Macroforge documentation sections:\n\n${formatted}`,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Handle get-documentation tool call
|
|
162
|
+
*/
|
|
163
|
+
function handleGetDocumentation(args) {
|
|
164
|
+
const sectionNames = Array.isArray(args.section) ? args.section : [args.section];
|
|
165
|
+
const results = [];
|
|
166
|
+
for (const name of sectionNames) {
|
|
167
|
+
const section = getSection(sections, name);
|
|
168
|
+
if (section) {
|
|
169
|
+
results.push(`# ${section.title}\n\n${section.content}`);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
// Try fuzzy search
|
|
173
|
+
const matches = searchSections(sections, name);
|
|
174
|
+
if (matches.length > 0) {
|
|
175
|
+
results.push(`# ${matches[0].title}\n\n${matches[0].content}`);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
results.push(`Documentation for "${name}" not found.`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
type: 'text',
|
|
186
|
+
text: results.join('\n\n---\n\n'),
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Handle macroforge-autofixer tool call
|
|
193
|
+
* Returns structured diagnostics from Macroforge's native validation
|
|
194
|
+
*/
|
|
195
|
+
async function handleAutofixer(args) {
|
|
196
|
+
const filename = args.filename || 'input.ts';
|
|
197
|
+
try {
|
|
198
|
+
const macroforge = await importMacroforge();
|
|
199
|
+
if (!macroforge) {
|
|
200
|
+
return {
|
|
201
|
+
content: [
|
|
202
|
+
{
|
|
203
|
+
type: 'text',
|
|
204
|
+
text: JSON.stringify({
|
|
205
|
+
diagnostics: [{
|
|
206
|
+
level: 'error',
|
|
207
|
+
message: 'Native Macroforge bindings not available. Install @macroforge/core.',
|
|
208
|
+
}],
|
|
209
|
+
summary: { errors: 1, warnings: 0, info: 0 },
|
|
210
|
+
require_another_tool_call_after_fixing: false,
|
|
211
|
+
}, null, 2),
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const result = macroforge.expandSync(args.code, filename, {});
|
|
217
|
+
const diagnostics = result.diagnostics || [];
|
|
218
|
+
const output = {
|
|
219
|
+
diagnostics: diagnostics.map((d) => ({
|
|
220
|
+
level: normalizeLevel(d.level),
|
|
221
|
+
message: d.message,
|
|
222
|
+
location: d.span ? { line: d.span.start.line, column: d.span.start.column } : undefined,
|
|
223
|
+
help: d.help || undefined,
|
|
224
|
+
notes: d.notes && d.notes.length > 0 ? d.notes : undefined,
|
|
225
|
+
})),
|
|
226
|
+
summary: {
|
|
227
|
+
errors: diagnostics.filter((d) => d.level === 'Error').length,
|
|
228
|
+
warnings: diagnostics.filter((d) => d.level === 'Warning').length,
|
|
229
|
+
info: diagnostics.filter((d) => d.level === 'Info').length,
|
|
230
|
+
},
|
|
231
|
+
require_another_tool_call_after_fixing: diagnostics.some((d) => d.level === 'Error'),
|
|
232
|
+
};
|
|
233
|
+
return {
|
|
234
|
+
content: [
|
|
235
|
+
{
|
|
236
|
+
type: 'text',
|
|
237
|
+
text: JSON.stringify(output, null, 2),
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
244
|
+
return {
|
|
245
|
+
content: [
|
|
246
|
+
{
|
|
247
|
+
type: 'text',
|
|
248
|
+
text: JSON.stringify({
|
|
249
|
+
diagnostics: [{
|
|
250
|
+
level: 'error',
|
|
251
|
+
message: `Error during analysis: ${message}`,
|
|
252
|
+
}],
|
|
253
|
+
summary: { errors: 1, warnings: 0, info: 0 },
|
|
254
|
+
require_another_tool_call_after_fixing: false,
|
|
255
|
+
}, null, 2),
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Handle expand-code tool call
|
|
263
|
+
* Returns expanded code with structured diagnostics
|
|
264
|
+
*/
|
|
265
|
+
async function handleExpandCode(args) {
|
|
266
|
+
const filename = args.filename || 'input.ts';
|
|
267
|
+
try {
|
|
268
|
+
const macroforge = await importMacroforge();
|
|
269
|
+
if (!macroforge) {
|
|
270
|
+
return {
|
|
271
|
+
content: [
|
|
272
|
+
{
|
|
273
|
+
type: 'text',
|
|
274
|
+
text: 'Native Macroforge bindings not available. Install @macroforge/core to enable code expansion.',
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
const result = macroforge.expandSync(args.code, filename, {});
|
|
280
|
+
const diagnostics = result.diagnostics || [];
|
|
281
|
+
// Build structured output
|
|
282
|
+
const output = {
|
|
283
|
+
expandedCode: result.code,
|
|
284
|
+
diagnostics: diagnostics.map((d) => ({
|
|
285
|
+
level: normalizeLevel(d.level),
|
|
286
|
+
message: d.message,
|
|
287
|
+
location: d.span?.start,
|
|
288
|
+
help: d.help || undefined,
|
|
289
|
+
})),
|
|
290
|
+
hasErrors: diagnostics.some((d) => d.level === 'Error'),
|
|
291
|
+
};
|
|
292
|
+
// Format human-readable text
|
|
293
|
+
let text = `## Expanded Code\n\n\`\`\`typescript\n${result.code}\n\`\`\``;
|
|
294
|
+
if (diagnostics.length > 0) {
|
|
295
|
+
text += '\n\n## Diagnostics\n\n';
|
|
296
|
+
for (const d of diagnostics) {
|
|
297
|
+
const loc = d.span ? ` (line ${d.span.start.line}, col ${d.span.start.column})` : '';
|
|
298
|
+
text += `- **[${normalizeLevel(d.level)}]**${loc} ${d.message}\n`;
|
|
299
|
+
if (d.help) {
|
|
300
|
+
text += ` - Help: ${d.help}\n`;
|
|
301
|
+
}
|
|
302
|
+
if (d.notes && d.notes.length > 0) {
|
|
303
|
+
for (const note of d.notes) {
|
|
304
|
+
text += ` - Note: ${note}\n`;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
content: [{ type: 'text', text }],
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
315
|
+
return {
|
|
316
|
+
content: [
|
|
317
|
+
{
|
|
318
|
+
type: 'text',
|
|
319
|
+
text: `Error expanding code: ${message}`,
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
// ============================================================================
|
|
326
|
+
// Helper functions
|
|
327
|
+
// ============================================================================
|
|
328
|
+
/**
|
|
329
|
+
* Try to import native Macroforge bindings
|
|
330
|
+
*/
|
|
331
|
+
async function importMacroforge() {
|
|
332
|
+
try {
|
|
333
|
+
// Dynamic import to avoid build-time errors
|
|
334
|
+
// @ts-expect-error - dynamic import of optional dependency
|
|
335
|
+
const mod = await import('@macroforge/core');
|
|
336
|
+
return mod;
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Normalize diagnostic level to lowercase for output
|
|
344
|
+
*/
|
|
345
|
+
function normalizeLevel(level) {
|
|
346
|
+
return level.toLowerCase();
|
|
347
|
+
}
|
|
348
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names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,OAAO,EAAE;iBACzC;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC;AAyDD,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;GAEG;AACH,KAAK,UAAU,gBAAgB;IAC7B,IAAI,CAAC;QACH,4CAA4C;QAC5C,2DAA2D;QAC3D,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAC7C,OAAO,GAAuB,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
*Macroforge provides a programmatic API for expanding macros in TypeScript code.*
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import {
|
|
9
|
+
expandSync,
|
|
10
|
+
transformSync,
|
|
11
|
+
checkSyntax,
|
|
12
|
+
parseImportSources,
|
|
13
|
+
NativePlugin,
|
|
14
|
+
PositionMapper
|
|
15
|
+
} from "macroforge";
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Core Functions
|
|
19
|
+
|
|
20
|
+
| [`expandSync()`]({base}/docs/api/expand-sync)
|
|
21
|
+
| Expand macros synchronously
|
|
22
|
+
|
|
23
|
+
| [`transformSync()`]({base}/docs/api/transform-sync)
|
|
24
|
+
| Transform code with additional metadata
|
|
25
|
+
|
|
26
|
+
| `checkSyntax()`
|
|
27
|
+
| Validate TypeScript syntax
|
|
28
|
+
|
|
29
|
+
| `parseImportSources()`
|
|
30
|
+
| Extract import information
|
|
31
|
+
|
|
32
|
+
## Classes
|
|
33
|
+
|
|
34
|
+
| [`NativePlugin`]({base}/docs/api/native-plugin)
|
|
35
|
+
| Stateful plugin with caching
|
|
36
|
+
|
|
37
|
+
| [`PositionMapper`]({base}/docs/api/position-mapper)
|
|
38
|
+
| Maps positions between original and expanded code
|
|
39
|
+
|
|
40
|
+
## Quick Example
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { expandSync } from "macroforge";
|
|
44
|
+
|
|
45
|
+
const sourceCode = \`
|
|
46
|
+
/** @derive(Debug) */
|
|
47
|
+
class User {
|
|
48
|
+
name: string;
|
|
49
|
+
constructor(name: string) {
|
|
50
|
+
this.name = name;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
\`;
|
|
54
|
+
|
|
55
|
+
const result = expandSync(sourceCode, "user.ts", {
|
|
56
|
+
keepDecorators: false
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log(result.code);
|
|
60
|
+
// Output: class with toString() method generated
|
|
61
|
+
|
|
62
|
+
if (result.diagnostics.length > 0) {
|
|
63
|
+
console.error("Errors:", result.diagnostics);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Detailed Reference
|
|
68
|
+
|
|
69
|
+
- [`expandSync()`]({base}/docs/api/expand-sync) - Full options and return types
|
|
70
|
+
|
|
71
|
+
- [`transformSync()`]({base}/docs/api/transform-sync) - Transform with source maps
|
|
72
|
+
|
|
73
|
+
- [`NativePlugin`]({base}/docs/api/native-plugin) - Caching for language servers
|
|
74
|
+
|
|
75
|
+
- [`PositionMapper`]({base}/docs/api/position-mapper) - Position mapping utilities
|