-
Notifications
You must be signed in to change notification settings - Fork 202
Update http-server.ts #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
potato-aesthetic-cyber
wants to merge
1
commit into
mastanley13:main
Choose a base branch
from
potato-aesthetic-cyber:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
MCP SDK StreamableHTTPServerTransport stateless mode server.connect pattern💡 Result:
In the MCP TypeScript SDK Streamable HTTP server transport, “stateless mode” is enabled by constructing the transport with sessionIdGenerator set to undefined; in that mode no Mcp-Session-Id/session validation is used. [1][2] 1) How server.connect fits the pattern - You still use the normal MCP pattern: create an McpServer, create a StreamableHTTPServerTransport (NodeStreamableHTTPServerTransport or WebStandardStreamableHTTPServerTransport), and attach it with server.connect(transport). The SDK explicitly describes connect(transport) as “Attaches to the given transport, starts it, and starts listening for messages.” [3][4] 2) What “stateless mode” changes for request handling - Stateful mode: the transport generates/uses a session id, includes it in responses (including initialization), and rejects requests with invalid/missing session ids. [5][6] - Stateless mode: no session id is included in any responses and “No session validation is performed.” [7][5] Practical consequence: because connections/messages are managed per-request, Streamable HTTP transport start is a no-op (“connections are managed per-request”). [1] 3) The server.connect + stateless server “pattern” - Create the transport with sessionIdGenerator: undefined (this signals stateless mode) and then call server.connect(transport) once per server instance. [1][4] - Then route incoming HTTP requests to transport.handleRequest(...). In the SDK’s stateless example, the server.connect(transport) call happens inside the HTTP route handler before calling transport.handleRequest(req, res, req.body), and cleanup happens on request close. [8] 4) Minimal TypeScript shape (Node.js) - Stateless transport: set sessionIdGenerator to undefined. [1][4] - Connect the MCP server: await server.connect(transport). [4][3] - Handle each HTTP request with transport.handleRequest(...). [8][1] Example (structurally matching the SDK example): - const transport = new NodeStreamableHTTPServerTransport({ sessionIdGenerator: undefined }); - await server.connect(transport); - await transport.handleRequest(req, res, req.body); 5) “server.connect pattern” with stateless and multiple requests - Because stateless mode doesn’t include/validate a Mcp-Session-Id, you should treat each HTTP request independently (no reusable session-based transport state). The transport/session-id generator behavior is what drives this. [7][5] Caveat (important): - Some SDK versions/history discussed issues around stateless behavior and reusing initialized transport state; the recommended approach in the current examples is to create/connect the right transport context for handling the request, and then close/cleanup after the request. [9][8] Bottom line: For StreamableHTTPServerTransport/NodeStreamableHTTPServerTransport stateless mode, “stateless” = sessionIdGenerator undefined (no Mcp-Session-Id, no session validation), while the overall server.connect attachment pattern stays the same: server.connect(transport) + per-request transport.handleRequest(...). [1][5][4][8]
Citations:
🏁 Script executed:
Repository: mastanley13/GoHighLevel-MCP
Length of output: 53
🏁 Script executed:
Repository: mastanley13/GoHighLevel-MCP
Length of output: 1161
🏁 Script executed:
Repository: mastanley13/GoHighLevel-MCP
Length of output: 1058
🏁 Script executed:
Repository: mastanley13/GoHighLevel-MCP
Length of output: 936
🏁 Script executed:
Repository: mastanley13/GoHighLevel-MCP
Length of output: 1805
🌐 Web query:
StreamableHTTPServerTransport close cleanup resource management per-request💡 Result:
In the Model Context Protocol (MCP) SDKs, StreamableHTTPServerTransport manages resources through both transport-level lifecycle methods and granular per-request cleanup mechanisms [1][2][3][4]. Per-request resource management is primarily handled via SSE stream management [3][4]: - Request-specific cleanup: The transport provides methods such as closeSSEStream(requestId) (in TypeScript) or closeSseStream(requestId) (in Kotlin), which close the specific SSE stream associated with a request [1][2][3][4]. This action triggers client reconnection, which is often used to implement polling behavior for long-running operations [1][2][3][4]. - Internal Mapping: The transport maintains internal mappings (e.g., _requestToStreamMapping and _streamMapping) to track and clean up these individual stream resources when requested or when an error occurs [3][4]. Lifecycle and Session management: - Transport-level close: The close method shuts down the transport and all its active connections [1]. This is used for broader resource reclamation, such as during server shutdown [5]. - Session-level cleanup: The transport supports an onsessionclosed callback, which is invoked when a session is closed (e.g., via an HTTP DELETE request) [3][4][6]. This callback is specifically designed for developers to perform custom cleanup of resources associated with a particular session [2][3][4]. - Distinction: It is important to distinguish between closing a transport and closing a session; for instance, if handling HTTP requests from multiple nodes, one might close a specific StreamableHTTPServerTransport instance after a single request finishes, while keeping the broader session active [2][3][4]. In practice, developers should leverage the onsessionclosed callback for session-associated resource management and use the provided SSE stream closing methods for granular, per-request stream control [2][3][4].
Citations:
Add explicit cleanup after handling stateless HTTP requests.
The
/mcpPOST and GET endpoints callserver.connect(transport)on each request but do not clean up the transport resources afterward. While the pattern of callingconnect()per-request is documented in the MCP SDK examples for stateless mode, the SDK also expects explicit resource management—either by callingtransport.close()afterhandleRequest()completes or by leveraging theonsessionclosedcallback for cleanup.Without cleanup, repeated calls to
server.connect()without releasing the previous transport may accumulate internal transport state and connections, leading to resource leaks or undefined behavior in the MCP Server instance.Add
await transport.close()aftertransport.handleRequest()completes in both handlers, or implement proper session lifecycle management using the SDK's cleanup callbacks.🤖 Prompt for AI Agents