Cover image
Try Now
2025-04-15

MCP服务器Frarmwork用C进行了有效而轻松的开发

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

mcp-c

mcp server frarmwork written in c, developing efficiently and effortlessly utilize annotate to generate code automatically, only need to focus on what to need to write mcp server function

how to use

  1. write your own mcp tools under src/mcp_server
    • add attributes EXPORT and EXPORT_AS(name) to the functions and structs you want to use
  2. build the project, cmake -B build -S . && cmake --build ., export.cpp will generate all the tedious code for you(like tools list, bridge json to struct, etc.)
  3. run the project, ./mcpc

quick start

  1. prerequisites
  • vcpkg(only for windows)
  • cmake
  • clang
  • cJSON
  1. build the project windows
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ^
    -DCMAKE_TOOLCHAIN_FILE="path/to/vcpkg/scripts/buildsystems/vcpkg.cmake" ^
    -G "Ninja" ^
    -DVCPKG_APPLOCAL_DEPS=ON ^
    -DCMAKE_BUILD_TYPE=Release ^
    -B build -S . 

  1. run the project
./mcpc

supported feature

  1. export struct first you need to add the macro to the struct consider this file name struct.c
#include "export_macro.h" //first include the export macro
typedef enum EXPORT COLOR {
    RED,
    GREEN,
    BLUE
} COLOR;

typedef struct EXPORT_AS(cloth) cloth {
    enum COLOR color DES("color of the cloth");
    int size;
} cloth;

typedef struct EXPORT person {
    bool isMale DES("whether is male or not male is true");
    int age DES("age of the person");
    char* name;
    cloth wearing_cloths;
} person;

after you execute export.exe struct.c this will generate the serialize code under the src folder generated_bridge_code.c contained the code to parse a json to object generated_function_signatures.c contained the code of definition of the struct

the above code sample will generate a get_all_function_signatures_json function to generate definition json like the following

{
        "$defs":        {
                "COLOR":        {
                        "type": "integer",
                        "enum": ["RED", "GREEN", "BLUE"]
                },
                "cloth":        {
                        "type": "object",
                        "properties":   {
                                "color":        {
                                        "$ref": "#/$defs/COLOR",
                                        "description":  "color of the cloth"
                                },
                                "size": {
                                        "type": "integer"
                                }
                        },
                        "required":     ["color", "size"]
                },
                "person":       {
                        "type": "object",
                        "properties":   {
                                "isMale":       {
                                        "type": "boolean",
                                        "description":  "whether is male or not male is true"
                                },
                                "age":  {
                                        "type": "integer",
                                        "description":  "age of the person"
                                },
                                "name": {
                                        "type": "string"
                                },
                                "wearing_cloths":       {
                                        "$ref": "#/$defs/cloth"
                                }
                        },
                        "required":     ["isMale", "age", "name", "wearing_cloths"]
                }
        },
        "tools":[]
}
  1. export function signature and struct via annotate

first you need to add the macro for functions and struct you need to export consider this file name func.c

#include "export_macro.h" //first include the export macro
... //struct definition here, with the code sample in section 1
EXPORT_AS(get_color) //if the function is a handler of tool "get_color", you need to add this macro
cJSON* get_color(COLOR c)
{

}

EXPORT_AS(get_person_info) //if the function is a handler of tool "get_person_info", you need to add this macro
cJSON* get_person_info(person* p, int id)
{

}

EXPORT_AS(tools, list) // if the function is a handler of tool "tools/list", you need to add this macro, use the comma to separate the tool name and the function name
cJSON* tools_list() {
    int i = 0;
    return get_all_function_signatures_json();
}

this will generate a get_all_function_signatures_json function which will return the following function signature json

{
   "#def": { ... } // param type defition here
   "tools":        [{
                        "name": "tools/list",
                        "description":  "",
                        "inputSchema":  {
                                "type": "object",
                                "properties":   {
                                },
                                "required":     [],
                                "additionalProperties": false,
                                "$schema":      "http://json-schema.org/draft-07/schema#"
                        }
                }, {
                        "name": "get_color",
                        "description":  "",
                        "inputSchema":  {
                                "type": "object",
                                "properties":   {
                                        "c":    {
                                                "$ref": "#/$defs/COLOR"
                                        }
                                },
                                "required":     ["c"],
                                "additionalProperties": false,
                                "$schema":      "http://json-schema.org/draft-07/schema#"
                        }
                }, {
                        "name": "get_person_info",
                        "description":  "",
                        "inputSchema":  {
                                "type": "object",
                                "properties":   {
                                        "p":    {
                                                "$ref": "#/$defs/person"
                                        },
                                        "id":   {
                                                "type": "integer"
                                        }
                                },
                                "required":     ["p", "id"],
                                "additionalProperties": false,
                                "$schema":      "http://json-schema.org/draft-07/schema#"
                        }
     }]
}
  1. use EXPORT for short

相关推荐

  • 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.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

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

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

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

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

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

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

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • appcypher
  • 很棒的MCP服务器 - 模型上下文协议服务器的策划列表

  • chongdashu
  • 使用模型上下文协议(MCP),启用Cursor,Windsurf和Claude Desktop等AI助手客户,以通过自然语言控制虚幻引擎。

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

    Reviews

    1 (1)
    Avatar
    user_uJWirMpv
    2025-04-17

    As a loyal user of the mcp application, I highly recommend the mcp-c product by ZenWayne. It is incredibly well-made and easy to use. The integration with existing systems is seamless, and the performance is impressive. The community and support around this product are strong, ensuring any issues are quickly addressed. You can find more information on GitHub at https://github.com/ZenWayne/mcp-c. Definitely worth checking out!