Skip to content

Commit bd46b3c

Browse files
Kevin-Glaserhustcc
andauthored
Update:Start Docker services with Docker Compose, speed up the docker build process (#209)
* Update:Start Docker services with Docker Compose, removing some unnecessary files during the Docker image build process to speed up the build. * Update index.ts Comment out the duplicated host field * Update:delete duplicate fields * Refactor host configuration in index.ts Removed duplicate host configuration and updated structure. * Clarify comments in docker-compose.yaml Updated comments in docker-compose.yaml for clarity. --------- Co-authored-by: hustcc <[email protected]>
1 parent f19d8f0 commit bd46b3c

File tree

7 files changed

+75
-19
lines changed

7 files changed

+75
-19
lines changed

.dockerignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.github/
2+
.git/
3+
node_modules/
4+
dist/
5+
docker/
6+
build/
7+
.vscode/
8+
.idea/
9+
.DS_Store
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
.pnpm-debug.log*
15+
coverage/
16+
*.tgz
17+
__tests__/
18+
*.swp
19+
README.md
20+
Dockerfile
21+
docker-compose.yaml
22+
.dockerignore
23+
.gitignore
24+
# LICENSE

Dockerfile

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
1-
FROM node:lts-alpine
2-
1+
FROM node:lts-alpine AS base
32
WORKDIR /app
43

5-
# Copy package files
4+
# Create non-root user
5+
RUN addgroup -g 1001 -S nodejs && \
6+
adduser -S appuser -u 1001 && \
7+
chown -R appuser:nodejs /app
8+
USER appuser
9+
10+
# === Download production environment dependencies ===
11+
FROM base AS deps
612
COPY package*.json ./
13+
RUN npm install --only=prod --no-audit --no-fund --no-optional --ignore-scripts && \
14+
npm cache clean --force
715

8-
# Install dependencies
9-
RUN npm install --ignore-scripts
16+
FROM base AS builder
17+
COPY package*.json ./
18+
RUN npm install --no-audit --no-fund --no-optional --ignore-scripts
1019

11-
# Copy application code
12-
COPY . .
20+
RUN mkdir -p public
1321

14-
# Build the application
22+
COPY . .
1523
RUN npm run build
1624

25+
# === Build final image ===
26+
FROM base AS final
27+
COPY --from=deps /app/node_modules ./node_modules
28+
COPY --from=builder /app/build ./build
29+
30+
COPY --from=builder /app/public ./public
31+
32+
# If use docker-compose to execute this Dockerfile, this EXPOSE is a good choice.
33+
EXPOSE 1122
1734
# Command will be provided by smithery.yaml
1835
CMD ["node", "build/index.js", "-t", "streamable"]

docker-compose.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
mcp-server-chart:
3+
build:
4+
context: . # Dockerfile dir
5+
dockerfile: Dockerfile
6+
image: mcp-server-chart:stable
7+
container_name: mcp-server-chart-1
8+
# environment:
9+
# - VIS_REQUEST_SERVER=http://127.0.0.1:3000/render # Notice: You can use AntV's project GPT-Vis-SSR to deploy an HTTP service in a private environment, and then pass the URL address through env VIS_REQUEST_SERVER.
10+
command: ["node", "build/index.js", "--transport", "sse", "--port", "1122", "--host", "0.0.0.0"]
11+
ports:
12+
- "1122:1122"
13+
# networks:
14+
# - internal

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ const parsed = parseArgs({
1515
default: "stdio",
1616
},
1717
host: {
18-
type: "boolean",
18+
type: "string",
1919
short: "h",
20-
default: false,
20+
default: "localhost",
2121
},
2222
port: {
2323
type: "string",
2424
short: "p",
2525
default: "1122",
2626
},
27+
2728
endpoint: {
2829
type: "string",
2930
short: "e",

src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function createServer(): Server {
3030

3131
setupToolHandlers(server);
3232

33-
server.onerror = (error) => console.error("[MCP Error]", error);
33+
server.onerror = (error: Error) => console.error("[MCP Error]", error);
3434
process.on("SIGINT", async () => {
3535
await server.close();
3636
process.exit(0);
@@ -61,7 +61,7 @@ function setupToolHandlers(server: Server): void {
6161
tools: getEnabledTools().map((chart) => chart.tool),
6262
}));
6363

64-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
64+
server.setRequestHandler(CallToolRequestSchema, async (request: any) => {
6565
return await callTool(request.params.name, request.params.arguments);
6666
});
6767
}

src/services/sse.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
22
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
3-
import express from "express";
3+
import express, { Request, Response } from "express";
44

55
export const startSSEMcpServer = async (
66
server: Server,
@@ -13,7 +13,7 @@ export const startSSEMcpServer = async (
1313

1414
const transports: Record<string, SSEServerTransport> = {};
1515

16-
app.get(endpoint, async (req, res) => {
16+
app.get(endpoint, async (req: Request, res: Response) => {
1717
try {
1818
const transport = new SSEServerTransport("/messages", res);
1919
transports[transport.sessionId] = transport;
@@ -25,7 +25,7 @@ export const startSSEMcpServer = async (
2525
}
2626
});
2727

28-
app.post("/messages", async (req, res) => {
28+
app.post('/messages', async (req: Request, res: Response) => {
2929
const sessionId = req.query.sessionId as string;
3030
if (!sessionId) return res.status(400).send("Missing sessionId parameter");
3131

src/services/streamable.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
22
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
3+
import express, { Request, Response } from "express";
34
import cors from "cors";
4-
import express from "express";
55

66
export const startHTTPStreamableServer = async (
77
createServer: () => Server,
@@ -13,7 +13,7 @@ export const startHTTPStreamableServer = async (
1313
app.use(express.json());
1414
app.use(cors({ origin: "*", exposedHeaders: ["Mcp-Session-Id"] }));
1515

16-
app.post(endpoint, async (req, res) => {
16+
app.post(endpoint, async (req: Request, res: Response) => {
1717
try {
1818
const server = createServer();
1919
const transport = new StreamableHTTPServerTransport({
@@ -36,15 +36,15 @@ export const startHTTPStreamableServer = async (
3636
}
3737
});
3838

39-
app.get(endpoint, (req, res) => {
39+
app.get(endpoint, (req: Request, res: Response) => {
4040
res.status(405).json({
4141
jsonrpc: "2.0",
4242
error: { code: -32000, message: "Method not allowed" },
4343
id: null,
4444
});
4545
});
4646

47-
app.delete(endpoint, (req, res) => {
47+
app.delete(endpoint, (req: Request, res: Response) => {
4848
res.status(405).json({
4949
jsonrpc: "2.0",
5050
error: { code: -32000, message: "Method not allowed" },

0 commit comments

Comments
 (0)