Skip to content

fix(sample-servers): use factory function for MCP server in stateless mode#48

Merged
xiaoyijun merged 1 commit intomasterfrom
xiaoyijun-fix-stateless-transport
Jan 24, 2026
Merged

fix(sample-servers): use factory function for MCP server in stateless mode#48
xiaoyijun merged 1 commit intomasterfrom
xiaoyijun-fix-stateless-transport

Conversation

@xiaoyijun
Copy link
Copy Markdown
Contributor

Summary

Fix the transport handling issue in sample-servers.

Problem: The original code used a singleton McpServer instance but called server.connect(transport) on every POST request. This is incorrect because in stateless mode, each request should have its own isolated server instance.

Solution: Following the MCP SDK's official simpleStatelessStreamableHttp.js example, use a factory function createMcpServer() to create a new server instance for each request.

Changes in todo-manager/index.ts:

  • Wrap McpServer creation and tool registration in a createMcpServer() factory function
  • Call createMcpServer() in each POST request handler
  • Add mcpServer.close() cleanup in the response close handler

Changes in whoami/index.ts and whoami/index.js:

  • Same pattern applied

Testing

N/A

Checklist

  • .changeset
  • unit tests
  • integration tests
  • necessary TSDoc comments

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@xiaoyijun xiaoyijun requested a review from a team January 24, 2026 00:59
@xiaoyijun xiaoyijun self-assigned this Jan 24, 2026
@xiaoyijun xiaoyijun merged commit 7ffcb25 into master Jan 24, 2026
5 checks passed
@xiaoyijun xiaoyijun deleted the xiaoyijun-fix-stateless-transport branch January 24, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants