|
1 | | -# Model Context Protocol Server |
| 1 | +# Model Context Protocol Code Analysis Server |
2 | 2 |
|
3 | | -A Kotlin server application that analyzes GitHub repositories to understand code structure and provide insights using AI |
4 | | -models. |
| 3 | +A Kotlin server application that analyzes GitHub repositories using AI models through the Model Context Protocol (MCP). |
5 | 4 |
|
6 | 5 | ## Features |
7 | 6 |
|
8 | 7 | - Clone and analyze GitHub repositories |
9 | 8 | - Extract code structure and relationships |
10 | | -- Process code using context-aware models |
| 9 | +- Process code using Model Context Protocol |
11 | 10 | - Generate detailed insights and summaries |
12 | | -- RESTful API for repository analysis |
| 11 | +- Functional architecture with immutable data classes |
| 12 | +- Multiple server modes (stdio, SSE) |
13 | 13 |
|
14 | 14 | ## Getting Started |
15 | 15 |
|
16 | 16 | ### Prerequisites |
17 | 17 |
|
18 | | -- JDK 11 or higher |
| 18 | +- JDK 23 or higher |
19 | 19 | - Kotlin 1.9.x |
20 | | -- An API key for the model service (optional) |
21 | 20 |
|
22 | 21 | ### Installation |
23 | 22 |
|
24 | 23 | 1. Clone this repository |
25 | 24 | 2. Build the project using Gradle: |
26 | | - ``` |
| 25 | + |
| 26 | + ```bash |
27 | 27 | ./gradlew build |
28 | 28 | ``` |
29 | 29 |
|
30 | 30 | ### Configuration |
31 | 31 |
|
32 | 32 | The application uses environment variables for configuration: |
33 | 33 |
|
34 | | -- `SERVER_PORT`: The port for the server (default: 8080) |
| 34 | +- `SERVER_PORT`: The port for the server (default: 3001) |
35 | 35 | - `GITHUB_TOKEN`: GitHub token for API access (optional) |
36 | | -- `WORKING_DIRECTORY`: Directory for cloning repositories (default: "temp") |
37 | | -- `MODEL_API_URL`: URL for the model API (default: "http://localhost:11434/v1") |
| 36 | +- `WORKING_DIRECTORY`: Directory for cloning repositories (default: system temp + "/mcp-code-analysis") |
| 37 | +- `MODEL_API_URL`: URL for the model API (default: "http://localhost:11434/api") |
38 | 38 | - `MODEL_API_KEY`: API key for the model service (optional) |
| 39 | +- `MODEL_NAME`: Name of the model to use (default: "llama3.2") |
39 | 40 |
|
40 | 41 | ### Running the Application |
41 | 42 |
|
42 | | -``` |
43 | | -./gradlew run |
44 | | -``` |
45 | | - |
46 | | -Or with custom configuration: |
47 | | - |
48 | | -``` |
49 | | -SERVER_PORT=9090 MODEL_API_URL=https://your-model-api.com/v1 ./gradlew run |
50 | | -``` |
| 43 | +The server supports multiple modes: |
51 | 44 |
|
52 | | -## API Usage |
| 45 | +```bash |
| 46 | +# Default: Run as SSE server with Ktor plugin on port 3001 |
| 47 | +./gradlew run |
53 | 48 |
|
54 | | -### Analyze a Repository |
| 49 | +# Run with standard input/output |
| 50 | +./gradlew run --args="--stdio" |
55 | 51 |
|
56 | | -``` |
57 | | -POST /analyze |
58 | | -``` |
| 52 | +# Run as SSE server with Ktor plugin on custom port |
| 53 | +./gradlew run --args="--sse-server-ktor 3002" |
59 | 54 |
|
60 | | -Request body: |
| 55 | +# Run as SSE server with plain configuration |
| 56 | +./gradlew run --args="--sse-server 3002" |
61 | 57 |
|
62 | | -```json |
63 | | -{ |
64 | | - "repoUrl": "https://github.com/username/repository", |
65 | | - "branch": "main", |
66 | | - "analysisType": "full" |
67 | | -} |
| 58 | +# With custom environment variables: |
| 59 | +SERVER_PORT=3002 MODEL_NAME=mistral ./gradlew run |
68 | 60 | ``` |
69 | 61 |
|
70 | | -Analysis types: |
| 62 | +## Model Context Protocol |
71 | 63 |
|
72 | | -- `full`: Analyze all code files |
73 | | -- `core`: Focus on core components only |
74 | | -- `basic`: Analyze only key files |
| 64 | +This server implements the Model Context Protocol (MCP) and provides the following tool: |
75 | 65 |
|
76 | | -Response: |
| 66 | +- `analyze-repository` Analyzes GitHub repositories to provide code insights and structure summary. |
77 | 67 |
|
78 | | -```json |
79 | | -{ |
80 | | - "id": "12345-uuid", |
81 | | - "status": "pending" |
82 | | -} |
83 | | -``` |
| 68 | +Required parameters: |
84 | 69 |
|
85 | | -### Check Analysis Status |
| 70 | +- repoUrl: GitHub repository URL (e.g., https://github.com/owner/repo) |
86 | 71 |
|
87 | | -``` |
88 | | -GET /status/{id} |
89 | | -``` |
| 72 | +Optional parameters: |
90 | 73 |
|
91 | | -Response: |
92 | | - |
93 | | -```json |
94 | | -{ |
95 | | - "id": "12345-uuid", |
96 | | - "status": "completed", |
97 | | - "summary": "This repository is a Kotlin web application...", |
98 | | - "codeStructure": { |
99 | | - /* Structure details */ |
100 | | - }, |
101 | | - "insights": [ |
102 | | - "The application uses MVC architecture", |
103 | | - "Authentication is implemented using JWT" |
104 | | - /* More insights */ |
105 | | - ] |
106 | | -} |
107 | | -``` |
| 74 | +- branch: Branch to analyze (default: main) |
108 | 75 |
|
109 | 76 | ## Project Structure |
110 | 77 |
|
111 | | -- `src/main/kotlin/Main.kt`: Application entry point |
| 78 | +- `Main.kt`: Application entry point |
112 | 79 | - `config/`: Configuration classes |
113 | | -- `routes/`: API route definitions |
| 80 | + - `AppConfig.kt`: Immutable configuration data class |
| 81 | +- `server/`: MCP server implementation |
| 82 | + - `Server.kt`: Functional MCP server with multiple run modes |
114 | 83 | - `service/`: Core services for repository analysis |
115 | | - - `GitService`: Handles repository cloning |
116 | | - - `CodeAnalyzer`: Analyzes code structure |
117 | | - - `ModelContextService`: Generates insights using AI models |
| 84 | + - `GitService.kt`: Handles repository cloning |
| 85 | + - `CodeAnalyzer.kt`: Analyzes code structure |
| 86 | + - `ModelContextService.kt`: Generates insights using AI models |
| 87 | + - `RepositoryAnalysisService.kt`: Coordinates the analysis process |
| 88 | + |
| 89 | +All services are implemented as functional data classes with explicit dependency injection. |
118 | 90 |
|
119 | 91 | ## License |
120 | 92 |
|
121 | | -This project is open source and available under the MIT License. |
| 93 | +This project is open source and available under the MIT License. |
0 commit comments