MCP Framework
MCP-Framework is a TypeScript-first development framework designed for building Model Context Protocol (MCP) servers with reduced boilerplate compared to the official SDK. Currently at version 0.2.22, the package maintains a rapid release cadence, with multiple minor versions published frequently, indicating active and ongoing development towards its 1.0 stable release. Key differentiators include CLI scaffolding for quick project setup, an elegant class-based approach for defining tools, resources, and prompts, and integrated Zod validation for schemas. It offers built-in authentication mechanisms (JWT, API Key, OAuth 2.1) and supports multiple transports like stdio, SSE, and HTTP Stream, with explicit support for serverless environments like AWS Lambda. The framework focuses on automatic discovery and loading of server components, providing full type inference and simplifying complex AI agent integrations.
Common errors
-
Error: Tool validation failed: Missing description for field 'fieldName' in tool 'toolName'.
cause A Zod schema property (e.g., in `inputSchema` or `outputSchema`) within a class-based tool lacks a `.describe('Your description here')` call, which is required for proper tool documentation and AI agent understanding.fixModify the Zod schema definition for the specified tool to include a `.describe()` call for every field, e.g., `z.string().describe('A description of what this field represents.')`. -
ERR_REQUIRE_ESM: require() of ES Module ... Not supported
cause Attempting to import `mcp-framework` or its sub-packages using CommonJS `require()` syntax in a project that is configured for ES Modules, or trying to import an ESM-only module into a CommonJS environment.fixEnsure your Node.js project is configured for ES Modules (by adding `"type": "module"` to `package.json` or using `.mjs` file extensions) and exclusively uses `import ... from 'mcp-framework'` syntax. If sticking with CommonJS, ensure compatibility or use an older version if available.
Warnings
- gotcha The package is currently in a 0.x.x version series (0.2.22), indicating that the API may not yet be stable. While frequent updates are provided, users should be prepared for potential breaking changes between minor versions as the project evolves towards a 1.0 release.
- gotcha When using `mcp create` with the `--http` and `--cors` flags for HTTP transport, the server defaults to setting `Access-Control-Allow-Origin: *`. This wildcard CORS policy is suitable for development but is a significant security risk in production environments as it allows any domain to make cross-origin requests.
- gotcha The framework includes comprehensive tool validation, which runs automatically during `npm run build` and can be run standalone via `mcp validate`. Skipping this validation (`MCP_SKIP_TOOL_VALIDATION=true`) is not recommended as it can lead to improperly documented or functionally incorrect tools, hindering AI agent interaction and potentially causing runtime errors.
Install
-
npm install mcp-framework -
yarn add mcp-framework -
pnpm add mcp-framework
Imports
- McpServer
const { McpServer } = require('mcp-framework')import { McpServer } from 'mcp-framework' - Tool, tool
import Tool from 'mcp-framework/tool'
import { Tool, tool } from '@mcp-framework/core' - createLambdaHandler
import { createLambdaHandler } from 'mcp-framework'
Quickstart
npm install -g mcp-framework
# Create a new MCP server project (default uses stdio transport)
mcp create my-mcp-server
# Navigate to your project directory
cd my-mcp-server
# Install project dependencies
npm install
# Add a new tool to your project
mcp add tool price-fetcher
# Open src/tools/price-fetcher.ts and define your tool logic using Zod for schema validation:
// import { Tool, tool } from '@mcp-framework/core';
// import { z } from 'zod';
//
// @tool({
// name: 'fetchStockPrice',
// description: 'Fetches the current stock price for a given ticker symbol.',
// inputSchema: z.object({
// ticker: z.string().describe('The stock ticker symbol (e.g., AAPL).'),
// }),
// outputSchema: z.object({
// price: z.number().describe('The current stock price.'),
// currency: z.string().describe('The currency of the price.'),
// }),
// })
// export class PriceFetcherTool extends Tool<typeof PriceFetcherTool> {
// async execute({ ticker }: z.infer<typeof PriceFetcherTool.inputSchema>) {
// // In a real application, this would call an external API
// console.log(`Fetching price for ${ticker}...`);
// const price = Math.random() * 1000 + 10;
// return { price: parseFloat(price.toFixed(2)), currency: 'USD' };
// }
// }
# Build and run your server
npm run build
npm start