.. MCP Send Mail
Create an MCP Microservice using Copilot Vibe

This illustrates GenAI-Logic automation to create an MCP system using Vibe:
1) Natural Language, 2) Declarative (what not now), 3) Trusted error correction with the coding assistant.
This enables Business Uses to choreograph new functionality composed of existing services. In the example above, a user has used NL to send email, leveraging the underlying services to query and send email.
Please load `.github/.copilot-instructions.md`
Important: be sure CoPilot is in "Agent" Mode. "Ask" will not work. Also, we get consistently good results with
Claude Sonnet 4.6.
How to Use This Demo
This demo teaches AI-assisted development patterns. Each step is a natural language prompt you copy/paste into Copilot chat. The prompts are self-documenting - they explain what they do.
Vibe Philosophy: AI makes errors. That's expected. When something fails, tell Copilot: "Error X occurred, fix it". Copilot is exceptionally good at finding and correcting its own mistakes.
Recommended Path: If you're new to GenAI-Logic, start with the Standard Demo (creates basic_demo with guided tutor) to learn platform fundamentals. Then return here to explore AI-assisted development with basic_demo_vibe.
Demo Overview: Vibe an MCP API and Business Logic; pre-reqs
Here we will use Vibe to:
-
Create From Existing DB - Provides a MCP-enabled API and an Admin App - Project Opens: Run - Launch and verify your system
-
Declare Business Logic - Add rules with natural language
-
Enterprise Connectivity: B2B - Create integration endpoints
-
MCP: Logic, User Interface - Implement Model Context Protocol
-
Iterate: Rules and Python - Advanced customization patterns
Pre-reqs:
- Install
- OpenAI API Key is useful but not required; click here.
- The
integration/mcp/mcp_client_executor.pyhascreate_tool_context_from_llmset to bypass LLM calls and use saved context; alter as required.
The entire process takes 20 minutes; usage notes:
- You may find it more convenient to view this in your Browser; click here
- A slide show summary is available on our Web Site
- Tip: look for readme files in created projects

1. Create From Existing DB
Create the Customer, Orders, Items and Product Project [typically already done using Manager]
Create a database project named basic_demo_vibe from samples/dbs/basic_demo.sqlite
Your project includes a data model diagram

1a. Project Opens: Run
The project should automatically open a new window in VSCode.
Please load `.github/.copilot-instructions.md`.
Run it as follows:
- Start the Server: F5
- Start the Admin App: browse to http://localhost:5656/. The Admin App screen shown below should appear in your Browser.
- Verify as shown below
API: filtering, sorting, pagination, optimistic locking,related data access... see Swagger
Your API is MCP enabled, and ready for custom app dev. For more information, click here.

Admin App: multi-page, multi-table, automatic joins, lookups, cascade add - collaboration-ready
For more information, click here.
The Admin App is ready for business user agile collaboration, and back office data maintenance. This complements custom UIs created with the API.
Explore the app - click Customer Alice, and see their Orders, and Items.

2. Declare Business Logic
Logic (multi-table derivations and constraints) is a significant portion of a system, typically nearly half. GenAI-Logic provides spreadsheet-like rules that dramatically simplify and accelerate logic development.
Rules are declared in Python, simplified with IDE code completion. The screen below shows the 5 rules for Check Credit Logic.
1. Stop the Server (Red Stop button, or Shift-F5 -- see Appendix)
2. Add Business Logic
on Placing Orders, Check Credit
1. The Customer's balance is less than the credit limit
2. The Customer's balance is the sum of the Order amount_total where date_shipped is null
3. The Order's amount_total is the sum of the Item amount
4. The Item amount is the quantity * unit_price
5. The Item unit_price is copied from the Product unit_price
Use case: App Integration
1. Send the Order to Kafka topic 'order_shipping' if the date_shipped is not None.

To test the logic:
1. Use the Admin App to access the first order for Customer Alice
2. Edit its first item to a very high quantity
The update is properly rejected because it exceeds the credit limit. Observe the rules firing in the console log - see Logic In Action, below.
Logic is critical - half the effort; Declarative is 40X More Concise, Maintainable
Logic is critical to your system - it represents nearly half the effort. Instead of procedural code, declare logic with WebGenAI, or in your IDE using code completion or Natural Language as shown above.
a. 40X More Concise
The 5 spreadsheet-like rules represent the same logic as 200 lines of code, shown here. That's a remarkable 40X decrease in the backend half of the system.
💡 No FrankenCode
Note the rules look like syntactically correct requirements. They are not turned into piles of unmanageable "frankencode" - see models not frankencode.
b. Maintainable: Debugging, Logging
The screenshot below shows our logic declarations, and the logging for inserting an Item. Each line represents a rule firing, and shows the complete state of the row.
Note that it's a Multi-Table Transaction, as indicated by the indentation. This is because - like a spreadsheet - rules automatically chain, including across tables.

3. Custom API - B2B Orders
To fit our system into the Value Chain, we need a Custom API to accept orders from B2B partners, and forward paid orders to shipping via Kafka.
Create a B2B order API called 'OrderB2B' that accepts orders from external partners.
The external format should map:
- 'Account' field to find customers by name
- 'Notes' field to order notes
- 'Items' array where each item maps 'Name' to find products and 'QuantityOrdered' to item quantity
The API should create complete orders with automatic lookups and inherit all business logic rules.
The Kafka logic was created earlier, so we are ready to test.
You can use Swagger (note the test data is provided), or use CLI:
curl -X POST http://localhost:5656/api/OrderB2BEndPoint/OrderB2B -H "Content-Type: application/json" -d '{"meta":{"args":{"data":{"Account":"Alice","Notes":"RUSH order for Q4 promotion","date_shipped":"2025-08-04","Items":[{"Name":"Widget","QuantityOrdered":5},{"Name":"Gadget","QuantityOrdered":3}]}}}}'
Observe the logic execution in the VSCode debug window.
4. MCP: Logic, User Interface
The server is automatically mcp-enabled, but we also require a user-interface to enable business users to send email, subject to business logic for customer email opt-outs. Build it as follows:
1. Stop the Server: click the red stop icon 🟥 or press Shift+F5.
4a. Create the email service
We use the Request Pattern to send emails, via Copilot (in conjunction with substantial Context Engineering in your project at .github/.copilot-instructions.md and docs/training):
Create a table SysEmail in `database/db.sqlite` as a child of customer,
with columns id, message, subject, customer_id and CreatedOn.
Follow the suggestions to update the admin app.
Ask it to do so if it fails to offer the suggestion.
Request objects are a common rule pattern - for more information, click here.
Add an after_flush event on SysEmail to produce a log message "email sent",
unless the customer has opted out.
Inserts into SysEmail will now send mails (stubbed here with a log message).
4b. Activate MCP Client Executor
Your project already has integration/mcp/mcp_client_executor.py, which processes MCP requests.
MCP Clients accept MCP Requests, invoke the LLM to obtain a series of API calls to run, and runs them. For more on MCP, click here.
To activate the MCP Client Executor:
Context Engineering has trained Copilot to use (again) the Request Pattern:
- Creates the
SysMcprequest object (new table, also added to Admin App) -
Creates Request Implementation:
logic/logic_discovery/send_email.py, which provides anafter_flush_row_eventonSysMcpto invokeintegration/mcp/mcp_client_executor.py.
Creates logic like this
When sending email, we require business rules to ensure it respects the opt-out policy:

5. Test in the Admin App
1. Restart the Server and Start the Admin App
List the orders date_shipped is null and CreatedOn before 2023-07-14,
and send a discount email (subject: 'Discount Offer')
to the customer for each one.

6. Iterate: Rules and Python
This is addressed in the related CLI-based demo - to continue, click here.
