@servicialo/mcp-server 0.7.0 → 0.8.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 (67) hide show
  1. package/README.en.md +392 -0
  2. package/README.md +315 -147
  3. package/dist/adapter-http.d.ts +51 -0
  4. package/dist/adapter-http.d.ts.map +1 -0
  5. package/dist/adapter-http.js +187 -0
  6. package/dist/adapter-http.js.map +1 -0
  7. package/dist/adapter.d.ts +42 -0
  8. package/dist/adapter.d.ts.map +1 -0
  9. package/dist/adapter.js +42 -0
  10. package/dist/adapter.js.map +1 -0
  11. package/dist/client.d.ts +5 -1
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/client.js +3 -0
  14. package/dist/client.js.map +1 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +63 -59
  17. package/dist/index.js.map +1 -1
  18. package/dist/mandate.d.ts +321 -0
  19. package/dist/mandate.d.ts.map +1 -0
  20. package/dist/mandate.js +349 -0
  21. package/dist/mandate.js.map +1 -0
  22. package/dist/provider-profile.d.ts +985 -0
  23. package/dist/provider-profile.d.ts.map +1 -0
  24. package/dist/provider-profile.js +210 -0
  25. package/dist/provider-profile.js.map +1 -0
  26. package/dist/tools/authenticated/cerrar.d.ts +5 -5
  27. package/dist/tools/authenticated/cerrar.d.ts.map +1 -1
  28. package/dist/tools/authenticated/cerrar.js.map +1 -1
  29. package/dist/tools/authenticated/comprometer.d.ts +4 -4
  30. package/dist/tools/authenticated/comprometer.d.ts.map +1 -1
  31. package/dist/tools/authenticated/comprometer.js.map +1 -1
  32. package/dist/tools/authenticated/delivery.d.ts +4 -4
  33. package/dist/tools/authenticated/delivery.d.ts.map +1 -1
  34. package/dist/tools/authenticated/delivery.js.map +1 -1
  35. package/dist/tools/authenticated/entender.d.ts +3 -3
  36. package/dist/tools/authenticated/entender.d.ts.map +1 -1
  37. package/dist/tools/authenticated/entender.js.map +1 -1
  38. package/dist/tools/authenticated/lifecycle.d.ts +5 -5
  39. package/dist/tools/authenticated/lifecycle.d.ts.map +1 -1
  40. package/dist/tools/authenticated/lifecycle.js.map +1 -1
  41. package/dist/tools/authenticated/resolve-auth.d.ts +118 -0
  42. package/dist/tools/authenticated/resolve-auth.d.ts.map +1 -0
  43. package/dist/tools/authenticated/resolve-auth.js +62 -0
  44. package/dist/tools/authenticated/resolve-auth.js.map +1 -0
  45. package/dist/tools/authenticated/resource.d.ts +295 -0
  46. package/dist/tools/authenticated/resource.d.ts.map +1 -0
  47. package/dist/tools/authenticated/resource.js +125 -0
  48. package/dist/tools/authenticated/resource.js.map +1 -0
  49. package/dist/tools/public/a2a.d.ts +18 -0
  50. package/dist/tools/public/a2a.d.ts.map +1 -0
  51. package/dist/tools/public/a2a.js +15 -0
  52. package/dist/tools/public/a2a.js.map +1 -0
  53. package/dist/tools/public/availability.d.ts +2 -2
  54. package/dist/tools/public/availability.d.ts.map +1 -1
  55. package/dist/tools/public/availability.js.map +1 -1
  56. package/dist/tools/public/registry.d.ts +8 -3
  57. package/dist/tools/public/registry.d.ts.map +1 -1
  58. package/dist/tools/public/registry.js +8 -0
  59. package/dist/tools/public/registry.js.map +1 -1
  60. package/dist/tools/public/resolve.d.ts +60 -0
  61. package/dist/tools/public/resolve.d.ts.map +1 -0
  62. package/dist/tools/public/resolve.js +60 -0
  63. package/dist/tools/public/resolve.js.map +1 -0
  64. package/dist/tools/public/services.d.ts +2 -2
  65. package/dist/tools/public/services.d.ts.map +1 -1
  66. package/dist/tools/public/services.js.map +1 -1
  67. package/package.json +2 -1
package/README.en.md ADDED
@@ -0,0 +1,392 @@
1
+ # @servicialo/mcp-server
2
+
3
+ > **Canonical MCP Registry entry:** `com.servicialo/mcp-server`
4
+ > The entry `io.github.danioni/servicialo` has been deprecated since March 2026.
5
+
6
+ > **[Versión en español](./README.md)**
7
+
8
+ **The missing protocol layer for AI agents that coordinate professional services.**
9
+
10
+ There is no standard way for an AI agent to book, verify, and settle a professional service. Servicialo is an open protocol that fixes this — and this MCP server is its reference implementation. Think HTTP for service coordination: any agent, any platform, one protocol.
11
+
12
+ ## The Problem
13
+
14
+ AI agents can browse the web, write code, and hold conversations. But ask one to book a physiotherapy session, verify it happened, and process the payment — and it falls apart.
15
+
16
+ Today, every platform is a silo. There's no standard for:
17
+
18
+ - **Discovery** — which provider, in which organization, offers what I need?
19
+ - **Identity** — who is this agent acting for, and what is it authorized to do?
20
+ - **Lifecycle** — what state is this service in? Who confirmed? Who showed up?
21
+ - **Proof of delivery** — did the session actually happen? For how long? Where?
22
+ - **Settlement** — how much, to whom, under what contract terms?
23
+
24
+ Without a shared protocol, every integration is bespoke. Every agent-to-platform connection is a custom API. This doesn't scale.
25
+
26
+ ## What is Servicialo
27
+
28
+ Servicialo is an **open protocol**, not a platform. It defines how professional services move through their lifecycle — from discovery to payment — in a way any AI agent or platform can implement.
29
+
30
+ The relationship is like HTTP to Apache, or SMTP to Gmail: Servicialo defines the rules, implementations bring them to life.
31
+
32
+ The protocol models every service across **8 orthogonal dimensions** (identity, provider, client, schedule, location, lifecycle, proof of delivery, billing) and defines **8 lifecycle states** that are universal across verticals — healthcare, legal, education, home services:
33
+
34
+ ```
35
+ Requested → Scheduled → Confirmed → In Progress → Delivered → Documented → Charged → Verified
36
+ ```
37
+
38
+ Any service, in any vertical, follows this sequence. Vertical-specific logic lives *within* each state, but the state machine is invariant.
39
+
40
+ ## What This MCP Server Does
41
+
42
+ This package exposes the Servicialo protocol as 20 MCP tools organized by the **6 phases** of a service lifecycle. An agent doesn't call endpoints by database entity — it follows the natural flow of coordinating a service.
43
+
44
+ ### Phase 1 — Discovery (4 public tools, no auth required)
45
+
46
+ | Tool | Description |
47
+ |---|---|
48
+ | `registry.search` | Search organizations by vertical, location, country |
49
+ | `registry.get_organization` | Get public details: services, providers, booking config |
50
+ | `scheduling.check_availability` | Check available slots (3-variable: provider ∧ client ∧ resource) |
51
+ | `services.list` | List the public service catalog of an organization |
52
+
53
+ ### Phase 2 — Understand (2 tools)
54
+
55
+ | Tool | Description | Scopes |
56
+ |---|---|---|
57
+ | `service.get` | Get the 8 dimensions of a service | `service:read` |
58
+ | `contract.get` | Get contract terms: required evidence, cancellation policy, dispute window | `service:read` `order:read` |
59
+
60
+ ### Phase 3 — Commit (3 tools)
61
+
62
+ | Tool | Description | Scopes |
63
+ |---|---|---|
64
+ | `clients.get_or_create` | Resolve client identity by email/phone — find or create in one call | `patient:write` |
65
+ | `scheduling.book` | Book a session → state `requested`. Optional `resource_id` for physical resources | `schedule:write` |
66
+ | `scheduling.confirm` | Confirm a booked session → state `confirmed` | `schedule:write` |
67
+
68
+ ### Phase 4 — Lifecycle (4 tools)
69
+
70
+ | Tool | Description | Scopes |
71
+ |---|---|---|
72
+ | `lifecycle.get_state` | Get current state, available transitions, and history | `service:read` |
73
+ | `lifecycle.transition` | Execute a state transition with evidence | `service:write` |
74
+ | `scheduling.reschedule` | Reschedule to new datetime (contract policy may apply) | `schedule:write` |
75
+ | `scheduling.cancel` | Cancel session (contract cancellation policy applied) | `schedule:write` |
76
+
77
+ ### Phase 5 — Verify Delivery (3 tools)
78
+
79
+ | Tool | Description | Scopes |
80
+ |---|---|---|
81
+ | `delivery.checkin` | Check-in with GPS + timestamp → state `in_progress` | `evidence:write` |
82
+ | `delivery.checkout` | Check-out with GPS + timestamp → state `delivered` (duration auto-calculated) | `evidence:write` |
83
+ | `delivery.record_evidence` | Record evidence: `gps`, `signature`, `photo`, `document`, `duration`, `notes` | `evidence:write` |
84
+
85
+ ### Phase 6 — Close (4 tools)
86
+
87
+ | Tool | Description | Scopes |
88
+ |---|---|---|
89
+ | `documentation.create` | Generate service record (clinical note, inspection report, etc.) → state `documented` | `document:write` |
90
+ | `payments.create_sale` | Create charge for documented service → state `charged` | `payment:write` |
91
+ | `payments.record_payment` | Record payment received against a sale | `payment:write` |
92
+ | `payments.get_status` | Get payment status for a sale or client account balance | `payment:read` |
93
+
94
+ ## Installation & Quickstart
95
+
96
+ ### Option 1: Discovery mode (zero config)
97
+
98
+ ```bash
99
+ npx -y @servicialo/mcp-server
100
+ ```
101
+
102
+ No API key. No org ID. 4 public tools available immediately. Try it:
103
+
104
+ ```json
105
+ {
106
+ "tool": "registry.search",
107
+ "arguments": {
108
+ "vertical": "kinesiologia",
109
+ "location": "santiago"
110
+ }
111
+ }
112
+ ```
113
+
114
+ ### Option 2: Full mode (authenticated)
115
+
116
+ ```bash
117
+ SERVICIALO_API_KEY=your_key SERVICIALO_ORG_ID=your_org npx -y @servicialo/mcp-server
118
+ ```
119
+
120
+ All 20 tools unlocked.
121
+
122
+ ### Claude Desktop / Cursor / any MCP client
123
+
124
+ Add to your MCP configuration:
125
+
126
+ ```json
127
+ {
128
+ "mcpServers": {
129
+ "servicialo": {
130
+ "command": "npx",
131
+ "args": ["-y", "@servicialo/mcp-server"],
132
+ "env": {
133
+ "SERVICIALO_API_KEY": "your_api_key",
134
+ "SERVICIALO_ORG_ID": "your_org_id"
135
+ }
136
+ }
137
+ }
138
+ }
139
+ ```
140
+
141
+ Omit the `env` block for discovery-only mode.
142
+
143
+ ### Environment Variables
144
+
145
+ | Variable | Required | Default | Description |
146
+ |---|---|---|---|
147
+ | `SERVICIALO_API_KEY` | No | — | Bearer token. Enables authenticated mode |
148
+ | `SERVICIALO_ORG_ID` | No | — | Organization slug. Enables authenticated mode |
149
+ | `SERVICIALO_BASE_URL` | No | `http://localhost:3000` | API endpoint of the Servicialo-compatible platform |
150
+ | `SERVICIALO_ADAPTER` | No | `coordinalo` | Backend adapter: `coordinalo` or `http` |
151
+
152
+ Both `SERVICIALO_API_KEY` and `SERVICIALO_ORG_ID` must be set together. If only one is present, the server falls back to discovery mode with a warning.
153
+
154
+ ## Connecting to a custom implementation
155
+
156
+ This MCP server supports any Servicialo-compatible backend through its pluggable adapter layer. Two adapters are included:
157
+
158
+ - **`coordinalo`** (default) — connects to a Coordinalo/Digitalo backend with org-scoped routes under `/api/organizations/{orgId}`.
159
+ - **`http`** — connects to any implementation that exposes the canonical `HTTP_PROFILE.md` endpoints under `/v1/*`.
160
+
161
+ ### 3 steps to connect your implementation
162
+
163
+ **Step 1.** Implement the REST endpoints defined in [`HTTP_PROFILE.md`](../../HTTP_PROFILE.md) in your platform.
164
+
165
+ **Step 2.** Configure the MCP server to use the HTTP adapter:
166
+
167
+ ```bash
168
+ SERVICIALO_ADAPTER=http \
169
+ SERVICIALO_BASE_URL=https://your-platform.com \
170
+ SERVICIALO_API_KEY=your_key \
171
+ npx -y @servicialo/mcp-server
172
+ ```
173
+
174
+ **Step 3.** Add to your MCP client configuration:
175
+
176
+ ```json
177
+ {
178
+ "mcpServers": {
179
+ "servicialo": {
180
+ "command": "npx",
181
+ "args": ["-y", "@servicialo/mcp-server"],
182
+ "env": {
183
+ "SERVICIALO_ADAPTER": "http",
184
+ "SERVICIALO_BASE_URL": "https://your-platform.com",
185
+ "SERVICIALO_API_KEY": "your_api_key",
186
+ "SERVICIALO_ORG_ID": "your_org_id"
187
+ }
188
+ }
189
+ }
190
+ }
191
+ ```
192
+
193
+ The HTTP adapter translates internal paths to canonical `/v1/*` endpoints and sends the organization context via the `X-Servicialo-Org` header. See `HTTP_PROFILE.md` for the full REST contract.
194
+
195
+ ## Delegated Agency Model
196
+
197
+ The protocol treats AI agents as first-class actors — but never trusts them implicitly. Every agent action requires a **ServiceMandate**: an explicit delegation of capability from a human principal to an agent.
198
+
199
+ ### How it works
200
+
201
+ 1. A human (professional, patient, or organization) issues a mandate to an agent
202
+ 2. The mandate specifies **who** the agent acts for, **what** it can do (scopes), and **for how long**
203
+ 3. On every tool call, the MCP server validates the mandate against 8 checks before executing
204
+ 4. Every action produces an audit entry — success or failure
205
+
206
+ ### Mandate example
207
+
208
+ ```json
209
+ {
210
+ "mandate_id": "550e8400-e29b-41d4-a716-446655440000",
211
+ "principal_id": "dr_barbara",
212
+ "principal_type": "professional",
213
+ "agent_id": "agent_scheduling_bot",
214
+ "agent_name": "Booking Assistant",
215
+ "acting_for": "professional",
216
+ "context": "org:clinica-kinesia",
217
+ "scopes": ["schedule:read", "schedule:write", "patient:write"],
218
+ "constraints": {
219
+ "max_actions_per_day": 50,
220
+ "allowed_hours": {
221
+ "start": "08:00",
222
+ "end": "20:00",
223
+ "timezone": "America/Santiago"
224
+ },
225
+ "require_confirmation_above": {
226
+ "amount": 100000,
227
+ "currency": "CLP"
228
+ }
229
+ },
230
+ "issued_at": "2026-03-01T00:00:00Z",
231
+ "expires_at": "2026-06-01T00:00:00Z",
232
+ "status": "active"
233
+ }
234
+ ```
235
+
236
+ ### Using mandates in tool calls
237
+
238
+ When `actor.type` is `"agent"`, include the `mandate_id`:
239
+
240
+ ```json
241
+ {
242
+ "tool": "scheduling.book",
243
+ "arguments": {
244
+ "service_id": "srv_123",
245
+ "provider_id": "prov_111",
246
+ "client_id": "cli_789",
247
+ "starts_at": "2026-03-03T10:00:00",
248
+ "actor": {
249
+ "type": "agent",
250
+ "id": "agent_scheduling_bot",
251
+ "mandate_id": "550e8400-e29b-41d4-a716-446655440000"
252
+ }
253
+ }
254
+ }
255
+ ```
256
+
257
+ ### The 8 validation checks
258
+
259
+ Every agent tool call is validated against:
260
+
261
+ | # | Check | What it prevents |
262
+ |---|---|---|
263
+ | 1 | **Status** — mandate must be `active` | Using revoked or expired mandates |
264
+ | 2 | **Temporal validity** — `issued_at ≤ now < expires_at` | Time-based attacks |
265
+ | 3 | **Agent identity** — `mandate.agent_id === requesting agent` | Agent impersonation |
266
+ | 4 | **Scope coverage** — mandate scopes cover the tool's requirements | Privilege escalation |
267
+ | 5 | **Context match** — mandate context matches the request | Cross-org data access |
268
+ | 6 | **Conflict of interest** — agent can't act for both sides | Dual-agency violations |
269
+ | 7 | **Constraints** — allowed hours, daily limits, financial thresholds | Over-autonomous agents |
270
+ | 8 | **Audit** — every action logged with sanitized inputs | Non-repudiation |
271
+
272
+ Non-agent actors (`client`, `provider`, `organization`) bypass mandate validation entirely.
273
+
274
+ ## Provider Discovery
275
+
276
+ Agents can search the registry and match providers to a patient's needs using structured queries.
277
+
278
+ ### Search the registry
279
+
280
+ ```json
281
+ {
282
+ "tool": "registry.search",
283
+ "arguments": {
284
+ "vertical": "kinesiologia",
285
+ "location": "santiago",
286
+ "country": "cl"
287
+ }
288
+ }
289
+ ```
290
+
291
+ Returns matching organizations with their services and providers.
292
+
293
+ ### Check availability
294
+
295
+ ```json
296
+ {
297
+ "tool": "scheduling.check_availability",
298
+ "arguments": {
299
+ "org_slug": "clinica-kinesia",
300
+ "service_id": "srv_pelvic_rehab",
301
+ "provider_id": "prov_111",
302
+ "date_from": "2026-03-10",
303
+ "date_to": "2026-03-14"
304
+ }
305
+ }
306
+ ```
307
+
308
+ The 3-variable scheduler checks availability across provider, client, and physical resource simultaneously.
309
+
310
+ ### End-to-end example
311
+
312
+ ```
313
+ 1. registry.search({ vertical: "kinesiologia", location: "santiago" })
314
+ → finds org "clinica-kinesia"
315
+
316
+ 2. services.list({ org_slug: "clinica-kinesia" })
317
+ → lists available services
318
+
319
+ 3. scheduling.check_availability({ org_slug: "clinica-kinesia", date_from: "2026-03-10", date_to: "2026-03-14" })
320
+ → returns available slots
321
+
322
+ 4. contract.get({ service_id: "srv_123", org_id: "org_456" })
323
+ → cancellation: 0% if >24h, 50% if 2-24h, 100% if <2h
324
+ → required evidence: check_in + check_out + clinical_record
325
+
326
+ 5. clients.get_or_create({ email: "maria@mail.com", name: "Maria", last_name: "Lopez" })
327
+ → client_id: "cli_789"
328
+
329
+ 6. scheduling.book({ service_id: "srv_123", provider_id: "prov_111", client_id: "cli_789", starts_at: "2026-03-12T10:00:00" })
330
+ → session_id: "ses_001", state: "requested"
331
+
332
+ 7. scheduling.confirm({ session_id: "ses_001" })
333
+ → state: "confirmed"
334
+
335
+ 8. delivery.checkin({ session_id: "ses_001", location: { lat: -33.45, lng: -70.66 } })
336
+ → state: "in_progress"
337
+
338
+ 9. delivery.checkout({ session_id: "ses_001", location: { lat: -33.45, lng: -70.66 } })
339
+ → state: "delivered", duration: 42min
340
+
341
+ 10. documentation.create({ session_id: "ses_001", content: "Pelvic floor rehabilitation session..." })
342
+ → state: "documented"
343
+
344
+ 11. payments.create_sale({ client_id: "cli_789", service_id: "srv_123", unit_price: 35000 })
345
+ → sale_id: "sale_001", state: "charged"
346
+
347
+ 12. lifecycle.transition({ session_id: "ses_001", to_state: "verified" })
348
+ → state: "verified" ✓
349
+ ```
350
+
351
+ ## Protocol Specification
352
+
353
+ The full Servicialo protocol specification is available at:
354
+
355
+ - **Repository:** [github.com/servicialo/protocol](https://github.com/servicialo/protocol)
356
+ - **Website:** [servicialo.com](https://servicialo.com)
357
+ - **Current stable version:** 0.7
358
+ - **JSON Schemas:** [`service.schema.json`](https://github.com/servicialo/protocol/blob/main/schema/service.schema.json), [`service-order.schema.json`](https://github.com/servicialo/protocol/blob/main/schema/service-order.schema.json), [`service-mandate.schema.json`](https://github.com/servicialo/protocol/blob/main/schema/service-mandate.schema.json)
359
+
360
+ The spec covers the 8 service dimensions, 8 lifecycle states, 5 exception flows (no-show, cancellation, dispute, reschedule, partial delivery), the two-entity architecture (atomic Service + Service Order), and the Delegated Agency Model.
361
+
362
+ ## Reference Implementation
363
+
364
+ **Digitalo** is the first production implementation of the Servicialo protocol, operating in healthcare in Chile. It implements the full lifecycle — from provider discovery through payment settlement — and serves as the validation ground for protocol evolution.
365
+
366
+ This MCP server connects to any Servicialo-compatible backend via `SERVICIALO_BASE_URL`. Digitalo is one such backend. The protocol is designed so that any CRM, EHR, or platform can implement it as a sovereign node.
367
+
368
+ ## Contributing to the Protocol
369
+
370
+ Servicialo follows semantic versioning for the protocol specification:
371
+
372
+ - **Patch** (0.7.x) — clarifications, typo fixes, non-breaking additions
373
+ - **Minor** (0.x.0) — new optional fields, new tool definitions, new exception flows
374
+ - **Major** (x.0.0) — breaking changes to schemas, state machine, or core semantics
375
+
376
+ ### How to propose changes
377
+
378
+ 1. Open an issue describing the problem and your proposed solution
379
+ 2. For significant changes, write an RFC in `spec/` with the section number it affects
380
+ 3. Protocol changes require at least one reference implementation before merging
381
+ 4. Schema changes must include updated JSON Schema files and Zod types in the MCP server
382
+
383
+ ### Areas actively seeking input
384
+
385
+ - Vertical-specific evidence requirements (beyond healthcare)
386
+ - Multi-language support for lifecycle state names
387
+ - Inter-node federation (how two Servicialo implementations interoperate)
388
+ - Agent SDK patterns for Python and TypeScript
389
+
390
+ ## License
391
+
392
+ Apache-2.0 — any implementation, commercial or otherwise, is welcome. See [LICENSE](./LICENSE).