Skip to content

Commit 8b40da7

Browse files
chore(mcp): refactor streamable http transport
1 parent 870995a commit 8b40da7

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

packages/mcp-server/src/http.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
13
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
24
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
35

@@ -67,19 +69,31 @@ const del = async (req: express.Request, res: express.Response) => {
6769
});
6870
};
6971

70-
export const launchStreamableHTTPServer = async (
71-
options: McpOptions,
72-
endpoints: Endpoint[],
73-
port: number | undefined,
74-
) => {
72+
export const streamableHTTPApp = (options: McpOptions) => {
7573
const app = express();
7674
app.use(express.json());
7775

7876
app.get('/', get);
7977
app.post('/', post(options));
8078
app.delete('/', del);
8179

82-
console.error(`MCP Server running on streamable HTTP on port ${port}`);
80+
return app;
81+
};
82+
83+
export const launchStreamableHTTPServer = async (
84+
options: McpOptions,
85+
endpoints: Endpoint[],
86+
port: number | undefined,
87+
) => {
88+
const app = streamableHTTPApp(options);
89+
const server = app.listen(port);
90+
const address = server.address();
8391

84-
app.listen(port);
92+
if (typeof address === 'string') {
93+
console.error(`MCP Server running on streamable HTTP at ${address}`);
94+
} else if (address !== null) {
95+
console.error(`MCP Server running on streamable HTTP on port ${address.port}`);
96+
} else {
97+
console.error(`MCP Server running on streamable HTTP on port ${port}`);
98+
}
8599
};

0 commit comments

Comments
 (0)