
go mcp lsp
基于 AST 深度分析的 Golang 元配置协议 (MCP) 语言服务器,用于代码规范强制执行。
Repository Info
About This Server
基于 AST 深度分析的 Golang 元配置协议 (MCP) 语言服务器,用于代码规范强制执行。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
Go-MCP-LSP: Golang Meta-Configuration Protocol Language Server
A Golang implementation of the Meta-Configuration Protocol (MCP) for language server integration and code governance enforcement through AST-based deep analysis.
Overview
This project implements a governance system for Go code that leverages deep Abstract Syntax Tree (AST) analysis to enforce organizational coding standards. It provides both a JSON-RPC server exposing governance rules and client libraries for validation.
graph TD
A[Go Source Code] -->|Submitted for validation| B[MCP Server]
B -->|AST Analysis| C[Analyzer Engine]
C -->|Detects Issues| D[Validation Results]
D -->|Returns to| E[Developer/CI]
F[Governance Rules] -->|Loaded by| B
Key Features
- Deep AST-based Code Analysis: Beyond simple pattern matching, understands code structure
- Multiple Rule Categories: Enforces standards for error handling, API design, concurrency, security, and organization standards
- Precise Issue Reporting: Provides exact file location (line, column) for detected issues
- Flexible Validation: Supports both CLI-based and server-based validation workflows
- Modular Architecture: Easily extend with new rule categories
Components
- MCP Server: JSON-RPC server that exposes governance rules
- Client Library: Go client for communicating with the MCP server
- AST Analyzer: Deep code inspection based on Go's AST package
- CLI Tools: Command-line interface for validation and testing
- Test Suite: Comprehensive test cases for each rule category
Rule Categories
- Error Handling: Enforces proper error checking and handling
- API Design: Validates API contracts, context usage, and parameter patterns
- Concurrency: Detects race conditions and ensures proper synchronization
- Security: Identifies weak cryptography, SQL injection risks, and credentials handling
- Organizational Standards: Enforces coding style and architectural patterns
Usage
CLI Validation
# Standard pattern-based validation
go run cmd/mcplsp/main.go validate path/to/file.go error_handling,api_design
# Deep AST-based analysis
go run cmd/mcplsp/main.go -deep validate path/to/file.go error_handling,api_design
Direct AST Analysis
go run cmd/ast-analyzer/main.go analyze --file path/to/file.go --rules error_handling
Testing
# Test all rule categories
./scripts/test-governance.sh
# Compare standard vs. deep validation
./scripts/compare-validation.sh
Project Structure
go-mcp-lsp/
├── cmd/
│ ├── mcplsp/ # CLI tool for MCP validation
│ └── ast-analyzer/ # CLI for AST-based code analysis
├── pkg/
│ ├── analyzer/ # Deep AST analysis engine
│ │ └── ast/ # AST-based code inspection
│ └── mcpclient/ # MCP client for JSON-RPC communication
├── server/
│ └── mcpserver/ # MCP server exposing governance rules
│ └── rules/ # Rule definitions by category
├── testdata/ # Test files for all rule categories
└── scripts/ # Test and validation scripts
Development
Prerequisites
- Go 1.19 or higher
- Understanding of Go's AST package for rule development
Setup
# Clone the repository
git clone https://github.com/yourorg/go-mcp-lsp
cd go-mcp-lsp
# Build the CLI tools
go build -o bin/mcplsp cmd/mcplsp/main.go
go build -o bin/ast-analyzer cmd/ast-analyzer/main.go
# Run tests
go test ./...
Adding New Rules
- Define the rule in the appropriate category under
server/mcpserver/rules/ - Implement AST-based detection in
pkg/analyzer/ast/analyzer.go - Add test cases in
testdata/ - Update the CLI to expose the new rule category
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Quick Start
Clone the repository
git clone https://github.com/copyleftdev/go-mcp-lspInstall dependencies
cd go-mcp-lsp
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.