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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It only states what the tool does (get details) and parameter format, missing critical information like authentication requirements, rate limits, error handling, or response structure. For a read operation with zero annotation coverage, this is insufficient transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded in a single sentence: '根据接口ID获取YAPI接口详情,支持格式:数字ID' (Get YAPI interface details by interface ID, supported format: numeric ID). It efficiently communicates the core purpose and parameter constraint without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (1 parameter, no output schema, no annotations), the description is incomplete. It lacks information about what '接口详情' (interface details) includes, potential authentication needs, or error scenarios. While the schema covers the parameter, the overall context for effective tool use remains underspecified.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the parameter 'id' documented as '接口ID,格式:数字ID' (interface ID, format: numeric ID). The description adds no additional parameter semantics beyond what the schema already provides. According to guidelines, with high schema coverage (>80%), the baseline is 3 even without extra param info in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '根据接口ID获取YAPI接口详情' (Get YAPI interface details by interface ID). It specifies the verb '获取' (get) and resource 'YAPI接口详情' (YAPI interface details). However, with no sibling tools mentioned, there's no opportunity to distinguish from alternatives, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal usage guidance: it mentions the parameter format '数字ID' (numeric ID). However, it lacks explicit when-to-use context, prerequisites, or comparisons with alternatives (though none exist). This leaves the agent without clear operational context beyond basic parameter formatting.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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