import { z } from "zod";
import { experimental_PaidMcpAgent as PaidMcpAgent } from "@stripe/agent-toolkit/cloudflare";
export function searchBuildingCodesTool(agent: PaidMcpAgent<Env, any, any>) {
const server = agent.server;
// @ts-ignore
server.tool(
"search_building_codes",
"Primary tool for finding specific building code requirements. Use technical terminology (IBC sections, NEC articles, etc.) and always specify jurisdiction when possible. Request clarifying questions for ambiguous scenarios.",
{
query: z.string().describe("Technical code search query using specific terminology (e.g., 'IBC 2021 deck ledger attachment', 'NEC 2020 GFCI protection commercial kitchens')"),
jurisdiction: z.string().optional().describe("Municipality, county, or state jurisdiction (e.g., 'Atlanta, GA', 'Miami-Dade County, FL')"),
codeType: z.enum(["IBC", "IRC", "NEC", "IPC", "IFC", "IEBC", "local"]).optional().describe("Specific code type to search within"),
year: z.number().optional().describe("Code edition year (e.g., 2021, 2020)"),
},
async ({ query, jurisdiction, codeType, year }: {
query: string;
jurisdiction?: string;
codeType?: string;
year?: number;
}) => {
// TODO: Implement this tool
// This would integrate with Municode API or similar building code database
// For now, return a structured response indicating the search parameters
const searchParams = {
query,
jurisdiction: jurisdiction || "Not specified",
codeType: codeType || "All codes",
year: year || "Current edition"
};
return {
content: [
{
type: "text",
text: `Building Code Search Results\n\nQuery: ${searchParams.query}\nJurisdiction: ${searchParams.jurisdiction}\nCode Type: ${searchParams.codeType}\nEdition: ${searchParams.year}\n\nThis tool would search the Municode API for specific building code requirements. The search would return:\n\n- Relevant code sections and subsections\n- Local amendments and modifications\n- Cross-references to related requirements\n- Professional requirements and exceptions\n- Inspection and compliance notes\n\nFor professional use, always verify the current code edition and local adoptions.`
}
]
};
}
);
}