Refactor server startup functions
Rename `startServer` to `startStreamableHTTPServer` and add a new `startStdioServer` helper to make the transport type explicit. Remove the `ServerOptions` interface in favor of reading `PORT` directly from the environment inside the function (defaulting to `3001`). Also update Python examples to default to port `3001` for consistency. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9557d41ce7
commit
6eb82b5562
23 changed files with 338 additions and 352 deletions
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3001", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Basic MCP App Server (Preact)" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -63,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -75,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3001", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Basic MCP App Server (React)" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3001", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Basic MCP App Server (Solid)" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3001", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Basic MCP App Server (Svelte)" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3102", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Basic MCP App Server (Vanilla JS)" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3001", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Basic MCP App Server (Vue)" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3103", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Marketing" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3104", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Cohort Heatmap Server" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,15 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3105", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, {
|
|
||||||
port,
|
|
||||||
name: "Customer Segmentation Server",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3110", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Debug Server" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3001", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Integration Test Server" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -63,7 +52,7 @@ export async function startServer(
|
||||||
});
|
});
|
||||||
|
|
||||||
const httpServer = app.listen(port, () => {
|
const httpServer = app.listen(port, () => {
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -75,12 +64,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3001", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "CesiumJS Map Server" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,19 +23,13 @@ import {
|
||||||
DEFAULT_PDF,
|
DEFAULT_PDF,
|
||||||
} from "./server.js";
|
} from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -71,7 +65,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -83,6 +77,17 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
function parseArgs(): { urls: string[]; stdio: boolean } {
|
function parseArgs(): { urls: string[]; stdio: boolean } {
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
const urls: string[] = [];
|
const urls: string[] = [];
|
||||||
|
|
@ -132,10 +137,9 @@ async function main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (stdio) {
|
if (stdio) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3120", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "PDF Server" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ from starlette.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
VIEW_URI = "ui://qr-server/view.html"
|
VIEW_URI = "ui://qr-server/view.html"
|
||||||
HOST = os.environ.get("HOST", "0.0.0.0") # 0.0.0.0 for Docker compatibility
|
HOST = os.environ.get("HOST", "0.0.0.0") # 0.0.0.0 for Docker compatibility
|
||||||
PORT = int(os.environ.get("PORT", "3108"))
|
PORT = int(os.environ.get("PORT", "3001"))
|
||||||
|
|
||||||
mcp = FastMCP("QR Code Server")
|
mcp = FastMCP("QR Code Server")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
VIEW_URI = "ui://say-demo/view.html"
|
VIEW_URI = "ui://say-demo/view.html"
|
||||||
HOST = os.environ.get("HOST", "0.0.0.0")
|
HOST = os.environ.get("HOST", "0.0.0.0")
|
||||||
PORT = int(os.environ.get("PORT", "3109"))
|
PORT = int(os.environ.get("PORT", "3001"))
|
||||||
|
|
||||||
# Speaker icon as SVG data URI
|
# Speaker icon as SVG data URI
|
||||||
SPEAKER_ICON = Icon(
|
SPEAKER_ICON = Icon(
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3106", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "SaaS Scenario Modeler" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3001", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "ShaderToy Server" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3001", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Sheet Music Server" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3107", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "System Monitor Server" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,6 @@
|
||||||
* Or: node dist/index.js [--stdio]
|
* Or: node dist/index.js [--stdio]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared utilities for running MCP servers with Streamable HTTP transport.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
||||||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
@ -16,22 +12,15 @@ import cors from "cors";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import { createServer } from "./server.js";
|
import { createServer } from "./server.js";
|
||||||
|
|
||||||
export interface ServerOptions {
|
|
||||||
port: number;
|
|
||||||
name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
* Starts an MCP server with Streamable HTTP transport in stateless mode.
|
||||||
*
|
*
|
||||||
* @param createServer - Factory function that creates a new McpServer instance per request.
|
* @param createServer - Factory function that creates a new McpServer instance per request.
|
||||||
* @param options - Server configuration options.
|
|
||||||
*/
|
*/
|
||||||
export async function startServer(
|
export async function startStreamableHTTPServer(
|
||||||
createServer: () => McpServer,
|
createServer: () => McpServer,
|
||||||
options: ServerOptions,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { port, name = "MCP Server" } = options;
|
const port = parseInt(process.env.PORT ?? "3001", 10);
|
||||||
|
|
||||||
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
const app = createMcpExpressApp({ host: "0.0.0.0" });
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
@ -67,7 +56,7 @@ export async function startServer(
|
||||||
console.error("Failed to start server:", err);
|
console.error("Failed to start server:", err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`${name} listening on http://localhost:${port}/mcp`);
|
console.log(`MCP server listening on http://localhost:${port}/mcp`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
|
|
@ -79,12 +68,22 @@ export async function startServer(
|
||||||
process.on("SIGTERM", shutdown);
|
process.on("SIGTERM", shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts an MCP server with stdio transport.
|
||||||
|
*
|
||||||
|
* @param createServer - Factory function that creates a new McpServer instance.
|
||||||
|
*/
|
||||||
|
export async function startStdioServer(
|
||||||
|
createServer: () => McpServer,
|
||||||
|
): Promise<void> {
|
||||||
|
await createServer().connect(new StdioServerTransport());
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.includes("--stdio")) {
|
if (process.argv.includes("--stdio")) {
|
||||||
await createServer().connect(new StdioServerTransport());
|
await startStdioServer(createServer);
|
||||||
} else {
|
} else {
|
||||||
const port = parseInt(process.env.PORT ?? "3108", 10);
|
await startStreamableHTTPServer(createServer);
|
||||||
await startServer(createServer, { port, name: "Three.js Server" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue