COBOL MCP服务器
提供COBOL函数提取功能的模型上下文协议(MCP)服务器。此服务器使LLM能够通过从COBOL文件中索引和提取函数、节、段落和过程与COBOL代码库进行交互。
特性
- 工作区索引:自动扫描工作区中的COBOL文件(.cob、.COBOL、.cbl)
- 函数提取:解析和提取COBOL函数、部分、段落和过程
- 智能搜索:按名称模式搜索函数,支持通配符和正则表达式
- 代码检索:提取包含行号和上下文的完整函数代码
- 多种方言:支持各种COBOL方言(COBOL-85、企业COBOL等)
需求
- Node.js 18或更新版本
- VS Code、Cursor、Windsurf、Claude Desktop、Goose或任何其他MCP客户端
安装
npm install @cobol/mcp用法
作为MCP服务器
添加到MCP客户端配置中:
{
"mcpServers": {
"cobol": {
"command": "npx",
"args": ["@cobol/mcp"]
}
}
}通过配置
{
"mcpServers": {
"cobol": {
"command": "npx",
"args": ["@cobol/mcp", "--config", "cobol-config.json"]
}
}
}命令行选项
npx @cobol/mcp [options]
Options:
--config
Path to configuration file
--root
Root path to scan for COBOL files (default: current directory)
--port Port for HTTP transport (default: stdio)
--debug Enable debug logging
--help, -h Show help message配置
创建一个 cobol-config.json 文件:
{
"workspace": {
"rootPaths": ["./src", "./legacy"],
"includePatterns": ["**/*.cob", "**/*.cobol", "**/*.cbl"],
"excludePatterns": ["**/backup/**", "**/temp/**"],
"maxFileSize": 10485760
},
"parser": {
"dialect": "cobol-85",
"extractComments": true,
"columnFormat": "fixed"
},
"functions": {
"extractTypes": ["section", "paragraph", "procedure", "program"],
"includeLineNumbers": true,
"includeContext": true,
"minimumLines": 1
},
"indexing": {
"autoIndex": true,
"maxFunctionsPerFile": 1000
}
}MCP工具
cobol_index_workspace
扫描工作区中的COBOL文件并构建函数索引。
参数:
rootPaths(可选):要扫描的根路径数组includePatterns(可选):要包含的文件模式excludePatterns(可选):要排除的文件模式
cobol_list_函数
列出所有带有可选筛选的索引COBOL函数。
参数:
type(可选):按函数类型(节、段、过程、程序)过滤division(可选):按部门筛选(标识、环境、数据、程序)filePath(可选):按文件路径筛选
cobol_get函数
按名称提取完整的功能代码。
参数:
name(必填):要提取的函数名称includeLineNumbers(可选):在输出中包含行号includeContext(可选):包括周围环境
cobol_search_函数
按名称模式或内容搜索功能。
参数:
pattern(必填):搜索模式(支持通配符或正则表达式)regex(可选):将模式视为正则表达式caseSensitive(可选):区分大小写的搜索type(可选):按功能类型筛选
例子
基本用法
# Index current directory
npx @cobol/mcp --root .
# Index specific COBOL project
npx @cobol/mcp --root /path/to/cobol/project使用MCP客户端
连接到MCP客户端后,您可以使用以下命令:
# Index the workspace
Use tool: cobol_index_workspace with rootPaths: ["/path/to/cobol/files"]
# List all functions
Use tool: cobol_list_functions
# Get specific function
Use tool: cobol_get_function with name: "CALCULATE-PAYROLL"
# Search functions
Use tool: cobol_search_functions with pattern: "*CALC*"支持的COBOL构造
- 程序:PROGRAM-ID声明
- 章节:程序部分中的指定部分
- 段落:程序部分中的指定段落
- 程序:一般程序构造
文件格式
- 固定格式(传统的72列COBOL)
- 自由格式(现代COBOL)
- 自动检测格式
日志记录和调试
COBOL MCP服务器包括全面的日志记录和调试功能。使用环境变量配置日志记录:
环境变量
COBOL_LOG_LEVEL:设置日志记录级别(错误、警告、信息、调试、跟踪)COBOL_DEBUG=true:启用调试模式COBOL_VERBOSE=true:启用详细上下文的详细模式NO_COLOR=true:禁用彩色输出
例子
# Enable debug logging
COBOL_DEBUG=true echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"cobol_index_workspace","arguments":{"rootPaths":["./src"]}}}' | node cli.js
# Verbose logging with timing information
COBOL_VERBOSE=true echo '...' | node cli.js
# Only show errors
COBOL_LOG_LEVEL=error echo '...' | node cli.js有关详细的日志记录文档,请参阅 docs/LOGGING.md.
依赖项
- Node.js 18+
- 模型上下文协议SDK
许可证
阿帕奇-2.0
贡献
欢迎投稿!请随时提交问题和拉取请求。
发展
# Clone the repository
git clone https://github.com/microsoft/cobol-mcp.git
cd cobol-mcp
# Install dependencies
npm install
# Build the project
npm run build
# Run in development mode
npm run dev