MCP Integration: AI for databases with .NET

Learn to use Model Context Protocol (MCP) and MaIN.NET to query databases with AI through natural language, connecting Airtable and other backends with CRUD and interactive assistants.

lunes, 18 de agosto de 2025 • 7 min read • Q2BSTUDIO Team

Artificial-Intelligence-

In this article explained and translated into Spanish you will learn to create powerful database tools with artificial intelligence using Model Context Protocol MCP and the MaIN.NET framework. The goal is to build applications that interact with any database through natural language queries, optimizing workflows for businesses and custom software projects.

What you will build: a console application that demonstrates natural language queries to databases, integration with MCP servers to connect any data engine, AI-driven data operations to create, read, update and delete records, and an interactive assistant to chat with data.

Why use Airtable: this tutorial uses Airtable for its simplicity and ease of setup, but the techniques are applicable to any database engine supported by MCP servers. You can adapt the pattern to SQL databases such as MySQL, PostgreSQL, SQLite and SQL Server; NoSQL such as MongoDB, Cassandra or Redis; cloud stores such as BigQuery, Snowflake or DynamoDB; file systems with CSV and JSON; or REST and GraphQL APIs. The advantage of the MCP protocol is that once you understand the pattern you can replace Airtable with any other backend by changing the MCP server configuration.

Requirements: Microsoft .NET SDK installed, Node.js to run MCP servers, Airtable account for the example, API key from OpenAI or the chosen AI provider, and basic knowledge of C# and DI patterns in .NET. It is also recommended to have development environments and permissions to manage tokens and environment variables.

Step 1 Set up the database in Airtable: create a new base called Employees and upload a sample CSV with fields Name Email Department Position Hire Date Salary Is Active. Example CSV content separated by commas: Name,Email,Department,Position,Hire Date,Salary,Is Active John Smith,john.smith@company.com,Engineering,Senior Developer,2024-01-15,85000,TRUE Sarah Johnson,sarah.j@company.com,Marketing,Marketing Manager,2024-03-20,75000,TRUE Mike Davis,mike.davis@company.com,Sales,Sales Representative,2024-06-10,65000,TRUE Lisa Chen,lisa.chen@company.com,Engineering,Junior Developer,2024-08-05,70000,TRUE Tom Wilson,tom.wilson@company.com,HR,HR Specialist,2024-02-28,60000,TRUE Emma Rodriguez,emma.rodriguez@company.com,Finance,Financial Analyst,2023-04-12,72000,TRUE David Kim,david.kim@company.com,Engineering,DevOps Engineer,2023-07-18,90000,TRUE Maria Garcia,maria.garcia@company.com,Marketing,Content Specialist,2023-05-25,68000,TRUE James Brown,james.brown@company.com,Sales,Sales Manager,2023-09-30,82000,TRUE Anna Lee,anna.lee@company.com,Engineering,Frontend Developer,2023-11-08,78000,TRUE. When importing, Airtable detects columns and adjusts types: Name and Email text, Department single select with values Engineering Marketing Sales HR Finance, Position text, Hire Date date, Salary number, Is Active checkbox. Generate a personal access token in Airtable with permissions schema.bases:read data.records:read data.records:write and assign access to the specific base. Save the token securely in an environment variable called AIRTABLE_API_KEY.

Step 2 Create the console application in .NET: run dotnet new console -n EmployeeMCP and navigate to the EmployeeMCP directory. Add the MaIN.NET package with dotnet add package MaIN.NET. The general flow of the app includes reading environment variables AIRTABLE_API_KEY and OPENAI_API_KEY, configuring MaIN.NET with the AI backend key, initializing the service container and creating the AIHub instance that will be the central interface for MCP calls.

Step 3 Structure and operation of the application: the application validates that environment variables are defined and explains how to initialize MaIN.NET using ConfigurationBuilder and ServiceCollection. MaIN.NET is registered using AddMaIN and the AI backend is configured by assigning BackendType OpenAi or the chosen provider and the OpenAI key. After building the service provider, UseMaIN is called to initialize the framework. Next, the MCP configuration for Airtable is defined specifying the server name, command npx airtable-mcp-server, the model to use and the necessary environment variables such as AIRTABLE_API_KEY. The application enters an interactive loop where the user writes natural language queries and the app sends those queries via AIHub.Mcp WithConfig PromptAsync to the MCP server, which interprets the intent with the AI model and executes calls to the Airtable API returning responses in natural language.

Key concepts about MCP and servers: Model Context Protocol is a standard that allows language models to interact with external tools in a structured way. The MCP server acts as a bridge between the AI and the service API, running as an independent Node.js process managed by MaIN.NET via stdio. MaIN.NET starts and stops the server as needed and handles the communication protocol. This allows sending natural language intents and receiving results ready to show to the user.

Interaction details: when the app runs AIHub.Mcp WithConfig PromptAsync the library starts the process npx -y airtable-mcp-server, establishes communication through standard input and output, transmits the query and waits for the response. The MCP processes the intent, makes calls to the Airtable API to read or modify records and returns a message that the app shows to the user. The flow supports CRUD operations and respects validations such as the exact use of values for single select fields.

Managing single select fields: when working with single select fields in Airtable you must use exact and case-sensitive values if the field is defined that way. Examples of valid departments Engineering Marketing Sales HR Finance. Example queries include Show me all employees List employees in Engineering department Who was hired in 2023 Show employees with salary above 80000 How many active employees do we have. For natural language data operations examples: Add a new employee Alex Brown alex@company.com Engineering Junior Developer Update Sarah Johnson salary to 80000 Mark Tom Wilson as inactive.

Environment variables and execution: define AIRTABLE_API_KEY and OPENAI_API_KEY in your environment before running the application. Basic commands to build and run dotnet build and dotnet run. Node.js must be installed for MCP servers to work correctly.

Support for other AI backends: MaIN.NET is not limited to OpenAI. You can change BackendType to GroqCloud Gemini DeepSeek and pass the corresponding key from environment variables GROQ_API_KEY GEMINI_API_KEY DEEPSEEK_API_KEY. Also adjust the model name according to the provider.

Testing and validation: perform basic queries and data operations that test reading, filtering, simple aggregations and updates. Verify AI responses and confirm that API calls modify real records as expected. Implement error handling and validations to avoid accidental changes in production.

Production best practices: do not hardcode keys in the repository, use vaults or secret management services, audit operations that modify data, implement access control and roles for MCP calls that execute destructive actions, and add logging and metrics to monitor performance and costs of AI model calls.

Next steps and extensions: add more MCP servers for integrations with GitHub File System BigQuery MySQL PostgreSQL MongoDB ClickHouse and others. Build a web interface with Blazor or React to offer a graphical experience, add caching to improve performance on frequent queries, and create AI agents that run scheduled tasks or automated workflows. Integrate visualizations with Power BI for dashboards and automatic reports from your AI-processed data.

Resources and MCP servers: check the server collection at mcpservers.org to discover connections with databases, file systems and cloud services. Review the official MaIN.NET documentation at github com slash wisedev-code Slash MaIN.NET and the Model Context Protocol site to understand the best practices of the protocol. For the Airtable server review the airtable-mcp-server entry at mcpservers org Slash servers.

About Q2BSTUDIO: we are Q2BSTUDIO, a custom software and application development company, specialists in artificial intelligence, cybersecurity and cloud services aws and azure. We design custom software and custom applications aimed at solving real business challenges, implementing business intelligence services and AI solutions for companies that require automation, advanced analytics and personalized AI agents. We offer comprehensive services that include security assessment, hardening, business continuity and cloud architecture consulting on AWS and Azure. We also develop integrations with Power BI and visualization tools to turn data into strategic decisions.

Why hire Q2BSTUDIO: we combine experience in custom software and custom software with practical implementation of artificial intelligence for businesses, creating AI agents that automate tasks, data pipelines and business intelligence solutions that accelerate decision-making. Our offering includes secure development with cybersecurity practices, deployment on cloud services aws and azure, and knowledge transfer for internal teams.

Strategic keywords for positioning: custom applications custom software artificial intelligence cybersecurity cloud services aws and azure business intelligence services AI for businesses AI agents power bi. We integrate these capabilities into real projects where AI facilitates natural language queries to databases, improves operational efficiency and enables creating intelligent user experiences.

Conclusion: with MaIN.NET and MCP you can build AI tools that talk to any database, facilitating natural queries, CRUD operations and interactive assistants that transform data into value. If you need support to implement a custom solution, integrate AI agents, secure your systems or deploy on cloud services aws and azure contact Q2BSTUDIO for a professional service in software development artificial intelligence solutions and cybersecurity.

Contact and next steps: evaluate your use case, prepare access and sample data, and get in touch with Q2BSTUDIO to design a proof of concept that connects your data sources with AI agents and business intelligence dashboards in Power BI. We can help you scale the solution and integrate more MCP servers for a unified and secure data platform.

Happy development and welcome to the world of AI applied to databases with MCP and MaIN.NET from Q2BSTUDIO, experts in custom applications custom software artificial intelligence cybersecurity cloud services aws and azure business intelligence services AI for businesses AI agents and power bi

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.