cbl-mcp-server
A COBOL-based MCP server that provides 7.5% sales tax calculations, demonstrating COBOL integration with modern API services.
README
COBOL MCP Server
A Model Context Protocol (MCP) server implementation written in COBOL. This server provides tools for tax calculations and demonstrates how COBOL can be used to build modern API services.
Overview
This project implements an MCP server that communicates via JSON-RPC 2.0 over stdin/stdout. It provides:
- Tax Calculation Tool: Calculate 7.5% sales tax on any amount
- MCP Protocol Compliance: Supports initialize, tools/list, tools/call, and ping methods
Project Structure
cbl-mcp-server/
├── src/
│ ├── server.cbl # Main entry point and request loop
│ ├── transport.cbl # I/O handling (read request, write response)
│ ├── parser.cbl # JSON-RPC request parsing
│ ├── dispatcher.cbl # Method routing
│ ├── response-builder.cbl # JSON-RPC response builders
│ └── tax-service.cbl # Tax calculation logic
├── copybooks/
│ ├── CONSTANTS.cpy # Protocol version constant
│ ├── STATUS.cpy # Status flags (EOF, parsed)
│ ├── REQUEST.cpy # Request data structure
│ ├── RESPONSE.cpy # Response buffer structure
│ └── TOOL.cpy # Tool definitions
├── Makefile # Build configuration
├── Dockerfile # Container build
└── README.md # This file
Prerequisites
- GnuCOBOL compiler (
cobc) - Make build tool
- Docker (optional, for containerized deployment)
Installing GnuCOBOL
Ubuntu/Debian:
sudo apt-get install gnucobol make
macOS (Homebrew):
brew install gnucobol
Building
Local Build
make
This produces the mcp-server executable.
Docker Build
docker build -t cbl-mcp-server .
Running
Command Line
./mcp-server
The server reads JSON-RPC requests from stdin and writes responses to stdout.
Docker
docker run --rm -i cbl-mcp-server
Testing
Run the test suite to verify all functionality:
# Test with Docker (default)
node test.js
# Or with npm
npm test
# Test with local binary (requires GnuCOBOL installed)
USE_DOCKER=false node test.js
Test Coverage
The test suite verifies:
- ✓ Server startup
- ✓ Initialize request/response
- ✓ Tools list endpoint
- ✓ Tax calculation (multiple amounts)
- ✓ Ping endpoint
- ✓ Error handling (unknown method)
Example output:
═══════════════════════════════════════════════════════
CBL-MCP-SERVER TEST SUITE
═══════════════════════════════════════════════════════
Test 1: Server startup
✓ Server started successfully
Test 2: Initialize request
✓ Initialize response is valid
Test 3: Tools list request
✓ Tools list response is valid
Test 4-7: Tax calculations
✓ All tax calculations correct
Test 8: Ping request
✓ Ping response is valid
Test 9: Unknown method error handling
✓ Error response is valid
═══════════════════════════════════════════════════════
Total: 9 | Passed: 9 ✓ | Failed: 0 ✗
═══════════════════════════════════════════════════════
API Reference
Methods
initialize
Initialize the MCP connection.
Request:
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}
Response:
{
"jsonrpc":"2.0",
"id":1,
"result":{
"protocolVersion":"2025-06-18",
"capabilities":{"tools":{}},
"serverInfo":{"name":"cbl-mcp","version":"1.0.0"}
}
}
tools/list
List available tools.
Request:
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
Response:
{
"jsonrpc":"2.0",
"id":2,
"result":{
"tools":[{
"name":"calculate_tax",
"description":"Calculate 7.5 percent sales tax on an amount",
"inputSchema":{
"type":"object",
"properties":{
"amount":{"type":"number","description":"The pre-tax amount"}
},
"required":["amount"]
}
}]
}
}
tools/call
Execute a tool with arguments.
Request:
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"calculate_tax","arguments":{"amount":100}}}
Response:
{
"jsonrpc":"2.0",
"id":3,
"result":{
"content":[{
"type":"text",
"text":"Amount 100.00, tax 7.50, total 107.50"
}]
}
}
ping
Health check endpoint.
Request:
{"jsonrpc":"2.0","id":6,"method":"ping"}
Response:
{"jsonrpc":"2.0","id":6,"result":{}}
Example Usage
Single Request
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"calculate_tax","arguments":{"amount":500}}}' | ./mcp-server
Multiple Requests
cat << 'EOF' | ./mcp-server
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"calculate_tax","arguments":{"amount":100}}}
EOF
With Docker
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"calculate_tax","arguments":{"amount":1000}}}' | docker run --rm -i cbl-mcp-server
Using with LLMs (Claude Desktop, etc.)
This MCP server can be connected to LLM clients that support the Model Context Protocol, allowing natural language interaction.
Claude Desktop Setup
-
Build the Docker image:
docker build -t cbl-mcp-server . -
Add to Claude Desktop config:
Edit your Claude Desktop configuration file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Add the server configuration:
{ "mcpServers": { "cbl-mcp-server": { "command": "docker", "args": ["run", "--rm", "-i", "cbl-mcp-server"] } } } - macOS:
-
Restart Claude Desktop
-
Use natural language:
You: What's the sales tax on $150? Claude: I'll calculate the 7.5% sales tax for you. [Uses calculate_tax tool] The sales tax on $150 is $11.25, making the total $161.25.
Local Binary Setup
If you have GnuCOBOL installed locally:
-
Build:
make -
Configure Claude Desktop:
{ "mcpServers": { "cbl-mcp-server": { "command": "/home/srinivasan/cbl-mcp-server/mcp-server", "args": [] } } }
Example Conversations
Once connected, you can interact naturally:
Example 1 - Tax Calculation:
You: Calculate the sales tax for a $500 purchase
Claude: [Calls calculate_tax tool]
For a $500 purchase with 7.5% sales tax:
- Tax: $37.50
- Total: $537.50
Example 2 - Price Comparison:
You: Which costs more after tax: $99.99 or $100?
Claude: [Calls calculate_tax tool twice]
After 7.5% sales tax:
- $99.99 → $107.48 (tax: $7.49)
- $100.00 → $107.50 (tax: $7.50)
$100 actually costs 2 cents more after tax ($107.50 vs $107.48).
Example 3 - Budget Planning:
You: I have $200 budget. What's the maximum pre-tax price I can afford?
Claude: [Calculates reverse: 200 / 1.075 ≈ 186.05]
With 7.5% tax, $186.05 pre-tax becomes $200.00 total.
Let me verify:
- Pre-tax: $186.05
- Tax (7.5%): $13.95
- Total: $200.00
You can afford items up to $186.05 before tax.
Tax Calculation Details
- Tax Rate: 7.5%
- Precision: 2 decimal places
- Formula:
- Tax = Amount × 0.075
- Total = Amount + Tax
Examples
| Amount | Tax | Total |
|---|---|---|
| $100.00 | $7.50 | $107.50 |
| $500.00 | $37.50 | $537.50 |
| $1,000.00 | $75.00 | $1,075.00 |
| $99.99 | $7.49 | $107.48 |
| $0.01 | $0.00 | $0.01 |
Architecture
Request Flow
stdin → READ-REQUEST → PARSE-REQUEST → DISPATCH-REQUEST → BUILD-*-RESPONSE → WRITE-RESPONSE → stdout
Components
| Module | Purpose |
|---|---|
server.cbl |
Main loop, orchestrates request processing |
transport.cbl |
Low-level I/O operations (ACCEPT, DISPLAY) |
parser.cbl |
JSON parsing using UNSTRING |
dispatcher.cbl |
Method routing via EVALUATE |
response-builder.cbl |
JSON response construction via STRING |
tax-service.cbl |
Business logic for tax calculation |
Development
Clean Build
make clean && make
Compiler Flags
The Makefile uses these GnuCOBOL flags:
-free: Free-format source code-fnot-reserved=ALL: Don't reserve common words-I copybooks: Include copybook directory-x: Create executable
Adding New Tools
- Add tool schema to
BUILD-TOOLS-LIST-RESPONSEinresponse-builder.cbl - Add case handler in
dispatcher.cblEVALUATE block - Create response builder in
response-builder.cbl - Implement business logic (e.g., new service file)
License
This project is provided as-is for educational and demonstration purposes.
Contributing
Contributions are welcome! Please ensure all COBOL code follows free-format style and includes appropriate comments.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。