Skip to content

Commit eab25b6

Browse files
committed
serve.py -> server.ts
1 parent 3c438c2 commit eab25b6

File tree

4 files changed

+60
-65
lines changed

4 files changed

+60
-65
lines changed

examples/simple-host/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "1.0.0",
55
"type": "module",
66
"scripts": {
7-
"start:server": "python3 serve.py",
7+
"start:server": "tsx server.ts",
88
"start:mcp-server": "cd ../simple-server && npm install && npm run start",
99
"build": "concurrently 'INPUT=example-host.html vite build' 'INPUT=example-host-react.html vite build' 'INPUT=sandbox.html vite build'",
1010
"server": "bun server.ts",

examples/simple-host/serve.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

examples/simple-host/server.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env npx tsx
2+
/**
3+
* Simple HTTP server to serve the host and sandbox html files with appropriate
4+
* Content Security Policy (CSP) headers.
5+
*/
6+
7+
import express from "express";
8+
import cors from "cors";
9+
import { fileURLToPath } from "url";
10+
import { dirname, join } from "path";
11+
12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = dirname(__filename);
14+
15+
const PORT = parseInt(process.env.PORT || "8080", 10);
16+
const DIRECTORY = join(__dirname, "dist");
17+
18+
const app = express();
19+
20+
// CORS middleware for all routes
21+
app.use(cors());
22+
23+
// Custom middleware for sandbox.html and root
24+
app.use((req, res, next) => {
25+
if (req.path === "/sandbox.html" || req.path === "/") {
26+
// Permissive CSP to allow external resources (images, styles, scripts)
27+
const csp = [
28+
"default-src 'self'",
29+
"img-src * data: blob: 'unsafe-inline'",
30+
"style-src * blob: data: 'unsafe-inline'",
31+
"script-src * blob: data: 'unsafe-inline' 'unsafe-eval'",
32+
"connect-src *",
33+
"font-src * blob: data:",
34+
"media-src * blob: data:",
35+
"frame-src * blob: data:",
36+
].join("; ");
37+
res.setHeader("Content-Security-Policy", csp);
38+
39+
// Disable caching to ensure fresh content on every request
40+
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
41+
res.setHeader("Pragma", "no-cache");
42+
res.setHeader("Expires", "0");
43+
}
44+
next();
45+
});
46+
47+
// Serve static files from dist directory
48+
app.use(express.static(DIRECTORY));
49+
50+
// Redirect root to example-host.html
51+
app.get("/", (_req, res) => {
52+
res.redirect("/example-host-react.html");
53+
});
54+
55+
app.listen(PORT, () => {
56+
console.log(`Server running on: http://localhost:${PORT}`);
57+
console.log("Press Ctrl+C to stop the server\n");
58+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"homepage": "https://gist.github.com/a9603ba2d6757d6038ce066eded4c354",
33
"name": "@modelcontextprotocol/ext-apps",
4-
"version": "1.0.0",
4+
"version": "0.0.1",
55
"description": "Hey",
66
"type": "module",
77
"main": "./dist/src/app.js",

0 commit comments

Comments
 (0)