Token导航 LogoToken导航TokenDH.com
MCP To Typescript logo
开发工具未说明官方级别未说明来源级核验

MCP To Typescript

MCP Server

一个将JSON模式转换为TypeScript类型并在沙盒环境中执行LLM生成代码的库,主要用于开发效率提升和AI工具集成。

工具数

2

提示词数

0

GitHub Stars

1

资源数

0
代码生成TypeScriptClaude开发工具Claude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

julianarchila

提供方

julianarchila

最后核验

2026/5/17 20:22

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

MCP到TypeScript

![TypeScript](https://www.typescriptlang.org/) ![Bun](https://bun.sh/) ![License: MIT](LICENSE)

一个库,用于将JSON模式转换为TypeScript类型,并在沙盒环境中使用工具访问执行LLM生成的代码。

特性

  • JSON 模式→ TypeScript转译器:使用中间AST将JSON模式转换为干净、可读的TypeScript类型定义
  • 代码执行沙盒:使AI代理能够在安全沙箱中使用工具执行代码
  • Composio集成:通过Composio工具包无缝连接到外部服务

安装

bun install

要求:

快速开始

模式转换器

将JSON模式转换为TypeScript类型:

import { convert } from "mcp-to-typescript";

const userSchema = {
  type: "object",
  properties: {
    id: { type: "integer" },
    name: { type: "string" },
    email: { type: "string" },
    age: { type: "number" },
  },
  required: ["id", "name", "email"],
};

console.log(convert(userSchema, "User"));
// Output:
// export type User = {
//   id: number;
//   name: string;
//   email: string;
//   age?: number;
// };

代码执行代理

创建一个可以使用自定义工具执行代码的AI代理:

import { generateText } from "ai";
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { createCodeExecutionTool, type Tool } from "mcp-to-typescript";

const openrouter = createOpenRouter({
  apiKey: process.env.OPENROUTER_API_KEY,
});

// Define custom tools
const tools: Tool[] = [
  {
    name: "calculate",
    description: "Performs mathematical calculations",
    parameters: {
      type: "object",
      properties: {
        expression: { type: "string", description: "Math expression to evaluate" },
      },
      required: ["expression"],
    },
    execute: (args: { expression: string }) => {
      const result = new Function(`return ${args.expression}`)();
      return { result };
    },
  },
  {
    name: "getCurrentTime",
    description: "Gets the current date and time",
    parameters: {
      type: "object",
      properties: {
        format: { type: "string", enum: ["iso", "unix", "human"] },
      },
    },
    execute: (args: { format?: string }) => {
      const now = new Date();
      if (args.format === "unix") return { timestamp: Math.floor(now.getTime() / 1000) };
      if (args.format === "human") return { time: now.toLocaleString() };
      return { time: now.toISOString() };
    },
  },
];

const executeCode = createCodeExecutionTool(tools);

const result = await generateText({
  model: openrouter.chat("anthropic/claude-sonnet-4"),
  messages: [{ role: "user", content: "What is 42 * 1337? Also, what time is it?" }],
  tools: { executeCode },
  maxSteps: 5,
});

console.log(result.text);

api参考

模式模块

convert(schema, typeName?): string

将JSON模式转换为TypeScript代码的简化函数。

import { convert } from "mcp-to-typescript";

const code = convert({ type: "string" }, "MyString");
// => "export type MyString = string;"

jsonSchemaToTypeScript(schema, options?): ConversionResult

具有选项的完整转换功能。

import { jsonSchemaToTypeScript } from "mcp-to-typescript";

// Get TypeScript code
const { code } = jsonSchemaToTypeScript(schema, { typeName: "User" });

// Get the intermediate AST
const { ast } = jsonSchemaToTypeScript(schema, { returnAST: true });

选项:

  • typeName?: string -生成类型的名称
  • returnAST?: boolean -返回AST而不是代码

parseSchema(schema): ASTNode

将JSON模式解析为中间AST。

generateTypeScript(ast, options?): string

从AST节点生成TypeScript代码。

代理模块

createCodeExecutionTool(tools, options?)

创建一个AI SDK工具,该工具通过访问提供的工具来执行代码。

import { createCodeExecutionTool } from "mcp-to-typescript";

const executeCode = createCodeExecutionTool(tools, {
  timeout: 30000, // 30 seconds
});

Tool 接口

interface Tool {
  name: string;
  description: string;
  parameters: {
    type: "object";
    properties: Record;
    required?: string[];
  };
  execute: (args: any) => any | Promise;
}

generateToolTypes(tools): string

从工具生成TypeScript函数签名(内部用于LLM提示)。

generateToolSummary(tools): string

生成可用工具的简要摘要。

适配器

getComposioTools(options): Promise

从Composio获取工具。

import { getComposioTools } from "mcp-to-typescript";

const tools = await getComposioTools({
  toolkits: ["GOOGLESHEETS", "SLACK"],
  userId: "your-composio-user-id",
});

listComposioToolkits(): Promise

列出可用的Composio工具包。

支持的JSON模式关键字

类别关键字TypeScript输出
原语string, number, integer, boolean, nullstring, number, number, boolean, null
对象type: "object", properties, required{ prop: T; optionalProp?: T; }
附加属性additionalProperties{ [key: string]: T }never
数组type: "array", items (对象)T[]
元组items (数组)[T1, T2, T3]
枚举enum, const`"a" \"b" \"c"`,文字类型
工会oneOf, anyOf, type: [...]`T1 \T2 \T3`
交点allOfT1 & T2 & T3
可空type: ["string", "null"]`string \null`

例子

请参阅 example/ 完整工作示例目录:

使用以下命令运行示例:

bun run example/transpiler.ts
bun run example/agent-custom.ts
bun run example/agent-composio.ts

发展

# Install dependencies
bun install

# Run tests
bun test

# Run tests in watch mode
bun test --watch

# Type check
bun run typecheck

参考文献

作者

  • 朱利安·阿奇拉
  • 圣地亚哥博特罗

许可证

麻省理工学院

目录标签

目录标签

代码生成TypeScriptClaude开发工具JSON转TypeScript本地部署AI工具集成沙盒执行

支持客户端

Claude

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

2

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP