Skip to content

Commit 99223b2

Browse files
author
haarer
committed
add traceability between concepts and stereotypes to SAF MCP server
1 parent 12c550d commit 99223b2

6 files changed

Lines changed: 577 additions & 3 deletions

File tree

tools/plan.md

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The driving question: *"Does viewpoint X expose enough concepts (data + relation
1313
3. **Least context per query.** Tools should return fully resolved, joined data — no raw GUIDs the model must chase.
1414
4. **One server.** Monolithic, with focused tools.
1515
5. **Proven stack.** Python + `mcp` SDK (official Python package).
16-
6. **Start small.** 11 tools, stdio + HTTP/SSE transport.
16+
6. **Start small.** 15 tools, stdio + HTTP/SSE transport.
1717

1818
## Data Model (Loaded at Startup)
1919

@@ -32,6 +32,11 @@ Index maps:
3232
stakeholders_by_guid: dict[str, Stakeholder]
3333
stakeholders_by_name: dict[str, Stakeholder]
3434
exposes_by_viewpoint_guid: dict[str, list[Expose]]
35+
stereotypes: dict[str, Stereotype]
36+
stereotypes_by_name: dict[str, Stereotype]
37+
realize_concepts: list[RealizeConcept]
38+
realizations_by_concept_id: dict[str, list[RealizeConcept]]
39+
realizations_by_stereotype_id: dict[str, list[RealizeConcept]]
3540
```
3641

3742
All cross-references resolved at load time:
@@ -67,6 +72,8 @@ Concern texts are normalized (strip, lowercase, collapse whitespace) and hashed
6772
3. `get_viewpoint_concepts(...)` → full concept details (~3 KB, only when model decides it needs them)
6873
4. `get_concept("Operational Context Role")` → specific concept deep-dive (~1 KB)
6974
5. `get_viewpoint_concerns(...)` → concerns with rationales (~2 KB)
75+
6. `get_concept_stereotypes("Conceptual System Context")` → what stereotypes realize this concept (~0.5 KB)
76+
7. `get_stereotype("SAF_ConceptualSystem")` → drill into stereotype details (~1 KB)
7077

7178
vs monolithic: step 1 alone returns 5-15 KB regardless of what the model needs.
7279

@@ -134,6 +141,89 @@ Returns a stakeholder's full profile: documentation, and all their concerns with
134141

135142
Returns a concern's details: the question it frames, its owner, and which viewpoints address it.
136143

144+
### 12. `get_stereotype`
145+
146+
Returns a stereotype's full details: documentation, which SAF concepts it realizes, and which special implementations (typing, containment, attribute) involve it. Use this to drill into a specific stereotype. To trace from a concept forward, use `get_concept_stereotypes`.
147+
148+
```json
149+
{
150+
"name": "SAF_ConceptualSystem",
151+
"id": "_19_0_1_26f0132_...",
152+
"documentation": "...",
153+
"realized_concepts": [
154+
{
155+
"concept_name": "Conceptual System",
156+
"concept_id": "...",
157+
"concept_type": "Class",
158+
"concept_documentation": "..."
159+
}
160+
]
161+
}
162+
```
163+
164+
### 13. `get_concept_stereotypes`
165+
166+
Returns all stereotypes that realize a given SAF concept — including both **direct realizations** (from `realizeconcept.json`) and **indirect UML metaclass mappings** via special implementations (SCM_TypedBy, SCM_ContainedIn, SCM_Attribute). This is the single entry point for full concept→stereotype→UML traceability. Use `get_stereotype` to drill into a specific stereotype for full detail.
167+
168+
Each entry includes:
169+
- `stereotype_name`, `stereotype_id`, `stereotype_documentation`
170+
- `realized_concepts` — concept names this stereotype realizes
171+
- `special_implementations` — resolved UML↔SAF relations with semantic role labels
172+
173+
```json
174+
[
175+
{
176+
"stereotype_name": "SAF_ConceptualExchangeType",
177+
"stereotype_id": "_19_0_3_26f0132_...",
178+
"stereotype_documentation": "...",
179+
"realized_concepts": ["Conceptual Exchange Type"],
180+
"special_implementations": [
181+
{
182+
"relation_type": "SCM_TypedBy",
183+
"typed_element": "FlowProperty",
184+
"type_definition": "SAF_ConceptualExchangeType"
185+
},
186+
{
187+
"relation_type": "SCM_TypedBy",
188+
"typed_element": "ItemFlow",
189+
"type_definition": "SAF_ConceptualExchangeType"
190+
}
191+
]
192+
}
193+
]
194+
```
195+
196+
Role labels vary by relation type:
197+
198+
| Relation | Role A | Role B |
199+
|---|---|---|
200+
| `SCM_TypedBy` | `typed_element` | `type_definition` |
201+
| `SCM_ContainedIn` | `contained_element` | `container` |
202+
| `SCM_Attribute` | `owner` | `value` |
203+
204+
### 14. `list_stereotypes`
205+
206+
Lists all stereotypes with their name and the concepts they realize. Useful for browsing the full catalog.
207+
208+
### 15. `get_special_implementations`
209+
210+
Returns special implementation relations (`SCM_TypedBy`, `SCM_ContainedIn`, `SCM_Attribute`) that link UML/SysML metaclasses to SAF stereotypes. Optionally filter by `stereotype_name` to see all special implementations involving a specific stereotype (as client or supplier). Use this to understand how UML/SysML elements are mapped to SAF stereotypes at the metamodel level.
211+
212+
```json
213+
[
214+
{
215+
"id": "_2021x_2_8710274_1681817408348_216387_29249",
216+
"stereotype": "SCM_TypedBy",
217+
"client": "FlowProperty",
218+
"client_id": "...",
219+
"supplier": "SAF_ConceptualExchangeType",
220+
"supplier_id": "...",
221+
"name": "",
222+
"documentation": ""
223+
}
224+
]
225+
```
226+
137227
## Why This Design Minimizes Context
138228

139229
- **No GUID chasing.** Every tool call returns names, not IDs. The model reads prose immediately.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# ADR 001: Merged Concept-to-Stereotype Traceability Tools
2+
3+
**Date:** 2026-06-06
4+
**Status:** Accepted
5+
**Deciders:** SAF designer, MCP server implementer
6+
7+
## Context
8+
9+
The SAF ontology MCP server exposes tools that let an LLM query the relationship between abstract SAF concepts and their UML/SysML stereotype implementations. This traceability spans two data sources:
10+
11+
1. **realizeconcept.json** — Direct mapping: `SAF Concept → SAF Stereotype` (e.g., `Conceptual Exchange Type → SAF_ConceptualExchangeType`).
12+
2. **special-implementations.json** — Metamodel-level relations (`SCM_TypedBy`, `SCM_ContainedIn`, `SCM_Attribute`) linking UML/SysML metaclasses (e.g., `FlowProperty`, `ProxyPort`) to SAF stereotypes.
13+
14+
A third data source, **stereotypes.json**, provides documentation for each stereotype but does not encode traceability edges itself.
15+
16+
An LLM in a fresh session cannot know, without being told, that it needs to:
17+
18+
- Call `get_concept_stereotypes` for direct realizations.
19+
- Call `get_special_implementations` for indirect UML-metaclass links.
20+
- Then mentally join the two results to see the full picture.
21+
- Interpret generic terms like "client" and "supplier" differently depending on the relation stereotype.
22+
23+
## Decision
24+
25+
We will merge the two traceability paths into a single tool output and use semantically transparent role labels.
26+
27+
### 1. Single entry point for traceability
28+
29+
`get_concept_stereotypes` returns **both**:
30+
- Direct `realizeconcept.json` realizations (stereotype → concept).
31+
- Indirect `special-implementations.json` relations (UML metaclass → relation → stereotype → concept) — fully resolved to concept level.
32+
33+
The LLM gets the complete trace in one call:
34+
35+
```json
36+
[
37+
{
38+
"stereotype_name": "SAF_ConceptualExchangeType",
39+
"stereotype_id": "...",
40+
"stereotype_documentation": "...",
41+
"realized_concepts": ["Conceptual Exchange Type"],
42+
"special_implementations": [
43+
{
44+
"relation_type": "SCM_TypedBy",
45+
"typed_element": "FlowProperty",
46+
"type_definition": "SAF_ConceptualExchangeType"
47+
},
48+
{
49+
"relation_type": "SCM_TypedBy",
50+
"typed_element": "ItemFlow",
51+
"type_definition": "SAF_ConceptualExchangeType"
52+
}
53+
]
54+
}
55+
]
56+
```
57+
58+
### 2. Semantic role labels instead of generic "client"/"supplier"
59+
60+
The return shape uses role labels that vary by relation stereotype:
61+
62+
| SCM Stereotype | Field A | Field B |
63+
|---|---|---|
64+
| `SCM_TypedBy` | `typed_element` | `type_definition` |
65+
| `SCM_ContainedIn` | `contained_element` | `container` |
66+
| `SCM_Attribute` | `owner` | `value` |
67+
68+
The `get_special_implementations` tool (retained as a secondary filter) uses the same labels.
69+
70+
### 3. Cross-reference hints in tool descriptions
71+
72+
Every tool description explicitly mentions the chain so an LLM can navigate:
73+
74+
- `get_concept_stereotypes`: "Returns both direct stereotype realizations and indirect UML metaclass mappings via special implementations. Each entry includes `realized_concepts` and `special_implementations` (SCM_TypedBy, SCM_ContainedIn, SCM_Attribute). Use `get_stereotype` to drill into a specific stereotype for full detail."
75+
- `get_stereotype`: "Shows which concepts this stereotype realizes and which special implementations involve it (as typed_element, container, etc.). To trace from a concept forward, use `get_concept_stereotypes`."
76+
- `get_special_implementations`: "Filter view of UML↔SAF mapping relations. Typically reached via `get_concept_stereotypes` or `get_stereotype` which already resolve these."
77+
78+
## Consequences
79+
80+
**Good:**
81+
- LLM gets the full trace in one call — no manual joining.
82+
- Role labels are self-documenting; an LLM can read `typed_element: "FlowProperty"` without knowing the special-implementations model.
83+
- Tool descriptions form a navigable graph; an LLM can discover the chain by reading tool names and descriptions alone.
84+
- Backward compatible: the old `client`/`supplier` fields are replaced, not appended to, so an LLM always sees the better shape.
85+
86+
**Risks:**
87+
- Increased payload size per `get_concept_stereotypes` call (more data returned). Mitigated by the fact that most SAF concepts have few special-implementations; the 44 entries across all concepts average well under 1 per concept.
88+
89+
**Non-goals:**
90+
- Removing the `get_special_implementations` standalone tool — it remains useful for ad-hoc queries (e.g., "show me all `SCM_ContainedIn` relations involving `StateMachine`").

0 commit comments

Comments
 (0)