Back to MCP directory
publicPublicdnsLocal runtime

Data Extractor

一个MCP协议服务器,用于从TypeScript/JavaScript源代码中提取嵌入式数据(如i18n翻译或键值配置)和SVG组件,生成结构化JSON配置文件和独立SVG文件。

article

README

🚀 MCP 数据提取器服务器文档

MCP 数据提取器服务器可从 TypeScript 或 JavaScript 源代码里提取字符串、模板字面量,还能处理复杂结构(像数组和对象)。下面为你详细介绍其功能、使用示例、扩展方法、开发与调试指南以及许可证信息。

🚀 快速开始

MCP 数据提取器服务器能高效地从 TypeScript 或 JavaScript 代码中提取所需的字符串和模板字面量,支持复杂结构处理,还可通过扩展方法满足更多定制需求。

✨ 主要特性

  • 字符串值提取:精准识别并提取字符串字面量和模板字面量。
  • 复杂结构支持:有效处理数组和对象,支持嵌套结构。
  • 自定义扩展:可通过扩展 extractStringValueprocessValue 方法,支持更多 AST 节点类型。

💻 使用示例

基础用法

字符串值提取

  • 输入
export default {
  greeting: 'Hello, {{username}}!',
  message: `Welcome to ${appName}`
};
  • 输出
{
  "greeting": "Hello, {{username}}!",
  "message": "Welcome to {{appName}}"
}

复杂结构处理

  • 输入
export default {
  header: {
    title: '欢迎使用',
    description: `这是一个示例 ${description}`
  },
  list: ['项目1', '项目2', { id: '3' }]
};
  • 输出
{
  "header.title": "欢迎使用",
  "header.description": "这是一个示例 {{description}}",
  "list.0": "项目1",
  "list.1": "项目2",
  "list.2.id": "3"
}

🔧 技术细节

添加新的 AST 节点类型

要扩展支持的节点类型,可在 src/index.ts 中修改 extractStringValue 方法:

private extractStringValue(node: t.Node): string | null {
  if (t.isStringLiteral(node)) {
    return node.value;
  } else if (t.isTemplateLiteral(node)) {
    return node.quasis.map(quasi => quasi.value.raw).join('{{}}');
  }
  // 添加新的节点类型支持
  if (t.isSome newNodeType(node)) {
    // 处理新节点类型
  }
  return null;
}

自定义值处理

通过重写 processValue 方法,可扩展对其他值类型的处理:

private processValue(value: t.Node, currentPath: string[]): void {
  if (t.isStringLiteral(value) || t.isTemplateLiteral(value)) {
    // 处理字符串值
  } else if (t.isArrayExpression(value)) {
    // 处理数组
  } else if (t.isObjectExpression(value)) {
    // 处理对象
  }
  // 添加新的值类型处理
}

自定义 AST 遍历

可通过添加自定义访问者来扩展 AST 遍历功能:

traverse(ast, {
  ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>) {
    // 处理默认导出
  },
  // 添加新的访问者
});

📦 安装指南

安装依赖

npm install

构建服务器

npm run build

开发模式(自动重建)

npm run watch

💡 使用建议

由于 MCP 服务器通过标准输入输出进行通信,调试可能较为困难。我们推荐使用 MCP Inspector 进行调试:

npm run inspector

Inspector 会提供一个 Web 界面,帮助你调试和分析代码。

📄 许可证

本项目遵循 MIT 许可证。请查看 LICENSE 文件以获取详细信息。


通过以上说明,你可以轻松扩展 MCP 数据提取器服务器的功能,并根据需求进行定制开发。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client