Merge pull request #85 from modelcontextprotocol/add-stdio-transport
Add optional stdio transport to marketing example servers
This commit is contained in:
commit
8f4a0c7d47
5 changed files with 240 additions and 183 deletions
|
|
@ -5,6 +5,7 @@
|
|||
* and industry benchmarks by company stage.
|
||||
*/
|
||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
||||
import type {
|
||||
CallToolResult,
|
||||
|
|
@ -292,14 +293,20 @@ server.registerResource(
|
|||
);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Express Server
|
||||
// Server Startup
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
async function main() {
|
||||
if (process.argv.includes("--stdio")) {
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
console.error("Budget Allocator Server running in stdio mode");
|
||||
} else {
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
app.post("/mcp", async (req: Request, res: Response) => {
|
||||
app.post("/mcp", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const transport = new StreamableHTTPServerTransport({
|
||||
sessionIdGenerator: undefined,
|
||||
|
|
@ -321,21 +328,25 @@ app.post("/mcp", async (req: Request, res: Response) => {
|
|||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const httpServer = app.listen(PORT, () => {
|
||||
const httpServer = app.listen(PORT, () => {
|
||||
console.log(
|
||||
`Budget Allocator Server listening on http://localhost:${PORT}/mcp`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function shutdown() {
|
||||
function shutdown() {
|
||||
console.log("\nShutting down...");
|
||||
httpServer.close(() => {
|
||||
console.log("Server closed");
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
}
|
||||
}
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
main().catch(console.error);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
||||
import type { ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
|
||||
import cors from "cors";
|
||||
|
|
@ -204,11 +205,17 @@ const server = new McpServer({
|
|||
);
|
||||
}
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
async function main() {
|
||||
if (process.argv.includes("--stdio")) {
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
console.error("Cohort Heatmap Server running in stdio mode");
|
||||
} else {
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
app.post("/mcp", async (req: Request, res: Response) => {
|
||||
app.post("/mcp", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const transport = new StreamableHTTPServerTransport({
|
||||
sessionIdGenerator: undefined,
|
||||
|
|
@ -231,19 +238,25 @@ app.post("/mcp", async (req: Request, res: Response) => {
|
|||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const httpServer = app.listen(PORT, () => {
|
||||
console.log(`Server listening on http://localhost:${PORT}/mcp`);
|
||||
});
|
||||
const httpServer = app.listen(PORT, () => {
|
||||
console.log(
|
||||
`Cohort Heatmap Server listening on http://localhost:${PORT}/mcp`,
|
||||
);
|
||||
});
|
||||
|
||||
function shutdown() {
|
||||
function shutdown() {
|
||||
console.log("\nShutting down...");
|
||||
httpServer.close(() => {
|
||||
console.log("Server closed");
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
}
|
||||
}
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
main().catch(console.error);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
||||
import type {
|
||||
CallToolResult,
|
||||
|
|
@ -103,11 +104,17 @@ const server = new McpServer({
|
|||
);
|
||||
}
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
async function main() {
|
||||
if (process.argv.includes("--stdio")) {
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
console.error("Customer Segmentation Server running in stdio mode");
|
||||
} else {
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
app.post("/mcp", async (req: Request, res: Response) => {
|
||||
app.post("/mcp", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const transport = new StreamableHTTPServerTransport({
|
||||
sessionIdGenerator: undefined,
|
||||
|
|
@ -130,21 +137,25 @@ app.post("/mcp", async (req: Request, res: Response) => {
|
|||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const httpServer = app.listen(PORT, () => {
|
||||
const httpServer = app.listen(PORT, () => {
|
||||
console.log(
|
||||
`Customer Segmentation Server listening on http://localhost:${PORT}/mcp`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function shutdown() {
|
||||
function shutdown() {
|
||||
console.log("\nShutting down...");
|
||||
httpServer.close(() => {
|
||||
console.log("Server closed");
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
}
|
||||
}
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
main().catch(console.error);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
||||
import type {
|
||||
CallToolResult,
|
||||
|
|
@ -308,14 +309,20 @@ const server = new McpServer({
|
|||
}
|
||||
|
||||
// ============================================================================
|
||||
// Express Server
|
||||
// Server Startup
|
||||
// ============================================================================
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
async function main() {
|
||||
if (process.argv.includes("--stdio")) {
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
console.error("SaaS Scenario Modeler Server running in stdio mode");
|
||||
} else {
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
app.post("/mcp", async (req: Request, res: Response) => {
|
||||
app.post("/mcp", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const transport = new StreamableHTTPServerTransport({
|
||||
sessionIdGenerator: undefined,
|
||||
|
|
@ -337,21 +344,25 @@ app.post("/mcp", async (req: Request, res: Response) => {
|
|||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const httpServer = app.listen(PORT, () => {
|
||||
const httpServer = app.listen(PORT, () => {
|
||||
console.log(
|
||||
`SaaS Scenario Modeler Server listening on http://localhost:${PORT}/mcp`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function shutdown() {
|
||||
function shutdown() {
|
||||
console.log("\nShutting down...");
|
||||
httpServer.close(() => {
|
||||
console.log("Server closed");
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
}
|
||||
}
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
main().catch(console.error);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
||||
import type {
|
||||
CallToolResult,
|
||||
|
|
@ -175,11 +176,17 @@ const server = new McpServer({
|
|||
);
|
||||
}
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
async function main() {
|
||||
if (process.argv.includes("--stdio")) {
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
console.error("System Monitor Server running in stdio mode");
|
||||
} else {
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
app.post("/mcp", async (req: Request, res: Response) => {
|
||||
app.post("/mcp", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const transport = new StreamableHTTPServerTransport({
|
||||
sessionIdGenerator: undefined,
|
||||
|
|
@ -202,21 +209,25 @@ app.post("/mcp", async (req: Request, res: Response) => {
|
|||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const httpServer = app.listen(PORT, () => {
|
||||
const httpServer = app.listen(PORT, () => {
|
||||
console.log(
|
||||
`System Monitor Server listening on http://localhost:${PORT}/mcp`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function shutdown() {
|
||||
function shutdown() {
|
||||
console.log("\nShutting down...");
|
||||
httpServer.close(() => {
|
||||
console.log("Server closed");
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
}
|
||||
}
|
||||
|
||||
process.on("SIGINT", shutdown);
|
||||
process.on("SIGTERM", shutdown);
|
||||
main().catch(console.error);
|
||||
|
|
|
|||
Loading…
Reference in a new issue