使用说明
BannerlordSearchMcpServer
A Model Context Protocol (MCP) server that provides code search functionality for Bannerlord modding projects. This tool enables developers to search through Bannerlord source code using regular expressions and retrieve class definitions and code snippets.
Project Structure
This project follows a clean architecture pattern with the following layers:
BannerlordSearchMcpServer.sln
├── BannerlordSearch.Domain/ # Domain Layer (core business logic)
│ ├── Entities/
│ ├── ValueObjects/
│ ├── Interfaces/
│ ├── Exceptions/
│ └── DomainServices/
├── BannerlordSearch.Application/ # Application Layer (use cases)
│ ├── UseCases/
│ ├── DTOs/
│ ├── Services/
│ └── Ports/ (interfaces to infrastructure)
├── BannerlordSearch.Infrastructure/ # Infrastructure Layer (external concerns)
│ ├── FileSystem/
│ ├── Configuration/
│ ├── Caching/
│ └── Repositories/
├── BannerlordSearch.Presentation/ # Presentation Layer (delivery mechanisms)
│ ├── MCP/
│ ├── WebAPI/
│ └── CLI/
├── BannerlordSearch.Tests/ # Test projects per layer
│ ├── Domain.Tests/
│ ├── Application.Tests/
│ ├── Infrastructure.Tests/
│ └── Presentation.Tests/
└── BannerlordSearch.sln
Key Components
Domain Layer
Contains core business logic and entities that are independent of any framework or technology:
SearchResultentity- Domain interfaces for external dependencies
- Domain exceptions and validation logic
Application Layer
Contains application-specific business rules and use cases:
GetBannerlordClassUseCase- Retrieves Bannerlord class definitionsSearchBannerlordCodeUseCase- Searches Bannerlord code using regular expressions- Application services that coordinate domain objects
Infrastructure Layer
Contains implementations of interfaces defined in Domain and Application layers:
SymbolFileRepository- File system access and cachingRealFileSystem- File system abstractionBannerlordSourceFolderPathProvider- Configuration provider
Presentation Layer
Contains delivery mechanisms and user interfaces:
SymbolSearchTool- MCP tool for searching codeGetBannerlordClassTool- MCP tool for retrieving class definitions
Testing Strategy
Each layer has its own test project to ensure comprehensive coverage:
- Domain Tests (
BannerlordSearch.Domain.Tests) - Tests domain entities and logic - Application Tests (
BannerlordSearch.Application.Tests) - Tests business logic and use cases - Infrastructure Tests (
BannerlordSearch.Infrastructure.Tests) - Tests file system operations and repositories - Presentation Tests (
BannerlordSearch.Presentation.Tests) - Tests MCP tools and presentation logic
Getting Started
Prerequisites
- .NET 6.0 SDK or later
- Visual Studio 2022 or JetBrains Rider
Building the Project
dotnet build
Running Tests
To run all tests:
dotnet test
To run tests for a specific project:
dotnet test BannerlordSearch.Application.Tests
dotnet test BannerlordSearch.Infrastructure.Tests
dotnet test BannerlordSearch.Presentation.Tests
dotnet test BannerlordSearchMcpServer.Tests
To run tests with coverage:
dotnet test --collect:"XPlat Code Coverage"
Usage
This project is designed to run as an MCP server. You can configure your IDE or tooling to connect to this server to leverage the Bannerlord code search functionality.
Versioning & Changelog
This project follows Semantic Versioning. The version number is derived automatically from commit history using GitVersion, based on Conventional Commits prefixes:
fix:bumps the patch versionfeat:bumps the minor versionfeat!:,fix!:, or aBREAKING CHANGEfooter bumps the major version
On every push to main, the CI pipeline determines the next version, publishes the NuGet package, updates CHANGELOG.md (generated with git-cliff from the commit history, grouped by commit type), tags the release, and publishes a GitHub Release with the generated notes.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Thanks to the Bannerlord modding community for inspiration
- Uses .NET and Model Context Protocol for robust functionality