AE

aaronwander/embedmcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

37 stars 8 forks 质量 51 趋势 0MIT

提供易于使用的套件,让你能够快速创建MCP服务器,任何嵌入式设备

概览

一个轻量级的C库,用于创建MCP(模型上下文协议)服务器,将现有的C函数转化为AI可访问的工具,只需最小化代码修改。 EmbedMCP 弥合了您现有 C 代码库与现代 AI 系统之间的鸿沟。EmbedMCP 无需重写经过实战考验的 C 函数,而是允许您通过标准化的模型上下文协议(MCP)将其暴露给 AI 模型,只需最小化代码修改。 - : 复制一个文件夹,包含一个头文件 - : 直接调用 C 函数,开销最小 - : 通过通用 HAL 在 15+ 平台上运行 - : 自包含库,无外部需求 - : 简单函数使用魔法宏,复杂功能完全控制 - : 支持不同用例的可流式 HTTP 和 STDIO 支持 - : 自动清理,拥有明确所有权规则 - : 处理简单参数和复杂数据结构 EmbedMCP 支持两种注册方法: 除了get_*辅助者,你还可以使用严格的try_get_*辅助来区分......

概述(AI 翻译)

一个轻量级的C库,用于创建MCP(模型上下文协议)服务器,将现有的C函数转化为AI可访问的工具,只需最小化代码修改。

英文 • 简体中文

为什么要嵌入MCP?

EmbedMCP 弥合了您现有 C 代码库与现代 AI 系统之间的鸿沟。EmbedMCP 无需重写经过实战考验的 C 函数,而是允许您通过标准化的模型上下文协议(MCP)将其暴露给 AI 模型,只需最小化代码修改。

主要特色

  • ** 🚀 简单集成**:复制一个文件夹,包含一个头文件
  • ** ⚡ 高性能**:直接C函数调用,开销最小
  • ** 🔧 跨平台**:通过Universal HAL运行于15+平台上
  • ** 📦 零依赖**:自包含库,无外部需求
  • ** 🎯 两种配准方法**:简单函数用魔法宏,复杂函数完全控制
  • ** 🌐 多重传输**:支持不同用例的可流式HTTP和STDIO支持。
  • ** 🧠 智能内存管理**:自动清理,拥有明确的所有权规则
  • ** 📊 数组支持**:既处理简单参数,也能处理复杂数据结构

快速启动

安装

  1. 下载 EmbedMCP

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

EmbedMCP - Embedded MCP Server Library

A lightweight C library for creating MCP (Model Context Protocol) servers that transforms your existing C functions into AI-accessible tools with minimal code changes.

English • 简体中文

Why EmbedMCP?

EmbedMCP bridges the gap between your existing C codebase and modern AI systems. Instead of rewriting your battle-tested C functions, EmbedMCP lets you expose them to AI models through the standardized Model Context Protocol (MCP) with minimal code changes.

Key Features

  • 🚀 Simple Integration: Copy one folder, include one header file
  • ⚡ High Performance: Direct C function calls with minimal overhead
  • 🔧 Cross-Platform: Runs on 15+ platforms via Universal HAL
  • 📦 Zero Dependencies: Self-contained library with no external requirements
  • 🎯 Two Registration Methods: Magic macros for simple functions, full control for complex ones
  • 🌐 Multiple Transports: Streamable HTTP and STDIO support for different use cases
  • 🧠 Smart Memory Management: Automatic cleanup with clear ownership rules
  • 📊 Array Support: Handle both simple parameters and complex data structures

Quick Start

Installation

  1. Download EmbedMCP

    git clone https://github.com/AaronWander/EmbedMCP.git
    cd EmbedMCP
    
  2. Copy to your project

    cp -r embed_mcp/ your_project/
    

Basic Usage

#include "embed_mcp/embed_mcp.h"

// Your business function
double add_numbers(double a, double b) {
    return a + b;
}

// Generate wrapper with macro
EMBED_MCP_WRAPPER(add_wrapper, add_numbers, DOUBLE, DOUBLE, a, DOUBLE, b)

int main() {
    embed_mcp_config_t config = {
        .name = "MathServer",
        .version = "1.0.0",
        .instructions = "Simple math operations server",
        .port = 8080
    };

    embed_mcp_server_t *server = embed_mcp_create(&config);

    // Register function
    const char* names[] = {"a", "b"};
    const char* descs[] = {"First number", "Second number"};
    mcp_param_type_t types[] = {MCP_PARAM_DOUBLE, MCP_PARAM_DOUBLE};

    embed_mcp_add_tool(server, "add", "Add two numbers",
                       names, descs, types, 2, MCP_RETURN_DOUBLE, add_wrapper, NULL);

    embed_mcp_run(server, EMBED_MCP_TRANSPORT_HTTP);
    embed_mcp_destroy(server);
    return 0;
}

Build and Run

# Build
make

# Run Streamable HTTP server
./bin/mcp_server --transport http --port 8080

# Or run STDIO server
./bin/mcp_server --transport stdio

Function Registration

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →