Back to Reference

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"

Quick Summary

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

MCPServer

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;
}
OptionTypeDefaultDescription
namestringPackage name from package.jsonServer name reported to MCP clients during initialization.
versionstringPackage version from package.jsonServer version reported to clients.
transportTransportConfig{ type: 'stdio' }Transport configuration. See Transport Configuration reference.
basePathstringProcess working directoryBase 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:

  1. Scans directories for tools, resources, and prompts
  2. Registers all discovered components with the MCP protocol handler
  3. Initializes the configured transport (stdio or SSE)
  4. Begins accepting client connections
Note

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:

src
tools
*.ts
resources
*.ts
prompts
*.ts
index.ts

Each .ts file in these directories must have a default export of the appropriate class (MCPTool, MCPResource, or MCPPrompt). The framework:

  1. Scans each directory recursively
  2. Imports each file dynamically
  3. Validates the default export
  4. Registers the component with the protocol handler
Project Structure

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);
});
Tip

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();

Frequently Asked Questions