Use an npm package when it makes the function clearer or implements a protocol you should not reproduce by hand. Import the dependency by package name and Microfn detects it during deployment.
Add and import a package
Create a function named read-frontmatter, then import gray-matter in the editor:
import matter from "gray-matter";
export async function main(input: { markdown?: string }) {
if (typeof input.markdown !== "string") {
throw new Error("markdown must be a string");
}
const parsed = matter(input.markdown);
return {
attributes: parsed.data,
content: parsed.content.trim(),
};
}
Save and wait for deployment. Test with:
{"markdown":"---\ntitle: Hello\n---\nArticle body"}
Keep dependencies deliberate
Microfn scans imports and installs the detected packages when it deploys the function. Remove unused imports, and prefer platform APIs such as fetch, URL, and crypto for simple jobs.
An MCP-connected agent can add a package import while creating or updating a function. Ask it to explain why the dependency is needed, then test the deployed function with representative input. Start with your first function if you have not deployed one yet.