Skip to content

Commit 4a80d9c

Browse files
committed
CAY-2936 Add a placeholder MCP server to the Modeler distribution
1 parent afd0b65 commit 4a80d9c

17 files changed

Lines changed: 801 additions & 0 deletions

File tree

assembly/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@
124124
<version>${project.version}</version>
125125
</dependency>
126126

127+
<dependency>
128+
<groupId>org.apache.cayenne</groupId>
129+
<artifactId>cayenne-mcp-server</artifactId>
130+
<version>${project.version}</version>
131+
</dependency>
132+
127133
</dependencies>
128134

129135
<build>

assembly/src/main/resources/assemblies/generic/assembly-generic.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,12 @@
114114
</excludes>
115115
</unpackOptions>
116116
</dependencySet>
117+
<dependencySet>
118+
<outputDirectory>bin</outputDirectory>
119+
<includes>
120+
<include>org.apache.cayenne:cayenne-mcp-server</include>
121+
</includes>
122+
<unpack>false</unpack>
123+
</dependencySet>
117124
</dependencySets>
118125
</assembly>

assembly/src/main/resources/assemblies/mac/assembly-mac.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,13 @@
112112
</excludes>
113113
</unpackOptions>
114114
</dependencySet>
115+
<dependencySet>
116+
<outputDirectory>CayenneModeler.app/Contents/Resources/mcp/</outputDirectory>
117+
<includes>
118+
<include>org.apache.cayenne:cayenne-mcp-server</include>
119+
</includes>
120+
<unpack>false</unpack>
121+
<outputFileNameMapping>${artifact.artifactId}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
122+
</dependencySet>
115123
</dependencySets>
116124
</assembly>

assembly/src/main/resources/assemblies/windows/assembly-windows.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,12 @@
112112
</excludes>
113113
</unpackOptions>
114114
</dependencySet>
115+
<dependencySet>
116+
<outputDirectory>bin</outputDirectory>
117+
<includes>
118+
<include>org.apache.cayenne:cayenne-mcp-server</include>
119+
</includes>
120+
<unpack>false</unpack>
121+
</dependencySet>
115122
</dependencySets>
116123
</assembly>

cayenne-mcp-server/pom.xml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
https://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
22+
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<parent>
26+
<groupId>org.apache.cayenne</groupId>
27+
<artifactId>cayenne-parent</artifactId>
28+
<version>5.0-SNAPSHOT</version>
29+
</parent>
30+
31+
<artifactId>cayenne-mcp-server</artifactId>
32+
<name>cayenne-mcp-server: CayenneModeler MCP Server</name>
33+
<packaging>jar</packaging>
34+
35+
<description>
36+
Self-contained MCP server that exposes CayenneModeler operations
37+
to AI coding agents via the Model Context Protocol over stdio.
38+
</description>
39+
40+
<dependencies>
41+
42+
<dependency>
43+
<groupId>io.modelcontextprotocol.sdk</groupId>
44+
<artifactId>mcp</artifactId>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.slf4j</groupId>
49+
<artifactId>slf4j-api</artifactId>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>ch.qos.logback</groupId>
54+
<artifactId>logback-classic</artifactId>
55+
</dependency>
56+
57+
<!-- Test dependencies -->
58+
<dependency>
59+
<groupId>org.junit.jupiter</groupId>
60+
<artifactId>junit-jupiter</artifactId>
61+
<scope>test</scope>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>org.mockito</groupId>
66+
<artifactId>mockito-core</artifactId>
67+
<scope>test</scope>
68+
</dependency>
69+
70+
</dependencies>
71+
72+
<build>
73+
<plugins>
74+
75+
<plugin>
76+
<artifactId>maven-shade-plugin</artifactId>
77+
<version>3.6.0</version>
78+
<executions>
79+
<execution>
80+
<phase>package</phase>
81+
<goals>
82+
<goal>shade</goal>
83+
</goals>
84+
<configuration>
85+
<shadedArtifactAttached>false</shadedArtifactAttached>
86+
<createDependencyReducedPom>false</createDependencyReducedPom>
87+
<filters>
88+
<filter>
89+
<artifact>*:*</artifact>
90+
<excludes>
91+
<exclude>META-INF/*.SF</exclude>
92+
<exclude>META-INF/*.DSA</exclude>
93+
<exclude>META-INF/*.RSA</exclude>
94+
</excludes>
95+
</filter>
96+
</filters>
97+
<transformers>
98+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
99+
<mainClass>org.apache.cayenne.mcp.CayenneMcpMain</mainClass>
100+
<manifestEntries>
101+
<Implementation-Version>${project.version}</Implementation-Version>
102+
</manifestEntries>
103+
</transformer>
104+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
105+
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/>
106+
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
107+
<addHeader>false</addHeader>
108+
</transformer>
109+
</transformers>
110+
</configuration>
111+
</execution>
112+
</executions>
113+
</plugin>
114+
115+
<plugin>
116+
<artifactId>maven-failsafe-plugin</artifactId>
117+
<version>${maven-surefire-plugin.version}</version>
118+
<executions>
119+
<execution>
120+
<goals>
121+
<goal>integration-test</goal>
122+
<goal>verify</goal>
123+
</goals>
124+
</execution>
125+
</executions>
126+
</plugin>
127+
128+
</plugins>
129+
</build>
130+
131+
</project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*****************************************************************
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
****************************************************************/
19+
package org.apache.cayenne.mcp;
20+
21+
/**
22+
* Entry point for the Cayenne MCP server.
23+
*/
24+
public class CayenneMcpMain {
25+
26+
public static void main(String[] args) {
27+
StderrLogging.install();
28+
29+
CayenneMcpOptions opts = CayenneMcpOptions.parse(args);
30+
31+
String version = version();
32+
33+
if (opts.isHelp()) {
34+
System.err.println("Usage: java -jar cayenne-mcp-server.jar [options]");
35+
System.err.println();
36+
System.err.println("Options:");
37+
System.err.println(" -h, --help Print this help and exit.");
38+
System.err.println(" -V, --version Print the server version and exit.");
39+
System.exit(0);
40+
}
41+
42+
if (opts.isVersion()) {
43+
System.err.println("cayenne-mcp-server " + version);
44+
System.exit(0);
45+
}
46+
47+
new CayenneMcpServer().run(version);
48+
}
49+
50+
static String version() {
51+
String v = CayenneMcpMain.class.getPackage().getImplementationVersion();
52+
return v != null ? v : "dev";
53+
}
54+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*****************************************************************
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
****************************************************************/
19+
package org.apache.cayenne.mcp;
20+
21+
/**
22+
* Parsed command-line options for the MCP server.
23+
*/
24+
public class CayenneMcpOptions {
25+
26+
private final boolean help;
27+
private final boolean version;
28+
29+
private CayenneMcpOptions(boolean help, boolean version) {
30+
this.help = help;
31+
this.version = version;
32+
}
33+
34+
public static CayenneMcpOptions parse(String[] args) {
35+
boolean help = false;
36+
boolean version = false;
37+
38+
for (String arg : args) {
39+
switch (arg) {
40+
case "-h", "--help" -> help = true;
41+
case "-V", "--version" -> version = true;
42+
default -> {
43+
System.err.println("Unknown option: " + arg);
44+
System.err.println("Run with -h for usage.");
45+
System.exit(2);
46+
}
47+
}
48+
}
49+
50+
return new CayenneMcpOptions(help, version);
51+
}
52+
53+
public boolean isHelp() {
54+
return help;
55+
}
56+
57+
public boolean isVersion() {
58+
return version;
59+
}
60+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*****************************************************************
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
****************************************************************/
19+
package org.apache.cayenne.mcp;
20+
21+
import io.modelcontextprotocol.json.McpJsonMapper;
22+
import io.modelcontextprotocol.json.McpJsonMapperSupplier;
23+
import io.modelcontextprotocol.server.McpServer;
24+
import io.modelcontextprotocol.server.McpSyncServer;
25+
import io.modelcontextprotocol.server.transport.StdioServerTransportProvider;
26+
import io.modelcontextprotocol.spec.McpSchema;
27+
import org.apache.cayenne.mcp.tools.HelloTool;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
31+
import java.util.ServiceLoader;
32+
33+
/**
34+
* Assembles and runs the MCP server on stdio.
35+
*/
36+
public class CayenneMcpServer {
37+
38+
private static final Logger LOGGER = LoggerFactory.getLogger(CayenneMcpServer.class);
39+
40+
public void run(String version) {
41+
LOGGER.info("Starting Cayenne MCP server {}", version);
42+
43+
McpJsonMapper jsonMapper = ServiceLoader.load(McpJsonMapperSupplier.class)
44+
.findFirst()
45+
.orElseThrow(() -> new IllegalStateException("No McpJsonMapperSupplier found on classpath"))
46+
.get();
47+
48+
StdioServerTransportProvider transport = new StdioServerTransportProvider(jsonMapper);
49+
50+
McpSyncServer server = McpServer.sync(transport)
51+
.serverInfo("cayenne-mcp-server", version)
52+
.capabilities(McpSchema.ServerCapabilities.builder().tools(true).build())
53+
.tools(HelloTool.spec())
54+
.build();
55+
56+
// Close server cleanly on SIGTERM / ctrl-C
57+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
58+
LOGGER.info("Cayenne MCP server stopping");
59+
server.closeGracefully();
60+
}));
61+
62+
LOGGER.info("Cayenne MCP server started, listening on stdio");
63+
// The transport's non-daemon threads keep the JVM alive until stdin closes.
64+
}
65+
}

0 commit comments

Comments
 (0)