Skip to content

Commit 11fd1c6

Browse files
authored
Merge pull request #4 from baruchiro/official-mcp
Add HTTP Transport Mode, Docker Support, and Migrate to Official MCP SDK
2 parents 5d7b3a4 + 1a32241 commit 11fd1c6

23 files changed

Lines changed: 2057 additions & 619 deletions

.cursor/rules/http-transport.mdc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: false
5+
---
6+
# HTTP Transport Mode for MCP Server
7+
8+
- The MCP server can run in HTTP mode using the `--http` CLI flag.
9+
- When `--http` is set, the entrypoint [src/index.ts](mdc:src/index.ts) starts an Express server and exposes the MCP API at `/mcp`.
10+
- Each POST to `/mcp` creates a new `McpServer` and `StreamableHTTPServerTransport` for stateless, isolated handling.
11+
- The HTTP port can be set with `--port` (default: 3000).
12+
- Express must be installed as a dependency for HTTP mode.
13+
- If `--http` is not set, the server runs in stdio mode as before.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# TypeScript MCP Server Migration
7+
8+
- The main entrypoint is [src/index.ts](mdc:src/index.ts), which starts an MCP server for Paperless-NGX using the @modelcontextprotocol/sdk package.
9+
- All core logic is now in TypeScript; all main files in src/ use the .ts extension.
10+
- The MCP server is started using `McpServer` and `StdioServerTransport` from the SDK, with `await server.connect(transport)`.
11+
- The project can be run directly in TypeScript using the npm script: `npm run start -- <baseUrl> <token>` (see [package.json](mdc:package.json)).
12+
- Node.js types are provided by @types/node in devDependencies.

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
build

.github/workflows/docker-build.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Docker Build (PR)
2+
on:
3+
pull_request:
4+
branches:
5+
- '**'
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Set up Docker Buildx
12+
uses: docker/setup-buildx-action@v3
13+
- name: Build Docker image
14+
uses: docker/build-push-action@v6
15+
with:
16+
context: .
17+
file: ./Dockerfile
18+
push: false
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Docker Publish
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- main
7+
8+
jobs:
9+
build-and-push:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up Docker Buildx
17+
uses: docker/setup-buildx-action@v3
18+
- name: Log in to GitHub Container Registry
19+
uses: docker/login-action@v3
20+
with:
21+
registry: ghcr.io
22+
username: ${{ github.actor }}
23+
password: ${{ secrets.GITHUB_TOKEN }}
24+
- name: Extract Docker metadata
25+
id: meta
26+
uses: docker/metadata-action@v5
27+
with:
28+
images: ghcr.io/${{ github.actor }}/${{ github.repository }}
29+
flavor: |
30+
latest=true
31+
- name: Build and push Docker image
32+
uses: docker/build-push-action@v6
33+
with:
34+
context: .
35+
file: ./Dockerfile
36+
push: true
37+
tags: ${{ steps.meta.outputs.tags }}
38+
labels: ${{ steps.meta.outputs.labels }}

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# Dependencies
22
node_modules/
3-
package-lock.json
4-
yarn.lock
5-
pnpm-lock.yaml
63

74
# Environment variables
85
.env

Dockerfile

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
# Generated by https://smithery.ai. See: https://smithery.ai/docs/config#dockerfile
2-
# Use a Node.js base image
3-
FROM node:18-alpine AS build
4-
5-
# Set the working directory
1+
# Builder stage
2+
FROM node:20-slim AS builder
63
WORKDIR /app
4+
COPY package.json package-lock.json ./
5+
RUN npm ci
6+
COPY . .
7+
RUN npm run build
78

8-
# Copy package.json and package-lock.json
9-
COPY package.json /app/
10-
11-
# Install dependencies
12-
RUN npm install
13-
14-
# Copy the rest of the application
15-
COPY . /app
9+
# Production stage
10+
FROM node:20-slim AS production
1611

17-
# Expose the port the app runs on
18-
EXPOSE 8080
19-
20-
# Define environment variable for base URL and token
21-
ENV BASE_URL=http://your-paperless-instance:8000
22-
ENV TOKEN=your-api-token
12+
WORKDIR /app
13+
COPY --from=builder /app/build .
14+
COPY --from=builder /app/node_modules ./node_modules
15+
COPY --from=builder /app/package.json ./package.json
16+
COPY --from=builder /app/package-lock.json ./package-lock.json
2317

24-
# Command to run the application
25-
CMD ["node", "src/index.js", "$BASE_URL", "$TOKEN"]
18+
EXPOSE 3000
19+
ENTRYPOINT [ "node", "index.js", "--http", "--port", "3000" ]

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,27 @@ The server is built with:
335335
## API Documentation
336336

337337
This MCP server implements endpoints from the Paperless-NGX REST API. For more details about the underlying API, see the [official documentation](https://docs.paperless-ngx.com/api/).
338+
339+
## Running the MCP Server
340+
341+
The MCP server can be run in two modes:
342+
343+
### 1. stdio (default)
344+
345+
This is the default mode. The server communicates over stdio, suitable for CLI and direct integrations.
346+
347+
```
348+
npm run start -- <baseUrl> <token>
349+
```
350+
351+
### 2. HTTP (Streamable HTTP Transport)
352+
353+
To run the server as an HTTP service, use the `--http` flag. You can also specify the port with `--port` (default: 3000). This mode requires [Express](https://expressjs.com/) to be installed (it is included as a dependency).
354+
355+
```
356+
npm run start -- <baseUrl> <token> --http --port 3000
357+
```
358+
359+
- The MCP API will be available at `POST /mcp` on the specified port.
360+
- Each request is handled statelessly, following the [StreamableHTTPServerTransport](https://github.com/modelcontextprotocol/typescript-sdk) pattern.
361+
- GET and DELETE requests to `/mcp` will return 405 Method Not Allowed.

0 commit comments

Comments
 (0)