Skip to content

Commit 81b8847

Browse files
authored
23 extend schema builder add validation based on builder schema (#24)
Extended Schema Builder with min/max, etc. Added Schema Validator to simplify validation based on the Schema Builder Schema Added a report to cleanup MCP sessions Added demo configuration as tabu entries Removed tests and moved them into their own repo mcp_tests Changed the origins table to avoid the key length warning - table conversion might be required Moved DDIC content into it's own package
1 parent 6cff6b1 commit 81b8847

File tree

95 files changed

+3652
-1845
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+3652
-1845
lines changed

changelog.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2025-05-18 v0.1
2+
-----------------
3+
4+
- Extended Schema Builder with min/max, etc.
5+
- Added Schema Validator to simplify validation based on the Schema Builder Schema
6+
- Added a report to cleanup MCP sessions
7+
- Added demo configuration as tabu entries
8+
- Removed tests and moved them into their own repo mcp_tests
9+
- Changed the origins table to avoid the key length warning - table conversion might be required
10+
- Moved DDIC content into it's own package
11+
112
2025-05-04 v0.0.3
213
-----------------
314

data/zmcp_servers.conf.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "ZMCP_SERVERS",
3+
"skip_initial": false,
4+
"type": "TABU",
5+
"where": [
6+
"AREA = 'demo'"
7+
]
8+
}

data/zmcp_servers.tabu.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"client": "001",
4+
"area": "demo",
5+
"server": "demo_session_icf",
6+
"class": "ZCL_MCP_DEMO_SERVER_ICFSESSION"
7+
},
8+
{
9+
"client": "001",
10+
"area": "demo",
11+
"server": "demo_session_mcp",
12+
"class": "ZCL_MCP_DEMO_SERVER_MCPSESSION"
13+
},
14+
{
15+
"client": "001",
16+
"area": "demo",
17+
"server": "demo_standard",
18+
"class": "ZCL_MCP_DEMO_SERVER_STATELESS"
19+
}
20+
]

docs/Overview.md

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ To install the MCP Server SDK, follow these steps:
4242
Create a new node e.g. zmcp with handler class zcl_mcp_http_handler
4343
3. Setup server configuration, e.g. create an entry for the stateless demo server zcl_mcp_demo_server_stateless
4444

45+
## Maintenance
46+
47+
You can use the report `zmcp_clear_mcp_sessions` to get rid of outdated MCP sessions. Ideally run it regularly as a background job if you use MCP sessions.
48+
4549
### Prerequisites
4650

4751
- SAP NetWeaver 7.52 or higher for the main branch
@@ -60,9 +64,8 @@ Configure your MCP servers in the `ZMCP_SERVERS` table:
6064
| AREA | Logical grouping for servers |
6165
| SERVER | Server identifier |
6266
| CLASS | Implementation class (must implement `ZIF_MCP_SERVER` or extend `ZCL_MCP_SERVER_BASE`) |
63-
| SESSION_MODE | Session handling mode (`No Session`, `MCP`, or `ICF`) |
6467

65-
Use the area to group your servers based on a well known structure in your company. This can e.g. be modules or end to end processes. For the session mode No Session is recommended except you really require session management.
68+
Use the area to group your servers based on a well known structure in your company. This can e.g. be modules or end to end processes.
6669

6770
### CORS Configuration
6871

@@ -114,7 +117,7 @@ ENDCLASS.
114117

115118
### Minimal Implementation
116119

117-
At minimum, you must implement the `HANDLE_INITIALIZE` method to define your server's capabilities:
120+
At minimum, you must implement the `HANDLE_INITIALIZE` method to define your server's capabilities and `GET_SESSION_MODE`:
118121

119122
```abap
120123
METHOD handle_initialize.
@@ -131,6 +134,10 @@ METHOD handle_initialize.
131134
`Instructions for the AI model on when to use this server...`
132135
).
133136
ENDMETHOD.
137+
138+
METHOD get_session_mode.
139+
result = zcl_mcp_session=>session_mode_stateless.
140+
ENDMETHOD.
134141
```
135142

136143
## Session Management
@@ -139,11 +146,11 @@ The MCP Server SDK offers three session management modes:
139146

140147
| Mode | Description |
141148
| ----------- | ----------------------------------------------------------- |
142-
| No Session | No session management (stateless) |
149+
| Stateless | No session management (stateless) |
143150
| MCP Session | Uses the custom MCP session handling mechanism via database |
144151
| ICF Session | Uses the standard ICF session management |
145152

146-
Note that ICF session management leads to potentially high number of sessions if the clients do not properly close them. Also your MCP client must support handling the session cookies. MCP Sessions are an alternative lightweight mode allowing you to store certain values in the DB between calls. In general use No Session --> Stateless where feasible.
153+
Note that ICF session management leads to potentially high number of sessions if the clients do not properly close them. Also your MCP client must support handling the session cookies. MCP Sessions are an alternative lightweight mode allowing you to store certain values in the DB between calls. In general use Stateless where feasible.
147154

148155
## Core Components
149156

@@ -166,22 +173,55 @@ Interface defining all required MCP server methods. The main methods include:
166173
- `resources_read` - Read resource content
167174
- `tools_list` - List available tools
168175
- `tools_call` - Execute tool function
176+
- `get_session_mode` - Define session logic
169177

170-
### ZCL_MCP_SCHEMA_BUILDER
178+
### Schema Builder
171179

172-
Helper class to build JSON schemas for tool input validation. You can call it multiple times like below or fully chain it.
180+
`ZCL_MCP_SCHEMA_BUILDER` creates JSON Schema definitions for tool input validation with a fluent, chainable API:
173181

174182
```abap
175183
DATA(schema) = NEW zcl_mcp_schema_builder( ).
176-
schema->add_string( name = 'parameter' required = abap_true ).
177-
schema->add_integer( name = 'count' ).
178-
schema->begin_object( name = 'options' ).
179-
schema->add_boolean( name = 'flag' ).
180-
schema->end_object( ).
184+
schema->add_string( name = 'parameter' required = abap_true )
185+
->add_integer( name = 'count' minimum = 1 )
186+
->begin_object( name = 'options' )
187+
->add_boolean( name = 'flag' )
188+
->end_object( ).
181189
```
182190

191+
Key features:
192+
193+
- Define basic property types (string, number, integer, boolean)
194+
- Apply validation constraints (min/max length, value ranges, enums)
195+
- Create nested objects and arrays
196+
- Mark required properties
197+
183198
For details see [Schema Builder](SchemaBuilder.md).
184199

200+
### Schema Validator
201+
202+
`ZCL_MCP_SCHEMA_VALIDATOR` validates JSON data against schemas created with the Schema Builder:
203+
204+
```abap
205+
" Create validator with a schema
206+
DATA(validator) = NEW zcl_mcp_schema_validator( schema ).
207+
208+
" Validate JSON input
209+
IF validator->validate( json_input ) = abap_false.
210+
" Get validation errors
211+
DATA(errors) = validator->get_errors( ).
212+
" Handle invalid input...
213+
ENDIF.
214+
```
215+
216+
Key features:
217+
218+
- Verifies data types match schema definitions
219+
- Checks presence of required properties
220+
- Validates string lengths and pattern constraints
221+
- Ensures numeric values are within defined ranges
222+
- Validates array sizes and nested structures
223+
- Provides detailed error messages for validation failures
224+
185225
## Demo Implementations
186226

187227
The SDK includes three demo implementations:
@@ -210,6 +250,8 @@ Demonstrates ICF session handling with:
210250

211251
### Demo Configuration
212252

253+
This is included in the repo. Delete if you don't want it.
254+
213255
| Area | Service | Class | SessionMode |
214256
|------|---------------------|-----------------------------------|---------------|
215257
| demo | demo_session_icf | ZCL_MCP_DEMO_SERVER_ICFSESSION | ICF Stateful |

0 commit comments

Comments
 (0)