When to Use This Approach
Choose TypeScript with Smithery CLI when you:- Want the simplest migration path from STDIO to HTTP
- Are using the official MCP SDK and don’t need custom middleware
- Want Smithery to handle containerization and deployment
- Want to maintain backward compatibility with STDIO transport
- Need a fully featured interactive development playground for testing
Show me the repo
View the fully runnable GitHub repo for this example
What We’re Building
We’ll build a simple MCP server with acount_characters
tool that:
- Takes text input and counts occurrences of a specific character
- Validates an API key from Smithery configuration to demonstrate configuration handling
- Uses Smithery CLI for building the server and containerization
- Supports both HTTP and STDIO transport
Code Migration
Let’s say you start with this…
Here’s a typical STDIO-based MCP server that you might be starting with:Step 1: Update Imports and Configuration Schema
Now let’s migrate this to work with Smithery CLI. First, update your imports and define your configuration schema:Configuration is Optional: If your MCP server doesn’t need any configuration (API keys, settings, etc.), you can remove all the config schema and validation code. The server will work perfectly fine without it.
Step 2: Create Server Function and Register Tools
Create the exported server function that Smithery CLI will use:Step 3: Maintaining STDIO Compatibility (Optional)
Now that we have ourcreateServer
function ready for Smithery CLI, we can optionally add STDIO support for backward compatibility. This gives you the best of both worlds:
- HTTP deployment: Smithery CLI uses your exported
createServer
function for scalable HTTP deployment - Local development: Keep the familiar STDIO transport for backwards compatibility
- NPM distribution: Publish your server so others can install and run it locally
main()
function at the bottom of your file:
How it works: When you deploy with Smithery CLI, it imports and uses your exported
createServer
function for HTTP transport. The main()
function only runs when you execute the file directly (like node dist/index.js
), giving you STDIO support for local development.Configuration Changes
Step 4: Update package.json
Configurepackage.json
so Smithery CLI can find your exported server and add scripts for both HTTP and STDIO workflows:
module
field tells Smithery CLI where to find your exported server function.
Script explanations:
dev
: Start development server with interactive playgroundbuild
: Build for production (defaults to HTTP)build:stdio
: Compile TypeScript for STDIO usagebuild:http
: Build for Smithery HTTP deploymentstart
: Start production server (defaults to HTTP)start:http
: Run the Smithery-built HTTP serverstart:stdio
: Run the compiled STDIO version locallyprepublishOnly
: Ensure STDIO build before publishing to npm
Step 5: Update smithery.yaml
No Dockerfile needed: Unlike custom container deployments, TypeScript projects using Smithery CLI don’t require a Dockerfile. The CLI handles containerization automatically.
Install the CLI locally with:Add your SDK dependency explicitly:
Local Testing
-
Using Smithery Interactive Playground:
The
npm run dev
command opens the Smithery interactive playground where you can:- Test your MCP server tools in real-time
- See tool responses and debug issues
- Validate your configuration schema
- Experiment with different inputs
-
Building for Production:
This compiles your TypeScript code and prepares it for deployment on Smithery.
-
Testing STDIO mode locally:
Deployment
- Push Code: Push your updated code (including updated
package.json
andsmithery.yaml
) to GitHub - Deploy: Go to smithery.ai/new and connect your GitHub repository
- Verify: Test your deployed server through the Smithery interface
Summary
This guide showed how to migrate a TypeScript MCP server from STDIO to HTTP transport using Smithery CLI. We transformed a traditional STDIO server into an exportedcreateServer
function using the official McpServer
from the SDK, configured session handling with Zod, and updated package.json
and smithery.yaml
for automatic containerization. This approach provides the simplest migration path while supporting both HTTP deployment through Smithery CLI and optional STDIO backward compatibility.
Need help? Join our Discord or email support@smithery.ai for assistance.