Complete workflow using postgres.query and filesystem.write_file to query database and save results to file.
Query data from PostgreSQL database and save results as JSON file.
Query users table where created_at > '2024-01-01'
Format query results as JSON
Save JSON to /Users/username/output/users.json
const query = await postgres.query({
sql: "SELECT * FROM users WHERE created_at > '2024-01-01'"
});
const json = JSON.stringify(query.rows, null, 2);
await filesystem.write_file({
path: "/Users/username/output/users.json",
content: json
});
You need PostgreSQL MCP Server and Filesystem MCP Server configured, along with database query permissions.
Primarily `postgres.query` for database querying and `filesystem.write_file` for saving the file.
Ensure the output directory is in the filesystem whitelist, otherwise the write operation may fail.
It is recommended to consider using a batch query strategy to avoid performance issues or timeouts.
Use `JSON.stringify` to convert the rows field from the query result into a formatted JSON string.
人类专家验证
官方机器人验证