MCPServer Class API Reference
Complete API reference for the MCPServer class in mcp-framework — configure, initialize, and run MCP servers with auto-discovery, transport selection, and authentication.
Published: 2026-04-01
title: "MCPServer Class API Reference" description: "Complete API reference for the MCPServer class in mcp-framework — configure, initialize, and run MCP servers with auto-discovery, transport selection, and authentication." order: 5 keywords: ["MCPServer", "MCP server", "mcp-framework server", "server configuration", "MCP transport", "server API"] date: "2026-04-01"
The MCPServer class is the entry point for every mcp-framework application. It handles server initialization, component auto-discovery, transport setup, and lifecycle management. Created by @QuantGeekDev (Alex Andrushevich) as part of mcp-framework — 3.3M+ npm downloads, 145 releases, officially on Anthropic's MCP servers repository.
Overview
The main server class that bootstraps an MCP server. It auto-discovers tools, resources, and prompts from their respective directories, configures the transport layer, and starts listening for client connections. Most projects use the default configuration and only need a single new MCPServer() call.
Basic Usage
The simplest possible MCP server entry point:
import { MCPServer } from "mcp-framework";
const server = new MCPServer();
server.start();
This uses all defaults: stdio transport, auto-discovery from src/tools/, src/resources/, and src/prompts/.
Constructor
new MCPServer(options?: MCPServerOptions)
MCPServerOptions
interface MCPServerOptions {
name?: string;
version?: string;
transport?: TransportConfig;
basePath?: string;
}
| Option | Type | Default | Description |
|---|---|---|---|
| name | string | Package name from package.json | Server name reported to MCP clients during initialization. |
| version | string | Package version from package.json | Server version reported to clients. |
| transport | TransportConfig | { type: 'stdio' } | Transport configuration. See Transport Configuration reference. |
| basePath | string | Process working directory | Base directory for auto-discovering tools, resources, and prompts. |
Configuration Examples
Default stdio Server
import { MCPServer } from "mcp-framework";
const server = new MCPServer();
server.start();
Named Server with Version
import { MCPServer } from "mcp-framework";
const server = new MCPServer({
name: "my-analytics-server",
version: "2.1.0",
});
server.start();
SSE Transport
import { MCPServer } from "mcp-framework";
const server = new MCPServer({
transport: {
type: "sse",
options: {
port: 8080,
cors: {
allowOrigins: ["https://myapp.com"],
},
},
},
});
server.start();
SSE with Authentication
import { MCPServer } from "mcp-framework";
const server = new MCPServer({
transport: {
type: "sse",
options: {
port: 8080,
auth: {
type: "jwt",
options: {
secret: process.env.JWT_SECRET!,
algorithms: ["HS256"],
},
},
},
},
});
server.start();
Methods
start()
Starts the MCP server, initializes the transport, and begins listening for client connections.
async start(): Promise<void>
This method:
- Scans directories for tools, resources, and prompts
- Registers all discovered components with the MCP protocol handler
- Initializes the configured transport (stdio or SSE)
- Begins accepting client connections
For stdio transport, start() immediately begins reading from stdin. For SSE transport, it starts an HTTP server on the configured port.
Auto-Discovery
MCPServer automatically discovers and registers components from:
Each .ts file in these directories must have a default export of the appropriate class (MCPTool, MCPResource, or MCPPrompt). The framework:
- Scans each directory recursively
- Imports each file dynamically
- Validates the default export
- Registers the component with the protocol handler
Keep the standard directory structure (src/tools/, src/resources/, src/prompts/). The CLI scaffolding creates this structure automatically. If you need to organize further, you can nest subdirectories — discovery is recursive.
Lifecycle
new MCPServer(options)
│
▼
server.start()
│
├── Scan src/tools/
├── Scan src/resources/
├── Scan src/prompts/
│
├── Register all components
│
├── Initialize transport
│ ├── stdio: Read from stdin, write to stdout
│ └── SSE: Start HTTP server on configured port
│
└── Accept client connections
Entry Point Pattern
The standard entry point (src/index.ts) generated by the CLI:
import { MCPServer } from "mcp-framework";
const server = new MCPServer();
server.start().catch((error) => {
console.error("Server failed to start:", error);
process.exit(1);
});
Always include error handling around server.start(). If auto-discovery fails (e.g., a tool file has a syntax error), the error will be thrown here.
Environment Configuration
Common patterns for configuring the server based on environment:
import { MCPServer } from "mcp-framework";
const isDev = process.env.NODE_ENV === "development";
const server = new MCPServer({
transport: isDev
? { type: "sse", options: { port: 3001 } }
: { type: "stdio" },
});
server.start();