mcp-ts-transcript 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 +29 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
-
import {
|
|
5
|
+
import { existsSync, writeFileSync } from "fs";
|
|
6
|
+
import { dirname, join } from "path";
|
|
6
7
|
import * as ts from "typescript";
|
|
7
8
|
const COMPILER_OPTIONS = {
|
|
8
9
|
noImplicitAny: false,
|
|
@@ -35,15 +36,34 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
35
36
|
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
36
37
|
}
|
|
37
38
|
const { file_path } = request.params.arguments;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
// Find nearest tsconfig.json to get all project files (needed for namespace resolution)
|
|
40
|
+
let dir = dirname(file_path);
|
|
41
|
+
let tsconfigPath = null;
|
|
42
|
+
while (true) {
|
|
43
|
+
const candidate = join(dir, "tsconfig.json");
|
|
44
|
+
if (existsSync(candidate)) {
|
|
45
|
+
tsconfigPath = candidate;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
const parent = dirname(dir);
|
|
49
|
+
if (parent === dir)
|
|
50
|
+
break;
|
|
51
|
+
dir = parent;
|
|
45
52
|
}
|
|
46
|
-
|
|
53
|
+
let fileNames = tsconfigPath
|
|
54
|
+
? ts.parseJsonConfigFileContent(ts.readConfigFile(tsconfigPath, ts.sys.readFile).config, ts.sys, dirname(tsconfigPath)).fileNames
|
|
55
|
+
: [];
|
|
56
|
+
// Ensure the target file is in the program (it may not match the tsconfig include pattern)
|
|
57
|
+
const normalizedTarget = file_path.toLowerCase();
|
|
58
|
+
if (!fileNames.some(f => f.toLowerCase() === normalizedTarget))
|
|
59
|
+
fileNames = [...fileNames, file_path];
|
|
60
|
+
// createProgram loads all project files so namespaces resolve correctly,
|
|
61
|
+
// but we only emit the single target file
|
|
62
|
+
const program = ts.createProgram(fileNames, COMPILER_OPTIONS);
|
|
63
|
+
program.emit(program.getSourceFile(file_path), (fileName, data) => {
|
|
64
|
+
if (fileName.endsWith(".js"))
|
|
65
|
+
writeFileSync(fileName, data, "utf-8");
|
|
66
|
+
});
|
|
47
67
|
return { content: [{ type: "text", text: "OK" }] };
|
|
48
68
|
});
|
|
49
69
|
const transport = new StdioServerTransport();
|