ApiLogicServer 15.3.2__py3-none-any.whl → 15.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- api_logic_server_cli/api_logic_server.py +3 -2
- api_logic_server_cli/api_logic_server_info.yaml +3 -3
- api_logic_server_cli/create_from_model/api_logic_server_utils.py +3 -1
- api_logic_server_cli/prototypes/base/.github/.copilot-instructions.md +147 -4
- api_logic_server_cli/prototypes/base/docs/training/MCP_Copilot_Integration.md +295 -0
- api_logic_server_cli/prototypes/base/logic/readme_logic.md +38 -25
- api_logic_server_cli/prototypes/basic_demo/.github/.copilot-instructions.md +291 -26
- api_logic_server_cli/prototypes/basic_demo/.github/welcome.md +26 -0
- api_logic_server_cli/prototypes/basic_demo/customizations/logic/declare_logic.py +5 -0
- api_logic_server_cli/prototypes/basic_demo/logic/procedural/declarative-vs-procedural-comparison.md +301 -198
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/logic/logic_discovery/check_credit.py +4 -1
- {apilogicserver-15.3.2.dist-info → apilogicserver-15.4.0.dist-info}/METADATA +1 -1
- {apilogicserver-15.3.2.dist-info → apilogicserver-15.4.0.dist-info}/RECORD +17 -15
- {apilogicserver-15.3.2.dist-info → apilogicserver-15.4.0.dist-info}/WHEEL +0 -0
- {apilogicserver-15.3.2.dist-info → apilogicserver-15.4.0.dist-info}/entry_points.txt +0 -0
- {apilogicserver-15.3.2.dist-info → apilogicserver-15.4.0.dist-info}/licenses/LICENSE +0 -0
- {apilogicserver-15.3.2.dist-info → apilogicserver-15.4.0.dist-info}/top_level.txt +0 -0
|
@@ -12,10 +12,10 @@ ApiLogicServer CLI: given a database url, create [and run] customizable ApiLogic
|
|
|
12
12
|
Called from api_logic_server_cli.py, by instantiating the ProjectRun object.
|
|
13
13
|
'''
|
|
14
14
|
|
|
15
|
-
__version__ = "15.
|
|
15
|
+
__version__ = "15.04.00" # last public release: 15.03.02
|
|
16
16
|
recent_changes = \
|
|
17
17
|
f'\n\nRecent Changes:\n' +\
|
|
18
|
-
"\t11/
|
|
18
|
+
"\t11/08/2025 - 15.04.00: Nat lang Copilot data access, fix Manager/Copilot startup, finding venv in project \n"\
|
|
19
19
|
"\t10/29/2025 - 15.03.00: Stable Tutor 3.3 (working, vibe transtion) \n"\
|
|
20
20
|
"\t10/26/2025 - 15.02.07: Clarify order created for ship test, security fixes [105], tutor 2.1 \n"\
|
|
21
21
|
"\t10/22/2025 - 15.02.03: Copilot test creation from rules and custom APIs with issues [103, 104] \n"\
|
|
@@ -402,6 +402,7 @@ def create_project_and_overlay_prototypes(project: 'ProjectRun', msg: str) -> st
|
|
|
402
402
|
os.rename(project.project_directory_path / 'readme.md', project.project_directory_path / 'readme_standard.md')
|
|
403
403
|
create_utils.copy_md(project = project, from_doc_file = "Sample-Basic-Demo.md", to_project_file = "readme.md")
|
|
404
404
|
create_utils.copy_md(project = project, from_doc_file = "Sample-Basic-Demo-Vibe.md", to_project_file="readme_vibe.md")
|
|
405
|
+
create_utils.copy_md(project = project, from_doc_file = "Integration-MCP-AI-Example.md", to_project_file="readme_ai_mcp.md")
|
|
405
406
|
|
|
406
407
|
|
|
407
408
|
if project.db_url == "mysql+pymysql://root:p@localhost:3306/classicmodels":
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
last_created_date:
|
|
2
|
-
last_created_project_name:
|
|
3
|
-
last_created_version: 15.
|
|
1
|
+
last_created_date: November 08, 2025 08:44:56
|
|
2
|
+
last_created_project_name: ../../../servers/basic_demo
|
|
3
|
+
last_created_version: 15.04.00
|
|
@@ -84,7 +84,7 @@ def copy_md(project, from_doc_file: str, to_project_file: str = "README.md"):
|
|
|
84
84
|
|
|
85
85
|
1. github (to acquire more recent version since release)
|
|
86
86
|
|
|
87
|
-
2. dev docs, iff exists (gold version in docs, not prototypes).
|
|
87
|
+
2. dev docs, iff exists (**gold version in docs, not prototypes**).
|
|
88
88
|
|
|
89
89
|
Used by Sample-AI; Sample-Integration (nw-), Tutorial, Tutorial-3 (3 projects), Sample-Basic-Demo; Manager
|
|
90
90
|
|
|
@@ -98,6 +98,8 @@ def copy_md(project, from_doc_file: str, to_project_file: str = "README.md"):
|
|
|
98
98
|
|
|
99
99
|
Doc Links are made absolute.
|
|
100
100
|
|
|
101
|
+
See: https://apilogicserver.github.io/Docs/Architecture-Internals/#docs-used-in-project-creation
|
|
102
|
+
|
|
101
103
|
Args:
|
|
102
104
|
project (ProjectRun or Path): project object (project name, etc)
|
|
103
105
|
from_doc_file (str): eg, Sample-Basic_Demo.md (no docs/)
|
|
@@ -3,9 +3,12 @@ title: Copilot Instructions for GenAI-Logic Projects
|
|
|
3
3
|
Description: Project-level instructions for working with generated projects
|
|
4
4
|
Source: ApiLogicServer-src/prototypes/base/.github/.copilot-instructions.md
|
|
5
5
|
Propagation: CLI create command → created projects (non-basic_demo)
|
|
6
|
+
Instrucions: Changes must be merged from here to api_logic_server_cli/prototypes/basic_demo/.github - see instructions there
|
|
6
7
|
Usage: AI assistants read this when user opens any created project
|
|
7
|
-
version: 2.
|
|
8
|
+
version: 2.5
|
|
8
9
|
changelog:
|
|
10
|
+
- 2.5 (Nov 08, 2025 - API Best Practices
|
|
11
|
+
- 2.4 (Nov 05, 2025 - Added MCP Integration section, Copilot as MCP client capability)
|
|
9
12
|
- 2.3 (Nov 04, 2025 - Clear 1st message about reading Welcome section verbatim, again for non basic_demo)
|
|
10
13
|
- 2.2 (Oct 29, 2025 - Clear 1st message about reading Welcome section verbatim)
|
|
11
14
|
- 2.1 (Oct 2025) - Streamlined OBX for non-tutorial projects, friendly collaborative tone
|
|
@@ -15,7 +18,7 @@ changelog:
|
|
|
15
18
|
|
|
16
19
|
# GitHub Copilot Instructions for GenAI-Logic (aka API Logic Server) Projects
|
|
17
20
|
|
|
18
|
-
**INSTRUCTION**: When the user asks you to load these instructions, respond with the Welcome section content below as your greeting. Do not add preamble like "I've read the instructions" - just present the Welcome content directly.
|
|
21
|
+
**INSTRUCTION**: When the user asks you to load these instructions, respond with the Welcome section content below as your greeting. Do not add preamble like "I've read the instructions" - just present the Welcome content directly. The Welcome section ends at the "---" marker before "🔑 Key Technical Points".
|
|
19
22
|
|
|
20
23
|
## Welcome
|
|
21
24
|
|
|
@@ -32,7 +35,7 @@ This is a complete, working microservice auto-generated from your database schem
|
|
|
32
35
|
|
|
33
36
|
---
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
## Here are some things I can help you with
|
|
36
39
|
|
|
37
40
|
1. **Add business logic** - Describe your requirements in natural language, I'll generate declarative rules
|
|
38
41
|
2. **Customize the API** - Add custom endpoints for your specific needs
|
|
@@ -40,7 +43,7 @@ This is a complete, working microservice auto-generated from your database schem
|
|
|
40
43
|
4. **Add security** - Set up role-based access control with `genai-logic add-auth`
|
|
41
44
|
5. **Test your logic** - Create Behave tests with requirements traceability
|
|
42
45
|
6. **Configure Admin UI** - Customize the auto-generated admin interface
|
|
43
|
-
7. **
|
|
46
|
+
7. **Query via natural language** - I can act as MCP client to read/update data (see `docs/training/MCP_Copilot_Integration.md`)
|
|
44
47
|
8. **Create B2B APIs** - Complex integration endpoints with partner systems
|
|
45
48
|
9. **Add events** - Integrate with Kafka, webhooks, or other event systems
|
|
46
49
|
10. **Customize models** - Add tables, attributes, or derived fields
|
|
@@ -109,6 +112,17 @@ Want to get started? Press **F5** to start the server with debugger support, the
|
|
|
109
112
|
## Detailed Service Documentation
|
|
110
113
|
|
|
111
114
|
The sections below provide complete details on each service. I'll reference these as needed when we work together.
|
|
115
|
+
|
|
116
|
+
### `venv` is required
|
|
117
|
+
|
|
118
|
+
To establish the virtual environment:
|
|
119
|
+
|
|
120
|
+
1. Attempt to find a `venv` folder in the parent or grandparent directory
|
|
121
|
+
2. Or, create it using requirements.txt
|
|
122
|
+
|
|
123
|
+
### Starting the server
|
|
124
|
+
|
|
125
|
+
```bash
|
|
112
126
|
python api_logic_server_run.py
|
|
113
127
|
# Then open: http://localhost:5656
|
|
114
128
|
```
|
|
@@ -236,6 +250,135 @@ When users provide natural language with multiple use cases like:
|
|
|
236
250
|
|
|
237
251
|
**NEVER put everything in `use_case.py`** - that defeats the discovery system purpose.
|
|
238
252
|
|
|
253
|
+
### MCP Integration - Acting as Database Client
|
|
254
|
+
|
|
255
|
+
**You (GitHub Copilot) can serve as an MCP client** to read and update database entities using natural language queries!
|
|
256
|
+
|
|
257
|
+
**Architecture**: This project implements **MCP Server Executor** - a business logic microservice that AI assistants interact with via authenticated REST API calls. See `docs/training/MCP_Copilot_Integration.md` for complete details.
|
|
258
|
+
|
|
259
|
+
**When users request database operations** (e.g., "list customers", "update credit limit", "what's the balance?"):
|
|
260
|
+
|
|
261
|
+
1. **Authenticate first** - Login to obtain JWT token:
|
|
262
|
+
```bash
|
|
263
|
+
curl -X POST http://localhost:5656/api/auth/login \
|
|
264
|
+
-H "Content-Type: application/json" \
|
|
265
|
+
-d '{"username":"admin","password":"p"}'
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
2. **Execute operations** - Use Bearer token for API calls:
|
|
269
|
+
```bash
|
|
270
|
+
# Read: List entities
|
|
271
|
+
curl -X GET http://localhost:5656/api/Customer/ \
|
|
272
|
+
-H "Authorization: Bearer {token}"
|
|
273
|
+
|
|
274
|
+
# Update: Change attributes (JSON:API format)
|
|
275
|
+
curl -X PATCH http://localhost:5656/api/Customer/ALFKI/ \
|
|
276
|
+
-H "Authorization: Bearer {token}" \
|
|
277
|
+
-H "Content-Type: application/vnd.api+json" \
|
|
278
|
+
-d '{"data": {"type": "Customer", "id": "ALFKI", "attributes": {"CreditLimit": 5000}}}'
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
3. **Handle constraint violations correctly** - Error code 2001 is SUCCESS!
|
|
282
|
+
- When LogicBank prevents invalid updates, report as: "✅ Business logic working - constraint prevented invalid operation"
|
|
283
|
+
- Example: "balance (2102.00) exceeds credit (1000.00)" = logic is protecting data integrity
|
|
284
|
+
|
|
285
|
+
**Natural Language Translation Examples**:
|
|
286
|
+
- "List customers" → `GET /api/Customer/`
|
|
287
|
+
- "Show customer ALFKI" → `GET /api/Customer/ALFKI/`
|
|
288
|
+
- "Set ALFKI credit to 5000" → `PATCH /api/Customer/ALFKI/` with CreditLimit
|
|
289
|
+
- "What's ALFKI's balance?" → `GET /api/Customer/ALFKI/` then extract Balance attribute
|
|
290
|
+
|
|
291
|
+
**Key Principle**: Constraint violations (code 2001) demonstrate that declarative business logic is working correctly - celebrate these as successes, not failures!
|
|
292
|
+
|
|
293
|
+
See `docs/training/MCP_Copilot_Integration.md` for comprehensive guide including JSON:API payload formats, authentication workflows, and architecture details.
|
|
294
|
+
|
|
295
|
+
### API Interaction Best Practices
|
|
296
|
+
|
|
297
|
+
**CRITICAL: Always Use API, Not Direct Database Access**
|
|
298
|
+
|
|
299
|
+
When users request data operations (read, update, create, delete), **ALWAYS use the REST API** instead of direct database queries:
|
|
300
|
+
|
|
301
|
+
✅ **Correct Approach - Use API:**
|
|
302
|
+
```bash
|
|
303
|
+
# Simple, readable commands that trigger business logic
|
|
304
|
+
curl 'http://localhost:5656/api/Customer/?page[limit]=100'
|
|
305
|
+
curl -X PATCH 'http://localhost:5656/api/Item/2/' \
|
|
306
|
+
-H 'Content-Type: application/vnd.api+json' \
|
|
307
|
+
-d '{"data": {"type": "Item", "id": "2", "attributes": {"quantity": 100}}}'
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
❌ **Wrong Approach - Direct Database:**
|
|
311
|
+
```bash
|
|
312
|
+
# DON'T use sqlite3 commands for data operations
|
|
313
|
+
sqlite3 database/db.sqlite "UPDATE item SET quantity=100 WHERE id=2"
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
**Why API is Required:**
|
|
317
|
+
1. **Business Logic Execution** - Rules automatically fire (calculations, validations, constraints)
|
|
318
|
+
2. **Data Integrity** - Cascading updates handled correctly
|
|
319
|
+
3. **Audit Trail** - Operations logged through proper channels
|
|
320
|
+
4. **Security** - Authentication/authorization enforced
|
|
321
|
+
5. **Testing Reality** - Tests actual system behavior
|
|
322
|
+
|
|
323
|
+
**Server Startup for API Operations:**
|
|
324
|
+
|
|
325
|
+
When server needs to be started for API operations:
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
# Option 1: Background process (for interactive testing)
|
|
329
|
+
python api_logic_server_run.py &
|
|
330
|
+
sleep 5 # Wait for full startup (not 3 seconds - too short!)
|
|
331
|
+
|
|
332
|
+
# Option 2: Use existing terminal/process
|
|
333
|
+
# Check if already running: lsof -i :5656
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
**Common Mistakes to Avoid:**
|
|
337
|
+
|
|
338
|
+
1. ❌ **Insufficient startup wait**: `sleep 3` often fails
|
|
339
|
+
- ✅ Use: `sleep 5` or check with `curl` in retry loop
|
|
340
|
+
|
|
341
|
+
2. ❌ **Complex inline Python**: Piping JSON to `python3 -c` with complex list comprehensions
|
|
342
|
+
- ✅ Use: Simple `curl` commands, pipe to `jq` for filtering, or save to file first
|
|
343
|
+
|
|
344
|
+
3. ❌ **Database queries for CRUD**: Using `sqlite3` commands
|
|
345
|
+
- ✅ Use: API endpoints that trigger business logic
|
|
346
|
+
|
|
347
|
+
**Simple API Query Patterns:**
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
# Get all records (simple, reliable)
|
|
351
|
+
curl 'http://localhost:5656/api/Customer/'
|
|
352
|
+
|
|
353
|
+
# Get specific record by ID
|
|
354
|
+
curl 'http://localhost:5656/api/Customer/1/'
|
|
355
|
+
|
|
356
|
+
# Get related records (follow relationships)
|
|
357
|
+
curl 'http://localhost:5656/api/Customer/1/OrderList'
|
|
358
|
+
|
|
359
|
+
# Filter results (use bracket notation)
|
|
360
|
+
curl 'http://localhost:5656/api/Customer/?filter[name]=Alice'
|
|
361
|
+
|
|
362
|
+
# Limit results
|
|
363
|
+
curl 'http://localhost:5656/api/Customer/?page[limit]=10'
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
**Parsing JSON Responses:**
|
|
367
|
+
|
|
368
|
+
```bash
|
|
369
|
+
# Simple: Pipe to python -m json.tool for pretty printing
|
|
370
|
+
curl 'http://localhost:5656/api/Customer/' | python3 -m json.tool
|
|
371
|
+
|
|
372
|
+
# Better: Use jq if available
|
|
373
|
+
curl 'http://localhost:5656/api/Customer/' | jq '.data[] | {id, name: .attributes.name}'
|
|
374
|
+
|
|
375
|
+
# Alternative: Save to file first, then parse
|
|
376
|
+
curl 'http://localhost:5656/api/Customer/' > customers.json
|
|
377
|
+
python3 -c "import json; data=json.load(open('customers.json')); print(data['data'][0])"
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
**Key Principle**: The API is not just a convenience - it's the **only correct way** to interact with data because it ensures business logic executes properly.
|
|
381
|
+
|
|
239
382
|
### Automated Testing
|
|
240
383
|
|
|
241
384
|
**CRITICAL WORKFLOW - When User Says "Create Tests":**
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# MCP Integration Guide for Copilot
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This GenAI-Logic project implements **MCP Server Executor** architecture - providing business logic services that AI assistants (like GitHub Copilot) can invoke to read and update database entities using natural language.
|
|
6
|
+
|
|
7
|
+
**Key Distinction**: GenAI-Logic is NOT a standard "MCP Protocol Server" (JSON-RPC over stdio). Instead, it's a **business logic microservice** that AI assistants interact with via authenticated REST API calls. This architecture is more scalable and enterprise-ready than stdio-based MCP servers.
|
|
8
|
+
|
|
9
|
+
## Architecture
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
┌─────────────────────────────────┐
|
|
13
|
+
│ GitHub Copilot / Claude │ Natural language interface
|
|
14
|
+
│ (MCP Client / AI Assistant) │
|
|
15
|
+
└────────────┬────────────────────┘
|
|
16
|
+
│ HTTP REST API (JSON:API format)
|
|
17
|
+
│ JWT Authentication
|
|
18
|
+
┌────────────▼────────────────────┐
|
|
19
|
+
│ GenAI-Logic Server │ MCP Server Executor
|
|
20
|
+
│ (Flask + LogicBank) │ - Business logic enforcement
|
|
21
|
+
│ │ - Constraint validation
|
|
22
|
+
│ Endpoints: │ - Declarative rules (44X reduction)
|
|
23
|
+
│ - /api/auth/login │ - Schema metadata
|
|
24
|
+
│ - /api/{Entity} │
|
|
25
|
+
│ - /.well-known/mcp.json │
|
|
26
|
+
│ - /mcp │
|
|
27
|
+
└────────────┬────────────────────┘
|
|
28
|
+
│
|
|
29
|
+
┌────────────▼────────────────────┐
|
|
30
|
+
│ Database (SQLAlchemy ORM) │
|
|
31
|
+
└─────────────────────────────────┘
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## How Copilot Acts as MCP Client
|
|
35
|
+
|
|
36
|
+
GitHub Copilot can serve as an interactive MCP client by:
|
|
37
|
+
|
|
38
|
+
1. **Authenticating** - Login to obtain JWT token
|
|
39
|
+
2. **Translating** - Convert natural language to API operations
|
|
40
|
+
3. **Executing** - Make authenticated HTTP calls
|
|
41
|
+
4. **Reporting** - Present results or explain constraint violations
|
|
42
|
+
|
|
43
|
+
## Copilot Usage Pattern
|
|
44
|
+
|
|
45
|
+
### Step 1: Authentication
|
|
46
|
+
|
|
47
|
+
When user requests database operations, Copilot should first authenticate:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
curl -X POST http://localhost:5656/api/auth/login \
|
|
51
|
+
-H "Content-Type: application/json" \
|
|
52
|
+
-d '{"username":"admin","password":"p"}'
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Response contains JWT token:
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
|
|
59
|
+
"token_type": "Bearer"
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Step 2: Execute Operations
|
|
64
|
+
|
|
65
|
+
Use token for authenticated requests:
|
|
66
|
+
|
|
67
|
+
#### Read Operations (GET)
|
|
68
|
+
```bash
|
|
69
|
+
# List customers
|
|
70
|
+
curl -X GET http://localhost:5656/api/Customer/ \
|
|
71
|
+
-H "Authorization: Bearer {token}"
|
|
72
|
+
|
|
73
|
+
# Get specific customer
|
|
74
|
+
curl -X GET http://localhost:5656/api/Customer/ALFKI/ \
|
|
75
|
+
-H "Authorization: Bearer {token}"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### Update Operations (PATCH)
|
|
79
|
+
```bash
|
|
80
|
+
# Update customer credit limit
|
|
81
|
+
curl -X PATCH http://localhost:5656/api/Customer/ALFKI/ \
|
|
82
|
+
-H "Authorization: Bearer {token}" \
|
|
83
|
+
-H "Content-Type: application/vnd.api+json" \
|
|
84
|
+
-d '{
|
|
85
|
+
"data": {
|
|
86
|
+
"type": "Customer",
|
|
87
|
+
"id": "ALFKI",
|
|
88
|
+
"attributes": {
|
|
89
|
+
"CreditLimit": 5000
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}'
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### Create Operations (POST)
|
|
96
|
+
```bash
|
|
97
|
+
# Create new customer
|
|
98
|
+
curl -X POST http://localhost:5656/api/Customer/ \
|
|
99
|
+
-H "Authorization: Bearer {token}" \
|
|
100
|
+
-H "Content-Type: application/vnd.api+json" \
|
|
101
|
+
-d '{
|
|
102
|
+
"data": {
|
|
103
|
+
"type": "Customer",
|
|
104
|
+
"attributes": {
|
|
105
|
+
"Id": "NEWCO",
|
|
106
|
+
"CompanyName": "New Company Inc",
|
|
107
|
+
"ContactName": "John Doe",
|
|
108
|
+
"CreditLimit": 1000
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}'
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Step 3: Handle Constraint Violations
|
|
115
|
+
|
|
116
|
+
**CRITICAL**: Constraint violations are SUCCESS demonstrations of business logic!
|
|
117
|
+
|
|
118
|
+
When an update violates business rules, the server returns error code 2001:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"error": {
|
|
123
|
+
"code": 2001,
|
|
124
|
+
"message": "balance (2102.00) exceeds credit (1000.00)"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Copilot should report this as**: "✅ Business logic working correctly - constraint prevented invalid update: balance exceeds credit limit"
|
|
130
|
+
|
|
131
|
+
Common constraint codes:
|
|
132
|
+
- **2001** - Business rule violation (the valuable demonstration!)
|
|
133
|
+
- **401** - Unauthorized (need to authenticate)
|
|
134
|
+
- **404** - Entity not found
|
|
135
|
+
- **422** - Validation error
|
|
136
|
+
|
|
137
|
+
## Natural Language → API Translation Examples
|
|
138
|
+
|
|
139
|
+
| User Request | Copilot Action | API Call |
|
|
140
|
+
|--------------|----------------|----------|
|
|
141
|
+
| "List all customers" | GET collection | `GET /api/Customer/` |
|
|
142
|
+
| "Show customer ALFKI" | GET single entity | `GET /api/Customer/ALFKI/` |
|
|
143
|
+
| "Update ALFKI credit to 5000" | PATCH entity | `PATCH /api/Customer/ALFKI/` with CreditLimit |
|
|
144
|
+
| "What's ALFKI's balance?" | GET entity, extract attribute | `GET /api/Customer/ALFKI/` → read Balance |
|
|
145
|
+
| "Increase ALFKI credit by 1000" | GET then PATCH | GET current → calculate → PATCH new value |
|
|
146
|
+
| "Create customer NEWCO" | POST entity | `POST /api/Customer/` with attributes |
|
|
147
|
+
|
|
148
|
+
## MCP Discovery Endpoints
|
|
149
|
+
|
|
150
|
+
The server exposes schema metadata for AI assistants:
|
|
151
|
+
|
|
152
|
+
### Well-Known Endpoint
|
|
153
|
+
```bash
|
|
154
|
+
curl http://localhost:5656/.well-known/mcp.json
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Returns full schema including:
|
|
158
|
+
- Available entities (tables)
|
|
159
|
+
- Attributes and types
|
|
160
|
+
- Relationships
|
|
161
|
+
- Business rules documentation
|
|
162
|
+
|
|
163
|
+
### MCP Endpoint
|
|
164
|
+
```bash
|
|
165
|
+
curl http://localhost:5656/mcp
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Same schema as well-known endpoint, alternate path for compatibility.
|
|
169
|
+
|
|
170
|
+
## Key Implementation Files
|
|
171
|
+
|
|
172
|
+
- **`api/api_discovery/mcp_discovery.py`** - MCP discovery endpoints
|
|
173
|
+
- **`integration/mcp/mcp_client_executor.py`** - Example MCP client script
|
|
174
|
+
- **`docs/mcp_learning/mcp_schema.json`** - Schema metadata
|
|
175
|
+
- **`logic/declare_logic.py`** - Declarative business rules (LogicBank)
|
|
176
|
+
- **`config/default.env`** - Server configuration (SECURITY_ENABLED)
|
|
177
|
+
|
|
178
|
+
## Testing Workflow for Copilot
|
|
179
|
+
|
|
180
|
+
When user says: "Can you query the database for me?"
|
|
181
|
+
|
|
182
|
+
1. **Acknowledge**: "I'll act as MCP client and query the server"
|
|
183
|
+
2. **Authenticate**: Login via `/api/auth/login` to get JWT token
|
|
184
|
+
3. **Execute**: Make appropriate GET/PATCH/POST call with Bearer token
|
|
185
|
+
4. **Present**: Format results or explain constraint violations as logic success
|
|
186
|
+
5. **Iterate**: Accept follow-up natural language requests
|
|
187
|
+
|
|
188
|
+
Example interaction:
|
|
189
|
+
```
|
|
190
|
+
User: "List customers with balance over 1000"
|
|
191
|
+
Copilot:
|
|
192
|
+
1. Login to get token
|
|
193
|
+
2. GET /api/Customer/?filter[Balance]=>1000
|
|
194
|
+
3. Present: "Found 3 customers: ALFKI (2102.00), ANATR (1500.50), ..."
|
|
195
|
+
|
|
196
|
+
User: "Try to set ALFKI credit to 500"
|
|
197
|
+
Copilot:
|
|
198
|
+
1. PATCH /api/Customer/ALFKI/ with CreditLimit=500
|
|
199
|
+
2. Receive error 2001: "balance (2102.00) exceeds credit (500.00)"
|
|
200
|
+
3. Present: "✅ Business logic prevented this - ALFKI's balance of 2102.00
|
|
201
|
+
exceeds the proposed credit limit of 500.00. The system is correctly
|
|
202
|
+
enforcing the constraint that credit must be >= balance."
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Business Logic Layer (LogicBank)
|
|
206
|
+
|
|
207
|
+
The real power is in declarative business rules that auto-execute on all API operations:
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
# From logic/declare_logic.py
|
|
211
|
+
|
|
212
|
+
# Constraint: Customer balance cannot exceed credit limit
|
|
213
|
+
Rule.constraint(validate=models.Customer,
|
|
214
|
+
as_condition=lambda row: row.Balance <= row.CreditLimit,
|
|
215
|
+
error_msg="balance ({row.Balance}) exceeds credit ({row.CreditLimit})")
|
|
216
|
+
|
|
217
|
+
# Sum rule: Customer balance = sum of unpaid order amounts
|
|
218
|
+
Rule.sum(derive=models.Customer.Balance,
|
|
219
|
+
as_sum_of=models.Order.AmountTotal,
|
|
220
|
+
where=lambda row: row.ShippedDate is None)
|
|
221
|
+
|
|
222
|
+
# Formula: Order amount = sum of items
|
|
223
|
+
Rule.sum(derive=models.Order.AmountTotal,
|
|
224
|
+
as_sum_of=models.OrderDetail.Amount)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
These rules:
|
|
228
|
+
- Execute automatically on INSERT/UPDATE/DELETE
|
|
229
|
+
- Provide **44X code reduction** vs. traditional procedural code
|
|
230
|
+
- Enforce multi-table constraints
|
|
231
|
+
- Chain automatically (Order → Customer balance)
|
|
232
|
+
|
|
233
|
+
## Why This Architecture?
|
|
234
|
+
|
|
235
|
+
**GenAI-Logic's HTTP-based approach** vs **stdio-based MCP servers**:
|
|
236
|
+
|
|
237
|
+
| Aspect | GenAI-Logic (HTTP) | Stdio MCP |
|
|
238
|
+
|--------|-------------------|-----------|
|
|
239
|
+
| Transport | HTTP REST API | JSON-RPC over stdin/stdout |
|
|
240
|
+
| Authentication | JWT Bearer tokens | Process isolation |
|
|
241
|
+
| Scalability | Horizontal scaling | One process per client |
|
|
242
|
+
| Network | Works across machines | Same machine only |
|
|
243
|
+
| Protocol | JSON:API standard | Custom JSON-RPC |
|
|
244
|
+
| Enterprise Ready | ✅ Yes | ⚠️ Limited |
|
|
245
|
+
|
|
246
|
+
For Microsoft demo: Position GenAI-Logic as the **business logic layer** that any MCP client can invoke, rather than trying to fit into stdio-based protocol constraints.
|
|
247
|
+
|
|
248
|
+
## Optional: JSON-RPC Wrapper
|
|
249
|
+
|
|
250
|
+
If standard MCP protocol compatibility is desired, you could add a thin JSON-RPC wrapper:
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
# Optional enhancement - not required for Copilot usage
|
|
254
|
+
@app.route('/mcp/jsonrpc', methods=['POST'])
|
|
255
|
+
def mcp_jsonrpc():
|
|
256
|
+
"""Translate JSON-RPC 2.0 to internal API calls"""
|
|
257
|
+
request_data = request.json
|
|
258
|
+
method = request_data.get('method')
|
|
259
|
+
params = request_data.get('params', {})
|
|
260
|
+
|
|
261
|
+
if method == 'customers/list':
|
|
262
|
+
# Translate to GET /api/Customer/
|
|
263
|
+
response = internal_api_call('GET', '/api/Customer/', params)
|
|
264
|
+
return jsonify({'jsonrpc': '2.0', 'result': response, 'id': request_data['id']})
|
|
265
|
+
# ... more method translations
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
**Effort estimate**: Half-day for experienced developer. But this is optional - Copilot can work directly with REST API.
|
|
269
|
+
|
|
270
|
+
## Demo Strategy
|
|
271
|
+
|
|
272
|
+
For Microsoft presentation:
|
|
273
|
+
|
|
274
|
+
1. **Position correctly**: "GenAI-Logic implements MCP Server Executor - the valuable business logic layer"
|
|
275
|
+
2. **Show constraint violations**: "Error 2001 is the success - logic is working!"
|
|
276
|
+
3. **Demonstrate declarative rules**: "44X code reduction with automatic multi-table chaining"
|
|
277
|
+
4. **Use Copilot as client**: "AI assistant translates natural language to authenticated API calls"
|
|
278
|
+
5. **Highlight enterprise architecture**: "HTTP-based, JWT auth, horizontally scalable"
|
|
279
|
+
|
|
280
|
+
The MCP discovery endpoints (`/.well-known/mcp.json` and `/mcp`) allow AI assistants to understand the schema and available operations, but the real innovation is the declarative business logic layer that enforces rules automatically.
|
|
281
|
+
|
|
282
|
+
## Quick Reference for Copilot
|
|
283
|
+
|
|
284
|
+
**Authentication**:
|
|
285
|
+
```bash
|
|
286
|
+
curl -X POST http://localhost:5656/api/auth/login -d '{"username":"admin","password":"p"}'
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**Common operations**:
|
|
290
|
+
- List: `GET /api/{Entity}/` with Bearer token
|
|
291
|
+
- Read: `GET /api/{Entity}/{id}/` with Bearer token
|
|
292
|
+
- Update: `PATCH /api/{Entity}/{id}/` with JSON:API payload and Bearer token
|
|
293
|
+
- Create: `POST /api/{Entity}/` with JSON:API payload and Bearer token
|
|
294
|
+
|
|
295
|
+
**Remember**: Constraint violations (code 2001) = business logic success! Report them positively.
|