[v2] Decouple server from express and hono - http framework-agnostic MCP server (#1326)
This commit is contained in:
parent
5ce4b5ef08
commit
f495077e08
1 changed files with 8193 additions and 15757 deletions
|
|
@ -14,8 +14,10 @@
|
|||
*/
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
import { createMcpExpressApp } from '@modelcontextprotocol/express';
|
||||
import { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';
|
||||
import type { CallToolResult } from '@modelcontextprotocol/server';
|
||||
import { createMcpExpressApp, McpServer, StreamableHTTPServerTransport } from '@modelcontextprotocol/server';
|
||||
import { McpServer } from '@modelcontextprotocol/server';
|
||||
import cors from 'cors';
|
||||
import type { Request, Response } from 'express';
|
||||
|
||||
|
|
@ -111,7 +113,7 @@ app.use(cors());
|
|||
const eventStore = new InMemoryEventStore();
|
||||
|
||||
// Track transports by session ID for session reuse
|
||||
const transports = new Map<string, StreamableHTTPServerTransport>();
|
||||
const transports = new Map<string, NodeStreamableHTTPServerTransport>();
|
||||
|
||||
// Handle all MCP requests
|
||||
app.all('/mcp', async (req: Request, res: Response) => {
|
||||
|
|
@ -121,7 +123,7 @@ app.all('/mcp', async (req: Request, res: Response) => {
|
|||
let transport = sessionId ? transports.get(sessionId) : undefined;
|
||||
|
||||
if (!transport) {
|
||||
transport = new StreamableHTTPServerTransport({
|
||||
transport = new NodeStreamableHTTPServerTransport({
|
||||
sessionIdGenerator: () => randomUUID(),
|
||||
eventStore,
|
||||
retryInterval: 2000, // Default retry interval for priming events
|
||||
|
|
|
|||
Loading…
Reference in a new issue