Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1mcp app Agent serveCommand

From Leeroopedia
Knowledge Sources
Domains CLI, MCP_Protocol
Last Updated 2026-10-29 00:00 GMT

Overview

Concrete CLI command for starting the 1MCP aggregated runtime server with HTTP or stdio transport, configuration loading, and optional background supervision.

Description

The serveCommand function is the primary entry point for starting the 1MCP runtime. It parses serve options from yargs (port, host, transport type, auth flags, async loading, preset, filter), initializes the server via `setupServer`, and starts the Express HTTP server or stdio transport. It writes a PID file for runtime scope ownership and supports background mode via `--background`. The command handles graceful shutdown on SIGINT/SIGTERM.

Usage

Import this function when you need to:

  • Start the 1MCP aggregated runtime as a foreground HTTP server
  • Start with stdio transport for direct agent communication
  • Enable authentication, async loading, or preset filtering at startup
  • Run in background mode with `--background`

Code Reference

Source Location

  • Repository: 1MCP Agent
  • File: src/sdk/legacy/commands/serve.ts (L56-336, re-exported via src/commands/serve/serve.ts)

Signature

export interface ServeOptions {
  config?: string;
  'config-dir'?: string;
  transport?: string;
  port?: number;
  host?: string;
  preset?: string;
  filter?: string;
  'enable-async-loading'?: boolean;
  'enable-auth'?: boolean;
  'external-url'?: string;
  'enable-scope-validation'?: boolean;
  'enable-enhanced-security'?: boolean;
  'credential-store'?: 'file' | 'native';
  'session-ttl'?: number;
  'session-storage-path'?: string;
  background?: boolean;
}

export async function serveCommand(parsedArgv: ServeOptions): Promise<void>;

Import

import { serveCommand } from '@src/commands/serve/serve.js';

I/O Contract

Inputs

Name Type Required Description
config string No Config file path
transport string No 'http' or 'stdio'
port number No HTTP port (default: 3000)
host string No HTTP host
enable-async-loading boolean No Non-blocking startup
enable-auth boolean No Enable OAuth 2.1

Outputs

Name Type Description
HTTP server ExpressServer Listening on configured port/host
PID file file Runtime scope ownership record

Usage Examples

Start HTTP Server

1mcp serve --config /path/to/config.json --port 3000
1mcp serve --enable-async-loading --enable-auth --external-url https://my-server.com
1mcp serve --transport stdio
1mcp serve --background

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment