
mcp create express app
一个用于创建支持模型上下文协议(MCP)的 Express 应用程序的工具模块。
Repository Info
About This Server
一个用于创建支持模型上下文协议(MCP)的 Express 应用程序的工具模块。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
MCP Create Express App
A utility module for creating Express applications with Model Context Protocol (MCP) support.
Installation
npm install mcp-create-express-app express
Usage
Stateless Mode
import express from "express";
import createExpressApp from "mcp-create-express-app";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
// Create an MCP server
const server = new McpServer({
name: "my-server",
version: "1.0.0",
});
// Define tools, prompts, and resources
server.tool("greet", { name: "string" }, async ({ name }) => {
return { content: [{ type: "text", text: `Hello, ${name}!` }] };
});
const app = await createExpressApp(server);
// Start the Express server
const port = 3000;
app.listen(port, () => {
console.log(`MCP server available at http://localhost:${port}${mcpPath}`);
});
Stateful Mode
import express from "express";
import { createStateful } from "mcp-client-router/create-express-app";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
// Create an Express app
const app = express();
// Create an MCP server
const server = new McpServer({
name: "my-server",
version: "1.0.0",
});
// Define tools, prompts, and resources
server.tool("greet", { name: "string" }, async ({ name }) => {
return { content: [{ type: "text", text: `Hello, ${name}!` }] };
});
// Mount the MCP server to the Express app with stateful behavior
const mcpPath = "/mcp";
createStateful(app, server, {
path: mcpPath,
sessionTimeout: 300000, // 5 minutes
});
// Start the Express server
const port = 3000;
app.listen(port, () => {
console.log(
`Stateful MCP server available at http://localhost:${port}${mcpPath}`
);
});
API Reference
createStateless
function createStateless(app, server, options)
Creates a stateless HTTP endpoint for an MCP server in an Express app. Each request is treated as independent.
Parameters
app(Express app): The Express applicationserver(McpServer): The MCP server to exposeoptions(object): Configuration optionspath(string): The URL path to mount the MCP server (default: '/mcp')corsOptions(object): CORS configuration options
createStateful
function createStateful(app, server, options)
Creates a stateful HTTP endpoint for an MCP server in an Express app. Maintains session state between requests.
Parameters
app(Express app): The Express applicationserver(McpServer): The MCP server to exposeoptions(object): Configuration optionspath(string): The URL path to mount the MCP server (default: '/mcp')sessionTimeout(number): Session timeout in milliseconds (default: 30 minutes)corsOptions(object): CORS configuration options
License
ISC
Quick Start
Clone the repository
git clone https://github.com/johnhenry/mcp-create-express-appInstall dependencies
cd mcp-create-express-app
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.