get_barangays
Retrieve a complete list of barangays across the Philippines for geographic data integration and location-based applications.
Instructions
List all barangays in the Philippines
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp.ts:88-134 (registration)Dynamically fetches the list of tools from remote API (https://mcp.xiaobenyang.com/getMcpDesc?mcpId=1777316659371011) and registers each one, including 'get_barangays' if it is in the list. This is the registration point for the tool.const apiDescList = data.tools; for (const apiDesc of apiDescList) { let inputSchema = JSON.parse(apiDesc.inputSchema); const zodDict: Record<string, z.ZodTypeAny> = {}; Object.entries(inputSchema.properties).forEach(([name, propConfig]) => { let zodType; let pt = (propConfig as { type: string }).type; switch (pt) { case 'string': zodType = z.string(); break; case 'number': zodType = z.number(); break; case 'boolean': zodType = z.boolean(); break; case 'integer': zodType = z.int32(); break; case 'array': zodType = z.array(z.any()); break; case 'object': zodType = z.object(z.any()); break; default: zodType = z.any(); } if (inputSchema.required?.includes(name)) { zodDict[name] = zodType; } else { zodDict[name] = zodType.optional(); } }); addToolXiaoBenYangApi( apiDesc.name, apiDesc.description ? apiDesc.description : apiDesc.name, zodDict); } isRegistered = true; state.isLoading = false;
- src/mcp.ts:91-127 (schema)Dynamically parses the inputSchema JSON from remote tool definition and builds Zod schema (inputSchema for MCP tool registration). Used for 'get_barangays' schema.let inputSchema = JSON.parse(apiDesc.inputSchema); const zodDict: Record<string, z.ZodTypeAny> = {}; Object.entries(inputSchema.properties).forEach(([name, propConfig]) => { let zodType; let pt = (propConfig as { type: string }).type; switch (pt) { case 'string': zodType = z.string(); break; case 'number': zodType = z.number(); break; case 'boolean': zodType = z.boolean(); break; case 'integer': zodType = z.int32(); break; case 'array': zodType = z.array(z.any()); break; case 'object': zodType = z.object(z.any()); break; default: zodType = z.any(); } if (inputSchema.required?.includes(name)) { zodDict[name] = zodType; } else { zodDict[name] = zodType.optional(); } });
- src/mcp.ts:50-65 (handler)Registers the tool with MCP server, providing schema and a handler lambda that calls the generic handleXiaoBenYangApi with the tool name (e.g., 'get_barangays').const addToolXiaoBenYangApi = function ( name: string, desc: string, params: Record<string, ZodType> ) { server.registerTool( name, { title: name, description: desc, inputSchema: params, } , async (args: Record<string, any>) => handleXiaoBenYangApi(args, name) ) };
- src/mcp.ts:39-48 (handler)Generic handler invoked for each tool call; merges args with toolName and delegates to calcXiaoBenYangApi. This handles execution for 'get_barangays'.const handleXiaoBenYangApi = async (args: Record<string, any>, toolName: string) => { // 校验aid是否存在 if (toolName === undefined || toolName === null) { throw new Error("缺少必要参数 'aid'"); } // 合并参数 const fullArgs = {...args, toolName: toolName}; // 调用API return calcXiaoBenYangApi(fullArgs); };
- src/mcp.ts:15-36 (helper)Core function that proxies the tool call to the remote https://mcp.xiaobenyang.com/api endpoint using the toolName as 'func', apiKey, and mcpID. This is the actual implementation logic for all tools including 'get_barangays'.const calcXiaoBenYangApi = async function (fullArgs: Record<string, any>) { // 发起 POST 请求 let response = await fetch('https://mcp.xiaobenyang.com/api', { method: 'POST', headers: { 'XBY-APIKEY': apiKey, 'func': fullArgs.toolName, 'mcpid': mcpID }, body: new URLSearchParams(fullArgs) }); const apiResult = await response.text(); return { content: [ { type: "text", text: apiResult // 将字符串结果放入 content 中 } ] } as { [x: string]: unknown; content: [{ type: "text"; text: string }] }; };