MM

mark3labs/mcp-go

开发工具

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

9215 stars 929 forks 质量 73 趋势 54MIT

模型上下文协议(MCP)的Go实现,实现LLM应用与外部数据源及工具之间的无缝集成。

概览

模型上下文协议(MCP)的Go实现,实现LLM应用与外部数据源及工具之间的无缝集成。 MCP Go 负责处理所有复杂的协议细节和服务器管理,因此你可以专注于打造优秀的工具。它的目标是高层次且易于使用。 * :高层接口意味着代码更少,开发更快 * :构建最小样板的MCP服务器 * ***:MCP Go旨在提供核心MCP规范的完整实现 🚨 🚧 🏗️ MCP Go 正在积极开发中,MCP 规范本身也在开发中。核心功能正在运行,但一些高级功能仍在开发中。 让我们创建一个简单的MCP服务器,它暴露一个计算器工具和一些数据: 模型上下文协议(MCP)允许你构建服务器,以安全、标准化的方式向大型语言模型应用展示数据和功能。可以把它想象成一个网页API,但专门为大型语言模型交互设计。

概述(AI 翻译)

模型上下文协议(MCP)的Go实现,实现LLM应用与外部数据源及工具之间的无缝集成。

在Discord上讨论SDK内容

就是这样!

MCP Go 负责处理所有复杂的协议细节和服务器管理,因此你可以专注于打造优秀的工具。它的目标是高层次且易于使用。

主要功能:

  • 快速:高级接口意味着代码更少,开发更快
  • 简单:构建最小模板的MCP服务器
  • 完成*:MCP Go 旨在提供核心 MCP 规范的完整实现

(*重点强调目标)

🚨 🚧 🏗️ MCP Go 正在积极开发中,MCP 规范本身也在开发中。核心功能正在运行,但一些高级功能仍在开发中。

目录

  • 安装
  • 快速启动
  • 什么是MCP?
  • 核心概念
  • 服务器
  • 资源
  • 工具
  • 提示
  • 示例
  • 附加内容
  • 运输船
  • OAuth 受保护资源元数据
  • 会话管理
  • 基础会话处理
  • 每会话工具
  • 工具过滤
  • 与上下文共事
  • 请求钩子
  • 工具处理中间件
  • 重生成服务器代码

安装

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

README

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

package main

import (
    "context"
    "fmt"

    "github.com/mark3labs/mcp-go/mcp"
    "github.com/mark3labs/mcp-go/server"
)

func main() {
    // Create a new MCP server
    s := server.NewMCPServer(
        "Demo 🚀",
        "1.0.0",
        server.WithToolCapabilities(false),
    )

    // Add tool
    tool := mcp.NewTool("hello_world",
        mcp.WithDescription("Say hello to someone"),
        mcp.WithString("name",
            mcp.Required(),
            mcp.Description("Name of the person to greet"),
        ),
    )

    // Add tool handler
    s.AddTool(tool, helloHandler)

    // Start the stdio server
    if err := server.ServeStdio(s); err != nil {
        fmt.Printf("Server error: %v\n", err)
    }
}

func helloHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
    name, err := request.RequireString("name")
    if err != nil {
        return mcp.NewToolResultError(err.Error()), nil
    }

    return mcp.NewToolResultText(fmt.Sprintf("Hello, %s!", name)), nil
}

That’s it!

MCP Go handles all the complex protocol details and server management, so you can focus on building great tools. It aims to be high-level and easy to use.

Key features:

  • Fast: High-level interface means less code and faster development
  • Simple: Build MCP servers with minimal boilerplate
  • Complete*: MCP Go aims to provide a full implementation of the core MCP specification

(*emphasis on aims)

🚨 🚧 🏗️ MCP Go is under active development, as is the MCP specification itself. Core features are working but some advanced capabilities are still in progress.

Table of Contents

在 GitHub 查看完整 README

安装

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

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