How to integrate local data with AI tools using MCP (Model Context Protocol) after Stack Overflow AI
Stack Overflow recently introduced AI Assist, and I see references to MCP (Model Context Protocol) as a way to connect local data sources to AI tools.
I have a local dataset (PostgreSQL + some files on disk), and I want to expose it to an AI assistant in a controlled way (not just dumping everything into prompts).
Questions:
- What is the correct architecture for MCP-based integration?
- Do I need to run a local MCP server or is it just a client-side protocol?
- How do you handle auth and data scoping (e.g. avoid leaking sensitive rows)?
- Any minimal working example?
I checked docs but most examples are abstract.
Answers
[email protected]
+++
[email protected]
+++
David Krüger
One thing missing in other answers: context vs tools.
MCP supports:
Use cases:
If you push everything as tools, model will over-call them.
If you push everything as context, you hit token limits.
Balanced approach:
Also:
Sebastian Braun
don't break tool contracts silently
Learned this the hard way. Model kept calling old schema for hours.
David Krüger
Yes, models cache patterns aggressively. Backward compatibility matters even here.
Jonas Richter
Minimal working setup (what actually worked for me):
Stack:
Steps:
Example (Node.js sketch):
server.tool("getUserByEmail", async ({ email }) => {
return db.query("SELECT id, name FROM users WHERE email = $1", [email]);
});
Important:
Gotchas:
Marie Hoffmann
Did you handle pagination at tool level or model level?
Jonas Richter
Tool level only. Model is unreliable for pagination control.
Felix Weber
You're overcomplicating it slightly.
You don't "connect database to AI". You expose capabilities, not raw data.
Bad approach:
Correct approach:
Example:
def get_customer_orders(customer_id: str) -> list:
# validated, scoped query
Then expose THIS as MCP tool.
Why:
For files:
Example:
Tobias Klein
This. People treat MCP like "AI can now see everything". That's exactly what you should avoid.
Felix Weber
Yes, MCP makes it easier to do the wrong thing faster.
Lukas Schneider
Short answer: MCP is essentially a structured bridge between your data and the model, and yes — you typically run an MCP server locally (or near your data).
Architecture (minimal):
Typical flow:
Example (simplified pseudo-config):
{
"tools": [
{
"name": "query_db",
"input_schema": {
"type": "object",
"properties": {
"sql": { "type": "string" }
}
}
}
]
}
Then your backend maps query_db → actual DB execution.
Security:
MCP itself does not enforce auth — you must handle it at the server layer.
Anna Müller
"MCP itself does not enforce auth"
This is what confused me. So basically it's just transport + schema, not policy?
Lukas Schneider
Exactly. Think of MCP like a typed RPC layer for models. All security is your responsibility.