Skip to content

Commit 9eb4e34

Browse files
committed
mcp cleanup
1 parent afec398 commit 9eb4e34

File tree

6 files changed

+34
-50
lines changed

6 files changed

+34
-50
lines changed

docs/Integration-MCP.md

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
## Architecture:
1818

19-
![Intro diagram](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/mcp/MCP_Arch.png?raw=true)
19+
![Intro diagram](images/integration/mcp/MCP_Arch.png)
2020

2121
1. MCP Client Executor Startup
2222

23-
* Calls *wellknown* endpoint to load schema
24-
* This schema is similar to `docs/db.dbml` (already created by als)
23+
* Calls `.well-known` endpoint to load schema
24+
* This is created by API Logic Server, and stored in `docs/mcp_schema.json`. You can edit this as required to control what is discovered, and to minimize the information sent to the LLM.
2525

2626
2. MCP Client Executor sends Bus User ***NL query + schema*** (as prompt or tool definition) to the external LLM, here, ChatGPT (requires API Key). LLM returns an ***MCP Tool Context*** JSON block.
2727

@@ -30,32 +30,11 @@
3030
* We are using a test version: `integration/mcp/mcp_client_executor.py`
3131
* Tool definitions are OpenAI specific, so we are sending the schema (in each prompt)
3232

33-
* Note this strongly suggests this is a **subset** of your database.
34-
* This schema is derived from `docs/db.dbml` (already created by als)
33+
* Note this strongly suggests this is a **subset** of your database - edit `docs/mcp_schema.json` as required.
3534

3635

3736
3. MCP Client Executor iterates through the Tool Context, calling the JSON:API Endpoint that enforces business logic.
3837

39-
Here is a typical `https://localhost:5656/.well-known/mcp.json` response (not yet implemented):
40-
41-
```json
42-
{
43-
"tool_type": "json-api",
44-
"base_url": "https://crm.company.com",
45-
"resources": [
46-
{
47-
"name": "Customer",
48-
"path": "/Customer",
49-
"methods": ["GET", "PATCH"],
50-
"fields": ["id", "name", "balance", "credit_limit"],
51-
"filterable": ["name", "credit_limit"],
52-
"example": "List customers with credit over 5000"
53-
}
54-
]
55-
}
56-
```
57-
58-
5938
 
6039

6140
## Example: send emails for pending orders
@@ -68,31 +47,26 @@ In this example, we want a new service to:
6847
1. Find Orders placed over 30 days ago that are not shipped
6948
2. Send an Email encouraging prompt payment
7049

71-
We want to do this without troubling IT by enabling business users, while maintaining integrity. MCP meets this need.
50+
We want to do this without troubling IT. MCP enables business users, while maintaining integrity through the existing logic-enabled JSON:APIs.
7251

7352
 
7453

7554
### Setup
7655

77-
There are 2 projects we have used for testing:
78-
79-
1. **basic_demo:** preferred, since has update - from Dev Source, run run config: `Create blt/genai_demo_ as IS_GENAI_DEMO`
80-
81-
2. **NW:** In the Manager, open `samples/nw_sample_nocust`, and explore `integration/mcp`. This has been successfully used to invoke the server, including with authorization.
56+
Create the **basic_demo** under the [Manager](Manager.md) as described in the Manager readme:
8257

83-
3. Create in manager
58+
1. In your IDE: `als create --project-name=basic_demo --db-url=basic_demo`
59+
2. Run `als add-cust` to load mcp (and logic)
60+
3. Start the Server (f5)
61+
4. Run `python integration/mcp/mcp_client_executor.py`
8462

85-
4. Run `als add-cust` to load mcp tests
8663

87-
5. Run `python integration/mcp/mcp_client_executor.py`
88-
89-
90-
You will need a ChatGPT APIKey.
64+
You will need an environment variable: `APILOGICSERVER_CHATGPT_APIKEY` ChatGPT APIKey.
9165

9266
 
9367
### Prompt
9468

95-
Here is a NL prompt using *basic_demo:*
69+
Here is a NL prompt using *basic_demo* coded into `mcp_client_executor`
9670

9771
```
9872
List the orders created more than 30 days ago, and send a discount offer email to the customer for each one.
@@ -108,22 +82,38 @@ Respond with a JSON array of tool context blocks using:
10882

10983
### Sample Flow
11084

111-
#### MCP Client Executor
85+
You can run `mcp_client_executor` under the debugger, and stop at each of the breakpoints noted in the screenshot below.
11286

113-
![0-MCP-client-executor](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/mcp/0-MCP-client-executor.png?raw=true)
87+
#### 0 - MCP Client Executor
88+
89+
Here is the basic driver of the test program (see the Architecture diagram above):
90+
![0-MCP-client-executor](images/integration/mcp/0-MCP-client-executor.png)
11491

11592
#### 1 - Discovery
11693

117-
![1-discovery-from-als](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/mcp/1-discovery-from-als.png?raw=true)
94+
Discovery uses a config file `integration/mcp/mcp_server_discovery.json` to discover 1 or more servers, and invoke their `.well-known` endpoint to obtain the schema.
95+
![1-discovery-from-als](images/integration/mcp/1-discovery-from-als.png)
11896

11997
#### 2 - Tool Context from LLM
12098

121-
![2-tool-context-from-LLM](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/mcp/2-tool-context-from-LLM.png?raw=true)
99+
We call the LLM, providing the NL Query and the schema returned above. It returns a Tool Context completion (response), with the steps to call in the MCP Server Executor, which here is the logic-enabled API Logic Server JSON:API.
100+
101+
![2-tool-context-from-LLM](images/integration/mcp/2-tool-context-from-LLM.png)
122102

123103
#### 3 - Invoke MCP Server
124104

125-
![3-MCP-server response](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/mcp/3-MCP-server-response.png?raw=true)
105+
The calls include GET, and a POST for each returned row.
126106

107+
![3-MCP-server response](images/integration/mcp/3-MCP-server-response.png)
108+
 
109+
110+
##### 3a - Logic (Request Pattern)
111+
112+
MCP is capable of executing email directly, but we have business policies providing for email opt-outs. We must respect this logic.
113+
114+
As shown below, a common logic pattern is a `Request Object`: you insert it, it's business logic runs. Here, the logic checks the opt-out, and sends the mail:
115+
116+
![3a-email-logic](images/integration/mcp/3a-email-logic.png)
127117

128118
 
129119

@@ -136,19 +126,13 @@ We welcome participation in this exploration. Please contact us via [discord](ht
136126
This exploration is changing rapidly. For updates, replace `integration/mcp` from [integration/msp](https://github.com/ApiLogicServer/ApiLogicServer-src/tree/main/api_logic_server_cli/prototypes/nw_no_cust/integration/mcp){:target="_blank" rel="noopener"}.
137127

138128
 
139-
## Appendix 1: Exposing Corp DB to public MCP
140129

141-
TBD - investigate exposing a corp db to MCP so it can be discovered and used in a choreography.
142-
143-
 
144-
## Appendix 2: MCP Background
130+
## Appendix: MCP Background
145131

146132

147133

148134
For more information:
149135

150-
151-
152136
- [see MCP Introduction](https://modelcontextprotocol.io/introduction)
153137

154138
- [and here](https://apilogicserver.github.io/Docs/Integration-MCP/)
Loading
Loading
Loading
Loading
1.16 MB
Loading

0 commit comments

Comments
 (0)