Cover image
Try Now
2025-03-10

Serverlose Implementierung des Modellkontextprotokolls (MCP)

3 years

Works with Finder

1

Github Watches

3

Github Forks

2

Github Stars

MCP Serverless

A serverless implementation for the Model Context Protocol (MCP) architecture that enables tool management through a clean interface.

Overview

This package provides a serverless implementation of the MCP server that allows you to:

  • Register and manage tools
  • Handle tool-related requests
  • Create in-memory client-server connections
  • Extend request with context to enable credential transmission from clients

Installation

npm install @tilfin/mcp-serverless

Usage

Tool Registration and create a client for service implements

import { createService, ToolManager } from '@tilfin/mcp-serverless';

// Create a tool manager
const toolManager = new ToolManager();

// Register tools
toolManager.registerTools([
  {
    name: 'calculator',
    description: 'Performs basic arithmetic operations',
    inputSchema: {
      type: 'object',
      properties: {
        operation: { type: 'string' },
        numbers: { type: 'array', items: { type: 'number' } }
      },
      required: ['operation', 'numbers']
    },
    toolFunction: async (params, ctx) => {
      if (ctx.apiKey !== 'xyz') throw new Error('Invalid API Key');

      let result;
      if (params.operation === 'add') {
        result = params.numbers.reduce((sum, n) => sum + n, 0);
      }
      return { result };
    }
  }
]);

// Create a serverless client
const client = createService(toolManager);

// List available tools
const toolsList = await client.listTools();

// Call a tool
try {
  const result = await client.callTool({
    name: 'calculator',
    arguments: {
      operation: 'add',
      numbers: [1, 2, 3]
    }
  });
} catch (err) {
  // raise Invalid API Key error
}

// Call a tool with context
const result = await client.callTool({
  name: 'calculator',
  arguments: {
    operation: 'add',
    numbers: [1, 2, 3]
  },
  ctx: { apiKey: 'xyz' }
});

API Reference

ToolManager class

Manages the registration and handling of tools.

Tool Interface

Tools must implement the following interface:

interface Tool {
  name: string;
  description: string;
  inputSchema: ToolInput;
  toolFunction: (args: CallToolRequestArguments, ctx: CallToolRequestContext) => Promise<CallToolResultContent>;
}

createServer(serverInfo, toolManager)

Creates an MCP server with the given tool manager.

createService(toolManager)

Creates an in-memory client-server setup for serverless operation.

Examples

Standard I/O Transport

The package includes examples for using the stdio transports for both client and server communication:

  • StdioClientTransport: Allows clients to communicate with servers over standard input/output
  • StdioServerTransport: Enables servers to handle requests through standard input/output

Check out the example implementation:

相关推荐

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

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

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

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

  • Callycode Limited
  • A geek-themed horoscope generator blending Bitcoin prices, tech jargon, and astrological whimsy.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Khalid kalib
  • Write professional emails

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

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

  • apappascs
  • Entdecken Sie die umfassendste und aktuellste Sammlung von MCP-Servern auf dem Markt. Dieses Repository dient als zentraler Hub und bietet einen umfangreichen Katalog von Open-Source- und Proprietary MCP-Servern mit Funktionen, Dokumentationslinks und Mitwirkenden.

  • OffchainLabs
  • GO -Umsetzung des Ethereum -Beweises des Anteils

  • huahuayu
  • Ein einheitliches API-Gateway zur Integration mehrerer Ethercan-ähnlicher Blockchain-Explorer-APIs mit Modellkontextprotokoll (MCP) für AI-Assistenten.

  • deemkeen
  • Steuern Sie Ihren MBOT2 mit einer Power Combo: MQTT+MCP+LLM

    Reviews

    5 (1)
    Avatar
    user_0dFu7NDU
    2025-04-15

    As a devoted user of MCP applications, I highly recommend the Mcp-server-v2ex. Developed by funnythingfunnylove, this server is both reliable and efficient. You can explore it further at https://mcp.so/server/mcp-server-v2ex/funnythingfunnylove. Its seamless performance in handling requests makes it a standout tool for developers. Whether you're managing a small project or a large-scale application, Mcp-server-v2ex never disappoints.