Skip to content

Commit a0aac60

Browse files
committed
adding html,react,basic and test react server
1 parent f62a30f commit a0aac60

File tree

18 files changed

+2799
-331
lines changed

18 files changed

+2799
-331
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
node_modules
2+
**/node_modules
23
npm-debug.log
34
Dockerfile*
45
.git
56
.gitignore
67
**/.DS_Store
78
.vscode
89
*.swp
10+
11+
# Web build artifacts (built inside container, don't copy from host)
12+
web/dist
13+
web/node_modules

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
/node_modules
2-
*env
2+
node_modules/
3+
*env
4+
5+
# Web build artifacts
6+
web/dist/
7+
web/node_modules/

Dockerfile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@
33
FROM node:20-alpine
44
WORKDIR /app
55

6-
# Install dependencies with caching
6+
# Install root dependencies with caching
77
COPY package.json package-lock.json ./
88
RUN --mount=type=cache,target=/root/.npm npm ci
99

10+
# Build web components if web/ directory exists (for React UI mode)
11+
# Copy entire web directory (package.json, src/, tsconfig.json)
12+
COPY web/ ./web/
13+
RUN if [ -f web/package.json ]; then \
14+
cd web && npm ci && npm run build; \
15+
fi
16+
1017
# Copy source
1118
COPY tsconfig.json ./
1219
COPY src ./src
1320

21+
# Note: web/dist is created during the build step above (line 12-14)
22+
# No need to copy it from host - it's built inside the container
23+
1424
# App listens on 3000
1525
EXPOSE 3000
1626

17-
# Explicitly disable auth by default in this image (can override at runtime)
18-
#ENV DISABLE_AUTH=false
19-
27+
# Tool mode: basic (default), ui-html, or ui-react
2028
# Start the MCP server (uses devDependency tsx)
21-
CMD ["npm", "run", "start:ui"]
29+
CMD ["npm", "run", "start:ui-react"]

README.md

Lines changed: 107 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,124 @@ Start the OAuth demo (port 3001):
3131
npm run dev:oauth
3232
```
3333

34-
## Development modes
34+
## Tool Modes & Development
35+
36+
This server supports three distinct tool modes, each optimized for different use cases. Choose the mode that best fits your needs:
37+
38+
### 🛠️ Basic Tools Mode (Default)
39+
40+
**Best for:** Learning MCP fundamentals, CLI tools, and simple text-based interactions.
41+
42+
The basic mode provides core MCP functionality with simple text-based tool responses. Perfect for understanding the MCP protocol without UI complexity.
3543

36-
**Pure MCP (default):**
3744
```bash
38-
# .env (local opaque token default)
39-
# OAUTH_SERVER_URL defaults to http://localhost:3001
40-
# OAUTH_INTROSPECT_URL defaults to ${OAUTH_SERVER_URL}/introspect
45+
npm run dev
46+
```
4147

42-
DISABLE_AUTH=false
43-
AUTH_TOKEN_MODE=introspection
48+
**Features:**
49+
- Pure MCP protocol implementation
50+
- Text-based tool responses
51+
- Minimal dependencies
52+
- Fast and lightweight
53+
54+
### 🎨 HTML UI Mode
55+
56+
**Best for:** Quick prototypes, simple forms, and lightweight interactive components.
57+
58+
HTML UI mode enables rich, interactive components using vanilla HTML, CSS, and JavaScript. Components are served as standalone HTML files that can be embedded in MCP clients.
4459

60+
```bash
61+
npm run dev:ui-html
62+
```
63+
64+
**Features:**
65+
- Interactive HTML components
66+
- No build step required
67+
- Fast iteration
68+
- Lightweight bundle size
69+
70+
### ⚛️ React UI Mode
71+
72+
**Best for:** Complex, stateful components and modern React-based UIs.
73+
74+
React UI mode provides full React component support with TypeScript, enabling sophisticated user interfaces with state management, hooks, and modern React patterns.
75+
76+
```bash
77+
npm run dev:ui-react
78+
```
79+
80+
**Features:**
81+
- Full React 18+ support
82+
- TypeScript for type safety
83+
- Component state management
84+
- Modern React patterns (hooks, context, etc.)
85+
86+
### 🧪 React Component Development
87+
88+
The `web/` directory contains a lightweight React development environment for designing and testing your UI components locally.
89+
90+
**Start the development server:**
91+
```bash
92+
cd web
4593
npm run dev
4694
```
4795

48-
**MCP + UI Components:**
96+
This launches a Vite-powered dev server with:
97+
- ⚡ Hot module replacement (instant updates)
98+
- 🔍 Component preview in browser
99+
- 🎯 Mock `window.openai` API for testing
100+
- 📦 Automatic TypeScript compilation
101+
102+
Edit `web/src/components/greet.tsx` and see your changes instantly. The mock API simulates tool calls, so you can develop and test your component's behavior without running the full MCP server.
103+
104+
**Build for production:**
49105
```bash
50-
# Same .env as above
51-
npm run dev:ui
106+
cd web
107+
npm run build
108+
```
109+
110+
This generates `web/dist/greet.js`, which is automatically included when running the MCP server in React UI mode.
111+
112+
### 🐳 Docker Configuration
113+
114+
In production deployments, configure the tool mode by changing the `CMD` in your Dockerfile to use the appropriate npm script. The npm scripts already set the `TOOL_MODE` environment variable internally, so you don't need to set it separately.
115+
116+
**Dockerfile:**
117+
```dockerfile
118+
# Choose the start script that matches your desired mode:
119+
# CMD ["npm", "run", "start"] # Basic tools (default)
120+
# CMD ["npm", "run", "start:ui-html"] # HTML UI
121+
CMD ["npm", "run", "start:ui-react"] # React UI
52122
```
53123

54-
The pure MCP mode focuses on core MCP functionality (auth, tools, endpoints). The UI mode adds rich component experiences with interactive forms and visual feedback.
124+
**Examples for different modes:**
125+
```dockerfile
126+
# Basic mode (no UI)
127+
CMD ["npm", "run", "start"]
55128

56-
Tip: If you want to run MCP without auth locally, set the explicit flag (in env or inline):
129+
# HTML UI mode
130+
CMD ["npm", "run", "start:ui-html"]
131+
132+
# React UI mode
133+
CMD ["npm", "run", "start:ui-react"]
134+
```
57135

136+
The Dockerfile automatically builds React components during the image build process, so React UI mode is ready to use in production.
137+
138+
---
139+
140+
### Development Tips
141+
142+
**Run without authentication (local testing):**
58143
```bash
59144
DISABLE_AUTH=true npm run dev
60145
```
61146

147+
**Switch between modes:**
148+
- `npm run dev` → Basic tools
149+
- `npm run dev:ui-html` → HTML UI
150+
- `npm run dev:ui-react` → React UI (builds web components first)
151+
62152
### Token modes: introspection (local default) or JWT (managed IdP)
63153

64154
This server supports two auth modes, controlled by `AUTH_TOKEN_MODE`:
@@ -205,9 +295,12 @@ curl -i -X POST http://localhost:3000/mcp \
205295
-d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"greet","arguments":{"name":"Elin"}}}'
206296
```
207297

208-
**UI Mode:** The `greet` tool renders a simple component with an input field. In rich-UI clients, it is associated with the template `ui://widget/greet.html` and can initiate tool calls from the iframe when supported. The tool also returns `structuredContent` with `{ name, greeting }` so the component can hydrate initial UI state.
298+
**Tool mode differences:**
299+
- **Basic mode:** Returns simple text response: `"Hello, Elin!"`
300+
- **HTML UI mode:** Returns HTML component template (`ui://widget/greet.html`) with structured content for hydration
301+
- **React UI mode:** Returns React component template (`ui://widget/greet.js`) with full React support and state management
209302

210-
**Pure MCP Mode:** The `greet` tool returns simple text responses without UI components, perfect for learning MCP fundamentals.
303+
In UI modes, rich clients can render interactive components that allow users to interact directly with the tool, and components can initiate tool calls via the `window.openai.callTool` API when supported.
211304

212305
Call `count`:
213306

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
"version": "1.0.0",
44
"main": "index.js",
55
"scripts": {
6-
"dev": "tsx --watch src/start.ts",
7-
"dev:ui": "tsx --watch src/server-with-ui.ts",
6+
"dev": "TOOL_MODE=basic tsx --watch src/start.ts",
7+
"dev:ui-html": "TOOL_MODE=ui-html tsx --watch src/start.ts",
8+
"dev:ui-react": "npm run build:web && TOOL_MODE=ui-react tsx --watch src/start.ts",
89
"dev:oauth": "tsx --watch src/oauth.ts",
910
"start": "tsx src/start.ts",
10-
"start:ui": "tsx src/server-with-ui.ts",
11+
"start:ui-html": "TOOL_MODE=ui-html tsx src/start.ts",
12+
"start:ui-react": "TOOL_MODE=ui-react tsx src/start.ts",
1113
"start:oauth": "tsx src/oauth.ts",
14+
"build:web": "cd web && npm install && npm run build",
1215
"docker:build": "docker build -t mcp-pluggdax-bare:dev .",
1316
"docker:run": "docker run --rm -p 3000:3000 --name mcp-pluggdax mcp-pluggdax-bare:dev",
1417
"docker:stop": "docker rm -f mcp-pluggdax || true",

0 commit comments

Comments
 (0)