Uh oh!
There was an error while loading. Please reload this page.
Refactor server start in examples - #229
Closed
jonathanhefner wants to merge 1 commit into
Closed
Conversation
Split server startup logic into two functions in each `server-utils.ts`:
- `startStdioServer(createServer)` - handles stdio transport
- `startHttpServer(createServer)` - handles HTTP transport
And keep the transport selection visible in each `server.ts`:
```typescript
process.argv.includes("--stdio")
? await startStdioServer(createServer)
: await startHttpServer(createServer);
```
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>@modelcontextprotocol/ext-apps@modelcontextprotocol/server-basic-react@modelcontextprotocol/server-basic-vanillajs@modelcontextprotocol/server-budget-allocator@modelcontextprotocol/server-cohort-heatmap@modelcontextprotocol/server-customer-segmentation@modelcontextprotocol/server-scenario-modeler@modelcontextprotocol/server-system-monitor@modelcontextprotocol/server-threejs@modelcontextprotocol/server-wiki-explorercommit: |
ochafik
reviewed
Jan 11, 2026
| options: ServerOptions, | ||
| ): Promise<void> { | ||
| const { port, name = "MCP Server" } = options; | ||
| const port = parseInt(process.env.PORT ?? "3001", 10); |
Contributor
There was a problem hiding this comment.
This introduces process.env again in server-utils, I don't like this direction tbh
And the startStdioServer method is a lot of lines to replace a one-liner.
MemberAuthor
There was a problem hiding this comment.
This introduces process.env again in server-utils, I don't like this direction tbh
The PORT env variable is very widely used, so reading from wherever in the code base is pretty typical for web servers.
And the startStdioServer method is a lot of lines to replace a one-liner.
The intent is instant clarity. Compare:
if(process.argv.includes("--stdio")){awaitcreateServer().connect(newStdioServerTransport());}else{constport=parseInt(process.env.PORT??"3001",10);awaitstartServer(createServer,{ port,name: "Basic MCP App Server (Preact)"});}vs
process.argv.includes("--stdio")
? awaitstartStdioServer(createServer)
: awaitstartHttpServer(createServer);Contributor
There was a problem hiding this comment.
Mmh fair enough won't die on this hill, thanks! ;-)
ochafik
approved these changes
Jan 12, 2026
jonathanhefner
commented
Jan 27, 2026
MemberAuthor
Addressed in #342. |
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
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Split server startup logic into two functions in each
server-utils.ts:startStdioServer(createServer)- handles stdio transportstartHttpServer(createServer)- handles HTTP transportAnd keep the transport selection visible in each
server.ts: