Skip to main content
Glama
Gorvey

YAPI Interface MCP Server

by Gorvey

yapi-get-interface

Retrieve detailed YAPI interface information by providing a numeric interface ID, enabling integration with AI development tools for efficient API management.

Instructions

根据接口ID获取YAPI接口详情,支持格式:数字ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes接口ID,格式:数字ID

Implementation Reference

  • Full registration of the 'yapi-get-interface' tool, including name, description, input schema, and complete handler implementation.
      server.tool("yapi-get-interface",
        "根据接口ID获取YAPI接口详情,支持格式:数字ID",
        {
          id: z.string().describe("接口ID,格式:数字ID")
        },
        async ({ id }) => {
          try {
            if (!yapiConfigManager.isConfigured()) {
              return {
                content: [{ 
                  type: "text", 
                  text: "❌ 请先通过命令行参数配置YAPI:--email, --password, --url" 
                }]
              };
            }
            const apiID = parseInt(id);
            if (isNaN(apiID)) {
              return {
                content: [{ 
                  type: "text", 
                  text: "❌ 无效的接口ID格式,请使用正确的ID" 
                }]
              };
            }
    
            const yapiClient = yapiConfigManager.getClient();
            const interfaceData = await yapiClient.getInterfaceById(apiID);
            // http://api.seevin.com/project/831/interface/api/36839
            const url = `http://${yapiConfigManager.getConfig().url}/project/${interfaceData.project_id}/interface/api/${interfaceData._id}`;
            interfaceData.url = url;
            const fieldDescriptions = {
              "_id": "接口唯一标识符",
              "title": "接口名称/标题",
              "path": "接口路径/URL",
              "method": "HTTP请求方法(GET/POST/PUT/DELETE等)",
              "desc": "接口描述信息",
              "markdown": "接口Markdown格式描述",
              "req_params": "请求路径参数列表",
              "req_query": "请求查询参数列表", 
              "req_headers": "请求头参数列表",
              "req_body_type": "请求体类型(form/json/raw等)",
              "req_body_other": "请求体内容/示例",
              "req_body_form": "表单类型请求体参数",
              "req_body_is_json_schema": "请求体是否为JSON Schema格式",
              "res_body": "响应体内容/示例",
              "res_body_type": "响应体类型",
              "res_body_is_json_schema": "响应体是否为JSON Schema格式",
              "status": "接口状态(undone/done)",
              "add_time": "创建时间(Unix时间戳)",
              "up_time": "更新时间(Unix时间戳)",
              "project_id": "所属项目ID",
              "catid": "所属分类ID",
              "uid": "创建者用户ID",
              "username": "创建者用户名",
              "edit_uid": "编辑者用户ID",
              "api_opened": "接口是否开放",
              "index": "接口排序索引",
              "query_path": "查询路径信息(包含path和params)",
              "tag": "接口标签列表",
              "type": "接口类型(static/dynamic)",
              "__v": "文档版本号(MongoDB字段)",
              "url": "接口URL地址"
            };
    
            return {
              content: [{ 
                type: "text", 
                text: `✅ 获取接口数据成功!
    
    ## 字段说明
    ${Object.entries(fieldDescriptions).map(([key, desc]) => `- **${key}**: ${desc}`).join('\n')}
    
    ## 原始数据
    ${JSON.stringify(interfaceData, null, 2)}` 
              }]
            };
          } catch (error) {
            return {
              content: [{ 
                type: "text", 
                text: `❌ 获取接口数据失败:${error instanceof Error ? error.message : '未知错误'}` 
              }]
            };
          }
        }
      );
  • The handler function that executes the tool's logic: checks configuration, parses ID, fetches interface data from YAPI client, adds URL, formats with field descriptions, and returns formatted text response.
        async ({ id }) => {
          try {
            if (!yapiConfigManager.isConfigured()) {
              return {
                content: [{ 
                  type: "text", 
                  text: "❌ 请先通过命令行参数配置YAPI:--email, --password, --url" 
                }]
              };
            }
            const apiID = parseInt(id);
            if (isNaN(apiID)) {
              return {
                content: [{ 
                  type: "text", 
                  text: "❌ 无效的接口ID格式,请使用正确的ID" 
                }]
              };
            }
    
            const yapiClient = yapiConfigManager.getClient();
            const interfaceData = await yapiClient.getInterfaceById(apiID);
            // http://api.seevin.com/project/831/interface/api/36839
            const url = `http://${yapiConfigManager.getConfig().url}/project/${interfaceData.project_id}/interface/api/${interfaceData._id}`;
            interfaceData.url = url;
            const fieldDescriptions = {
              "_id": "接口唯一标识符",
              "title": "接口名称/标题",
              "path": "接口路径/URL",
              "method": "HTTP请求方法(GET/POST/PUT/DELETE等)",
              "desc": "接口描述信息",
              "markdown": "接口Markdown格式描述",
              "req_params": "请求路径参数列表",
              "req_query": "请求查询参数列表", 
              "req_headers": "请求头参数列表",
              "req_body_type": "请求体类型(form/json/raw等)",
              "req_body_other": "请求体内容/示例",
              "req_body_form": "表单类型请求体参数",
              "req_body_is_json_schema": "请求体是否为JSON Schema格式",
              "res_body": "响应体内容/示例",
              "res_body_type": "响应体类型",
              "res_body_is_json_schema": "响应体是否为JSON Schema格式",
              "status": "接口状态(undone/done)",
              "add_time": "创建时间(Unix时间戳)",
              "up_time": "更新时间(Unix时间戳)",
              "project_id": "所属项目ID",
              "catid": "所属分类ID",
              "uid": "创建者用户ID",
              "username": "创建者用户名",
              "edit_uid": "编辑者用户ID",
              "api_opened": "接口是否开放",
              "index": "接口排序索引",
              "query_path": "查询路径信息(包含path和params)",
              "tag": "接口标签列表",
              "type": "接口类型(static/dynamic)",
              "__v": "文档版本号(MongoDB字段)",
              "url": "接口URL地址"
            };
    
            return {
              content: [{ 
                type: "text", 
                text: `✅ 获取接口数据成功!
    
    ## 字段说明
    ${Object.entries(fieldDescriptions).map(([key, desc]) => `- **${key}**: ${desc}`).join('\n')}
    
    ## 原始数据
    ${JSON.stringify(interfaceData, null, 2)}` 
              }]
            };
          } catch (error) {
            return {
              content: [{ 
                type: "text", 
                text: `❌ 获取接口数据失败:${error instanceof Error ? error.message : '未知错误'}` 
              }]
            };
          }
        }
  • Zod input schema for the tool, defining the 'id' parameter as string.
    {
      id: z.string().describe("接口ID,格式:数字ID")
    },
  • YAPIClient method to fetch interface details by ID from YAPI server, ensuring login first and handling API response. Directly called by the tool handler.
    async getInterfaceById(interfaceId: number): Promise<YAPIInterface> {
      await this.ensureLoggedIn();
    
      try {
        const response = await this.axios.get(`/api/interface/get?id=${interfaceId}`);
        
        if (response.data.errcode === 0) {
          return response.data.data;
        } else {
          throw new Error(`获取接口失败: ${response.data.errmsg}`);
        }
      } catch (error) {
        throw new Error(`获取YAPI接口失败: ${error instanceof Error ? error.message : '未知错误'}`);
      }
    }
  • TypeScript interface defining the structure of the YAPI interface data returned and used by the tool.
    export interface YAPIInterface {
      url?: string;
      _id: number;
      title: string;
      path: string;
      method: string;
      project_id: number;
      catid: number;
      status: string;
      type: string;
      uid: number;
      username: string;
      add_time: number;
      up_time: number;
      api_opened: boolean;
      edit_uid: number;
      index: number;
      query_path: {
        path: string;
        params: any[];
      };
      req_body_type?: string;
      req_body_other?: string;
      req_body_is_json_schema?: boolean;
      req_body_form?: any[];
      req_query?: Array<{
        name: string;
        desc: string;
        required: '1' | '0';
        example?: string;
      }>;
      req_params?: Array<{
        name: string;
        desc: string;
      }>;
      req_headers?: Array<{
        required: '1' | '0';
        _id: string;
        name: string;
        value: string;
      }>;
      res_body?: string;
      res_body_type?: string;
      res_body_is_json_schema?: boolean;
      desc?: string;
      markdown?: string;
      tag?: any[];
      __v?: number;
    }
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Gorvey/yapi-get-interface-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server