Demonstrates the complete workflow of using MCP PostgreSQL tool to query database and save results as JSON file, including multi-tool collaboration and error handling.
This scenario demonstrates how to combine MCP PostgreSQL tool and Filesystem tool to complete the workflow from database query to result saving [^1].
mcp-server-postgres configuredmcp-server-filesystem configuredUse postgres/query tool to execute SQL query:
{
"connection_string": "postgresql://user:pass@localhost:5432/mydb",
"query": "SELECT * FROM users WHERE created_at > '2024-01-01'"
}
Query results returned in JSON format:
{
"rows": [
{"id": 1, "name": "Alice", "email": "alice@example.com"},
{"id": 2, "name": "Bob", "email": "bob@example.com"}
],
"rowCount": 2
}
Use filesystem/write_file tool to save results:
{
"path": "/Users/username/data/users_2024.json",
"content": "{\"users\": [{\"id\": 1, ...}]}"
}
[^1]: MCP with Postgres - PostgreSQL MCP tool usage guide
[^2]: PostgreSQL MCP Server Setup - PostgreSQL MCP server configuration tutorial
You need to configure both `mcp-server-postgres` and `mcp-server-filesystem` tools.
Check the connection string format, confirm the database service is running, and verify network connectivity.
The best practice is to use parameterized queries to prevent SQL injection.
It is recommended to add timestamps to the filename to avoid overwriting existing files.
Use the `filesystem/write_file` tool to save the processed results as a JSON file.
第三方BOT
人类专家验证
官方机器人验证