Skip to content

Commit a62a1d8

Browse files
Shridhaddavidgomes
andauthored
feat: Support for /sse and OAuth flow (#36)
- [x] Refactor the app to start in both `stdio` and `sse` mode - [x] Using express for `sse` - we can switch to Fastify or something else in future - [x] Added `morgan` for API access logs - [x] Added `winston` for App logs - [x] Implement the OAuth flow as a middle - [x] Using `keyv` and Neon for store tokens and auth codes - [x] Implement the `refresh_token` flow - [x] ~Testing on Vercel~ Deploy on Fly - [x] Security review for OAuth flow - PKCE code exchange, client-secret verification cc: @davidgomes --------- Co-authored-by: David Gomes <[email protected]>
1 parent dbfa184 commit a62a1d8

28 files changed

+3011
-769
lines changed

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# flyctl launch added from .gitignore
2+
**/node_modules
3+
**/*.log
4+
**/.env
5+
**/dist
6+
**/build
7+
# VS Code history extension
8+
**/.history
9+
fly.toml

.env.example

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,20 @@ BRAINTRUST_API_KEY=
55
NEON_API_KEY=
66

77
## Anthropic api key to run the evals
8-
ANTHROPIC_API_KEY=
8+
ANTHROPIC_API_KEY=
9+
10+
## Neon API
11+
NEON_API_HOST=https://api.neon.tech/api/v2
12+
13+
## OAuth upstream oauth host
14+
UPSTREAM_OAUTH_HOST='https://oauth2.neon.tech';
15+
16+
## OAuth client id
17+
CLIENT_ID=
18+
19+
## OAuth client secret
20+
CLIENT_SECRET=
21+
22+
## Redirect URI for OIDC callback
23+
REDIRECT_URI=http://localhost:3001/callback
24+

.github/workflows/fly-deploy.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
2+
3+
name: Fly Deploy
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
deploy:
11+
name: Deploy app
12+
runs-on: ubuntu-latest
13+
concurrency: deploy-group # optional: ensure only one action runs at a time
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: superfly/flyctl-actions/setup-flyctl@master
17+
- run: flyctl deploy --remote-only
18+
env:
19+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

.github/workflows/fly-preview.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Deploy Preview App
2+
on:
3+
# Run this workflow on every PR event. Existing review apps will be updated when the PR is updated.
4+
pull_request:
5+
types: [opened, reopened, synchronize, closed, labeled]
6+
7+
jobs:
8+
preview:
9+
if: contains(github.event.pull_request.labels.*.name, 'deploy-preview')
10+
name: Deploy Preview
11+
runs-on: ubuntu-latest
12+
concurrency: deploy-group # optional: ensure only one action runs at a time
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: superfly/flyctl-actions/setup-flyctl@master
16+
- run: flyctl secrets set --app preview-mcp-server-neon CLIENT_ID=${{secrets.CLIENT_ID}} CLIENT_SECRET=${{secrets.CLIENT_SECRET}} OAUTH_DATABASE_URL=${{secrets.PREVIEW_OAUTH_DATABASE_URL}} SERVER_HOST=${{vars.PREVIEW_SERVER_HOST}} NEON_API_HOST=${{vars.NEON_API_HOST_STAGING}} UPSTREAM_OAUTH_HOST=${{vars.OAUTH_HOST_STAGING}}
17+
env:
18+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
19+
- run: flyctl deploy --remote-only --config ./fly.preview.toml
20+
env:
21+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## UNRELEASED
4+
5+
- Feature: Support for remote MCP with OAuth flow.
6+
37
## [0.3.7] - 2025-04-23
48

59
- Fixes Neon Auth instructions to install latest version of the SDK

Dockerfile.fly

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
# Use the imbios/bun-node image as the base image with Node and Bun
3+
# Keep bun and node version in sync with package.json
4+
ARG NODE_VERSION=22.0.0
5+
ARG BUN_VERSION=1.1.38
6+
FROM imbios/bun-node:1.1.38-22-slim AS base
7+
8+
LABEL fly_launch_runtime="Node.js"
9+
10+
# Set the working directory in the container
11+
WORKDIR /app
12+
13+
# Set production environment
14+
ENV NODE_ENV="production"
15+
16+
# Throw-away build stage to reduce size of final image
17+
From base As builder
18+
19+
# Install packages needed to build node modules
20+
RUN apt-get update -qq && \
21+
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3
22+
23+
# Copy package.json and package-lock.json
24+
COPY package.json package-lock.json ./
25+
26+
# Copy the entire project to the working directory
27+
COPY . .
28+
29+
# Install the dependencies and devDependencies
30+
RUN npm ci --include=dev
31+
32+
# Build the project
33+
RUN npm run build
34+
35+
# Remove development dependencies
36+
RUN npm prune --omit=dev
37+
38+
# Final stage for app image
39+
FROM base
40+
41+
# Copy built application
42+
COPY --from=builder /app /app
43+
44+
45+
# Define environment variables
46+
ENV NODE_ENV=production
47+
48+
EXPOSE 3001
49+
# Specify the command to run the MCP server
50+
CMD ["node", "dist/index.js", "start:sse"]

bun.lock

Lines changed: 231 additions & 21 deletions
Large diffs are not rendered by default.

fly.preview.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
3+
#
4+
5+
app = 'preview-mcp-server-neon'
6+
primary_region = 'fra'
7+
8+
[build]
9+
dockerfile = 'Dockerfile.fly'
10+
11+
[http_service]
12+
internal_port = 3001
13+
force_https = true
14+
auto_stop_machines = 'stop'
15+
auto_start_machines = true
16+
min_machines_running = 0
17+
processes = ['app']
18+
19+
[[vm]]
20+
memory = '1gb'
21+
cpu_kind = 'shared'
22+
cpus = 1

fly.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
3+
#
4+
5+
app = 'mcp-server-neon'
6+
primary_region = 'ams'
7+
8+
[build]
9+
dockerfile = 'Dockerfile.fly'
10+
11+
[http_service]
12+
internal_port = 3001
13+
force_https = true
14+
auto_stop_machines = 'stop'
15+
auto_start_machines = true
16+
min_machines_running = 1
17+
processes = ['app']
18+
19+
[[vm]]
20+
memory = '2gb'
21+
cpu_kind = 'performance'
22+
cpus = 1

0 commit comments

Comments
 (0)