API文档转换库

MCP Spring Bridge是一个Spring Boot库,用于将OpenAPI文档转换为MCP格式,使大型语言模型能够理解和响应API规范。

  • by SALARY-MARKET
  • Java
  • 本地部署
  • 更新于
在 GitHub 查看 SALARY-MARKET/MCP-BRIDGE

使用说明

MCP弹簧桥

一个Spring Boot库,通过模型上下文协议(MCP)向大型语言模型(LLM)公开REST API文档。这允许通过ChatGPT或其他LLM接口与API规范进行自然语言交互。

韩语 | 英语


韩语

概述

MCP Spring Bridge是一个库,可将Spring Boot应用程序的OpenAPI文档转换为模型上下文协议(MCP)格式,使LLM能够理解和响应API规范。

主要功能

  • OpenAPI 3.0规格自动解析和转换
  • 提供基于MCP协议的API文档
  • 基于Bearer令牌的身份验证
  • 零配置支持
  • Spring Boot自动配置

安装

Gradle

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.SALARY-MARKET:MCP-BRIDGE:1.0.8'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.4'
}

梅文

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.github.SALARY-MARKET</groupId>
    <artifactId>MCP-BRIDGE</artifactId>
    <version>1.0.8</version>
</dependency>

设置

application.yml

mcp:
  enabled: true
  base-path: /mcp
  open-api-path: /v3/api-docs
  token: "your-secret-token"

springdoc:
  api-docs:
    enabled: true

设置属性

属性默认说明 |------|--------|------| | mcp.enabled | true |是否启用MCP Bridge | | mcp.base-path | /mcp | MCP端点默认路径| | mcp.open-api-path | /v3/api-docs | OpenAPI文档路径| | mcp.token |-|Bearer身份验证令牌(可选)|

API端点

GET/mcp/工具

返回可用MCP工具的列表。

示例响应:

{
  "tools": [
    {
      "name": "getApiDocumentation",
      "description": "Get comprehensive API documentation",
      "inputSchema": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string",
            "description": "Search query for filtering APIs"
          }
        }
      }
    }
  ]
}

POST/mcp/呼叫

运行MCP工具。

请求示例:

{
  "name": "getApiDocumentation",
  "arguments": {
    "query": "all"
  }
}

示例响应:

{
  "status": "success",
  "result": "# API Documentation\n\n## Available Endpoints\n..."
}

可用工具

  1. getApi文档:查看所有API文档
  2. searchEndpoints:使用关键字搜索端点
  3. getEndpointDetails:查看特定端点的详细信息

安全

支持Bearer令牌身份验证。 mcp.token 设置属性后,所有MCP端点请求 Authorization: Bearer {token} 需要标题。

curl -X POST http://localhost:8080/mcp/call \
  -H "Authorization: Bearer your-secret-token" \
  -H "Content-Type: application/json" \
  -d '{"name":"getApiDocumentation","arguments":{"query":"all"}}'

设置外部访问

使用ngrok

# ngrok 설치
choco install ngrok  # Windows
brew install ngrok   # macOS

# 터널 실행
ngrok http 8080

# 출력된 URL을 application.yml에 설정
springdoc:
  server:
    url: https://your-ngrok-url.ngrok-free.dev

许可证

MIT许可证


英语

概述

MCP Spring Bridge是一个Spring Boot库,它将OpenAPI文档转换为模型上下文协议(MCP)格式,使LLM能够理解和响应API规范。

特性

  • OpenAPI 3.0规范的自动解析与转换
  • 基于MCP协议的API文档
  • 承载令牌身份验证
  • 零配置支持
  • Spring Boot自动配置

安装

Gradle

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.SALARY-MARKET:MCP-BRIDGE:1.0.8'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.4'
}

梅文

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.github.SALARY-MARKET</groupId>
    <artifactId>MCP-BRIDGE</artifactId>
    <version>1.0.8</version>
</dependency>

配置

application.yml

mcp:
  enabled: true
  base-path: /mcp
  open-api-path: /v3/api-docs
  token: "your-secret-token"

springdoc:
  api-docs:
    enabled: true

配置属性

属性 默认值 描述
mcp.enabled true 启用/禁用MCP网桥
mcp.base-path /mcp MCP端点的基本路径
mcp.open-api-path /v3/api-docs OpenAPI文档路径
mcp.token - 承载身份验证令牌(可选)

API终点

GET/mcp/工具

返回可用MCP工具的列表。

响应示例:

{
  "tools": [
    {
      "name": "getApiDocumentation",
      "description": "Get comprehensive API documentation",
      "inputSchema": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string",
            "description": "Search query for filtering APIs"
          }
        }
      }
    }
  ]
}

POST/mcp/呼叫

执行MCP工具。

请求示例:

{
  "name": "getApiDocumentation",
  "arguments": {
    "query": "all"
  }
}

响应示例:

{
  "status": "success",
  "result": "# API Documentation\n\n## Available Endpoints\n..."
}

可用工具

  1. getApi文档:检索完整的API文档
  2. searchEndpoints:按关键字搜索端点
  3. getEndpointDetails:获取特定端点的详细信息

安全

支持承载令牌身份验证。当 mcp.token 已配置,所有MCP端点请求都需要 Authorization: Bearer {token} 头球

curl -X POST http://localhost:8080/mcp/call \
  -H "Authorization: Bearer your-secret-token" \
  -H "Content-Type: application/json" \
  -d '{"name":"getApiDocumentation","arguments":{"query":"all"}}'

外部访问设置

使用ngrok

# Install ngrok
choco install ngrok  # Windows
brew install ngrok   # macOS

# Start tunnel
ngrok http 8080

# Configure the generated URL in application.yml
springdoc:
  server:
    url: https://your-ngrok-url.ngrok-free.dev

ChatGPT集成

1.创建自定义GPT

  1. 转到ChatGPT→ “探索GPT”→ “创建GPT”
  2. 使用以下架构配置操作:
{
  "openapi": "3.1.0",
  "info": {
    "title": "API Assistant",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://your-server-url.com"
    }
  ],
  "paths": {
    "/mcp/call": {
      "post": {
        "operationId": "callTool",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "enum": ["getApiDocumentation", "searchEndpoints", "getEndpointDetails"]
                  },
                  "arguments": {
                    "type": "object",
                    "properties": {},
                    "additionalProperties": true
                  }
                },
                "required": ["name", "arguments"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "result": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

2.配置身份验证

  • 身份验证类型:API密钥
  • API密钥:你到哪儿
  • 身份验证类型:承载

需求

  • Java 17或更高版本
  • 弹簧靴3.x
  • SpringDoc OpenAPI 2.x

许可证

MIT许可证

链接