get_apifox_project_id_and_api_id_from_url
Extract Apifox project ID and API ID directly from a provided URL to enable integration and understanding of API details within Apifox projects.
Instructions
Get the project ID and API ID of Apifox from the URL.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"text": "<text>"
},
"name": "get_apifox_project_id_and_api_id_from_url"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The text to extract the project id and api id from |
Implementation Reference
- src/index.ts:21-32 (handler)Handler function for the tool that extracts projectId and apiId from text using a helper and returns as JSON string.
({ text }) => { const { projectId, apiId } = extractProjectIdAndApiIdFromText(text) return { content: [ { type: "text", text: JSON.stringify({ projectId, apiId }), }, ], } }, - src/index.ts:16-20 (schema)Input schema defining the 'text' parameter as a string.
{ text: z .string() .describe("The text to extract the project id and api id from"), }, - src/index.ts:13-33 (registration)Registers the MCP tool 'get_apifox_project_id_and_api_id_from_url' with description, input schema, and handler function.
server.tool( "get_apifox_project_id_and_api_id_from_url", "Get the project ID and API ID of Apifox from the URL.", { text: z .string() .describe("The text to extract the project id and api id from"), }, ({ text }) => { const { projectId, apiId } = extractProjectIdAndApiIdFromText(text) return { content: [ { type: "text", text: JSON.stringify({ projectId, apiId }), }, ], } }, ) - src/utils/apifox.ts:32-66 (helper)Supporting utility that implements the extraction logic using regex to find project ID and API ID from Apifox URLs or paths in the input text.
export function extractProjectIdAndApiIdFromText(text: string) { const urlPattern = /apifox\.com\/link\/project\/(\d+)\/apis\/api-(\d+)/ const contentPattern = /project\/(\d+).*api-(\d+)/ let projectId = "" let apiId = "" // 寻找输入中的 URL 或相关内容 const lines = text.split("\n") for (const line of lines) { const trimmedLine = line.trim() // 尝试匹配完整 URL const urlMatch = trimmedLine.match(urlPattern) if (urlMatch) { projectId = urlMatch[1] apiId = urlMatch[2] break } // 尝试匹配部分路径 const contentMatch = trimmedLine.match(contentPattern) if (contentMatch) { projectId = contentMatch[1] apiId = contentMatch[2] break } } return { projectId, apiId } }