Skip to content

Commit 0db92d1

Browse files
Apply spotless plugin (#5)
1 parent 4adefba commit 0db92d1

38 files changed

Lines changed: 2780 additions & 2336 deletions

build.gradle.kts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.spring.dependency.management)
77
jacoco
88
alias(libs.plugins.errorprone)
9+
alias(libs.plugins.spotless)
910
}
1011

1112
group = "org.apache.solr"
@@ -77,4 +78,24 @@ tasks.withType<JavaCompile>().configureEach {
7778
option("NullAway:OnlyNullMarked", "true") // Enable nullness checks only in null-marked code
7879
error("NullAway") // bump checks from warnings (default) to errors
7980
}
80-
}
81+
}
82+
83+
tasks.build {
84+
dependsOn(tasks.spotlessApply)
85+
}
86+
87+
spotless {
88+
java {
89+
target("src/**/*.java")
90+
googleJavaFormat().aosp().reflowLongStrings()
91+
removeUnusedImports()
92+
trimTrailingWhitespace()
93+
endWithNewline()
94+
importOrder()
95+
formatAnnotations()
96+
}
97+
kotlinGradle {
98+
target("*.gradle.kts")
99+
ktlint()
100+
}
101+
}

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
spring-boot = "3.5.6"
44
spring-dependency-management = "1.1.7"
55
errorprone-plugin = "4.2.0"
6+
spotless = "7.0.2"
67

78
# Main dependencies
89
spring-ai = "1.1.0-M3"
@@ -79,4 +80,5 @@ errorprone = [
7980
[plugins]
8081
spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot" }
8182
spring-dependency-management = { id = "io.spring.dependency-management", version.ref = "spring-dependency-management" }
82-
errorprone = { id = "net.ltgt.errorprone", version.ref = "errorprone-plugin" }
83+
errorprone = { id = "net.ltgt.errorprone", version.ref = "errorprone-plugin" }
84+
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }

src/main/java/org/apache/solr/mcp/server/Main.java

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -25,57 +25,65 @@
2525

2626
/**
2727
* Main Spring Boot application class for the Apache Solr Model Context Protocol (MCP) Server.
28-
*
29-
* <p>This class serves as the entry point for the Solr MCP Server application, which provides
30-
* a bridge between AI clients (such as Claude Desktop) and Apache Solr search and indexing
31-
* capabilities through the Model Context Protocol specification.</p>
32-
*
33-
* <p><strong>Application Architecture:</strong></p>
28+
*
29+
* <p>This class serves as the entry point for the Solr MCP Server application, which provides a
30+
* bridge between AI clients (such as Claude Desktop) and Apache Solr search and indexing
31+
* capabilities through the Model Context Protocol specification.
32+
*
33+
* <p><strong>Application Architecture:</strong>
34+
*
3435
* <p>The application follows a service-oriented architecture where each major Solr operation
35-
* category is encapsulated in its own service class:</p>
36+
* category is encapsulated in its own service class:
37+
*
3638
* <ul>
37-
* <li><strong>SearchService</strong>: Search operations, faceting, sorting, pagination</li>
38-
* <li><strong>IndexingService</strong>: Document indexing, schema-less ingestion, batch processing</li>
39-
* <li><strong>CollectionService</strong>: Collection management, metrics, health monitoring</li>
40-
* <li><strong>SchemaService</strong>: Schema introspection and field management</li>
39+
* <li><strong>SearchService</strong>: Search operations, faceting, sorting, pagination
40+
* <li><strong>IndexingService</strong>: Document indexing, schema-less ingestion, batch
41+
* processing
42+
* <li><strong>CollectionService</strong>: Collection management, metrics, health monitoring
43+
* <li><strong>SchemaService</strong>: Schema introspection and field management
4144
* </ul>
42-
*
43-
* <p><strong>Spring Boot Features:</strong></p>
45+
*
46+
* <p><strong>Spring Boot Features:</strong>
47+
*
4448
* <ul>
45-
* <li><strong>Auto-Configuration</strong>: Automatic setup of Solr client and service beans</li>
46-
* <li><strong>Property Management</strong>: Externalized configuration through application.properties</li>
47-
* <li><strong>Dependency Injection</strong>: Automatic wiring of service dependencies</li>
48-
* <li><strong>Component Scanning</strong>: Automatic discovery of service classes</li>
49+
* <li><strong>Auto-Configuration</strong>: Automatic setup of Solr client and service beans
50+
* <li><strong>Property Management</strong>: Externalized configuration through
51+
* application.properties
52+
* <li><strong>Dependency Injection</strong>: Automatic wiring of service dependencies
53+
* <li><strong>Component Scanning</strong>: Automatic discovery of service classes
4954
* </ul>
50-
*
51-
* <p><strong>Communication Flow:</strong></p>
55+
*
56+
* <p><strong>Communication Flow:</strong>
57+
*
5258
* <ol>
53-
* <li>AI client connects to MCP server via stdio</li>
54-
* <li>Client discovers available tools through MCP protocol</li>
55-
* <li>Client invokes tools with natural language parameters</li>
56-
* <li>Server routes requests to appropriate service methods</li>
57-
* <li>Services interact with Solr via SolrJ client library</li>
58-
* <li>Results are serialized and returned to AI client</li>
59+
* <li>AI client connects to MCP server via stdio
60+
* <li>Client discovers available tools through MCP protocol
61+
* <li>Client invokes tools with natural language parameters
62+
* <li>Server routes requests to appropriate service methods
63+
* <li>Services interact with Solr via SolrJ client library
64+
* <li>Results are serialized and returned to AI client
5965
* </ol>
60-
*
61-
* <p><strong>Configuration Requirements:</strong></p>
62-
* <p>The application requires the following configuration properties:</p>
66+
*
67+
* <p><strong>Configuration Requirements:</strong>
68+
*
69+
* <p>The application requires the following configuration properties:
70+
*
6371
* <pre>{@code
6472
* # application.properties
6573
* solr.url=http://localhost:8983
6674
* }</pre>
67-
*
68-
* <p><strong>Deployment Considerations:</strong></p>
75+
*
76+
* <p><strong>Deployment Considerations:</strong>
77+
*
6978
* <ul>
70-
* <li>Ensure Solr server is running and accessible at configured URL</li>
71-
* <li>Verify network connectivity between MCP server and Solr</li>
72-
* <li>Configure appropriate timeouts for production workloads</li>
73-
* <li>Monitor application logs for connection and performance issues</li>
79+
* <li>Ensure Solr server is running and accessible at configured URL
80+
* <li>Verify network connectivity between MCP server and Solr
81+
* <li>Configure appropriate timeouts for production workloads
82+
* <li>Monitor application logs for connection and performance issues
7483
* </ul>
7584
*
7685
* @version 0.0.1
7786
* @since 0.0.1
78-
*
7987
* @see SearchService
8088
* @see IndexingService
8189
* @see CollectionService
@@ -87,35 +95,36 @@ public class Main {
8795

8896
/**
8997
* Main application entry point that starts the Spring Boot application.
90-
*
91-
* <p>This method initializes the Spring application context, configures all
92-
* service beans, establishes Solr connectivity, and begins listening for
93-
* MCP client connections via standard input/output.</p>
94-
*
95-
* <p><strong>Startup Process:</strong></p>
98+
*
99+
* <p>This method initializes the Spring application context, configures all service beans,
100+
* establishes Solr connectivity, and begins listening for MCP client connections via standard
101+
* input/output.
102+
*
103+
* <p><strong>Startup Process:</strong>
104+
*
96105
* <ol>
97-
* <li>Initialize Spring Boot application context</li>
98-
* <li>Load configuration properties from various sources</li>
99-
* <li>Create and configure SolrClient bean</li>
100-
* <li>Initialize all service beans with dependency injection</li>
101-
* <li>Register MCP tools from service methods</li>
102-
* <li>Start MCP server listening on stdio</li>
106+
* <li>Initialize Spring Boot application context
107+
* <li>Load configuration properties from various sources
108+
* <li>Create and configure SolrClient bean
109+
* <li>Initialize all service beans with dependency injection
110+
* <li>Register MCP tools from service methods
111+
* <li>Start MCP server listening on stdio
103112
* </ol>
104-
*
105-
* <p><strong>Error Handling:</strong></p>
106-
* <p>Startup failures typically indicate configuration issues such as:</p>
113+
*
114+
* <p><strong>Error Handling:</strong>
115+
*
116+
* <p>Startup failures typically indicate configuration issues such as:
117+
*
107118
* <ul>
108-
* <li>Missing or invalid Solr URL configuration</li>
109-
* <li>Network connectivity issues to Solr server</li>
110-
* <li>Missing required dependencies or classpath issues</li>
119+
* <li>Missing or invalid Solr URL configuration
120+
* <li>Network connectivity issues to Solr server
121+
* <li>Missing required dependencies or classpath issues
111122
* </ul>
112-
*
123+
*
113124
* @param args command-line arguments passed to the application
114-
*
115125
* @see SpringApplication#run(Class, String...)
116126
*/
117127
public static void main(String[] args) {
118128
SpringApplication.run(Main.class, args);
119129
}
120-
121-
}
130+
}

src/main/java/org/apache/solr/mcp/server/config/SolrConfig.java

Lines changed: 72 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,63 +16,67 @@
1616
*/
1717
package org.apache.solr.mcp.server.config;
1818

19+
import java.util.concurrent.TimeUnit;
1920
import org.apache.solr.client.solrj.SolrClient;
2021
import org.apache.solr.client.solrj.impl.Http2SolrClient;
2122
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2223
import org.springframework.context.annotation.Bean;
2324
import org.springframework.context.annotation.Configuration;
2425

25-
import java.util.concurrent.TimeUnit;
26-
2726
/**
2827
* Spring Configuration class for Apache Solr client setup and connection management.
29-
*
30-
* <p>This configuration class is responsible for creating and configuring the SolrJ client
31-
* that serves as the primary interface for communication with Apache Solr servers. It handles
32-
* URL normalization, connection parameters, and timeout configurations to ensure reliable
33-
* connectivity for the MCP server operations.</p>
34-
*
35-
* <p><strong>Configuration Features:</strong></p>
28+
*
29+
* <p>This configuration class is responsible for creating and configuring the SolrJ client that
30+
* serves as the primary interface for communication with Apache Solr servers. It handles URL
31+
* normalization, connection parameters, and timeout configurations to ensure reliable connectivity
32+
* for the MCP server operations.
33+
*
34+
* <p><strong>Configuration Features:</strong>
35+
*
3636
* <ul>
37-
* <li><strong>Automatic URL Normalization</strong>: Ensures proper Solr URL formatting</li>
38-
* <li><strong>Connection Timeout Management</strong>: Configurable timeouts for reliability</li>
39-
* <li><strong>Property Integration</strong>: Uses externalized configuration through properties</li>
40-
* <li><strong>Production-Ready Defaults</strong>: Optimized timeout values for production use</li>
37+
* <li><strong>Automatic URL Normalization</strong>: Ensures proper Solr URL formatting
38+
* <li><strong>Connection Timeout Management</strong>: Configurable timeouts for reliability
39+
* <li><strong>Property Integration</strong>: Uses externalized configuration through properties
40+
* <li><strong>Production-Ready Defaults</strong>: Optimized timeout values for production use
4141
* </ul>
42-
*
43-
* <p><strong>URL Processing:</strong></p>
44-
* <p>The configuration automatically normalizes Solr URLs to ensure proper communication:</p>
42+
*
43+
* <p><strong>URL Processing:</strong>
44+
*
45+
* <p>The configuration automatically normalizes Solr URLs to ensure proper communication:
46+
*
4547
* <ul>
46-
* <li>Adds trailing slashes if missing</li>
47-
* <li>Appends "/solr/" path if not present in the URL</li>
48-
* <li>Handles various URL formats (with/without protocols, paths, etc.)</li>
48+
* <li>Adds trailing slashes if missing
49+
* <li>Appends "/solr/" path if not present in the URL
50+
* <li>Handles various URL formats (with/without protocols, paths, etc.)
4951
* </ul>
50-
*
51-
* <p><strong>Connection Parameters:</strong></p>
52+
*
53+
* <p><strong>Connection Parameters:</strong>
54+
*
5255
* <ul>
53-
* <li><strong>Connection Timeout</strong>: 10 seconds (10,000ms) for establishing connections</li>
54-
* <li><strong>Socket Timeout</strong>: 60 seconds (60,000ms) for read operations</li>
56+
* <li><strong>Connection Timeout</strong>: 10 seconds (10,000ms) for establishing connections
57+
* <li><strong>Socket Timeout</strong>: 60 seconds (60,000ms) for read operations
5558
* </ul>
56-
*
57-
* <p><strong>Configuration Example:</strong></p>
59+
*
60+
* <p><strong>Configuration Example:</strong>
61+
*
5862
* <pre>{@code
5963
* # application.properties
6064
* solr.url=http://localhost:8983
61-
*
65+
*
6266
* # Results in normalized URL: http://localhost:8983/solr/
6367
* }</pre>
64-
*
65-
* <p><strong>Supported URL Formats:</strong></p>
68+
*
69+
* <p><strong>Supported URL Formats:</strong>
70+
*
6671
* <ul>
67-
* <li>{@code http://localhost:8983} → {@code http://localhost:8983/solr/}</li>
68-
* <li>{@code http://localhost:8983/} → {@code http://localhost:8983/solr/}</li>
69-
* <li>{@code http://localhost:8983/solr} → {@code http://localhost:8983/solr/}</li>
70-
* <li>{@code http://localhost:8983/solr/} → {@code http://localhost:8983/solr/} (unchanged)</li>
72+
* <li>{@code http://localhost:8983} → {@code http://localhost:8983/solr/}
73+
* <li>{@code http://localhost:8983/} → {@code http://localhost:8983/solr/}
74+
* <li>{@code http://localhost:8983/solr} → {@code http://localhost:8983/solr/}
75+
* <li>{@code http://localhost:8983/solr/} → {@code http://localhost:8983/solr/} (unchanged)
7176
* </ul>
7277
*
7378
* @version 0.0.1
7479
* @since 0.0.1
75-
*
7680
* @see SolrConfigurationProperties
7781
* @see Http2SolrClient
7882
* @see org.springframework.boot.context.properties.EnableConfigurationProperties
@@ -87,44 +91,48 @@ public class SolrConfig {
8791

8892
/**
8993
* Creates and configures a SolrClient bean for Apache Solr communication.
90-
*
91-
* <p>This method serves as the primary factory for creating SolrJ client instances
92-
* that are used throughout the application for all Solr operations. It performs
93-
* automatic URL normalization and applies production-ready timeout configurations.</p>
94-
*
95-
* <p><strong>URL Normalization Process:</strong></p>
94+
*
95+
* <p>This method serves as the primary factory for creating SolrJ client instances that are
96+
* used throughout the application for all Solr operations. It performs automatic URL
97+
* normalization and applies production-ready timeout configurations.
98+
*
99+
* <p><strong>URL Normalization Process:</strong>
100+
*
96101
* <ol>
97-
* <li><strong>Trailing Slash</strong>: Ensures URL ends with "/"</li>
98-
* <li><strong>Solr Path</strong>: Appends "/solr/" if not already present</li>
99-
* <li><strong>Validation</strong>: Checks for proper Solr endpoint format</li>
102+
* <li><strong>Trailing Slash</strong>: Ensures URL ends with "/"
103+
* <li><strong>Solr Path</strong>: Appends "/solr/" if not already present
104+
* <li><strong>Validation</strong>: Checks for proper Solr endpoint format
100105
* </ol>
101-
*
102-
* <p><strong>Connection Configuration:</strong></p>
106+
*
107+
* <p><strong>Connection Configuration:</strong>
108+
*
103109
* <ul>
104-
* <li><strong>Connection Timeout</strong>: 10,000ms - Time to establish initial connection</li>
105-
* <li><strong>Socket Timeout</strong>: 60,000ms - Time to wait for data/response</li>
110+
* <li><strong>Connection Timeout</strong>: 10,000ms - Time to establish initial connection
111+
* <li><strong>Socket Timeout</strong>: 60,000ms - Time to wait for data/response
106112
* </ul>
107-
*
108-
* <p><strong>Client Type:</strong></p>
109-
* <p>Creates an {@code HttpSolrClient} configured for standard HTTP-based communication
110-
* with Solr servers. This client type is suitable for both standalone Solr instances
111-
* and SolrCloud deployments when used with load balancers.</p>
112-
*
113-
* <p><strong>Error Handling:</strong></p>
114-
* <p>URL normalization is defensive and handles various input formats gracefully.
115-
* Invalid URLs or connection failures will be caught during application startup
116-
* or first usage, providing clear error messages for troubleshooting.</p>
117-
*
118-
* <p><strong>Production Considerations:</strong></p>
113+
*
114+
* <p><strong>Client Type:</strong>
115+
*
116+
* <p>Creates an {@code HttpSolrClient} configured for standard HTTP-based communication with
117+
* Solr servers. This client type is suitable for both standalone Solr instances and SolrCloud
118+
* deployments when used with load balancers.
119+
*
120+
* <p><strong>Error Handling:</strong>
121+
*
122+
* <p>URL normalization is defensive and handles various input formats gracefully. Invalid URLs
123+
* or connection failures will be caught during application startup or first usage, providing
124+
* clear error messages for troubleshooting.
125+
*
126+
* <p><strong>Production Considerations:</strong>
127+
*
119128
* <ul>
120-
* <li>Timeout values are optimized for production workloads</li>
121-
* <li>Connection pooling is handled by the HttpSolrClient internally</li>
122-
* <li>Client is thread-safe and suitable for concurrent operations</li>
129+
* <li>Timeout values are optimized for production workloads
130+
* <li>Connection pooling is handled by the HttpSolrClient internally
131+
* <li>Client is thread-safe and suitable for concurrent operations
123132
* </ul>
124-
*
133+
*
125134
* @param properties the injected Solr configuration properties containing connection URL
126135
* @return configured SolrClient instance ready for use in application services
127-
*
128136
* @see Http2SolrClient.Builder
129137
* @see SolrConfigurationProperties#url()
130138
*/
@@ -153,4 +161,4 @@ SolrClient solrClient(SolrConfigurationProperties properties) {
153161
.withIdleTimeout(SOCKET_TIMEOUT_MS, TimeUnit.MILLISECONDS)
154162
.build();
155163
}
156-
}
164+
}

0 commit comments

Comments
 (0)