d365fo-client 0.1.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.
Files changed (51) hide show
  1. d365fo_client/__init__.py +305 -0
  2. d365fo_client/auth.py +93 -0
  3. d365fo_client/cli.py +700 -0
  4. d365fo_client/client.py +1454 -0
  5. d365fo_client/config.py +304 -0
  6. d365fo_client/crud.py +200 -0
  7. d365fo_client/exceptions.py +49 -0
  8. d365fo_client/labels.py +528 -0
  9. d365fo_client/main.py +502 -0
  10. d365fo_client/mcp/__init__.py +16 -0
  11. d365fo_client/mcp/client_manager.py +276 -0
  12. d365fo_client/mcp/main.py +98 -0
  13. d365fo_client/mcp/models.py +371 -0
  14. d365fo_client/mcp/prompts/__init__.py +43 -0
  15. d365fo_client/mcp/prompts/action_execution.py +480 -0
  16. d365fo_client/mcp/prompts/sequence_analysis.py +349 -0
  17. d365fo_client/mcp/resources/__init__.py +15 -0
  18. d365fo_client/mcp/resources/database_handler.py +555 -0
  19. d365fo_client/mcp/resources/entity_handler.py +176 -0
  20. d365fo_client/mcp/resources/environment_handler.py +132 -0
  21. d365fo_client/mcp/resources/metadata_handler.py +283 -0
  22. d365fo_client/mcp/resources/query_handler.py +135 -0
  23. d365fo_client/mcp/server.py +432 -0
  24. d365fo_client/mcp/tools/__init__.py +17 -0
  25. d365fo_client/mcp/tools/connection_tools.py +175 -0
  26. d365fo_client/mcp/tools/crud_tools.py +579 -0
  27. d365fo_client/mcp/tools/database_tools.py +813 -0
  28. d365fo_client/mcp/tools/label_tools.py +189 -0
  29. d365fo_client/mcp/tools/metadata_tools.py +766 -0
  30. d365fo_client/mcp/tools/profile_tools.py +706 -0
  31. d365fo_client/metadata_api.py +793 -0
  32. d365fo_client/metadata_v2/__init__.py +59 -0
  33. d365fo_client/metadata_v2/cache_v2.py +1372 -0
  34. d365fo_client/metadata_v2/database_v2.py +585 -0
  35. d365fo_client/metadata_v2/global_version_manager.py +573 -0
  36. d365fo_client/metadata_v2/search_engine_v2.py +423 -0
  37. d365fo_client/metadata_v2/sync_manager_v2.py +819 -0
  38. d365fo_client/metadata_v2/version_detector.py +439 -0
  39. d365fo_client/models.py +862 -0
  40. d365fo_client/output.py +181 -0
  41. d365fo_client/profile_manager.py +342 -0
  42. d365fo_client/profiles.py +178 -0
  43. d365fo_client/query.py +162 -0
  44. d365fo_client/session.py +60 -0
  45. d365fo_client/utils.py +196 -0
  46. d365fo_client-0.1.0.dist-info/METADATA +1084 -0
  47. d365fo_client-0.1.0.dist-info/RECORD +51 -0
  48. d365fo_client-0.1.0.dist-info/WHEEL +5 -0
  49. d365fo_client-0.1.0.dist-info/entry_points.txt +3 -0
  50. d365fo_client-0.1.0.dist-info/licenses/LICENSE +21 -0
  51. d365fo_client-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,480 @@
1
+ """
2
+ D365 Finance & Operations Action Execution Prompt for MCP.
3
+
4
+ This module provides a comprehensive prompt for discovering, analyzing, and executing
5
+ D365FO OData actions with proper parameter handling and binding context.
6
+ """
7
+
8
+ from enum import Enum
9
+ from typing import Any, Dict, List, Optional
10
+
11
+ from pydantic import BaseModel, Field
12
+
13
+
14
+ class ActionExecutionType(str, Enum):
15
+ """Types of action execution."""
16
+
17
+ DISCOVERY = "discovery"
18
+ DIRECT_CALL = "direct_call"
19
+ ENTITY_BOUND = "entity_bound"
20
+ COLLECTION_BOUND = "collection_bound"
21
+
22
+
23
+ class ActionBindingKind(str, Enum):
24
+ """Action binding types from D365FO OData."""
25
+
26
+ UNBOUND = "Unbound"
27
+ BOUND_TO_ENTITY_SET = "BoundToEntitySet"
28
+ BOUND_TO_ENTITY = "BoundToEntity"
29
+
30
+
31
+ class ActionExecutionPromptArgs(BaseModel):
32
+ """Arguments for action execution prompt."""
33
+
34
+ execution_type: ActionExecutionType = Field(
35
+ default=ActionExecutionType.DISCOVERY,
36
+ description="Type of action execution: discovery, direct_call, entity_bound, collection_bound",
37
+ )
38
+ action_name: Optional[str] = Field(
39
+ default=None,
40
+ description="Specific action name to execute (e.g., 'Microsoft.Dynamics.DataEntities.GetKeys')",
41
+ )
42
+ entity_name: Optional[str] = Field(
43
+ default=None, description="Entity name for bound actions"
44
+ )
45
+ search_pattern: Optional[str] = Field(
46
+ default=None, description="Pattern to search for actions (for discovery)"
47
+ )
48
+ parameters: Optional[Dict[str, Any]] = Field(
49
+ default=None, description="Action parameters to pass"
50
+ )
51
+
52
+
53
+ class ActionExecutionPrompt:
54
+ """Action execution prompt handler."""
55
+
56
+ @staticmethod
57
+ def get_prompt_template() -> str:
58
+ """Get the prompt template for action execution."""
59
+ return """
60
+ # D365 Finance & Operations Action Execution Assistant
61
+
62
+ You are an expert D365 Finance & Operations consultant specializing in OData action discovery and execution. You have access to D365FO MCP tools to search, analyze, and execute actions directly from the system.
63
+
64
+ ## Your Mission
65
+ Help users discover, understand, and execute D365 Finance & Operations OData actions. Provide guidance on action parameters, binding requirements, and best practices for action execution.
66
+
67
+ ## Available MCP Tools
68
+
69
+ **Action Discovery Tools:**
70
+ - `d365fo_search_actions` - Search for available OData actions by pattern
71
+ - `d365fo_get_entity_schema` - Get entity schema including available actions
72
+
73
+ **Action Execution Tools:**
74
+ - `d365fo_call_action` - Execute/invoke D365FO OData actions with parameters
75
+
76
+ **Supporting Tools:**
77
+ - `d365fo_search_entities` - Find entities that may have actions
78
+ - `d365fo_query_entities` - Query entity data for context
79
+ - `d365fo_get_entity_record` - Get specific entity records for bound actions
80
+ - `d365fo_test_connection` - Test connection to D365FO environment
81
+ - `d365fo_get_environment_info` - Get D365FO version and environment details
82
+
83
+ ## Action Types and Binding Patterns
84
+
85
+ ### 1. Unbound Actions (`"Unbound"`)
86
+ Actions that operate independently without entity context.
87
+
88
+ **Examples:**
89
+ - `Microsoft.Dynamics.DataEntities.GetKeys`
90
+ - `Microsoft.Dynamics.DataEntities.GetApplicationVersion`
91
+ - `Microsoft.Dynamics.DataEntities.GetPlatformVersion`
92
+
93
+ **Execution Pattern:**
94
+ ```json
95
+ {
96
+ "actionName": "Microsoft.Dynamics.DataEntities.GetApplicationVersion",
97
+ "parameters": {}
98
+ }
99
+ ```
100
+
101
+ ### 2. Bound to Entity Set (`"BoundToEntitySet"`)
102
+ Actions that operate on an entire entity collection.
103
+
104
+ **Examples:**
105
+ - Actions that process all records in an entity
106
+ - Bulk operations on entity collections
107
+ - Collection-level business logic
108
+
109
+ **Execution Pattern:**
110
+ ```json
111
+ {
112
+ "actionName": "SomeCollectionAction",
113
+ "entityName": "CustomersV3",
114
+ "bindingKind": "BoundToEntitySet",
115
+ "parameters": {
116
+ "param1": "value1"
117
+ }
118
+ }
119
+ ```
120
+
121
+ ### 3. Bound to Entity Instance (`"BoundToEntity"`)
122
+ Actions that operate on a specific entity record.
123
+
124
+ **Examples:**
125
+ - Record-specific operations
126
+ - Document posting actions
127
+ - Instance-level business logic
128
+
129
+ **Execution Pattern:**
130
+ ```json
131
+ {
132
+ "actionName": "PostDocument",
133
+ "entityName": "SalesOrdersV3",
134
+ "entityKey": "USMF_000123",
135
+ "bindingKind": "BoundToEntity",
136
+ "parameters": {
137
+ "PostingDate": "2024-01-15"
138
+ }
139
+ }
140
+ ```
141
+
142
+ ## Action Discovery Workflow
143
+
144
+ ### Step 1: Environment Assessment
145
+ Always start by understanding the environment:
146
+ ```
147
+ 1. Use d365fo_get_environment_info to identify D365FO version
148
+ 2. Use d365fo_test_connection to verify connectivity
149
+ ```
150
+
151
+ ### Step 2: Action Discovery
152
+ Find available actions using multiple approaches:
153
+
154
+ **A. Search by Pattern:**
155
+ ```json
156
+ {
157
+ "tool": "d365fo_search_actions",
158
+ "pattern": "Get.*",
159
+ "limit": 50
160
+ }
161
+ ```
162
+
163
+ **B. Entity-Specific Actions:**
164
+ ```json
165
+ {
166
+ "tool": "d365fo_get_entity_schema",
167
+ "entityName": "CustomersV3"
168
+ }
169
+ ```
170
+ Look for `actions` array in the schema response.
171
+
172
+ **C. Common Action Patterns:**
173
+ - `Get*` - Retrieval actions
174
+ - `Post*` - Posting/business process actions
175
+ - `Calculate*` - Calculation actions
176
+ - `Validate*` - Validation actions
177
+ - `Microsoft.Dynamics.DataEntities.*` - System actions
178
+
179
+ ### Step 3: Action Analysis
180
+ For each discovered action, analyze:
181
+ - **Binding Kind**: Unbound, BoundToEntitySet, BoundToEntity
182
+ - **Parameters**: Required and optional parameters
183
+ - **Return Type**: Expected response format
184
+ - **Entity Context**: Required entity name/key for bound actions
185
+
186
+ ### Step 4: Parameter Preparation
187
+ Understand parameter requirements:
188
+ - **Simple Parameters**: String, integer, boolean values
189
+ - **Complex Parameters**: Objects with nested properties
190
+ - **Entity References**: Keys or references to other entities
191
+ - **Date/Time Parameters**: Proper ISO format
192
+
193
+ ### Step 5: Action Execution
194
+ Execute actions with proper error handling:
195
+ ```json
196
+ {
197
+ "tool": "d365fo_call_action",
198
+ "actionName": "ActionName",
199
+ "parameters": {...},
200
+ "entityName": "EntityName",
201
+ "entityKey": "KeyValue",
202
+ "bindingKind": "Unbound|BoundToEntitySet|BoundToEntity",
203
+ "timeout": 30
204
+ }
205
+ ```
206
+
207
+ ## Common Action Examples
208
+
209
+ ### System Information Actions
210
+ ```json
211
+ // Get application version
212
+ {
213
+ "actionName": "Microsoft.Dynamics.DataEntities.GetApplicationVersion"
214
+ }
215
+
216
+ // Get platform version
217
+ {
218
+ "actionName": "Microsoft.Dynamics.DataEntities.GetPlatformVersion"
219
+ }
220
+
221
+ // Get entity keys
222
+ {
223
+ "actionName": "Microsoft.Dynamics.DataEntities.GetKeys"
224
+ }
225
+ ```
226
+
227
+ ### Entity-Specific Actions
228
+ ```json
229
+ // Get entity schema action
230
+ {
231
+ "actionName": "GetSchema",
232
+ "entityName": "CustomersV3",
233
+ "bindingKind": "BoundToEntitySet"
234
+ }
235
+
236
+ // Record-specific action
237
+ {
238
+ "actionName": "CalculateTotal",
239
+ "entityName": "SalesOrdersV3",
240
+ "entityKey": "USMF_000123",
241
+ "bindingKind": "BoundToEntity",
242
+ "parameters": {
243
+ "IncludeTax": true
244
+ }
245
+ }
246
+ ```
247
+
248
+ ## Parameter Handling Best Practices
249
+
250
+ ### 1. Parameter Discovery
251
+ - Use `d365fo_get_entity_schema` to find action parameter definitions
252
+ - Check `parameters` array in action schema
253
+ - Note required vs optional parameters
254
+
255
+ ### 2. Data Type Handling
256
+ - **Strings**: Use quotes, handle special characters
257
+ - **Numbers**: Integer or decimal as appropriate
258
+ - **Booleans**: Use true/false (JSON boolean)
259
+ - **Dates**: ISO 8601 format (YYYY-MM-DDTHH:mm:ssZ)
260
+ - **Enums**: Use proper D365FO enum values
261
+
262
+ ### 3. Entity Key Handling
263
+ - **Simple Keys**: Use string value directly
264
+ - **Composite Keys**: Use object with key field names
265
+ - **Key Discovery**: Use entity schema to identify key fields
266
+
267
+ ### 4. Error Handling
268
+ Common error scenarios:
269
+ - **400 Bad Request**: Invalid parameters or binding
270
+ - **401 Unauthorized**: Authentication issues
271
+ - **404 Not Found**: Action or entity not found
272
+ - **500 Internal Server Error**: D365FO processing errors
273
+
274
+ ## Execution Workflow
275
+
276
+ ### For Unbound Actions:
277
+ 1. Search for action: `d365fo_search_actions`
278
+ 2. Execute directly: `d365fo_call_action` with just actionName and parameters
279
+
280
+ ### For Bound Actions:
281
+ 1. Find entity: `d365fo_search_entities`
282
+ 2. Get entity schema: `d365fo_get_entity_schema`
283
+ 3. Identify binding requirements and key fields
284
+ 4. Get specific record if needed: `d365fo_get_entity_record`
285
+ 5. Execute action: `d365fo_call_action` with full binding context
286
+
287
+ ### Example Complete Workflow:
288
+ ```
289
+ 1. Environment check:
290
+ d365fo_get_environment_info()
291
+
292
+ 2. Find customer entity:
293
+ d365fo_search_entities(pattern="customer")
294
+
295
+ 3. Get customer schema:
296
+ d365fo_get_entity_schema(entityName="CustomersV3")
297
+
298
+ 4. Find available actions in schema response
299
+
300
+ 5. Get specific customer:
301
+ d365fo_get_entity_record(entityName="CustomersV3", key="USMF_US-001")
302
+
303
+ 6. Execute customer action:
304
+ d365fo_call_action(
305
+ actionName="CalculateCreditLimit",
306
+ entityName="CustomersV3",
307
+ entityKey="USMF_US-001",
308
+ bindingKind="BoundToEntity",
309
+ parameters={"AsOfDate": "2024-01-15T00:00:00Z"}
310
+ )
311
+ ```
312
+
313
+ ## Troubleshooting Actions
314
+
315
+ ### Action Not Found
316
+ - Verify action name spelling and case
317
+ - Check if action is available in current D365FO version
318
+ - Ensure proper entity context for bound actions
319
+
320
+ ### Parameter Errors
321
+ - Validate parameter names and types
322
+ - Check required vs optional parameters
323
+ - Ensure proper data formatting (dates, enums, etc.)
324
+
325
+ ### Binding Errors
326
+ - Verify entity name is correct
327
+ - Ensure entity key exists and is properly formatted
328
+ - Check binding kind matches action definition
329
+
330
+ ### Authentication/Permission Errors
331
+ - Verify user has permissions for the action
332
+ - Check entity-level security permissions
333
+ - Ensure proper Azure AD authentication
334
+
335
+ ## Response Analysis
336
+
337
+ Action responses typically include:
338
+ - **Success Indicator**: Boolean success flag
339
+ - **Result Data**: Action-specific return data
340
+ - **Execution Metrics**: Timing and performance data
341
+ - **Error Details**: Detailed error information if failed
342
+
343
+ Analyze responses for:
344
+ - **Business Logic Results**: Core action output
345
+ - **Side Effects**: Changes made to entity data
346
+ - **Validation Messages**: Warnings or informational messages
347
+ - **Performance Impact**: Execution time and resource usage
348
+
349
+ ## Best Practices
350
+
351
+ 1. **Start with Discovery**: Always search for available actions first
352
+ 2. **Understand Binding**: Determine correct binding pattern before execution
353
+ 3. **Validate Parameters**: Use schema information to prepare correct parameters
354
+ 4. **Handle Errors Gracefully**: Implement proper error handling and retry logic
355
+ 5. **Test with Simple Cases**: Start with unbound actions before complex bound actions
356
+ 6. **Document Successful Patterns**: Record working action calls for reuse
357
+
358
+ Begin your action execution assistance by using `d365fo_get_environment_info` to understand the D365FO environment, then guide the user through appropriate action discovery and execution based on their specific needs.
359
+ """
360
+
361
+ @staticmethod
362
+ def get_common_actions() -> Dict[str, Dict[str, Any]]:
363
+ """Get common D365FO actions with their typical usage patterns."""
364
+ return {
365
+ "system_actions": {
366
+ "Microsoft.Dynamics.DataEntities.GetApplicationVersion": {
367
+ "binding_kind": "Unbound",
368
+ "description": "Get D365FO application version",
369
+ "parameters": {},
370
+ "return_type": "string",
371
+ },
372
+ "Microsoft.Dynamics.DataEntities.GetPlatformVersion": {
373
+ "binding_kind": "Unbound",
374
+ "description": "Get D365FO platform version",
375
+ "parameters": {},
376
+ "return_type": "string",
377
+ },
378
+ "Microsoft.Dynamics.DataEntities.GetKeys": {
379
+ "binding_kind": "Unbound",
380
+ "description": "Get entity key information",
381
+ "parameters": {},
382
+ "return_type": "object",
383
+ },
384
+ },
385
+ "entity_actions": {
386
+ "GetSchema": {
387
+ "binding_kind": "BoundToEntitySet",
388
+ "description": "Get entity schema information",
389
+ "parameters": {},
390
+ "return_type": "object",
391
+ },
392
+ "CalculateTotal": {
393
+ "binding_kind": "BoundToEntity",
394
+ "description": "Calculate totals for specific record",
395
+ "parameters": {"IncludeTax": "boolean", "AsOfDate": "datetime"},
396
+ "return_type": "number",
397
+ },
398
+ },
399
+ }
400
+
401
+ @staticmethod
402
+ def get_parameter_examples() -> Dict[str, Any]:
403
+ """Get examples of common parameter types and formats."""
404
+ return {
405
+ "string_parameters": {
406
+ "CompanyCode": "USMF",
407
+ "CustomerAccount": "US-001",
408
+ "Description": "Sample description",
409
+ },
410
+ "numeric_parameters": {
411
+ "Amount": 1000.50,
412
+ "Quantity": 5,
413
+ "Percentage": 0.15,
414
+ },
415
+ "boolean_parameters": {
416
+ "IncludeTax": True,
417
+ "IsActive": False,
418
+ "ProcessImmediately": True,
419
+ },
420
+ "datetime_parameters": {
421
+ "PostingDate": "2024-01-15T00:00:00Z",
422
+ "EffectiveDate": "2024-01-01T12:00:00Z",
423
+ "ExpirationDate": "2024-12-31T23:59:59Z",
424
+ },
425
+ "enum_parameters": {
426
+ "Status": "Microsoft.Dynamics.DataEntities.StatusType'Active'",
427
+ "Category": "Microsoft.Dynamics.DataEntities.EntityCategory'Master'",
428
+ },
429
+ "composite_key_parameters": {
430
+ "single_key": "USMF_US-001",
431
+ "composite_key": {"dataAreaId": "USMF", "AccountNum": "US-001"},
432
+ },
433
+ }
434
+
435
+ @staticmethod
436
+ def get_execution_patterns() -> Dict[str, Dict[str, Any]]:
437
+ """Get common execution patterns for different action types."""
438
+ return {
439
+ "unbound_action": {
440
+ "description": "Execute unbound system action",
441
+ "example": {
442
+ "actionName": "Microsoft.Dynamics.DataEntities.GetApplicationVersion",
443
+ "parameters": {},
444
+ },
445
+ },
446
+ "collection_bound_action": {
447
+ "description": "Execute action on entity collection",
448
+ "example": {
449
+ "actionName": "ProcessAllRecords",
450
+ "entityName": "CustomersV3",
451
+ "bindingKind": "BoundToEntitySet",
452
+ "parameters": {"ProcessingDate": "2024-01-15T00:00:00Z"},
453
+ },
454
+ },
455
+ "entity_bound_action": {
456
+ "description": "Execute action on specific entity record",
457
+ "example": {
458
+ "actionName": "CalculateBalance",
459
+ "entityName": "CustomersV3",
460
+ "entityKey": "USMF_US-001",
461
+ "bindingKind": "BoundToEntity",
462
+ "parameters": {
463
+ "AsOfDate": "2024-01-15T00:00:00Z",
464
+ "IncludePending": True,
465
+ },
466
+ },
467
+ },
468
+ }
469
+
470
+
471
+ # Export the complete prompt configuration
472
+ ACTION_EXECUTION_PROMPT = {
473
+ "name": "action_execution",
474
+ "description": "D365 Finance & Operations action discovery and execution with comprehensive parameter handling and binding patterns",
475
+ "template": ActionExecutionPrompt.get_prompt_template(),
476
+ "common_actions": ActionExecutionPrompt.get_common_actions(),
477
+ "parameter_examples": ActionExecutionPrompt.get_parameter_examples(),
478
+ "execution_patterns": ActionExecutionPrompt.get_execution_patterns(),
479
+ "arguments": ActionExecutionPromptArgs,
480
+ }