Home / Class/ Server Class — mcp Architecture

Server Class — mcp Architecture

Architecture documentation for the Server class in server.ts from the mcp codebase.

Entity Profile

Dependency Diagram

graph TD
  50dc88e1_e79b_8a97_364b_4502057dd58f["Server"]
  54581714_e921_5e5e_17c6_d2040cdc3b55["server.ts"]
  50dc88e1_e79b_8a97_364b_4502057dd58f -->|defined in| 54581714_e921_5e5e_17c6_d2040cdc3b55
  65787d30_1025_d531_cde5_ded3572607bd["constructor()"]
  50dc88e1_e79b_8a97_364b_4502057dd58f -->|method| 65787d30_1025_d531_cde5_ded3572607bd
  6471f5ca_fcb9_6e5d_af84_17b245dc7c0f["setupHandlers()"]
  50dc88e1_e79b_8a97_364b_4502057dd58f -->|method| 6471f5ca_fcb9_6e5d_af84_17b245dc7c0f
  9d72a623_8b26_a485_5797_5f53c18e4294["start()"]
  50dc88e1_e79b_8a97_364b_4502057dd58f -->|method| 9d72a623_8b26_a485_5797_5f53c18e4294

Relationship Graph

Source Code

src/server.ts lines 47–179

export class Server {
  private server: McpServer;
  private client: ClientContext;
  private defaultWorkdir?: string;
  private options?: ServerOptions;
  constructor(defaultWorkdir?: string, options?: ServerOptions) {
    this.defaultWorkdir = defaultWorkdir;
    this.options = options;
    // Note: noApiFallback is deferred to start() so startup precaching can use the API
    this.server = new McpServer(
      {
        name: 'supermodel_api',
        version: '0.0.1',
      },
      {
        capabilities: { tools: {}, logging: {} },
        instructions: `# Supermodel: Codebase Intelligence

Two tools for instant codebase understanding. Pre-computed graphs enable sub-second responses.

## Recommended workflow
1. \`overview\` first to learn architecture and key symbols (1 call)
2. \`symbol_context\` on 1-2 symbols from the issue to see source, callers, callees (1-2 calls)
3. Stop calling MCP tools. Use the results to make your fix.

## Anti-patterns
- >3 MCP calls total = diminishing returns. Aim for 1 overview + 1-2 symbol lookups.
- Chasing callers-of-callers burns iterations without helping.

## After fixing
Run the project's existing test suite (e.g. pytest). Do NOT write standalone test scripts.

## Tool reference
- \`overview\`: Architecture map, domains, hub functions, file counts. Zero-arg, sub-second.
- \`symbol_context\`: Source, callers, callees, domain for any function/class/method. Supports "Class.method" and partial matching.`,
      },
    );

    const config = new Configuration({
      basePath: process.env.SUPERMODEL_BASE_URL || 'https://api.supermodeltools.com',
      apiKey: process.env.SUPERMODEL_API_KEY,
      fetchApi: fetchWithTimeout,
    });

    logger.debug('Server configuration:');
    logger.debug('Base URL:', config.basePath);
    logger.debug('API Key set:', !!process.env.SUPERMODEL_API_KEY);
    if (this.defaultWorkdir) {
      logger.debug('Default workdir:', this.defaultWorkdir);
    }

    const api = new DefaultApi(config);
    this.client = {
      graphs: new SupermodelClient(api),
    };

    this.setupHandlers();
  }

  private setupHandlers() {
    const allTools = [
      overviewTool,
      symbolContextTool,
    ];

    // Create a map for quick handler lookup
    const toolMap = new Map<string, typeof allTools[0]>();
    for (const t of allTools) {
      if (toolMap.has(t.tool.name)) {
        throw new Error(`Duplicate tool name: ${t.tool.name}`);
      }
      toolMap.set(t.tool.name, t);
    }

    this.server.server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: allTools.map(t => t.tool),
      };
    });

    this.server.server.setRequestHandler(CallToolRequestSchema, async (request) => {

Domain

Defined In

Frequently Asked Questions

What is the Server class?
Server is a class in the mcp codebase, defined in src/server.ts.
Where is Server defined?
Server is defined in src/server.ts at line 47.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free