yapi-get-interface
Retrieve detailed API interface information from YApi documentation by providing the interface ID to access specifications and parameters.
Instructions
根据接口ID获取接口详情
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| interfaceId | Yes | 接口ID |
Input Schema (JSON Schema)
{
"properties": {
"interfaceId": {
"description": "接口ID",
"type": "number"
}
},
"required": [
"interfaceId"
],
"type": "object"
}
Implementation Reference
- src/tools/yapiTools.ts:53-75 (handler)Executes the core logic of the 'yapi-get-interface' tool by calling YApiClient to fetch interface details and formatting the response as MCP content (JSON string) or error.private async getInterface(interfaceId: number) { try { const interface_ = await this.yapiClient.getInterface(interfaceId); return { content: [ { type: "text", text: JSON.stringify(interface_, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`, }, ], isError: true, }; } }
- src/services/yapiClient.ts:38-58 (helper)Supporting utility that performs the HTTP request to YApi's /api/interface/get endpoint to retrieve interface data by ID.async getInterface(interfaceId: number): Promise<any> { try { const response = await this.client.get("/api/interface/get", { params: { id: interfaceId, }, }); if (response.data.errcode !== 0) { throw new Error(`Failed to get interface: ${response.data.errmsg}`); } return response.data.data; } catch (error) { throw new Error( `Error fetching interface: ${ error instanceof Error ? error.message : "Unknown error" }` ); } }
- src/tools/yapiTools.ts:9-22 (schema)Input schema and metadata definition for the 'yapi-get-interface' tool, specifying the required 'interfaceId' parameter."yapi-get-interface": { name: "yapi-get-interface", description: "根据接口ID获取接口详情", inputSchema: { type: "object", properties: { interfaceId: { type: "number", description: "接口ID", }, }, required: ["interfaceId"], }, },
- src/index.ts:46-50 (registration)Registers the MCP listTools handler, exposing the 'yapi-get-interface' tool definition to clients.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: Object.values(yapiTools.getToolDefinitions()), }; });
- src/index.ts:52-72 (registration)Registers the MCP callTool handler, which dispatches tool calls including 'yapi-get-interface' to the YApiTools.handleToolCall method.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; if (!name) { throw new Error("Tool name is required"); } try { return await yapiTools.handleToolCall(name, args); } catch (error) { return { content: [ { type: "text", text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`, }, ], isError: true, }; } });