MCP cover image
See in Github
2025-01-28

Un SDK de TypeScript para ejecutar servidores MCP (protocolo de contexto del modelo) con capacidades de reutilización de procesos

1

Github Watches

2

Github Forks

5

Github Stars

mcp-runner

A TypeScript SDK and CLI for running MCP (Model Context Protocol) servers.

Overview

mcp-runner is designed to facilitate the execution of MCP servers based on configurations defined in cline_mcp_settings.json. It supports reusable server processes and controlled cleanup, allowing multiple operations to be performed using the same server instance.

You can call it from the command line or use it as a library in your own TypeScript projects or even from other MCP servers.

Features

  • Server process reuse across multiple calls
  • Graceful termination with timeout handling
  • Automatic server lifecycle management
  • TypeScript support
  • Error handling and logging

Installation

npm install

CLI Usage

The package includes a command-line interface for interacting with MCP servers.

Commands

List Tools

Lists all available tools for a specified MCP server:

npm run cli -- list-tools <server-name>

Example:

npm run cli -- list-tools sequential-thinking

Run Server

Runs a specified MCP server with optional tool name and parameters:

npm run cli -- runserver <server-name> [tool-name] [params] [options]
# or
npm run cli -- runserver <server-name> [params] [options] # uses first available tool

Options:

  • --text: Output only the text content from the response instead of the full JSON

Examples:

# Run a specific tool
npm run cli -- runserver sequential-thinking sequentialthinking '{"thought": "Initial thought", "thoughtNumber": 1, "totalThoughts": 5, "nextThoughtNeeded": true}'

# Use first available tool
npm run cli -- runserver sequential-thinking '{"thought": "Initial thought", "thoughtNumber": 1, "totalThoughts": 5, "nextThoughtNeeded": true}'

# Output only text content
npm run cli -- runserver sequential-thinking sequentialthinking '{"thought": "Initial thought", "thoughtNumber": 1, "totalThoughts": 1}' --text

Programmatic Usage

Basic Example

import { runServer, terminateServer } from 'mcp-runner';

async function main() {
  try {
    // First call (specific tool)
    const result1 = await runServer('openrouterai', 'chat_completion', {
      messages: [
        { role: 'user', content: 'Say hello!' }
      ]
    });
    console.log('Result 1:', result1);

    // Second call (uses first available tool)
    const result2 = await runServer('openrouterai', undefined, {
      messages: [
        { role: 'user', content: 'How are you?' }
      ]
    });
    console.log('Result 2:', result2);

    // Terminate server when done
    await terminateServer();
  } catch (error) {
    console.error('Error:', error);
    await terminateServer();
  }
}

Error Handling

The SDK includes comprehensive error handling:

  • Server process errors
  • Tool execution errors
  • Timeout handling for graceful termination
  • Automatic cleanup on errors

API

runServer(serverName: string, params: Record<string, unknown>)

Runs a tool on the specified server using provided parameters. The server process is reused for subsequent calls until explicitly terminated.

Parameters:

  • serverName: Name of the server from configuration
  • params: Parameters to pass to the server's tool

Returns: Promise resolving with the server's response

terminateServer()

Terminates the server process managed by the SDK. Should be called when all operations are complete.

Returns: Promise that resolves when the server is terminated

Architecture

ServerManager

The ServerManager class is implemented as a singleton that manages the lifecycle of MCP server processes. Key responsibilities include:

  • Process lifecycle management
  • Client connection handling
  • Graceful termination
  • Error handling and logging

The manager ensures that only one server process is running at any given time and provides methods to start, reuse, and terminate the server.

Configuration

The SDK reads server configurations from cline_mcp_settings.json, which should be located in the standard configuration directory. Each server configuration includes:

{
  "command": "string",
  "args": "string[]",
  "env": "Record<string, string>",
  "disabled": "boolean",
  "alwaysAllow": "string[]"
}

Development

Building

npm run build

Running Tests

npm test

License

This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Andris Teikmanis
  • Latvian GPT assistant for developing GPT applications

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://jgadvisorycpa.com
  • This GPT assists in finding a top-rated business CPA - local or virtual. We account for their qualifications, experience, testimonials and reviews. Business operators provide a short description of your business, services wanted, and city or state.

  • Jan Meindl
  • Builds new GPTs

  • Contraband Interactive
  • Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.

  • rustassistant.com
  • Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.

  • apappascs
  • Descubra la colección más completa y actualizada de servidores MCP en el mercado. Este repositorio sirve como un centro centralizado, que ofrece un extenso catálogo de servidores MCP de código abierto y propietarios, completos con características, enlaces de documentación y colaboradores.

  • modelcontextprotocol
  • Servidores de protocolo de contexto modelo

  • Mintplex-Labs
  • La aplicación AI de escritorio todo en uno y Docker con trapo incorporado, agentes de IA, creador de agentes sin código, compatibilidad de MCP y más.

  • ShrimpingIt
  • Manipulación basada en Micrypthon I2C del expansor GPIO de la serie MCP, derivada de AdaFruit_MCP230xx

  • OffchainLabs
  • Implementación de la prueba de estaca Ethereum

  • n8n-io
  • Plataforma de automatización de flujo de trabajo de código justo con capacidades de IA nativas. Combine el edificio visual con código personalizado, auto-anfitrión o nube, más de 400 integraciones.

  • huahuayu
  • Una puerta de enlace de API unificada para integrar múltiples API de explorador de blockchain similar a Esterscan con soporte de protocolo de contexto modelo (MCP) para asistentes de IA.

    Reviews

    1 (1)
    Avatar
    user_VSiKQ7tu
    2025-04-15

    The MCP Time Server by chrishayuk is an exceptional tool for precise time synchronization. Its reliability and ease of use make it a top choice for anyone needing accurate timekeeping. The seamless integration and robust performance are particularly impressive. Highly recommended!