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

  • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

    David Krüger

    (Edited)

    One thing missing in other answers: context vs tools.

    MCP supports:

    • 1.resources (context)
    • 2.tools (actions)

    Use cases:

    • 1.Resources → static or semi-static data (docs, configs)
    • 2.Tools → dynamic queries / mutations

    If you push everything as tools, model will over-call them.
    If you push everything as context, you hit token limits.

    Balanced approach:

    • 1.small reference datasets → resources
    • 2.everything dynamic → tools

    Also:

    • 1.version your schemas
    • 2.don't break tool contracts silently
    0
    • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

      Sebastian Braun

      (Edited)

      don't break tool contracts silently

      Learned this the hard way. Model kept calling old schema for hours.

      • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

        David Krüger

        (Edited)

        Yes, models cache patterns aggressively. Backward compatibility matters even here.

  • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

    Jonas Richter

    (Edited)

    Minimal working setup (what actually worked for me):

    Stack:

    • local MCP server (Node.js)
    • wrapper around PostgreSQL
    • AI client (AI Assist)<

    Steps:

    • 1. Start MCP server with tool registry
    • 2. Implement tool handler
    • 3. Register server in AI client
    • 4. Test with simple prompt

    Example (Node.js sketch):

    		
    server.tool("getUserByEmail", async ({ email }) => { return db.query("SELECT id, name FROM users WHERE email = $1", [email]); });

    Important:

    • Return structured JSON, not text blobs
    • Keep responses small
    • Add timeouts

    Gotchas:

    • If tool is slow → model may retry
    • If schema is vague → model sends garbage input
    • Logging is critical (you need to see what model is calling)
    0
    • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

      Marie Hoffmann

      (Edited)

      Did you handle pagination at tool level or model level?

      • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

        Jonas Richter

        (Edited)

        Tool level only. Model is unreliable for pagination control.

  • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

    Felix Weber

    (Edited)

    You're overcomplicating it slightly.

    You don't "connect database to AI". You expose capabilities, not raw data.

    Bad approach:

    • Give model direct SQL access

    Correct approach:

    • Wrap domain logic into tools

    Example:

    		
    def get_customer_orders(customer_id: str) -> list: # validated, scoped query

    Then expose THIS as MCP tool.

    Why:

    • Models are bad at writing safe SQL
    • You control performance and limits
    • Easier to audit

    For files:

    • expose semantic access, not filesystem paths

    Example:

    • get_invoice_pdf(invoice_id)
    • NOT: read_file("/mnt/data/...")
    0
    • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

      Tobias Klein

      (Edited)

      This. People treat MCP like "AI can now see everything". That's exactly what you should avoid.

      • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

        Felix Weber

        (Edited)

        Yes, MCP makes it easier to do the wrong thing faster.

  • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

    Lukas Schneider

    (Edited)

    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):

    • MCP Server → exposes tools/resources (DB queries, file access, etc.)
    • AI Client (e.g. AI Assist) → connects to MCP server
    • Model → calls MCP tools via the client

    Typical flow:

    • 1. You define "resources" (read-only datasets, file trees, etc.)
    • 2. You define "tools" (functions like query_db, read_file)
    • 3. MCP server exposes these over a standardized interface
    • 4. AI client negotiates capabilities and invokes tools

    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:

    • NEVER expose raw SQL execution without validation
    • Use allowlists or query builders
    • Scope data per session/user

    MCP itself does not enforce auth — you must handle it at the server layer.

    0
    • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

      Anna Müller

      (Edited)

      "MCP itself does not enforce auth"

      This is what confused me. So basically it's just transport + schema, not policy?

      • Gravatar — онлайн-сервис, позволяющий пользователям Интернета поддерживать постоянную картинку на большинстве сайтов.

        Lukas Schneider

        (Edited)

        Exactly. Think of MCP like a typed RPC layer for models. All security is your responsibility.