Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"env": {
"node": true,
"es2022": true
},
"extends": [
"eslint:recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
"no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
"prefer-const": "error",
"no-var": "error",
"no-console": ["warn", { "allow": ["error", "warn"] }],
"eqeqeq": ["error", "always"],
"curly": ["error", "all"]
},
"overrides": [
{
"files": ["tests/**/*.ts", "**/*.test.ts", "**/*.spec.ts"],
"env": {
"jest": true
},
"rules": {
"no-console": "off"
}
}
]
}
120 changes: 120 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: CI

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run linting
run: npm run lint

- name: Check formatting
run: npm run format:check

- name: Run tests
run: npm run test:coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage/lcov.info
fail_ci_if_error: false

- name: Build project
run: npm run build

- name: Test build artifact
run: |
chmod +x build/index.js
node build/index.js --help || echo "Expected help output or error"

security:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run security audit
run: npm audit --audit-level moderate

- name: Check for known vulnerabilities
run: npx audit-ci --moderate

type-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Type check
run: npx tsc --noEmit

integration-test:
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build project
run: npm run build

- name: Test MCP server integration
run: |
# Test that the server can start and respond to basic requests
timeout 10s node build/index.js < /dev/null || exit_code=$?
if [ ${exit_code:-0} -eq 124 ]; then
echo "Server started and ran for 10 seconds - likely working correctly"
exit 0
else
echo "Server exited with code: ${exit_code:-0}"
exit 1
fi
28 changes: 28 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"printWidth": 100,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "avoid",
"endOfLine": "lf",
"quoteProps": "as-needed",
"bracketSameLine": false,
"overrides": [
{
"files": "*.json",
"options": {
"singleQuote": false
}
},
{
"files": "*.md",
"options": {
"printWidth": 80,
"proseWrap": "always"
}
}
]
}
116 changes: 116 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.0] - 2024-08-30

### Added

#### Build System Features
- **New Tools**: Added `generate_build_zig`, `analyze_build_zig`, and `generate_build_zon` tools
- **Build System Resources**: Added comprehensive Zig build system documentation resources
- **Best Practices Guide**: Comprehensive guide to modern Zig build patterns and cross-compilation
- **Troubleshooting Guide**: Common build issues and their solutions
- **Example Configurations**: Sample build.zig files for different project types

#### Code Quality Improvements
- **Modern TypeScript Patterns**: Refactored codebase to use modern TypeScript idioms
- **Modular Architecture**: Split code into logical modules (types, utils, zig-build)
- **Comprehensive Type System**: Added proper TypeScript interfaces and types
- **Enhanced Error Handling**: Improved error handling with proper logging
- **Code Organization**: Better separation of concerns and cleaner architecture

#### Testing Infrastructure
- **Jest Testing Framework**: Comprehensive test suite with 70%+ coverage requirements
- **Unit Tests**: Extensive unit tests for all major functionality
- **Integration Tests**: Tests for MCP server functionality
- **Test Coverage**: Coverage reporting and thresholds
- **Mock Support**: Proper mocking for external dependencies

#### Development Tooling
- **ESLint Configuration**: Strict linting rules for code quality
- **Prettier Configuration**: Consistent code formatting
- **GitHub Actions CI**: Automated testing, linting, and security checks
- **Pre-commit Hooks**: Quality checks before commits
- **Development Scripts**: Enhanced npm scripts for development workflow

#### Enhanced Zig Knowledge
- **Modern Build API**: Support for Zig 0.11+ build API patterns
- **Dependency Management**: build.zig.zon generation and management
- **Cross-compilation**: Comprehensive cross-compilation examples and patterns
- **Build Optimization**: Modern optimization strategies and patterns
- **Popular Dependencies**: Curated list of popular Zig packages

### Enhanced

#### Existing Tools
- **Code Optimization**: Enhanced with modern Zig patterns and better analysis
- **Compute Units Estimation**: More detailed analysis with modern patterns
- **Code Generation**: Improved with modern Zig idioms and better structure
- **Recommendations**: Enhanced with comprehensive analysis and modern best practices

#### Documentation
- **Resource Expansion**: Added MIME types and better resource organization
- **Enhanced README**: More comprehensive examples and usage instructions
- **Inline Documentation**: Better code comments and documentation
- **API Documentation**: Clearer tool and resource descriptions

#### Error Handling
- **Structured Logging**: Proper logging with different levels
- **Better Error Messages**: More descriptive error messages and context
- **Graceful Shutdown**: Proper signal handling for clean shutdown
- **Timeout Handling**: Better timeout handling for external requests

### Changed

- **Version**: Bumped to 0.2.0 to reflect major enhancements
- **Dependencies**: Pinned axios version for reproducible builds
- **Build Output**: Enhanced build process with better error handling
- **Code Structure**: Reorganized codebase for better maintainability

### Deprecated

- **Legacy Patterns**: Identified and documented deprecated Zig build patterns
- **Old Analysis Methods**: Replaced with more sophisticated utility classes

### Security

- **Dependency Auditing**: Added npm audit checks in CI
- **Security Headers**: Better HTTP request headers
- **Input Validation**: Enhanced parameter validation

## [0.1.0] - 2024-08-29

### Added
- Initial MCP server implementation
- Basic Zig code optimization tool
- Compute units estimation
- Code generation from natural language
- Code recommendations system
- Resource access for Zig documentation
- Popular repositories fetching

### Features
- TypeScript implementation with Node.js
- MCP (Model Context Protocol) integration
- Axios for HTTP requests
- Basic build system

---

## Development Guidelines

### Version Numbering
- **Major** (X.0.0): Breaking changes or major feature additions
- **Minor** (0.X.0): New features, enhancements, backward compatible
- **Patch** (0.0.X): Bug fixes, security patches, minor improvements

### Release Process
1. Update version in package.json
2. Update CHANGELOG.md with new changes
3. Run full test suite and ensure CI passes
4. Create git tag with version number
5. Push changes and tag to repository
44 changes: 38 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
# Zig MCP Server
[![smithery badge](https://smithery.ai/badge/zig-mcp-server)](https://smithery.ai/server/zig-mcp-server)

A Model Context Protocol (MCP) server that provides Zig language tooling, code analysis, and documentation access. This server enhances AI capabilities with Zig-specific functionality including code optimization, compute unit estimation, code generation, and best practices recommendations.
**Modern Zig AI 10x dev assistant with comprehensive build system support**

A powerful Model Context Protocol (MCP) server that provides comprehensive Zig language assistance, including modern build system support, code optimization, and best practices guidance.

<a href="https://glama.ai/mcp/servers/oxiw2bsb15"><img width="380" height="200" src="https://glama.ai/mcp/servers/oxiw2bsb15/badge" alt="Zig Server MCP server" /></a>

## πŸš€ What's New in v0.2.0

- **πŸ—οΈ Modern Build System Support**: Generate and analyze build.zig files with Zig 0.12+ patterns
- **πŸ“¦ Dependency Management**: Create build.zig.zon files for modern package management
- **πŸ”§ Enhanced Code Analysis**: Improved optimization suggestions and pattern detection
- **πŸ§ͺ Comprehensive Testing**: 85+ test cases with full coverage reporting
- **⚑ Better Performance**: Modular architecture with improved error handling
- **πŸ“š Extended Documentation**: Build system troubleshooting and best practices guides

## πŸ› οΈ Features

### πŸ—οΈ Build System Tools (NEW!)

#### 1. Build System Generation (`generate_build_zig`)
Generate modern build.zig files with Zig 0.12+ patterns:
- Cross-compilation support
- Modern dependency management
- Test and documentation integration

#### 2. Build System Analysis (`analyze_build_zig`)
Analyze existing build files and get modernization recommendations:
- Detect deprecated patterns
- Suggest Zig 0.12+ alternatives
- Identify missing best practices

#### 3. Dependency Management (`generate_build_zon`)
Generate build.zig.zon files for modern package management:
- Popular Zig packages catalog
- Version management guidance
- Best practices documentation

## Features

### Tools

#### 1. Code Optimization (`optimize_code`)
Analyzes and optimizes Zig code with support for different optimization levels:
- Debug
- ReleaseSafe
- ReleaseFast
- ReleaseSmall
Enhanced with modern Zig patterns and build mode analysis:
- Debug, ReleaseSafe, ReleaseFast, ReleaseSmall
- Modern optimization suggestions
- Zig 0.12+ pattern recommendations

```typescript
// Example usage
Expand Down
23 changes: 23 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/tests'],
testMatch: [
'**/__tests__/**/*.(ts|js)',
'**/*.(test|spec).(ts|js)'
],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts'
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov'],
verbose: true,
testTimeout: 10000,
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
transform: {
'^.+\\.(ts|tsx)$': ['ts-jest', {
tsconfig: 'tests/tsconfig.json'
}],
}
};
Loading
Loading