Skip to content

Commit 004cc26

Browse files
committed
feat: add database MCP module and refactor github/filesystem modules
- Add .gitignore to exclude build artifacts, IDE files, and lib/ - Add database/ module with: - Database.java: MCP server entrypoint registering DatabaseTool - DatabaseTool.java: Tools for list-tables, describe, query, insert, update, delete, and execute with SQL-injection guards - DatabaseToolTest.java: 10 unit tests using in-memory H2 DB - application.properties: default H2 datasource config - pom.xml: module descriptor with H2 and Kafka dependencies - Refactor GitHub.java: - Extract fetchGitHubApiJson() to eliminate HTTP boilerplate - Fix resource leaks with try-with-resources on Git handles - Fix clone directory parsing edge cases - Refactor FileSystem.java: - Standardize to StandardCharsets.UTF_8 throughout - Fix deleteRecursively() to properly clean up parent dirs - Cleanup pom.xml files: - Upgrade tinystruct to 1.7.27 - Sync compiler settings across all modules - Add maven-surefire-plugin where tests were bypassed - Cleanup GitHubToolTest.java: - Tag network-dependent tests with @tag(network) - Remove unused imports
1 parent eb62024 commit 004cc26

12 files changed

Lines changed: 972 additions & 257 deletions

File tree

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Maven build output
2+
target/
3+
*/target/
4+
5+
# IntelliJ IDEA
6+
.idea/
7+
*.iml
8+
*.iws
9+
*.ipr
10+
11+
# Eclipse
12+
.classpath
13+
.project
14+
.settings/
15+
16+
# NetBeans
17+
nbproject/private/
18+
build/
19+
nbbuild/
20+
dist/
21+
nbdist/
22+
.nb-gradle/
23+
24+
# VS Code
25+
.vscode/
26+
27+
# OS files
28+
.DS_Store
29+
Thumbs.db
30+
31+
# Local jars (built artifacts)
32+
lib/

database/pom.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.tinystruct</groupId>
8+
<artifactId>tinystruct-mcp</artifactId>
9+
<version>1.0.0</version>
10+
</parent>
11+
<artifactId>tinystruct-mcp-database</artifactId>
12+
<packaging>jar</packaging>
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<groupId>org.apache.maven.plugins</groupId>
17+
<artifactId>maven-surefire-plugin</artifactId>
18+
<version>3.0.0</version>
19+
</plugin>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-dependency-plugin</artifactId>
23+
<executions>
24+
<execution>
25+
<id>copy-dependencies</id>
26+
<phase>compile</phase>
27+
<goals>
28+
<goal>copy-dependencies</goal>
29+
</goals>
30+
<configuration>
31+
<outputDirectory>../lib</outputDirectory>
32+
<overWriteReleases>false</overWriteReleases>
33+
<overWriteSnapshots>false</overWriteSnapshots>
34+
<overWriteIfNewer>true</overWriteIfNewer>
35+
</configuration>
36+
</execution>
37+
</executions>
38+
</plugin>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-jar-plugin</artifactId>
42+
<configuration>
43+
<archive>
44+
<manifest>
45+
<addClasspath>true</addClasspath>
46+
<classpathPrefix>lib/</classpathPrefix>
47+
<mainClass>org.tinystruct.system.Dispatcher</mainClass>
48+
</manifest>
49+
</archive>
50+
</configuration>
51+
</plugin>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-antrun-plugin</artifactId>
55+
<version>3.0.0</version>
56+
<executions>
57+
<execution>
58+
<id>copy-jar</id>
59+
<phase>package</phase>
60+
<goals>
61+
<goal>run</goal>
62+
</goals>
63+
<configuration>
64+
<target>
65+
<copy file="${project.build.directory}/${project.build.finalName}.jar"
66+
todir="../lib" />
67+
</target>
68+
</configuration>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
</plugins>
73+
</build>
74+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.tinystruct.mcp;
2+
3+
import org.tinystruct.data.component.Builder;
4+
5+
/**
6+
* Database MCP Server
7+
* Provides tools for inspecting and querying relational databases.
8+
*/
9+
public class Database extends MCPServer {
10+
private static final String DATABASE_PROTOCOL_VERSION = "1.0.0";
11+
12+
@Override
13+
public void init() {
14+
super.init();
15+
16+
// Register Database tool methods
17+
DatabaseTool databaseTool = new DatabaseTool();
18+
this.registerTool(databaseTool);
19+
20+
// Register sql-query-helper prompt
21+
Builder promptSchema = new Builder();
22+
Builder properties = new Builder();
23+
24+
Builder intentParam = new Builder();
25+
intentParam.put("type", "string");
26+
intentParam.put("description", "What the user wants to accomplish");
27+
28+
properties.put("intent", intentParam);
29+
promptSchema.put("type", "object");
30+
promptSchema.put("properties", properties);
31+
promptSchema.put("required", new String[]{"intent"});
32+
33+
MCPPrompt sqlHelperPrompt = new MCPPrompt(
34+
"sql-query-helper",
35+
"Generate a SQL query based on the user's intent",
36+
"Generate a valid SQL query for the user's intent: {{intent}}\n\nBefore returning the query, use the db/info tool to determine the database dialect, and use db/list-tables and db/describe to ensure the tables and columns exist.",
37+
promptSchema,
38+
null
39+
) {
40+
@Override
41+
protected boolean supportsLocalExecution() {
42+
return true;
43+
}
44+
};
45+
46+
this.registerPrompt(sqlHelperPrompt);
47+
}
48+
49+
@Override
50+
public String version() {
51+
return DATABASE_PROTOCOL_VERSION;
52+
}
53+
}

0 commit comments

Comments
 (0)