@abgov/adsp-sdk-mcp-server 0.0.0

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 (124) hide show
  1. package/README.md +51 -0
  2. package/assets/docs/architecture.md +79 -0
  3. package/assets/docs/getting-started.md +118 -0
  4. package/assets/docs/important-notes.md +47 -0
  5. package/assets/docs/index.md +9 -0
  6. package/assets/docs/platform/deployment.md +80 -0
  7. package/assets/docs/platform/getting-started.md +66 -0
  8. package/assets/docs/platform/operations.md +8 -0
  9. package/assets/docs/platform/platform-django-sdk.md +330 -0
  10. package/assets/docs/platform/platform-dotnet-sdk.md +457 -0
  11. package/assets/docs/platform/platform-flask-sdk.md +355 -0
  12. package/assets/docs/platform/platform-node-sdk.md +433 -0
  13. package/assets/docs/platform/platform-spring-sdk.md +344 -0
  14. package/assets/docs/platform/platform.md +8 -0
  15. package/assets/docs/services/access-service.md +75 -0
  16. package/assets/docs/services/agent-service.md +316 -0
  17. package/assets/docs/services/cache-service.md +61 -0
  18. package/assets/docs/services/calendar-service.md +86 -0
  19. package/assets/docs/services/comment-service.md +87 -0
  20. package/assets/docs/services/configuration-service.md +92 -0
  21. package/assets/docs/services/directory-service.md +57 -0
  22. package/assets/docs/services/event-service.md +122 -0
  23. package/assets/docs/services/feedback-service.md +152 -0
  24. package/assets/docs/services/file-service.md +164 -0
  25. package/assets/docs/services/form-service.md +149 -0
  26. package/assets/docs/services/notification-service.md +151 -0
  27. package/assets/docs/services/pdf-service.md +116 -0
  28. package/assets/docs/services/pii-service.md +45 -0
  29. package/assets/docs/services/push-service.md +106 -0
  30. package/assets/docs/services/services.md +6 -0
  31. package/assets/docs/services/status-service.md +29 -0
  32. package/assets/docs/services/task-service.md +139 -0
  33. package/assets/docs/services/tenant-service.md +18 -0
  34. package/assets/docs/services/token-handler.md +135 -0
  35. package/assets/docs/services/value-service.md +80 -0
  36. package/assets/docs/services/verify-service.md +61 -0
  37. package/assets/docs/tutorials/access-service/access-service.md +9 -0
  38. package/assets/docs/tutorials/access-service/adsp-clients.md +29 -0
  39. package/assets/docs/tutorials/access-service/application-clients.md +61 -0
  40. package/assets/docs/tutorials/access-service/front-end-access.md +53 -0
  41. package/assets/docs/tutorials/access-service/introduction.md +33 -0
  42. package/assets/docs/tutorials/access-service/tenants.md +68 -0
  43. package/assets/docs/tutorials/access-service/themes.md +43 -0
  44. package/assets/docs/tutorials/feedback-service/accessing-data.md +41 -0
  45. package/assets/docs/tutorials/feedback-service/feedback-service.md +9 -0
  46. package/assets/docs/tutorials/feedback-service/installation.md +142 -0
  47. package/assets/docs/tutorials/feedback-service/introduction.md +28 -0
  48. package/assets/docs/tutorials/feedback-service/security.md +40 -0
  49. package/assets/docs/tutorials/feedback-service/triggering.md +21 -0
  50. package/assets/docs/tutorials/file-service/file-service.md +9 -0
  51. package/assets/docs/tutorials/file-service/file-types.md +35 -0
  52. package/assets/docs/tutorials/file-service/introduction.md +34 -0
  53. package/assets/docs/tutorials/file-service/security.md +31 -0
  54. package/assets/docs/tutorials/file-service/working-with.md +65 -0
  55. package/assets/docs/tutorials/form-service/Integration.md +31 -0
  56. package/assets/docs/tutorials/form-service/ai-agent.md +450 -0
  57. package/assets/docs/tutorials/form-service/building-forms.md +264 -0
  58. package/assets/docs/tutorials/form-service/cheat-sheet.md +1461 -0
  59. package/assets/docs/tutorials/form-service/custom-error-messages.md +87 -0
  60. package/assets/docs/tutorials/form-service/data-registers.md +204 -0
  61. package/assets/docs/tutorials/form-service/file-uploader.md +81 -0
  62. package/assets/docs/tutorials/form-service/form-app.md +72 -0
  63. package/assets/docs/tutorials/form-service/form-editor.md +62 -0
  64. package/assets/docs/tutorials/form-service/form-service.md +9 -0
  65. package/assets/docs/tutorials/form-service/form-submissions.md +77 -0
  66. package/assets/docs/tutorials/form-service/instructions.md +173 -0
  67. package/assets/docs/tutorials/form-service/introduction.md +66 -0
  68. package/assets/docs/tutorials/form-service/repeated-items.md +87 -0
  69. package/assets/docs/tutorials/form-service/security.md +36 -0
  70. package/assets/docs/tutorials/form-service/steppers.md +237 -0
  71. package/assets/docs/tutorials/notification-service/emailAttachment.md +75 -0
  72. package/assets/docs/tutorials/notification-service/events.md +20 -0
  73. package/assets/docs/tutorials/notification-service/introduction.md +37 -0
  74. package/assets/docs/tutorials/notification-service/notification-service.md +9 -0
  75. package/assets/docs/tutorials/notification-service/notification-types.md +86 -0
  76. package/assets/docs/tutorials/notification-service/subscribers.md +33 -0
  77. package/assets/docs/tutorials/pdf-service/building-a-template.md +339 -0
  78. package/assets/docs/tutorials/pdf-service/generate-a-pdf.md +150 -0
  79. package/assets/docs/tutorials/pdf-service/handlebars.md +51 -0
  80. package/assets/docs/tutorials/pdf-service/introduction.md +26 -0
  81. package/assets/docs/tutorials/pdf-service/pdf-service.md +9 -0
  82. package/assets/docs/tutorials/pdf-service/puppeteer.md +25 -0
  83. package/assets/docs/tutorials/pdf-service/video.md +18 -0
  84. package/assets/docs/tutorials/status-service/Introduction.md +46 -0
  85. package/assets/docs/tutorials/status-service/health.md +51 -0
  86. package/assets/docs/tutorials/status-service/notices.md +34 -0
  87. package/assets/docs/tutorials/status-service/notifications.md +107 -0
  88. package/assets/docs/tutorials/status-service/status-service.md +9 -0
  89. package/assets/docs/tutorials/status-service/status.md +35 -0
  90. package/assets/docs/tutorials/status-service/webhooks.md +24 -0
  91. package/assets/docs/tutorials/task-service/introduction.md +23 -0
  92. package/assets/docs/tutorials/task-service/task-app.md +43 -0
  93. package/assets/docs/tutorials/task-service/task-definitions.md +49 -0
  94. package/assets/docs/tutorials/task-service/task-queues.md +67 -0
  95. package/assets/docs/tutorials/task-service/task-service.md +9 -0
  96. package/assets/docs/tutorials/tutorials.md +8 -0
  97. package/package.json +18 -0
  98. package/src/docs/docsRepository.d.ts +22 -0
  99. package/src/docs/docsRepository.js +110 -0
  100. package/src/docs/docsRepository.js.map +1 -0
  101. package/src/main.d.ts +2 -0
  102. package/src/main.js +16 -0
  103. package/src/main.js.map +1 -0
  104. package/src/sdk-reference/reference.d.ts +17 -0
  105. package/src/sdk-reference/reference.js +547 -0
  106. package/src/sdk-reference/reference.js.map +1 -0
  107. package/src/sdk-reference/search.d.ts +6 -0
  108. package/src/sdk-reference/search.js +41 -0
  109. package/src/sdk-reference/search.js.map +1 -0
  110. package/src/server.d.ts +6 -0
  111. package/src/server.js +30 -0
  112. package/src/server.js.map +1 -0
  113. package/src/tools/registerDocsTools.d.ts +3 -0
  114. package/src/tools/registerDocsTools.js +66 -0
  115. package/src/tools/registerDocsTools.js.map +1 -0
  116. package/src/tools/registerQuickstartTool.d.ts +2 -0
  117. package/src/tools/registerQuickstartTool.js +82 -0
  118. package/src/tools/registerQuickstartTool.js.map +1 -0
  119. package/src/tools/registerSdkTools.d.ts +2 -0
  120. package/src/tools/registerSdkTools.js +43 -0
  121. package/src/tools/registerSdkTools.js.map +1 -0
  122. package/src/tools/types.d.ts +12 -0
  123. package/src/tools/types.js +3 -0
  124. package/src/tools/types.js.map +1 -0
@@ -0,0 +1,330 @@
1
+ ---
2
+ layout: page
3
+ title: Service SDK (Django)
4
+ nav_order: 6
5
+ parent: Platform development
6
+ ---
7
+
8
+ <details open markdown="block">
9
+ <summary>
10
+ Table of contents
11
+ </summary>
12
+ {: .text-delta }
13
+ 1. TOC
14
+ {:toc}
15
+ </details>
16
+
17
+ # ADSP service SDK (Django)
18
+ Platform services integrate into the foundational capabilities via a Software Development Kit (SDK). The SDK includes interfaces and utilities for handling tenancy, configurations, and registration. The same SDK can be used for development of tenant services.
19
+
20
+ Note that the SDK provides friendly interfaces on top of APIs. It is intended to speed up service development but is not the only way to access platform capabilities.
21
+
22
+ Install the ADSP SDK for Django wheel from release artifacts in the repository.
23
+
24
+ ```bash
25
+ poetry add https://github.com/GovAlta/adsp-monorepo/releases/download/adsp-service-django-sdk-v1.0.2/adsp_service_django_sdk-1.0.0-py3-none-any.whl
26
+ ```
27
+
28
+ ## Setting up a service account
29
+ The SDK requires credentials for a service account and uses this account for accessing platform capabilities. Fine grained configuration is possible and principle of least privilege should be applied.
30
+
31
+ In order to create the service account.
32
+ 1. Create a confidential Client with a client ID in the format: `urn:ads:{tenant}:{service}` . The SDK does not authenticate end users and so all authentication grant types can be disabled.
33
+ 2. Enable service account for the client.
34
+ 3. In Service Account Roles, add the appropriate Client Roles for the capabilities that will be accessed:
35
+ 1. Client `urn:ads:platform:tenant-service ` role `platform-service` is required.
36
+ 2. Client `urn:ads:platform:configuration-service` role `configured-service` is needed for registration and accessing service specific configuration
37
+ 3. Client `urn:ads:platform:event-service` role `event-sender` is needed for sending domain events.
38
+ 4. Additional audiences in the service account access token are required for some capabilities:
39
+ 1. Client `urn:ads:platform:push-service` needs to be include via an audience mapper for socket based configuration cache invalidation.
40
+
41
+ ## Initializing the SDK
42
+ The SDK includes Django Middleware, View and utility functions. Configure SDK settings in Django settings module.
43
+
44
+ ```python
45
+ MIDDLEWARE = [
46
+ "adsp_service_django_sdk.middleware.AccessRequestMiddleware",
47
+ "adsp_service_django_sdk.middleware.TenantRequestMiddleware",
48
+ ...
49
+ ]
50
+
51
+ # ADSP SDK settings
52
+ ADSP_ACCESS_SERVICE_URL = env.get("ADSP_ACCESS_SERVICE_URL")
53
+ ADSP_REALM = env.get("ADSP_REALM")
54
+ ADSP_DIRECTORY_URL = env.get("ADSP_DIRECTORY_URL")
55
+ ADSP_SERVICE_ID = env.get("ADSP_SERVICE_ID", "urn:ads:demo:hello-world-service")
56
+ ADSP_CLIENT_SECRET = env.get("ADSP_CLIENT_SECRET")
57
+ ```
58
+
59
+ Register service configuration in a registration module, and identify the module with the `ADSP_REGISTRATION_MODULE` environment variable.
60
+ ```python
61
+ os.environ.setdefault('ADSP_REGISTRATION_MODULE', 'hello_world_django.registration')
62
+ ```
63
+
64
+ ```python
65
+ from adsp_service_django_sdk AdspRegistration
66
+
67
+
68
+ registration = AdspRegistration(
69
+ "Hello world service",
70
+ "Hello world example for Django"
71
+ )
72
+ ```
73
+
74
+ ## Enabling service metadata
75
+ The service directory aggregates service metadata from the root resource of services registered in the directory. This metadata is used to simplify configuration and for OpenAPI documentation aggregation at https://api.adsp.alberta.ca/{tenant}. SDK includes a view for exposing the metadata endpoint.
76
+
77
+ Enabling service metadata:
78
+ ```python
79
+ from adsp_service_django_sdk import get_metadata
80
+ from django.urls import path
81
+
82
+
83
+ urlpatterns = [
84
+ ...,
85
+ path("", get_metadata)
86
+ ]
87
+ ```
88
+
89
+ ## Authorizing requests
90
+ The SDK provides `get_user` function for retrieving the user from a request and `require_user` decorator for authorizing requests.
91
+
92
+ Require ADSP user for request:
93
+ ```python
94
+ from adsp_service_django_sdk import get_user, require_user, User
95
+ ...
96
+
97
+ @require_user()
98
+ def hello_world(request):
99
+ return f"hello {get_user(request).name}"
100
+ ```
101
+
102
+ ### Role-based authorization
103
+ The SDK maps Keycloak access token `realm_access` and `resource_access` roles to the request user.
104
+
105
+ Keycloak issued tokens contain client roles nested under `realm_access`. SDK claim mapping flatten service specific roles from the token and qualifies roles related to other service clients with the client ID.
106
+
107
+ For example:
108
+ ```json
109
+ {
110
+ "realm_access": { "roles": ["user"] },
111
+ "resource_access": {
112
+ "my-service": { "roles": ["my-user"] },
113
+ "other-service": { "roles": ["other-user"] }
114
+ }
115
+ }
116
+ ```
117
+
118
+ For my-service, the roles are mapped to role claims:
119
+ - user
120
+ - my-user
121
+ - other-service:other-user
122
+
123
+ Authorize based on a role:
124
+ ```python
125
+ from adsp_service_django_sdk import get_user, require_user, User
126
+ ...
127
+
128
+ @require_user("other-service:other-user")
129
+ def hello_world(request):
130
+ return f"hello {get_user(request).name}"
131
+ ```
132
+
133
+ Accessing user information directly and checking for role:
134
+ ```python
135
+ from adsp_service_django_sdk import get_user
136
+ ...
137
+
138
+ def hello_world(request):
139
+ has_role = "other-service:other-user" in get_user(request).roles
140
+ ...
141
+ ```
142
+
143
+ ## Determining tenancy
144
+ Requests to platform services are in the context of a specific tenant with few exceptions. The context is implicit when a request is made with a tenant bearer token. It can be explicit in cases where an endpoint allows anonymous access or when a platform service makes a request to another platform service under a core service account.
145
+
146
+ The SDK `TenantRequestMiddleware` resolves implicit tenancy from user tenancy and explicit from a `tenantId` query parameter. Resolved tenant is set on the request object; no value is set if tenancy cannot be resolved.
147
+
148
+ Getting tenancy from the context:
149
+ ```python
150
+ from adsp_service_django_sdk import get_tenant
151
+ ...
152
+
153
+ @require_user()
154
+ def hello_world(request):
155
+ return f"hello {get_tenant(request).name}"
156
+ ```
157
+
158
+ The handler uses the tenant service client to retrieve tenant information. This is also available from the SDK for direct use. The tenant service is available on the `adsp` variable that can be imported from SDK package.
159
+
160
+ Getting tenant information using the tenant service:
161
+ ```python
162
+ from adsp_service_django_sdk import adsp, AdspId
163
+
164
+
165
+ @require_user()
166
+ def hello_world(request, tenant_id=None):
167
+ tenant = adsp.tenant_service.get_tenant(AdspId.parse(tenant_id))
168
+ ...
169
+ ```
170
+
171
+ ## Finding services
172
+ Service discovery in ADSP is handled using client side service discovery with a directory of services providing a register of available services.
173
+
174
+ Getting a service URL from the directory:
175
+ ```python
176
+ from adsp_service_django_sdk import adsp, AdspId
177
+
178
+ @require_user()
179
+ def hello_world(request):
180
+ service_url = adsp.directory.get_service_url(AdspId.parse("urn:ads:platform:tenant-service"))
181
+ ...
182
+ ```
183
+
184
+ ## Handling configuration
185
+ Platform services can make use of a common configuration service for managing configuration. The SDK allows services to define their configuration schema and access configuration.
186
+
187
+ Defining the configuration json schema:
188
+ ```python
189
+ from adsp_service_django_sdk import AdspRegistration, ConfigurationDefinition
190
+
191
+
192
+ registration = AdspRegistration(
193
+ "Hello world service",
194
+ "Hello world example for Django",
195
+ configuration=ConfigurationDefinition(
196
+ "Configuration of the hello world sample service.",
197
+ {
198
+ "type": "object",
199
+ "properties": {
200
+ "responses": {
201
+ "type": "object",
202
+ "additionalProperties": {"type": "string"},
203
+ },
204
+ },
205
+ },
206
+ ),
207
+ )
208
+ ```
209
+
210
+ Each service can have core configuration that applies across tenants and configuration specific to each tenant. The SDK provides a `get_configuration` function that uses the current service and context tenant.
211
+
212
+ Getting configuration via the context:
213
+ ```python
214
+ from adsp_service_django_sdk import adsp
215
+
216
+
217
+ @require_user()
218
+ def hello_world(request):
219
+ tenant_config, core_config = adsp.get_configuration()
220
+ ...
221
+ ```
222
+
223
+ The function uses a configuration service client to retrieve configuration. This is also available from the SDK via dependency injection for direct use.
224
+
225
+ Getting configuration using the configuration service:
226
+ ```python
227
+ from adsp_service_django_sdk import adsp
228
+
229
+
230
+
231
+ @require_user()
232
+ def hello_world() -> str:
233
+ tenant_config, core_config = adsp.configuration_service.get_configuration(
234
+ service_id, request_tenant.id
235
+ )
236
+ ...
237
+ ```
238
+
239
+ ### Converting configuration
240
+ Services may want to apply transformations on the retrieved configuration. The SDK allows services to provide functions for combining core and tenant configuration. For example, services can use these to generate effective configuration when tenant overrides parts of core configuration.
241
+
242
+ Provide conversion functions:
243
+ ```python
244
+ from adsp_service_django_sdk import AdspRegistration, ConfigurationDefinition
245
+
246
+
247
+ def convert_config(tenant_config, _) -> Dict[str, Any]:
248
+ return tenant_config
249
+
250
+
251
+ registration = AdspRegistration(
252
+ "Hello world service",
253
+ "Hello world example for Django",
254
+ configuration=ConfigurationDefinition(
255
+ "Configuration of the hello world sample service.",
256
+ {"type": "object", "properties":{"responses":{"type":"object"}}}
257
+ convert_config,
258
+ )
259
+ )
260
+ ```
261
+
262
+ ## Registering event definitions, notification types, etc.
263
+ The SDK allows services to register configuration for some platform services.
264
+
265
+ - `roles` defines the client roles of the service. New tenant realms are created with a client that includes the roles specified here.
266
+ - `events` defines the domain events of the service signalled for domain significant changes.
267
+
268
+ Defining configuration for other platform services:
269
+ ```python
270
+ from adsp_service_django_sdk import (
271
+ AdspRegistration, ConfigurationDefinition, DomainEventDefinition, ServiceRole
272
+ )
273
+ ...
274
+
275
+ registration = AdspRegistration(
276
+ display_name="My platform service",
277
+ description="Hello world platform service.",
278
+ roles=[ServiceRole(HELLO_WORLDER, "Role that allows people to hello the world.")],
279
+ events=[
280
+ DomainEventDefinition(
281
+ HELLO_WORLD_EVENT,
282
+ "Signalled when a hello world message is posted to the API.",
283
+ payload_schema={
284
+ "type": "object",
285
+ "properties": {
286
+ "fromUserId": {"type": "string"},
287
+ "fromUser": {"type": "string"},
288
+ "message": {"type": "string"},
289
+ "response": {"type": "string"},
290
+ },
291
+ },
292
+ )
293
+ ]
294
+ )
295
+ ```
296
+
297
+ ## Sending domain events
298
+ Domain events can be sent using the event service.
299
+
300
+ ```python
301
+ import json
302
+ from adsp_service_django_sdk import adsp, DomainEvent
303
+
304
+
305
+ @require_user()
306
+ def hello_world(request):
307
+ body = json.loads(request.body)
308
+ message = body.get("message", None)
309
+ ...
310
+ adsp.event_service.send(
311
+ DomainEvent(
312
+ HELLO_WORLD_EVENT,
313
+ datetime.utcnow(),
314
+ {
315
+ "fromUserId": get_user.id,
316
+ "fromUser": get_user.name,
317
+ "message": message,
318
+ "response": response,
319
+ },
320
+ )
321
+ )
322
+ ...
323
+ ```
324
+
325
+ ## Additional utilities
326
+ The SDK provides several other useful utilities.
327
+
328
+ ### ADSP ID
329
+ Utilities for handling ADSP URNs.
330
+