Skip to content

Commit 02b159a

Browse files
feat: add mcp service, python and java sse server. (#20)
* add python mcp sse server. * fix python image bug. * add springboot. * add springboot. * fix python bug. * add readme. * fix python readme bug. * change readme location. * change python image. * change python image. * change java image. * change java image.
1 parent f67cea8 commit 02b159a

File tree

14 files changed

+776
-0
lines changed

14 files changed

+776
-0
lines changed

Service/mcp/python-3-12/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM ghcr.io/labring-actions/devbox/debian-ssh-12.6:547a61
2+
3+
RUN cd /home/devbox/project && \rm -rf ./*
4+
COPY /Service/mcp/python-3-12/project /home/devbox/project
5+
6+
RUN apt-get update && \
7+
apt-get install -y python3 python3-pip python3-venv && \
8+
apt-get clean && \
9+
rm -rf /var/lib/apt/lists/* && \
10+
ln -s /usr/bin/python3 /usr/bin/python && \
11+
chown -R devbox:devbox /home/devbox/project && \
12+
chmod -R u+rw /home/devbox/project && \
13+
chmod -R +x /home/devbox/project/entrypoint.sh
14+
15+
USER devbox
16+
RUN cd /home/devbox/project && \
17+
python3 -m venv .venv && \
18+
. .venv/bin/activate && \
19+
pip3 install "mcp[cli]==1.6.0" && \
20+
deactivate
21+
22+
RUN mkdir -p /home/devbox/.devbox
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Python MCP Server Example
2+
3+
This is a simple Python MCP server application that uses Claude's official MCP-related dependencies to implement the remote server function of SSE communication.
4+
5+
## Project Description
6+
7+
This project uses Python's FastMCP package to create an SSE MCP server. And a MCP Tool is built in, which returns "Hello, World!" when called.
8+
9+
This project supports development and production environment modes.
10+
11+
## Environment
12+
13+
This project runs on a Debian 12 system with Python 3.3.2 installed. The environment is pre-configured in Devbox, so you don't need to worry about setting up Python or other system dependencies yourself. If you need to make adjustments to meet your specific requirements, you can modify the configuration file accordingly.
14+
15+
## Project Execution
16+
17+
**Development Mode**: For a normal development environment, just enter Devbox and run "bash entrypoint.sh" in the terminal. This will compile and run the Java application.
18+
**Production mode:** Once published, the project will be automatically packaged into a Docker image and deployed according to the `entrypoint.sh` script (run `bash entrypoint.sh production`).
19+
DevBox: Code. Build. Deploy. We do the rest.
20+
With DevBox, you can fully focus on writing great code while we take care of infrastructure, scaling, and deployment. Seamless development from start to production.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
app_env=${1:-development}
4+
5+
# ※To use pip, parameters need to be added: --break-system-packages
6+
. .venv/bin/activate
7+
# Activate virtual environment
8+
9+
# Development environment commands
10+
dev_commands() {
11+
echo "Running development environment commands..."
12+
# In the development environment, we may need more debugging information
13+
python manage.py --host 0.0.0.0 --port 8080 --env dev
14+
}
15+
16+
# Production environment commands
17+
prod_commands() {
18+
echo "Running production environment commands..."
19+
# In the production environment, we may need to add other parameters
20+
python manage.py --host 0.0.0.0 --port 8080 --env prod
21+
}
22+
23+
# Check environment variables to determine the running environment
24+
if [ "$app_env" = "production" ] || [ "$app_env" = "prod" ] ; then
25+
echo "Production environment detected"
26+
prod_commands
27+
else
28+
echo "Development environment detected"
29+
dev_commands
30+
fi
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from mcp.server.fastmcp import FastMCP
2+
from starlette.applications import Starlette
3+
from mcp.server.sse import SseServerTransport
4+
from starlette.requests import Request
5+
from starlette.routing import Mount, Route
6+
from mcp.server import Server
7+
import uvicorn
8+
9+
"""Define your mcp server name"""
10+
mcp = FastMCP("demo")
11+
12+
13+
"""Define your mcp server logic"""
14+
@mcp.tool()
15+
async def demo_toolcall() -> str:
16+
return "Hello,World!"
17+
18+
19+
def create_starlette_app(mcp_server: Server, *, debug: bool = False) -> Starlette:
20+
"""Create a Starlette application that can server the provied mcp server with SSE."""
21+
sse = SseServerTransport("/messages/")
22+
23+
async def handle_sse(request: Request) -> None:
24+
async with sse.connect_sse(
25+
request.scope,
26+
request.receive,
27+
request._send, # noqa: SLF001
28+
) as (read_stream, write_stream):
29+
await mcp_server.run(
30+
read_stream,
31+
write_stream,
32+
mcp_server.create_initialization_options(),
33+
)
34+
return Starlette(
35+
debug=debug,
36+
routes=[
37+
Route("/sse", endpoint=handle_sse),
38+
Mount("/messages/", app=sse.handle_post_message),
39+
],
40+
)
41+
42+
if __name__ == "__main__":
43+
mcp_server = mcp._mcp_server
44+
import argparse
45+
parser = argparse.ArgumentParser(description='Run MCP SSE-based server')
46+
parser.add_argument('--host', default='0.0.0.0', help='Host to bind to')
47+
parser.add_argument('--port', type=int, default=8080, help='Port to listen on')
48+
parser.add_argument('--env', default='dev', help='Environment (dev/prod)')
49+
args = parser.parse_args()
50+
# Configure based on environment
51+
if args.env == 'prod':
52+
debug = False
53+
else:
54+
debug = True
55+
# Bind SSE request handling to MCP server
56+
starlette_app = create_starlette_app(mcp_server, debug=debug)
57+
uvicorn.run(starlette_app, host=args.host, port=args.port)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM ghcr.io/labring-actions/devbox/debian-ssh-12.6:547a61
2+
3+
RUN cd /home/devbox/project && \
4+
rm -rf ./*
5+
6+
COPY /Service/mcp/spring-boot-3-3-2/project /home/devbox/project
7+
8+
RUN apt-get update && \
9+
apt-get install -y wget && \
10+
wget https://download.java.net/openjdk/jdk17/ri/openjdk-17+35_linux-x64_bin.tar.gz && \
11+
mkdir /usr/lib/jvm && \
12+
tar -xvf openjdk-17+35_linux-x64_bin.tar.gz -C /usr/lib/jvm && \
13+
mv /usr/lib/jvm/jdk-17 /usr/lib/jvm/java-17-openjdk-amd64 && \
14+
rm openjdk-17+35_linux-x64_bin.tar.gz && \
15+
curl -o /tmp/apache-maven-3.8.6-bin.tar.gz https://archive.apache.org/dist/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz && \
16+
mkdir -p /opt/maven && \
17+
tar -xzf /tmp/apache-maven-3.8.6-bin.tar.gz -C /opt/maven && \
18+
ln -s /opt/maven/apache-maven-3.8.6 /opt/maven/latest && \
19+
ln -s /opt/maven/latest/bin/mvn /usr/bin/mvn && \
20+
rm /tmp/apache-maven-3.8.6-bin.tar.gz && \
21+
apt-get clean && \
22+
rm -rf /var/lib/apt/lists/* && \
23+
echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /home/devbox/.bashrc && \
24+
echo 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64' >> /home/devbox/.bashrc && \
25+
chown -R devbox:devbox /home/devbox/project && \
26+
chmod -R u+rw /home/devbox/project && \
27+
chmod -R +x /home/devbox/project/entrypoint.sh
28+
29+
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
30+
ENV PATH=$PATH:$JAVA_HOME/bin
31+
RUN mkdir /root/.devbox
32+
33+
USER devbox
34+
RUN cd /home/devbox/project && \
35+
mvn install
36+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Springboot MCP Server Example
2+
3+
This is a simple Springboot MCP server application that uses Claude's official MCP-related dependencies to implement the remote server function of SSE communication.
4+
5+
## Project Description
6+
7+
This project uses Spring's spring-ai-starter-mcp-server-webmvc package to create an SSE MCP server. And a MCP Tool is built in, which returns "Hello, World!" when called.
8+
9+
This project supports development and production environment modes.
10+
11+
## Environment
12+
13+
This project is run on a Debian 12 system with Springboot 3.3.2 installed. The environment is pre-configured in Devbox, so you don't need to worry about setting up Java or other system dependencies yourself. If you need to make adjustments to meet your specific requirements, you can modify the configuration file accordingly.
14+
15+
## Project Execution
16+
17+
**Development Mode**: For a normal development environment, just enter Devbox and run "bash entrypoint.sh" in the terminal. This will compile and run the Java application.
18+
**Production mode:** Once published, the project will be automatically packaged into a Docker image and deployed according to the `entrypoint.sh` script (run `bash entrypoint.sh production`).
19+
DevBox: Code. Build. Deploy. We do the rest.
20+
With DevBox, you can fully focus on writing great code while we take care of infrastructure, scaling, and deployment. Seamless development from start to production.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
app_env=${1:-development}
3+
4+
# Development environment commands
5+
dev_commands() {
6+
echo "Running development environment commands..."
7+
mvn spring-boot:run
8+
}
9+
10+
# Production environment commands
11+
prod_commands() {
12+
echo "Running production environment commands..."
13+
mvn clean install
14+
mvn spring-boot:run
15+
}
16+
17+
# prod_commands
18+
# Check environment variables to determine the running environment
19+
if [ "$app_env" = "production" ] || [ "$app_env" = "prod" ] ; then
20+
echo "Production environment detected"
21+
prod_commands
22+
else
23+
echo "Development environment detected"
24+
dev_commands
25+
fi

0 commit comments

Comments
 (0)