Skip to content

Commit 7aad4f7

Browse files
Merge pull request #28 from Youssef-Erradi/code-clean-up
Remove unused code and add missing JavaDoc
2 parents ff326e4 + f3590e9 commit 7aad4f7

File tree

6 files changed

+153
-73
lines changed

6 files changed

+153
-73
lines changed

src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/OracleDatabaseMCPToolkit.java

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public class OracleDatabaseMCPToolkit {
5959
public static void main(String[] args) {
6060
installExternalExtensionsFromDir();
6161

62-
McpSyncServer server;
63-
6462
switch (LoadedConstants.TRANSPORT_KIND) {
6563
case "http" -> {
6664
serverInstance = startHttpServer();
@@ -81,15 +79,7 @@ public static void main(String[] args) {
8179
}
8280
Utils.addSyncToolSpecifications(serverInstance, config);
8381

84-
// if (LoadedConstants.CONFIG_FILE != null) {
85-
// Thread watcher = new Thread(() -> {
86-
// watchConfigFile(LoadedConstants.CONFIG_FILE);
87-
// }, "config-file-watcher");
88-
// watcher.setDaemon(true);
89-
// watcher.start();
90-
// }
91-
92-
Thread pollingThread = new Thread(() -> pollConfigFile(LoadedConstants.CONFIG_FILE), "config-file-poller");
82+
Thread pollingThread = new Thread(() -> pollConfigFile(), "config-file-poller");
9383
pollingThread.setDaemon(true);
9484
pollingThread.start();
9585
}
@@ -151,7 +141,7 @@ private static McpSyncServer startHttpServer() {
151141
if (LoadedConstants.HTTPS_PORT == null || LoadedConstants.KEYSTORE_PATH == null || LoadedConstants.KEYSTORE_PASSWORD == null)
152142
throw new RuntimeException("SSL setup failed: HTTPS port, Keystore path or password not specified");
153143

154-
enableHttps(tomcat, LoadedConstants.KEYSTORE_PATH, LoadedConstants.KEYSTORE_PASSWORD);
144+
enableHttps(tomcat);
155145

156146
tomcat.start();
157147

@@ -166,11 +156,9 @@ private static McpSyncServer startHttpServer() {
166156
* Configures and enables HTTPS on the provided Tomcat server using the specified keystore.
167157
*
168158
* @param tomcat the Tomcat server instance to configure
169-
* @param keystorePath the file path to the PKCS12 keystore containing the SSL certificate
170-
* @param keystorePassword the password for the keystore
171159
* @throws RuntimeException if the HTTPS connector or SSL configuration fails
172160
*/
173-
private static void enableHttps(Tomcat tomcat, String keystorePath, String keystorePassword) {
161+
private static void enableHttps(Tomcat tomcat) {
174162
try {
175163
// Create HTTPS connector
176164
Connector https = new Connector("org.apache.coyote.http11.Http11NioProtocol");
@@ -188,8 +176,8 @@ private static void enableHttps(Tomcat tomcat, String keystorePath, String keyst
188176
SSLHostConfigCertificate.Type.RSA
189177
);
190178

191-
cert.setCertificateKeystoreFile(keystorePath);
192-
cert.setCertificateKeystorePassword(keystorePassword);
179+
cert.setCertificateKeystoreFile(LoadedConstants.KEYSTORE_PATH);
180+
cert.setCertificateKeystorePassword(LoadedConstants.KEYSTORE_PASSWORD);
193181
cert.setCertificateKeystoreType("PKCS12");
194182

195183
// Attach certificate to SSL config
@@ -217,32 +205,6 @@ public static McpSyncServer getServer() {
217205
return serverInstance;
218206
}
219207

220-
221-
private static void watchConfigFile(String filePath) {
222-
Path configPath = Paths.get(filePath);
223-
try (WatchService watcher = FileSystems.getDefault().newWatchService()) {
224-
Path dir = configPath.getParent();
225-
if (dir == null) dir = Paths.get(".");
226-
dir.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
227-
228-
while (true) {
229-
WatchKey key = watcher.take(); // block until events
230-
for (WatchEvent<?> event : key.pollEvents()) {
231-
Path changed = ((WatchEvent<Path>)event).context();
232-
LOG.info(()->"[DEBUG] Watch event: " + event.kind() + ", file: " + changed);
233-
LOG.info(()->"[DEBUG] Looking for file: " + configPath.getFileName());
234-
if (changed.endsWith(configPath.getFileName())) {
235-
LOG.info(()->"[DEBUG] Detected relevant config file event: " + event.kind());
236-
reloadConfigAndResetTools();
237-
}
238-
}
239-
key.reset();
240-
}
241-
} catch (Exception e) {
242-
System.err.println("[oracle-db-mcp-toolkit] Config file watcher failed: " + e);
243-
}
244-
}
245-
246208
private static void reloadConfigAndResetTools() {
247209
try {
248210
LOG.info(()->"[DEBUG] Reloading config...");
@@ -257,9 +219,9 @@ private static void reloadConfigAndResetTools() {
257219
}
258220
}
259221

260-
// For now, we rely on this instead of the nio watcher logic (for container sake)
261-
private static void pollConfigFile(String filePath) {
262-
File configFile = new File(filePath);
222+
// For now, we rely on this instead of the nio watcher logic (for container’s sake)
223+
private static void pollConfigFile() {
224+
File configFile = new File(LoadedConstants.CONFIG_FILE);
263225
long lastModified = configFile.lastModified();
264226
while (true) {
265227
long nowModified = configFile.lastModified();

src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/config/ConfigRoot.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ public class ConfigRoot {
1919
/**
2020
* Optional named toolsets allowing users to group custom tools and enable them with -Dtools.
2121
* Example YAML:
22+
* <pre>
2223
* toolsets:
2324
* reporting: [top_customers, sales_by_region]
25+
* </pre>
2426
*/
2527
public Map<String, List<String>> toolsets;
2628

src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/config/ToolConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ public void substituteEnvVars() {
6161
}
6262
}
6363

64+
/**
65+
* Builds a JSON representation of the input schema for this tool configuration.
66+
* <p>
67+
* The input schema is constructed based on the tool's parameter configurations.
68+
* Each parameter is represented as a property in the schema, with its type and description.
69+
* Required parameters are listed in the "required" section of the schema.
70+
* <p>
71+
* The resulting JSON string can be used to validate input data for the tool.
72+
*
73+
* @return a JSON string representing the input schema for this tool configuration
74+
*/
6475
public String buildInputSchemaJson() {
6576
ObjectNode schema = JsonNodeFactory.instance.objectNode();
6677
schema.put("type", "object");

src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/tools/DatabaseOperatorTools.java

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,24 @@
2121
import static com.oracle.database.mcptoolkit.Utils.*;
2222

2323
/**
24-
* Database operator tools:
25-
* - read-query: execute SELECT queries and return JSON results
26-
* - write-query: execute DML/DDL statements
27-
* - create-table: create table.
28-
* - delete-table: drop table by name
29-
* - list-tables: list all tables and synonyms in the current schema
30-
* - describe-table: get column details for a specific table
31-
* - start-transaction: begin a new JDBC transaction
32-
* - resume-transaction: verify a transaction ID is active
33-
* - commit-transaction: commit and close a transaction
34-
* - rollback-transaction: rollback and close a transaction
35-
* - db-ping: check database connectivity and latency
36-
* - db-metrics-range: retrieve Oracle performance metrics from V$SYSSTAT
37-
* - explain-plan: generate and explain Oracle SQL execution plans (static or dynamic)
24+
* Provides a set of database operator tools for various database operations.
25+
*
26+
* <p>The available tools are:</p>
27+
* <ul>
28+
* <li><strong>read-query</strong>: Execute SELECT queries and return JSON results.</li>
29+
* <li><strong>write-query</strong>: Execute DML/DDL statements.</li>
30+
* <li><strong>create-table</strong>: Create table.</li>
31+
* <li><strong>delete-table</strong>: Drop table by name.</li>
32+
* <li><strong>list-tables</strong>: List all tables and synonyms in the current schema.</li>
33+
* <li><strong>describe-table</strong>: Get column details for a specific table.</li>
34+
* <li><strong>start-transaction</strong>: Begin a new JDBC transaction.</li>
35+
* <li><strong>resume-transaction</strong>: Verify a transaction ID is active.</li>
36+
* <li><strong>commit-transaction</strong>: Commit and close a transaction.</li>
37+
* <li><strong>rollback-transaction</strong>: Rollback and close a transaction.</li>
38+
* <li><strong>db-ping</strong>: Check database connectivity and latency.</li>
39+
* <li><strong>db-metrics-range</strong>: Retrieve Oracle performance metrics from V$SYSSTAT.</li>
40+
* <li><strong>explain-plan</strong>: Generate and explain Oracle SQL execution plans (static or dynamic).</li>
41+
* </ul>
3842
*/
3943
public final class DatabaseOperatorTools {
4044

@@ -44,7 +48,31 @@ public final class DatabaseOperatorTools {
4448
private DatabaseOperatorTools() {}
4549

4650
/**
47-
* Returns all database operator tool specifications.
51+
* Returns a list of database operator tool specifications based on the provided server configuration.
52+
* The returned tools are used for various database operations such as executing queries, managing transactions,
53+
* and retrieving database metrics.
54+
*
55+
* <p>The tools returned include:</p>
56+
* <ul>
57+
* <li><strong>read-query</strong>: Execute SELECT queries and return JSON results.</li>
58+
* <li><strong>write-query</strong>: Execute DML/DDL statements.</li>
59+
* <li><strong>create-table</strong>: Create table.</li>
60+
* <li><strong>delete-table</strong>: Drop table by name.</li>
61+
* <li><strong>list-tables</strong>: List all tables and synonyms in the current schema.</li>
62+
* <li><strong>describe-table</strong>: Get column details for a specific table.</li>
63+
* <li><strong>start-transaction</strong>: Begin a new JDBC transaction.</li>
64+
* <li><strong>resume-transaction</strong>: Verify a transaction ID is active.</li>
65+
* <li><strong>commit-transaction</strong>: Commit and close a transaction.</li>
66+
* <li><strong>rollback-transaction</strong>: Rollback and close a transaction.</li>
67+
* <li><strong>db-ping</strong>: Check database connectivity and latency.</li>
68+
* <li><strong>db-metrics-range</strong>: Retrieve Oracle performance metrics from V$SYSSTAT.</li>
69+
* <li><strong>explain-plan</strong>: Generate and explain Oracle SQL execution plans (static or dynamic).</li>
70+
* </ul>
71+
*
72+
* <p>A shutdown hook is added to clean up any active transactions when the JVM shuts down.</p>
73+
*
74+
* @param config the server configuration to use for database connections
75+
* @return a list of tool specifications for database operations
4876
*/
4977
public static List<McpServerFeatures.SyncToolSpecification> getTools(ServerConfig config) {
5078
List<McpServerFeatures.SyncToolSpecification> tools = new ArrayList<>();

src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/tools/McpAdminTools.java

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,52 @@
2424
import java.util.*;
2525

2626
/**
27-
* Admin/maintenance tools:
28-
* - list-tools: list all available tools with descriptions
29-
* - edit-tools: upsert a YAML-defined tool in the config file and rely on runtime reload
27+
* Provides a set of admin/maintenance tools for various operations.
28+
*
29+
* <p>The available tools are:</p>
30+
* <ul>
31+
* <li><strong>list-tools</strong>: List all available tools with descriptions.</li>
32+
* <li><strong>edit-tools</strong>: Upsert a YAML-defined tool in the config file and rely on runtime reload.</li>
33+
* </ul>
3034
*/
3135
public class McpAdminTools {
3236

3337
private McpAdminTools() {}
3438

3539
/**
36-
* Returns all MCP admin tool specifications.
40+
* Returns a list of all MCP admin tool specifications, including "list-tools" and "edit-tools".
41+
* The returned tools are filtered based on the configuration provided.
42+
*
43+
* @param config the server configuration used to filter the tools
44+
* @return a list of MCP admin tool specifications
3745
*/
3846
public static List<McpServerFeatures.SyncToolSpecification> getTools(ServerConfig config) {
3947
List<McpServerFeatures.SyncToolSpecification> tools = new ArrayList<>();
4048

4149
tools.add(getListToolsTool(config));
42-
tools.add(getEditToolsTool(config));
50+
tools.add(getEditToolsTool());
4351

4452
return tools;
4553
}
4654

55+
/**
56+
* Returns a tool specification for the "list-tools" tool, which lists all available tools
57+
* with their descriptions. The tool respects the tools filter configuration.
58+
*
59+
* <p>The tool returns a list of tools, including:</p>
60+
* <ul>
61+
* <li>Built-in log analyzer tools</li>
62+
* <li>RAG tools</li>
63+
* <li>Database operator tools</li>
64+
* <li>Custom YAML tools</li>
65+
* <li>MCP admin tools</li>
66+
* </ul>
67+
*
68+
* <p>The tool's output is filtered based on the {@link ServerConfig#toolsFilter} configuration.</p>
69+
*
70+
* @param config the server configuration used to filter the tools
71+
* @return a tool specification for the "list-tools" tool
72+
*/
4773
public static McpServerFeatures.SyncToolSpecification getListToolsTool(ServerConfig config) {
4874
return McpServerFeatures.SyncToolSpecification.builder()
4975
.tool(McpSchema.Tool.builder()
@@ -132,7 +158,38 @@ public static McpServerFeatures.SyncToolSpecification getListToolsTool(ServerCon
132158
.build();
133159
}
134160

135-
public static McpServerFeatures.SyncToolSpecification getEditToolsTool(ServerConfig config) {
161+
/**
162+
* Returns a tool specification for the "edit-tools" tool, which creates or updates
163+
* YAML-defined tools in the configuration file. The changes are auto-reloaded.
164+
*
165+
* <p>The tool accepts the following input parameters:</p>
166+
* <ul>
167+
* <li><strong>name</strong>: The name of the tool to create or update (required).</li>
168+
* <li><strong>remove</strong>: A boolean flag indicating whether to remove the tool (optional).</li>
169+
* <li><strong>description</strong>: A description of the tool (optional).</li>
170+
* <li><strong>dataSource</strong>: The data source for the tool (optional).</li>
171+
* <li><strong>statement</strong>: The SQL statement for the tool (optional).</li>
172+
* <li><strong>parameters</strong>: A list of parameter objects for the tool (optional).
173+
* Each parameter object can have the following properties:
174+
* <ul>
175+
* <li><strong>name</strong>: The name of the parameter.</li>
176+
* <li><strong>type</strong>: The data type of the parameter.</li>
177+
* <li><strong>description</strong>: A description of the parameter.</li>
178+
* <li><strong>required</strong>: A boolean indicating whether the parameter is required.</li>
179+
* </ul>
180+
* </li>
181+
* </ul>
182+
*
183+
* <p>The tool returns a result with the following properties:</p>
184+
* <ul>
185+
* <li><strong>status</strong>: The status of the operation (e.g., "ok", "noop", "error").</li>
186+
* <li><strong>message</strong>: A human-readable message describing the result.</li>
187+
* <li><strong>configFile</strong>: The path to the configuration file.</li>
188+
* </ul>
189+
*
190+
* @return a tool specification for the "edit-tools" tool
191+
*/
192+
public static McpServerFeatures.SyncToolSpecification getEditToolsTool() {
136193
return McpServerFeatures.SyncToolSpecification.builder()
137194
.tool(McpSchema.Tool.builder()
138195
.name("edit-tools")

src/oracle-db-mcp-java-toolkit/src/main/java/com/oracle/database/mcptoolkit/tools/RagTools.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,43 @@ public class RagTools {
4040
private RagTools() {}
4141

4242
/**
43-
* Returns all RAG tool specifications.
43+
* Returns a list of all RAG tool specifications based on the provided server configuration.
44+
* <p>
45+
* The returned list includes tool specifications for RAG applications, such as similarity search
46+
* using vector embeddings. The tools are filtered based on the configuration settings.
47+
*
48+
* @param config the server configuration to use for determining which tools to include
49+
* @return a list of tool specifications for RAG tools
4450
*/
4551
public static List<McpServerFeatures.SyncToolSpecification> getTools(ServerConfig config) {
4652
List<McpServerFeatures.SyncToolSpecification> tools = new ArrayList<>();
47-
tools.add(getSymilaritySearchTool(config));
53+
tools.add(getSimilaritySearchTool(config));
4854
return tools;
4955
}
5056

5157
/**
52-
* Returns a tool specification for the "similarity_search" tool.
58+
* Returns a tool specification for the {@code similarity-search} tool.
5359
* <p>
5460
* This tool allows users to perform similarity searches using vector embeddings.
61+
* The tool's behavior is configured based on the provided server configuration.
62+
* <p>
63+
* The tool accepts the following input arguments:
64+
* <ul>
65+
* <li>{@code question}: the natural-language query text (required, non-blank)</li>
66+
* <li>{@code topK}: the maximum number of rows to return (optional, default=5, clamped to [1, 100])</li>
67+
* <li>{@code table}: the table name containing text + embedding columns (optional, default="profile_oracle")</li>
68+
* <li>{@code dataColumn}: the column holding the text/CLOB to return (optional, default="text")</li>
69+
* <li>{@code embeddingColumn}: the vector column used by the similarity function (optional, default="embedding")</li>
70+
* <li>{@code modelName}: the database vector model used to embed the question (optional, default="doc_model")</li>
71+
* <li>{@code textFetchLimit}: the substring length to return from the text column (optional, default=4000)</li>
72+
* </ul>
73+
* <p>
74+
* The tool returns a list of text snippets ranked by similarity, along with a structured content map containing the results.
5575
*
56-
* @param config server configuration
57-
* @return tool specification
76+
* @param config the server configuration to use for determining the tool's behavior
77+
* @return a tool specification for the {@code similarity-search} tool
5878
*/
59-
public static McpServerFeatures.SyncToolSpecification getSymilaritySearchTool(ServerConfig config) {
79+
public static McpServerFeatures.SyncToolSpecification getSimilaritySearchTool(ServerConfig config) {
6080
return McpServerFeatures.SyncToolSpecification.builder()
6181
.tool(McpSchema.Tool.builder()
6282
.name("similarity-search")

0 commit comments

Comments
 (0)