mcp-ts-transcript 1.0.0 → 1.0.2

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 (2) hide show
  1. package/dist/index.js +19 -22
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2,22 +2,30 @@
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 { readFileSync, writeFileSync } from "fs";
5
6
  import * as ts from "typescript";
7
+ const COMPILER_OPTIONS = {
8
+ noImplicitAny: false,
9
+ noEmitOnError: false,
10
+ removeComments: true,
11
+ sourceMap: false,
12
+ target: ts.ScriptTarget.ES5,
13
+ };
6
14
  const server = new Server({ name: "ts-transcript", version: "1.0.0" }, { capabilities: { tools: {} } });
7
15
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
8
16
  tools: [
9
17
  {
10
18
  name: "compile_typescript",
11
- description: "Receives TypeScript code, compiles it and returns the JavaScript output.",
19
+ description: "Compiles a TypeScript file to JavaScript.",
12
20
  inputSchema: {
13
21
  type: "object",
14
22
  properties: {
15
- code: {
23
+ file_path: {
16
24
  type: "string",
17
- description: "TypeScript source code to compile",
25
+ description: "Absolute path to the .ts file to compile",
18
26
  },
19
27
  },
20
- required: ["code"],
28
+ required: ["file_path"],
21
29
  },
22
30
  },
23
31
  ],
@@ -26,28 +34,17 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
26
34
  if (request.params.name !== "compile_typescript") {
27
35
  throw new Error(`Unknown tool: ${request.params.name}`);
28
36
  }
29
- const { code } = request.params.arguments;
30
- const result = ts.transpileModule(code, {
31
- compilerOptions: {
32
- target: ts.ScriptTarget.ES2020,
33
- module: ts.ModuleKind.CommonJS,
34
- esModuleInterop: true,
35
- strict: false,
36
- },
37
- reportDiagnostics: true,
38
- });
39
- if (result.diagnostics && result.diagnostics.length > 0) {
37
+ const { file_path } = request.params.arguments;
38
+ const code = readFileSync(file_path, "utf-8");
39
+ const result = ts.transpileModule(code, { compilerOptions: COMPILER_OPTIONS, reportDiagnostics: true });
40
+ if (result.diagnostics?.length) {
40
41
  const errors = result.diagnostics
41
42
  .map((d) => ts.flattenDiagnosticMessageText(d.messageText, "\n"))
42
43
  .join("\n");
43
- return {
44
- content: [{ type: "text", text: `Compilation errors:\n${errors}` }],
45
- isError: true,
46
- };
44
+ return { content: [{ type: "text", text: `Compilation errors:\n${errors}` }], isError: true };
47
45
  }
48
- return {
49
- content: [{ type: "text", text: result.outputText }],
50
- };
46
+ writeFileSync(file_path.replace(/\.ts$/, ".js"), result.outputText, "utf-8");
47
+ return { content: [{ type: "text", text: "OK" }] };
51
48
  });
52
49
  const transport = new StdioServerTransport();
53
50
  await server.connect(transport);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-ts-transcript",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "MCP server that compiles TypeScript code to JavaScript",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",