Skip to content

Commit 3d381df

Browse files
Added cors settings to simpleStreamableHttp example server
1 parent bda811a commit 3d381df

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/examples/server/simpleStreamableHttp.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { setupAuthServer } from './demoInMemoryOAuthProvider.js';
1111
import { OAuthMetadata } from 'src/shared/auth.js';
1212
import { checkResourceAllowed } from 'src/shared/auth-utils.js';
1313

14+
import cors from 'cors';
15+
1416
// Check for OAuth flag
1517
const useOAuth = process.argv.includes('--oauth');
1618
const strictOAuth = process.argv.includes('--oauth-strict');
@@ -420,12 +422,18 @@ const getServer = () => {
420422
return server;
421423
};
422424

423-
const MCP_PORT = 3000;
424-
const AUTH_PORT = 3001;
425+
const MCP_PORT = process.env.MCP_PORT ? parseInt(process.env.MCP_PORT, 10) : 3000;
426+
const AUTH_PORT = process.env.MCP_AUTH_PORT ? parseInt(process.env.MCP_AUTH_PORT, 10) : 3001;
425427

426428
const app = express();
427429
app.use(express.json());
428430

431+
// Allow CORS all domains, expose the Mcp-Session-Id header
432+
app.use(cors({
433+
origin: '*', // Allow all origins
434+
exposedHeaders: ["Mcp-Session-Id"]
435+
}));
436+
429437
// Set up OAuth if enabled
430438
let authMiddleware = null;
431439
if (useOAuth) {

0 commit comments

Comments
 (0)