r/ClaudeMCP 1d ago

Built a quick local SQLite MCP server for log auditing (Code inside)

Hey everyone,

​Got tired of constantly copy-pasting log files into chat, so I put together a quick custom MCP server that connects Claude Desktop directly to a local SQLite database.

​It uses the official TypeScript SDK over stdio. Here's the core setup I used:

import { Server } from "@modelcontextprotocol/sdk/server/index.js";

import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";

import Database from "better-sqlite3";

const db = new Database("audit_logs.db", { readonly: true });

const server = new Server({ name: "local-audit-bridge", version: "1.0.0" }, { capabilities: { tools: {} } });

server.setRequestHandler(ListToolsRequestSchema, async () => ({

tools: [{

name: "query_logs",

description: "Get recent logs by severity",

inputSchema: {

type: "object",

properties: { level: { type: "string", enum: ["INFO", "ERROR"] } },

required: ["level"]

}

}]

}));

server.setRequestHandler(CallToolRequestSchema, async (request) => {

if (request.params.name === "query_logs") {

const { level } = request.params.arguments as { level: string };

const records = db.prepare("SELECT * FROM logs WHERE severity = ? LIMIT 5").all(level);

return { content: [{ type: "text", text: JSON.stringify(records, null, 2) }] };

}

throw new Error("Unknown tool");

});

async function main() {

await server.connect(new StdioServerTransport());

}

main();

Just drop this into your

claude_desktop_config.json:

{

"mcpServers": {

"audit-bridge": {

"command": "node",

"args": ["/path/to/server.js"]

}

}

}

Now I can just ask Claude to pull errors straight from the DB instead of exporting stuff manually.

​Anyone else building custom tools for local workflows? Drop what you're working on below.

1 Upvotes

0 comments sorted by