@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,355 @@
1
+ ---
2
+ layout: page
3
+ title: Service SDK (Flask)
4
+ nav_order: 5
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 (Flask)
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 Flask wheel from release artifacts in the repository.
23
+
24
+ ```bash
25
+ poetry add https://github.com/GovAlta/adsp-monorepo/releases/download/adsp-service-flask-sdk-v1.3.1/adsp_service_flask_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 a Flask Extension, Blueprint, and context proxies. Create the extension and initialize on the Flask app to get started.
43
+
44
+ ```python
45
+ from adsp import AdspExtension, AdspRegistration
46
+ from flask import Flask
47
+
48
+ app = Flask(__name__)
49
+ extension = AdspExtension()
50
+ extension.init_app(
51
+ app,
52
+ AdspRegistration(
53
+ display_name="My platform service",
54
+ description="Hello world platform service."
55
+ )
56
+ )
57
+ ```
58
+
59
+ ## Enabling service metadata
60
+ 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 components for exposing the metadata endpoint.
61
+
62
+ Enabling service metadata:
63
+ ```python
64
+ from adsp import AdspExtension, AdspRegistration
65
+ from flask import Flask
66
+
67
+ app = Flask(__name__)
68
+ extension = AdspExtension()
69
+ adsp = extension.init_app(
70
+ app,
71
+ AdspRegistration(
72
+ display_name="My platform service",
73
+ description="Hello world platform service.",
74
+ api_path="/hello-world/v1"
75
+ )
76
+ )
77
+
78
+ app.register_blueprint(adsp.metadata_blueprint)
79
+ ```
80
+
81
+ ## Authorizing requests
82
+ The SDK extension adds a `before_request` function to process access tokens. It provides a `request_user` context value and `require_user` decorator for authorizing requests.
83
+
84
+ Require ADSP user for request:
85
+ ```python
86
+ from adsp_service_flask_sdk import request_user, require_user, User
87
+ ...
88
+
89
+ @app.route("hello-world/v1/hello")
90
+ @require_user()
91
+ def hello_world() -> str:
92
+ return f"hello {request_user.name}"
93
+ ```
94
+
95
+ ### Role-based authorization
96
+ The SDK maps Keycloak access token `realm_access` and `resource_access` roles to the request user.
97
+
98
+ 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.
99
+
100
+ For example:
101
+ ```json
102
+ {
103
+ "realm_access": { "roles": ["user"] },
104
+ "resource_access": {
105
+ "my-service": { "roles": ["my-user"] },
106
+ "other-service": { "roles": ["other-user"] }
107
+ }
108
+ }
109
+ ```
110
+
111
+ For my-service, the roles are mapped to role claims:
112
+ - user
113
+ - my-user
114
+ - other-service:other-user
115
+
116
+ Authorize based on a role:
117
+ ```python
118
+ from adsp_service_flask_sdk import request_user, require_user, User
119
+ ...
120
+
121
+ @app.route("hello-world/v1/hello")
122
+ @require_user("other-service:other-user")
123
+ def hello_world() -> str:
124
+ return f"hello {request_user.name}"
125
+ ```
126
+
127
+ Accessing user information directly and checking for role:
128
+ ```python
129
+ from adsp_service_flask_sdk import request_user
130
+
131
+ has_role = "other-service:other-user" in request_user.roles
132
+ ```
133
+
134
+ ## Determining tenancy
135
+ 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.
136
+
137
+ The SDK extension adds a `before_request` function that 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.
138
+
139
+ Getting tenancy from the context:
140
+ ```python
141
+ from adsp_service_flask_sdk import request_tenant
142
+ ...
143
+
144
+ @app.route("hello-world/v1/hello")
145
+ @require_user()
146
+ def hello_world() -> str:
147
+ return f"hello {request_tenant.name}"
148
+ ```
149
+
150
+ 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 via dependency injection.
151
+
152
+ Getting tenant information using the tenant service:
153
+ ```python
154
+ adsp = extension.init_app(
155
+ app,
156
+ AdspRegistration(
157
+ display_name="My platform service",
158
+ description="Hello world platform service."
159
+ )
160
+ )
161
+
162
+ @app.route("hello-world/v1/hello")
163
+ @require_user()
164
+ def hello_world() -> str:
165
+ tenant_id = request.args.get("tenantId")
166
+ tenant = adsp.tenant_service.get_tenant(AdspId.parse(tenant_id))
167
+ ...
168
+ ```
169
+
170
+ ## Finding services
171
+ Service discovery in ADSP is handled using client side service discovery with a directory of services providing a register of available services.
172
+
173
+ Getting a service URL from the directory:
174
+ ```python
175
+ adsp = extension.init_app(
176
+ app,
177
+ AdspRegistration(
178
+ display_name="My platform service",
179
+ description="Hello world platform service."
180
+ )
181
+ )
182
+
183
+ @app.route("hello-world/v1/hello")
184
+ @require_user()
185
+ def hello_world() -> str:
186
+ service_url = adsp.directory.get_service_url(AdspId.parse("urn:ads:platform:tenant-service"))
187
+ ...
188
+ ```
189
+
190
+ ## Handling configuration
191
+ 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.
192
+
193
+ Defining the configuration json schema:
194
+ ```python
195
+ adsp = extension.init_app(
196
+ app,
197
+ AdspRegistration(
198
+ display_name="My platform service",
199
+ description="Hello world platform service.",
200
+ configuration=ConfigurationDefinition(
201
+ "Configuration of messages.",
202
+ {"type": "object", "properties":{"responses":{"type":"object"}}}
203
+ )
204
+ )
205
+ )
206
+ ```
207
+
208
+ 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.
209
+
210
+ Getting configuration via the context:
211
+ ```python
212
+ adsp = extension.init_app(
213
+ app,
214
+ AdspRegistration(
215
+ display_name="My platform service",
216
+ description="Hello world platform service.",
217
+ configuration=ConfigurationDefinition(
218
+ "Configuration of messages.",
219
+ {"type": "object", "properties":{"responses":{"type":"object"}}}
220
+ )
221
+ )
222
+ )
223
+
224
+ @app.route("hello-world/v1/hello")
225
+ @require_user()
226
+ def hello_world() -> str:
227
+ tenant_config, core_config = adsp.get_configuration()
228
+ ...
229
+ ```
230
+
231
+ The function uses a configuration service client to retrieve configuration. This is also available from the SDK via dependency injection for direct use.
232
+
233
+ Getting configuration using the configuration service:
234
+ ```python
235
+ adsp = extension.init_app(
236
+ app,
237
+ AdspRegistration(
238
+ display_name="My platform service",
239
+ description="Hello world platform service.",
240
+ configuration=ConfigurationDefinition(
241
+ "Configuration of messages.",
242
+ {"type": "object", "properties":{"responses":{"type":"object"}}}
243
+ )
244
+ )
245
+ )
246
+
247
+ @app.route("hello-world/v1/hello")
248
+ @require_user()
249
+ def hello_world() -> str:
250
+ tenant_config, core_config = adsp.configuration_service.get_configuration(
251
+ service_id, request_tenant.id
252
+ )
253
+ ...
254
+ ```
255
+
256
+ ### Converting configuration
257
+ 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.
258
+
259
+ Provide conversion functions:
260
+ ```python
261
+ adsp = extension.init_app(
262
+ app,
263
+ AdspRegistration(
264
+ display_name="My platform service",
265
+ description="Hello world platform service.",
266
+ configuration=ConfigurationDefinition(
267
+ "Configuration of messages.",
268
+ {"type": "object", "properties":{"responses":{"type":"object"}}}
269
+ lambda tenant_config, core_config: core_config.update(tenant_config.items())
270
+ )
271
+ )
272
+ )
273
+ ```
274
+
275
+ ## Registering event definitions, notification types, etc.
276
+ The SDK allows services to register configuration for some platform services.
277
+
278
+ - `roles` defines the client roles of the service. New tenant realms are created with a client that includes the roles specified here.
279
+ - `events` defines the domain events of the service signalled for domain significant changes.
280
+
281
+ Defining configuration for other platform services:
282
+ ```python
283
+ adsp = extension.init_app(
284
+ app,
285
+ AdspRegistration(
286
+ display_name="My platform service",
287
+ description="Hello world platform service.",
288
+ roles=[ServiceRole(HELLO_WORLDER, "Role that allows people to hello the world.")],
289
+ events=[
290
+ DomainEventDefinition(
291
+ HELLO_WORLD_EVENT,
292
+ "Signalled when a hello world message is posted to the API.",
293
+ payload_schema={
294
+ "type": "object",
295
+ "properties": {
296
+ "fromUserId": {"type": "string"},
297
+ "fromUser": {"type": "string"},
298
+ "message": {"type": "string"},
299
+ "response": {"type": "string"},
300
+ },
301
+ },
302
+ )
303
+ ]
304
+ )
305
+ )
306
+ ```
307
+
308
+ ## Sending domain events
309
+ Domain events can be sent using the event service.
310
+
311
+ ```python
312
+ adsp = extension.init_app(
313
+ app,
314
+ AdspRegistration(
315
+ display_name="My platform service",
316
+ description="Hello world platform service.",
317
+ roles=[ServiceRole(HELLO_WORLDER, "Role that allows people to hello the world.")],
318
+ events=[
319
+ DomainEventDefinition(
320
+ HELLO_WORLD_EVENT,
321
+ "Signalled when a hello world message is posted to the API.",
322
+ payload_schema={
323
+ ...
324
+ },
325
+ )
326
+ ]
327
+ )
328
+ )
329
+
330
+ @app.route("hello-world/v1/hello")
331
+ @require_user()
332
+ def hello_world() -> str:
333
+ message = request.args.get("message")
334
+ ...
335
+ adsp.event_service.send(
336
+ DomainEvent(
337
+ HELLO_WORLD_EVENT,
338
+ datetime.utcnow(),
339
+ {
340
+ "fromUserId": request_user.id,
341
+ "fromUser": request_user.name,
342
+ "message": message,
343
+ "response": response,
344
+ },
345
+ )
346
+ )
347
+ ...
348
+ ```
349
+
350
+ ## Additional utilities
351
+ The SDK provides several other useful utilities.
352
+
353
+ ### ADSP ID
354
+ Utilities for handling ADSP URNs.
355
+