Logfire ACTION
Run SQL Query
Executes an arbitrary SQL query against Logfire's
records (unified logs + traces, one row per span) or metrics tables and returns the results. Use this for any analysis, search, or aggregation over your telemetry — recent activity, error hunting, latency analysis, counts, etc. To discover what columns are available before writing a query, run SELECT column_name, data_type FROM information_schema.columns WHERE table_name = 'records' (or 'metrics') with this same tool — there is no separate schema-discovery tool. Useful columns on records include start_timestamp, span_name, message, level, service_name, duration, is_exception, exception_type, and exception_message. Example — find exceptions: SELECT span_name, exception_type, exception_message FROM records WHERE is_exception = true ORDER BY start_timestamp DESC. Example — count by level: SELECT level, count(*) AS n FROM records GROUP BY level ORDER BY n DESC. After using Record Log Entry to write data, use this tool to confirm what was recorded. See the SQL reference and query API docs.- Action
- Read only
- API key
- SDK
- MCP
IMPLEMENTATION
Call this tool
Connect a user's Logfire account once, then configure and run Run SQL Query from your backend or agent.
import { PipedreamClient } from "@pipedream/sdk"
const pd = new PipedreamClient({
projectId: process.env.PIPEDREAM_PROJECT_ID!,
clientId: process.env.PIPEDREAM_CLIENT_ID!,
clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
projectEnvironment: "production",
})
const result = await pd.actions.run({
id: "logfire-run-sql-query",
externalUserId: "{external_user_id}", // any stable ID for this user in your system
configuredProps: {
logfire: { authProvisionId: "apn_xxxxxxx" },
sql: "SQL Query",
minTimestamp: "Min Timestamp",
},
})
console.log(result)curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
-H "Content-Type: application/json" \
-H "X-PD-Environment: production" \
-H "Authorization: Bearer {access_token}" \
-d '{
"external_user_id": "{external_user_id}",
"id": "logfire-run-sql-query",
"configured_props": {
"logfire": { "authProvisionId": "apn_xxxxxxx" },
"sql": "SQL Query",
"minTimestamp": "Min Timestamp"
}
}'// accessToken: mint a short-lived token with the Connect SDK — see the MCP guide
const transport = new StreamableHTTPClientTransport(
new URL("https://remote.mcp.pipedream.net/v3"),
{
requestInit: {
headers: {
Authorization: `Bearer ${accessToken}`,
"x-pd-project-id": "{project_id}",
"x-pd-environment": "production",
"x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
"x-pd-app-slug": "logfire",
},
},
},
)
const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)
const { tools } = await mcp.listTools()
// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
name: "logfire-run-sql-query",
arguments: {
sql: "SQL Query",
minTimestamp: "Min Timestamp",
},
})SCHEMA
Inputs
Pipedream supplies the connected account. Your application provides the operation-specific values below. Dynamic inputs are resolved against that user's account.
| Property | Type | Description |
|---|---|---|
sql SQL Query | string | The SQL query to run, e.g. SELECT start_timestamp, message, level FROM records ORDER BY start_timestamp DESC LIMIT 20. Required |
minTimestamp Min Timestamp | string | ISO 8601 timestamp to bound the query's start time, e.g. 2025-01-15T00:00:00Z. Defaults to 24 hours before now if not provided. Optional |
maxTimestamp Max Timestamp | string | ISO 8601 timestamp to bound the query's end time, e.g. 2025-01-15T23:59:59Z. Defaults to now if not provided. Optional |
limit Limit | integer | Maximum number of rows to return. Defaults to 100, max 10000. Optional |
REFERENCE
Tool details
Behavior hints are published with the component in the Pipedream registry and surface as MCP tool annotations, so an agent can reason about a tool before it calls it.
- Registry key
- logfire-run-sql-query
- Version
- 0.0.2
- App
- Logfire
- Authentication
- API key
- Read-only
- Yes
- Destructive
- No
- Open world
- Yes
- Source
- View on GitHub ↗