MCP is a framework for building Model Context Protocol (MCP) servers elegantly in TypeScript.
MCP-Framework gives you architecture out of the box, with automatic directory-based discovery for tools, resources, and prompts. Use our powerful MCP abstractions to define tools, resources, or prompts in an elegant way. Our cli makes getting started with your own MCP server a breeze
Get started fast with mcp-framework ⚡⚡⚡
- 🛠️ Automatic directory-based discovery and loading for tools, prompts, and resources
- 🏗️ Powerful abstractions with full type safety
- 🚀 Simple server setup and configuration
- 📦 CLI for rapid development and project scaffolding
# Install the framework globally
npm install -g mcp-framework
# Create a new MCP server project
mcp create my-mcp-server
# Navigate to your project
cd my-mcp-server
# Your server is ready to use!
npm install mcp-framework
The framework provides a powerful CLI for managing your MCP server projects:
# Create a new project
mcp create <your project name here>
# Add a new tool
mcp add tool price-fetcher
# Add a new prompt
mcp add prompt price-analysis
# Add a new prompt
mcp add resource market-data
- Create your project:
mcp create my-mcp-server
cd my-mcp-server
-
Add tools as needed:
mcp add tool data-fetcher mcp add tool data-processor mcp add tool report-generator
-
Build:
npm run build
-
Add to MCP Client (Read below for Claude Desktop example)
Add this configuration to your Claude Desktop config file:
MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json` Windows: `%APPDATA%/Claude/claude_desktop_config.json`
{
"mcpServers": {
"${projectName}": {
"command": "node",
"args":["/absolute/path/to/${projectName}/dist/index.js"]
}
}
}
Add this configuration to your Claude Desktop config file:
MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json` Windows: `%APPDATA%/Claude/claude_desktop_config.json`
{
"mcpServers": {
"${projectName}": {
"command": "npx",
"args": ["${projectName}"]
}
}
}
- Make changes to your tools
- Run `npm run build` to compile
- The server will automatically load your tools on startup
Tools are the primary way to extend an LLM's capabilities. Each tool should perform a specific function:
import { MCPTool } from "mcp-framework";
import { z } from "zod";
interface ExampleInput {
message: string;
}
class ExampleTool extends MCPTool<ExampleInput> {
name = "example_tool";
description = "An example tool that processes messages";
schema = {
message: {
type: z.string(),
description: "Message to process",
},
};
async execute(input: ExampleInput) {
return `Processed: ${input.message}`;
}
}
export default ExampleTool;
Prompts help structure conversations with Claude:
import { MCPPrompt } from "mcp-framework";
import { z } from "zod";
interface GreetingInput {
name: string;
language?: string;
}
class GreetingPrompt extends MCPPrompt<GreetingInput> {
name = "greeting";
description = "Generate a greeting in different languages";
schema = {
name: {
type: z.string(),
description: "Name to greet",
required: true,
},
language: {
type: z.string().optional(),
description: "Language for greeting",
required: false,
},
};
async generateMessages({ name, language = "English" }: GreetingInput) {
return [
{
role: "user",
content: {
type: "text",
text: `Generate a greeting for ${name} in ${language}`,
},
},
];
}
}
export default GreetingPrompt;
Resources provide data access capabilities:
import { MCPResource, ResourceContent } from "mcp-framework";
class ConfigResource extends MCPResource {
uri = "config://app/settings";
name = "Application Settings";
description = "Current application configuration";
mimeType = "application/json";
async read(): Promise<ResourceContent[]> {
const config = {
theme: "dark",
language: "en",
};
return [
{
uri: this.uri,
mimeType: this.mimeType,
text: JSON.stringify(config, null, 2),
},
];
}
}
export default ConfigResource;
your-project/
├── src/
│ ├── tools/ # Tool implementations (Required)
│ │ └── ExampleTool.ts
│ ├── prompts/ # Prompt implementations (Optional)
│ │ └── GreetingPrompt.ts
│ ├── resources/ # Resource implementations (Optional)
│ │ └── ConfigResource.ts
│ └── index.ts
├── package.json
└── tsconfig.json
The framework automatically discovers and loads:
- Tools from the
src/tools
directory - Prompts from the
src/prompts
directory (if present) - Resources from the
src/resources
directory (if present)
Each feature should be in its own file and export a default class that extends the appropriate base class:
MCPTool
for toolsMCPPrompt
for promptsMCPResource
for resources
- Handles input validation using Zod
- Provides error handling and response formatting
- Includes fetch helper for HTTP requests
- Manages prompt arguments and validation
- Generates message sequences for LLM interactions
- Supports dynamic prompt templates
- Exposes data through URI-based system
- Supports text and binary content
- Optional subscription capabilities for real-time updates
All features use Zod for runtime type validation and TypeScript for compile-time type checking. Define your input schemas using Zod types:
schema = {
parameter: {
type: z.string().email(),
description: "User email address",
},
count: {
type: z.number().min(1).max(100),
description: "Number of items",
},
};
MIT