Learn how to build MCP servers from your API specifications using Speakeasy for production-ready servers with extensive customization options.
Getting started with Speakeasy
To build an MCP server using Speakeasy:
Install the Speakeasy CLI:
Run Speakeasy quickstart:
Indicate whether you plan to deploy your server on Cloudflare:
Cloudflare is a popular choice for hosting MCP servers. If selected, a Cloudflare Worker config file will be generated with your MCP server code. This will make deploying your server to Cloudflare Worker easy.
This creates a TypeScript-based MCP server in the specified directory ready to be deployed into production.
Example server code
The generated MCP server includes a comprehensive file structure with TypeScript source code:
core.ts
build.mts
cli.ts
console-logger.ts
extensions.ts
mcp-server.ts
prompts.ts
resources.ts
scopes.ts
server.ts
shared.ts
tools.ts
Run your MCP server locally
Local Development Setup
For local development and debugging, you can run your MCP server directly from the generated code:
This configuration allows you to:
Debug your server code directly
Make real-time changes during development
Test API integrations locally
Validate tool functionality before distribution
Testing with Published Package
Once you’ve published your MCP server to npm (following our SDK Publishing Guide), you can test using the npm package format that will be used in production:
Note: You must first publish your package to npm before you can test it using this configuration.
Using the Generated DXT
For the most user-friendly testing experience, use the generated DXT package. Claude Desktop and other MCP clients can load DXT files directly:
Locate your generated DXT file in the output directory (typically with a .dxt extension)
Install the DXT in your MCP client following the client’s installation process
Configure environment variables if your server requires authentication
Advanced configuration
Specify scopes at runtime
When starting the MCP server, you can specify which scopes to include:
This example configuration only mounts tools tagged with the read scope, creating a read-only server.
Specify individual tools
You can further limit the subset of tools mounted on an MCP server by specifying individual tool names:
Distribution and hosting options
Speakeasy generates MCP servers with three primary distribution methods. These methods are not mutually exclusive - most customers use all three approaches to serve different use cases, with npm being the most common starting point:
1. Distribute on npm
Publishing your MCP server as an npm package provides the most flexible distribution method. Follow the SDK publishing guide for detailed instructions on publishing to npm and other package managers.
Benefits:
Universal compatibility: Single command works with all major MCP clients
Easy customization: Users can modify tools, add tools, and extend functionality
Version management: Standard npm versioning and dependency management
Team sharing: Simple distribution across development teams
Usage:
2. Host on Cloudflare Workers
Cloudflare hosting enables OAuth authentication flows and eliminates the need for users to manage API keys directly:
Benefits:
OAuth support: End-users authenticate through OAuth instead of providing API keys
Serverless hosting: No infrastructure management required
Global distribution: Cloudflare’s edge network for low latency
Same customization: Full tool customization capabilities available
A manifest.json file with metadata describing your MCP server
All necessary server files packaged for distribution
Tool descriptions and parameters automatically inferred from your OpenAPI specification
Icon and branding assets (if provided)
DXT Customization:
You can customize the generated DXT manifest through the gen.yaml configuration file:
Hybrid Distribution Strategy
You can use all three distribution methods simultaneously, giving users flexibility to choose their preferred installation method based on their specific needs and technical requirements.