返回市场
MCP服务器-大模型训练

MCP服务器-大模型训练

作者:phil655 星标更新:2025-11-05

项目介绍

mcp-server-llmling

PyPI License Package status Monthly downloads Distribution format Wheel availability Python version Implementation Releases Github Contributors Github Discussions Github Forks Github Issues Github Issues Github Watchers Github Stars Github Repository size Github last commit Github release date Github language count Github commits this month Package status PyUp

阅读文档!

LLMling 服务器手册

概述

mcp-server-llmling 是一个基于机器聊天协议(MCP)的服务器,提供了一个基于 YAML 的配置系统用于 LLM 应用程序。

LLMLing,作为后端,提供了一个基于 YAML 的配置系统用于 LLM 应用程序。它允许设置自定义的 MCP 服务器来提供在 YAML 文件中定义的内容。

  • 静态声明:使用 YAML 定义 LLM 的环境,无需编写代码
  • MCP 协议:基于机器聊天协议(MCP),实现标准化的 LLM 交互
  • 组件类型
    • 资源:内容提供者(文件、文本、CLI 输出等)
    • 提示:带有参数的消息模板
    • 工具:可由 LLM 调用的 Python 函数

YAML 配置创建了一个完整的环境,为 LLM 提供了:

  • 通过资源访问内容
  • 结构化的提示以实现一致的交互
  • 扩展功能的工具

主要特性

1. 资源管理

  • 加载和管理不同类型的资源:
    • 文本文件(PathResource
    • 原始文本内容(TextResource
    • CLI 命令输出(CLIResource
    • Python 源代码(SourceResource
    • Python 可调用结果(CallableResource
    • 图像(ImageResource
  • 支持资源监视/热重载
  • 资源处理流水线
  • 基于 URI 的资源访问

2. 工具系统

  • 注册并执行 Python 函数作为 LLM 工具
  • 支持基于 OpenAPI 的工具
  • 基于入口点的工具发现
  • 工具验证和参数检查
  • 结构化的工具响应

3. 提示管理

  • 带有模板支持的静态提示
  • 来自 Python 函数的动态提示
  • 基于文件的提示
  • 提示参数验证
  • 提示参数的补全建议

4. 多种传输选项

  • 基于标准 I/O 的通信(默认)
  • 适用于 Web 客户端的 Server-Sent Events (SSE) / 可流式传输的 HTTP
  • 支持自定义传输实现

使用方法

与 Zed 编辑器一起使用

在你的 settings.json 中添加 LLMLing 作为上下文服务器:

{
  "context_servers": {
    "llmling": {
      "command": {
        "env": {},
        "label": "llmling",
        "path": "uvx",
        "args": [
          "mcp-server-llmling",
          "start",
          "path/to/your/config.yml"
        ]
      },
      "settings": {}
    }
  }
}

与 Claude Desktop 一起使用

在你的 claude_desktop_config.json 中配置 LLMLing:

{
  "mcpServers": {
    "llmling": {
      "command": "uvx",
      "args": [
        "mcp-server-llmling",
        "start",
        "path/to/your/config.yml"
      ],
      "env": {}
    }
  }
}

手动启动服务器

从命令行直接启动服务器:

# 最新版本
uvx mcp-server-llmling@latest

1. 程序化使用

from llmling import RuntimeConfig
from mcp_server_llmling import LLMLingServer

async def main() -> None:
    async with RuntimeConfig.open(config) as runtime:
        server = LLMLingServer(runtime, enable_injection=True)
        await server.start()

asyncio.run(main())

2. 使用自定义传输

from llmling import RuntimeConfig
from mcp_server_llmling import LLMLingServer

async def main() -> None:
    async with RuntimeConfig.open(config) as runtime:
        server = LLMLingServer(
            config,
            transport="sse",
            transport_options={
                "host": "localhost",
                "port": 3001,
                "cors_origins": ["http://localhost:3000"]
            }
        )
        await server.start()

asyncio.run(main())

3. 资源配置

resources:
  python_code:
    type: path
    path: "./src/**/*.py"
    watch:
      enabled: true
      patterns:
        - "*.py"
        - "!**/__pycache__/**"

  api_docs:
    type: text
    content: |
      API 文档
      ================
      ...

4. 工具配置

tools:
  analyze_code:
    import_path: "mymodule.tools.analyze_code"
    description: "分析 Python 代码结构"

toolsets:
  api:
    type: openapi
    spec: "https://api.example.com/openapi.json"

[!TIP] 对于 OpenAPI 模式,你可以安装 Redocly CLI 来捆绑和解析 OpenAPI 规范,然后再将其与 LLMLing 一起使用。这有助于确保你的模式引用被正确解析,并且规范格式正确。如果已安装 Redocly,它将自动使用。

服务器配置

服务器通过 YAML 文件进行配置,包含以下部分:

global_settings:
  timeout: 30
  max_retries: 3
  log_level: "INFO"
  requirements: []
  pip_index_url: null
  extra_paths: []

resources:
  # 资源定义...

tools:
  # 工具定义...

toolsets:
  # 工具集定义...

prompts:
  # 提示定义...

MCP 协议

服务器实现了 MCP 协议,支持以下操作:

  1. 资源操作

    • 列出可用资源
    • 读取资源内容
    • 监视资源变化
  2. 工具操作

    • 列出可用工具
    • 使用参数执行工具
    • 获取工具模式
  3. 提示操作

    • 列出可用提示
    • 获取格式化的提示
    • 获取提示参数的补全
  4. 通知

    • 资源变化
    • 工具/提示列表更新
    • 进度更新
    • 日志消息