Skip to content

Commit 71faaea

Browse files
HandyS11Copilot
andauthored
Add mcp integration primitives (#52)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 9dc10af commit 71faaea

34 files changed

Lines changed: 3158 additions & 248 deletions

.github/agents/copilot-instructions.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
# ProjGraph Development Guidelines
1+
# ProjGraph Development Guidelines
22

33
Auto-generated from all feature plans. Last updated: 2026-01-13
44

55
## Active Technologies
66

7+
- .NET 10.0 (C# 14+) + `ModelContextProtocol` v1.0.0, `Microsoft.Extensions.Hosting` (012-mcp-integration-primitives)
8+
- In-memory only (`DiagramResourceCache` singleton, max 50 entries, LRU eviction) (012-mcp-integration-primitives)
9+
710
- .NET 10.0 (C# 14+) + `mcp-publisher` (npm), GitHub Actions (011-mcp-registry-submission)
811

912
- .NET 10.0 (C# 14+) + `Spectre.Console.Cli` (CLI formatting), `ModelContextProtocol.Server` (MCP tool),
@@ -50,13 +53,15 @@ tests/
5053

5154
## Recent Changes
5255

56+
- 012-mcp-integration-primitives: Added .NET 10.0 (C# 14+) + `ModelContextProtocol` v1.0.0,
57+
`Microsoft.Extensions.Hosting`
58+
5359
- 011-mcp-registry-submission: Added .NET 10.0 (C# 14+) + `mcp-publisher` (npm), GitHub Actions
5460

5561
- 010-project-stats-mcp: Added .NET 10.0 (C# 14+) + `Spectre.Console.Cli` (CLI formatting),
5662
`ModelContextProtocol.Server` (MCP tool), `System.Text.Json` (MCP response serialisation),
5763
`Microsoft.Extensions.DependencyInjection` (DI wiring)
5864

59-
- 009-directory-class-diagram: Added .NET 10.0 (C# 14+) + Microsoft.CodeAnalysis.CSharp (Roslyn)
6065

6166
Spectre.Console (for rendering)
6267

.markdownlint.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"MD013": false,
33
"MD024": false,
44
"MD033": false,
5-
"MD036": false
6-
}
5+
"MD036": false,
6+
"MD041": false
7+
}

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"sdk": {
3-
"version": "10.0.101",
3+
"version": "10.0.103",
44
"rollForward": "latestMajor",
55
"allowPrerelease": true
66
}
7-
}
7+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Specification Quality Checklist: MCP Integration Primitives
2+
3+
**Purpose**: Validate specification completeness and quality before proceeding to planning
4+
**Created**: 2026-03-10
5+
**Feature**: [spec.md](../spec.md)
6+
7+
## Content Quality
8+
9+
- [x] No implementation details (languages, frameworks, APIs)
10+
- [x] Focused on user value and business needs
11+
- [x] Written for non-technical stakeholders
12+
- [x] All mandatory sections completed
13+
14+
## Requirement Completeness
15+
16+
- [x] No [NEEDS CLARIFICATION] markers remain
17+
- [x] Requirements are testable and unambiguous
18+
- [x] Success criteria are measurable
19+
- [x] Success criteria are technology-agnostic (no implementation details)
20+
- [x] All acceptance scenarios are defined
21+
- [x] Edge cases are identified
22+
- [x] Scope is clearly bounded
23+
- [x] Dependencies and assumptions identified
24+
25+
## Feature Readiness
26+
27+
- [x] All functional requirements have clear acceptance criteria
28+
- [x] User scenarios cover primary flows
29+
- [x] Feature meets measurable outcomes defined in Success Criteria
30+
- [x] No implementation details leak into specification
31+
32+
## Notes
33+
34+
- Spec references MCP primitive names (Resources, Prompts, Roots, Notifications) as domain concepts, not implementation details — these are protocol-level constructs.
35+
- Tool names (`get_project_graph`, etc.) are referenced as existing system interfaces, not implementation details.
36+
- URI templates for resources use the `projgraph://` scheme as a domain-level identifier.
37+
- All four user stories are independently testable and ordered by impact (P1–P4).
38+
- No [NEEDS CLARIFICATION] markers present — all decisions were made with reasonable defaults documented in Assumptions.
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# MCP Prompts Contract
2+
3+
**Date**: 2026-03-10
4+
**Branch**: `012-mcp-integration-primitives`
5+
**Registration**: `builder.Services.AddMcpServer().WithPrompts<ProjGraphPrompts>()`
6+
**SDK type**: `[McpServerPromptType]` / `[McpServerPrompt]`
7+
8+
---
9+
10+
## Prompt: `architecture_review`
11+
12+
**Description**: Guides an LLM through a comprehensive architecture review of a .NET solution, including dependency visualization and project metrics.
13+
14+
### Arguments
15+
16+
| Name | Type | Required | Description |
17+
|------|------|----------|-----------------------------------------------------------------------------------------------|
18+
| `path` | string | yes | Absolute (or root-relative) path to the solution file (.sln, .slnx) or project file (.csproj) |
19+
20+
### Returned Messages
21+
22+
**Message 1 — User role**:
23+
24+
```none
25+
Please perform a comprehensive architecture review of the .NET solution at: {path}
26+
27+
Use the following steps in order:
28+
29+
1. Call `get_project_graph` with path="{path}" to generate the dependency graph.
30+
2. Call `get_project_stats` with path="{path}" to retrieve architectural metrics.
31+
3. Analyze the results and provide:
32+
- A summary of the overall architecture and structure
33+
- Projects with the most dependencies (hotspots)
34+
- Any suspicious dependency patterns (deep chains, violations of layering)
35+
- A health assessment: what is well-structured and what could be improved
36+
- Specific actionable recommendations
37+
```
38+
39+
**Message 2 — Assistant role (pre-fill)**:
40+
41+
```none
42+
I'll analyze the .NET solution architecture step by step. Starting with the dependency graph and metrics.
43+
```
44+
45+
---
46+
47+
## Prompt: `dependency_analysis`
48+
49+
**Description**: Guides an LLM to analyze dependency depth, identify hotspot projects, and detect potential circular dependencies in a .NET solution.
50+
51+
### Arguments
52+
53+
| Name | Type | Required | Default | Description |
54+
|------|------|----------|--------|-------------|
55+
| `path` | string | yes || Absolute path to the solution or project file |
56+
| `topN` | string | no | `"5"` | Number of top hotspot projects to highlight |
57+
58+
### Returned Messages
59+
60+
**Message 1 — User role**:
61+
62+
```none
63+
Analyze the dependency structure of the .NET solution at: {path}
64+
65+
Steps:
66+
1. Call `get_project_graph` with path="{path}" to visualize the dependency graph.
67+
2. Call `get_project_stats` with path="{path}" and topN={topN} to retrieve depth statistics and top {topN} most-referenced projects.
68+
3. Report:
69+
- Dependency depth distribution (min, max, average)
70+
- Top {topN} most-referenced (hotspot) projects and why they matter
71+
- Any detected circular dependencies — list them explicitly
72+
- Recommendations to reduce coupling or break cycles
73+
```
74+
75+
**Message 2 — Assistant role**:
76+
77+
```none
78+
I'll analyze the dependency structure and identify hotspots and cycles.
79+
```
80+
81+
---
82+
83+
## Prompt: `database_schema_review`
84+
85+
**Description**: Guides an LLM through reviewing an Entity Framework Core database schema for design quality, relationships, and potential issues.
86+
87+
### Arguments
88+
89+
| Name | Type | Required | Description |
90+
|------|------|----------|------------------------------------------------------------------------------------|
91+
| `path` | string | yes | Absolute path to a .cs file containing a `DbContext` or `ModelSnapshot` |
92+
| `contextName` | string | no | Specific DbContext or ModelSnapshot class name to use if multiple exist in the file |
93+
94+
### Returned Messages
95+
96+
**Message 1 — User role**:
97+
98+
```none
99+
Please review the Entity Framework Core database schema defined in: {path}{contextName_clause}
100+
101+
Steps:
102+
1. Call `get_erd` with path="{path}"{context_arg} to generate the Entity Relationship Diagram.
103+
2. Analyze the ERD and provide:
104+
- An overview of the entity model (count, main entities, key relationships)
105+
- Assessment of relationship cardinality (one-to-many, many-to-many, etc.)
106+
- Any potential design issues: missing indexes, over-normalized or under-normalized tables, overly wide entities
107+
- Naming consistency review
108+
- Recommendations for improving the schema design
109+
```
110+
111+
Where `{contextName_clause}` = `" (using context: {contextName})"` if contextName is provided, else empty.
112+
Where `{context_arg}` = `, contextName="{contextName}"` if contextName is provided, else empty.
113+
114+
**Message 2 — Assistant role**:
115+
116+
```none
117+
I'll review the Entity Framework Core database schema and identify design issues and improvements.
118+
```
119+
120+
---
121+
122+
## Prompt: `class_structure_review`
123+
124+
**Description**: Guides an LLM through reviewing C# class hierarchies, inheritance patterns, and overall design structure.
125+
126+
### Arguments
127+
128+
| Name | Type | Required | Description |
129+
|------|------|----------|-----------------------------------------------------|
130+
| `path` | string | yes | Absolute path to a .cs file or directory to analyze |
131+
132+
### Returned Messages
133+
134+
**Message 1 — User role**:
135+
136+
```none
137+
Please review the class structure and design of the C# code at: {path}
138+
139+
Steps:
140+
1. Call `get_class_diagram` with path="{path}" and options including includeInheritance=true and includeDependencies=true to generate the class diagram.
141+
2. Analyze the diagram and provide:
142+
- Overview of the class hierarchy (depth, breadth, key types)
143+
- Assessment of inheritance vs. composition usage
144+
- Identification of potential design issues: god classes, deep inheritance chains, circular dependencies between classes
145+
- Interface segregation: are interfaces focused and cohesive?
146+
- Recommendations to improve the design (e.g., extract interfaces, favor composition)
147+
```
148+
149+
**Message 2 — Assistant role**:
150+
151+
```none
152+
I'll review the class structure and design patterns in the provided C# code.
153+
```
154+
155+
---
156+
157+
## Implementation Notes
158+
159+
- Class: `ProjGraphPrompts` in `src/ProjGraph.Mcp/ProjGraphPrompts.cs`
160+
- Attribute: `[McpServerPromptType]` on class, `[McpServerPrompt]` on each method
161+
- Return type: `IEnumerable<ChatMessage>` (from `Microsoft.Extensions.AI`)
162+
- All methods are `static` (no DI dependencies — prompts are pure functions of their arguments)
163+
- Parameter binding: `string path`, `string? contextName = null`, `string topN = "5"` (MCP prompt args are always strings)
164+
- Registration: `.WithPrompts<ProjGraphPrompts>()` in `Program.cs`
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# MCP Resources Contract
2+
3+
**Date**: 2026-03-10
4+
**Branch**: `012-mcp-integration-primitives`
5+
**Registration**: `builder.Services.AddMcpServer().WithResources<ProjGraphResources>()`
6+
**SDK type**: `[McpServerResourceType]` / `[McpServerResource]`
7+
8+
---
9+
10+
## Static Resource: `projgraph://welcome`
11+
12+
**URI**: `projgraph://welcome`
13+
**Name**: `projgraph-welcome`
14+
**MIME Type**: `text/plain`
15+
**Description**: Static welcome resource describing ProjGraph's capabilities and available tools.
16+
**Lifecycle**: Always present (registered at startup, never evicted).
17+
18+
### Content
19+
20+
```none
21+
Welcome to ProjGraph MCP Server
22+
23+
ProjGraph analyzes .NET solution architectures and generates Mermaid diagrams and metrics.
24+
25+
Available Tools:
26+
─────────────────────────────────────────────────────────────────────────────
27+
• get_project_graph — Dependency graph for a .sln, .slnx, or .csproj file
28+
• get_class_diagram — Class diagram for a .cs file or directory
29+
• get_erd — Entity Relationship Diagram from an EF Core DbContext or ModelSnapshot
30+
• get_project_stats — Architectural metrics (dependency depth, hotspots, cycles)
31+
32+
Available Prompts (guided workflows):
33+
─────────────────────────────────────────────────────────────────────────────
34+
• architecture_review — Comprehensive architecture review of a .NET solution
35+
• dependency_analysis — Hotspot and cycle analysis for a solution
36+
• database_schema_review — EF Core schema design review
37+
• class_structure_review — Class hierarchy and design pattern review
38+
39+
Generated Diagrams (session cache):
40+
─────────────────────────────────────────────────────────────────────────────
41+
Diagrams generated during this session are cached as resources under
42+
projgraph://diagrams/{type}/{encodedPath} and appear in listResources.
43+
```
44+
45+
---
46+
47+
## Dynamic Resource Template: `projgraph://diagrams/{type}/{path}`
48+
49+
**URI Template**: `projgraph://diagrams/{type}/{path}`
50+
**Name**: `projgraph-diagram`
51+
**MIME Type**: Varies per entry (`text/plain` for Mermaid, `application/json` for stats)
52+
**Description**: Cached diagram output from a previous tool invocation.
53+
**Lifecycle**: Session-scoped. Created when a tool generates output. Evicted (LRU) when cache reaches 50 entries. Cleared on server restart.
54+
55+
### URI Template Parameters
56+
57+
| Parameter | Description | Example |
58+
|-----------|-------------|------------------------------------|
59+
| `type` | Analysis type | `graph`, `class`, `erd`, `stats` |
60+
| `path` | URL-encoded absolute file path | `D%3A%5CProjects%5CMySolution.slnx` |
61+
62+
### Concrete URI Examples
63+
64+
| Tool | Example URI |
65+
|------|----------------------------------------------------------------|
66+
| `get_project_graph` | `projgraph://diagrams/graph/D%3A%5CProjects%5CMySolution.slnx` |
67+
| `get_class_diagram` | `projgraph://diagrams/class/D%3A%5CSrc%5CMyClass.cs` |
68+
| `get_erd` | `projgraph://diagrams/erd/D%3A%5CSrc%5CMyDbContext.cs` |
69+
| `get_project_stats` | `projgraph://diagrams/stats/D%3A%5CProjects%5CMySolution.slnx` |
70+
71+
### ResourceContents Type
72+
73+
When read, each resource returns a `TextResourceContents` with:
74+
75+
- `Uri`: exact resource URI
76+
- `MimeType`: `text/plain` or `application/json`
77+
- `Text`: full diagram or JSON content
78+
79+
### Metadata Annotation
80+
81+
Each concrete resource registered in `ResourceCollection` includes:
82+
83+
- `Name`: `"{type} — {filename}"` (e.g., `"graph — MySolution.slnx"`)
84+
- `Description`: `"Generated {timestamp} from {sourcePath}"`
85+
- `MimeType`: as above
86+
87+
---
88+
89+
## Resource Listing Behavior
90+
91+
| MCP Method | Returns | Includes |
92+
|------------|---------|-------------------------------------------------------------------|
93+
| `resources/list` | Concrete resources | Welcome resource + all currently cached diagram resources |
94+
| `resources/templates/list` | Template resources | The `projgraph://diagrams/{type}/{path}` template |
95+
| `resources/read` | Content | Any exact URI in `listResources`; or any URI matching the template |
96+
97+
---
98+
99+
## Notification Behavior
100+
101+
| Event | Notification Sent |
102+
|-------|----------------------------------------------------------------------------------------------------|
103+
| New diagram resource created | `notifications/resources/list_changed` (automatic via `ResourceCollection.Add()`) |
104+
| Existing diagram resource updated | `notifications/resources/updated` with `Uri` parameter (sent explicitly by `DiagramResourceCache`) |
105+
| LRU eviction of a resource | `notifications/resources/list_changed` (automatic via `ResourceCollection.Remove()`) |
106+
| Server restart | No notification — client must re-list on reconnect |
107+
108+
---
109+
110+
## Cache Limits
111+
112+
| Parameter | Value |
113+
|-----------|--------------------------------------------------|
114+
| Max entries | 50 |
115+
| Eviction policy | LRU (least recently used) |
116+
| Eviction granularity | One entry at a time (evict before inserting new) |
117+
| Thread safety | `Lock` on all operations |
118+
119+
---
120+
121+
## Implementation Notes
122+
123+
- Class: `ProjGraphResources` in `src/ProjGraph.Mcp/ProjGraphResources.cs`
124+
- Services: `DiagramResourceCache` singleton in `src/ProjGraph.Mcp/DiagramResourceCache.cs`
125+
- `ProjGraphResources` has `[McpServerResourceType]`; methods have `[McpServerResource]`
126+
- Welcome resource: `static string GetWelcome()` — no DI
127+
- Template read handler: instance method with `DiagramResourceCache` injected via constructor
128+
- `DiagramResourceCache` injects `IOptions<McpServerOptions>` to access `ResourceCollection`
129+
- `ProjGraphTools` is updated to call `DiagramResourceCache.Store(...)` after generating each output
130+
- `McpServer server` parameter in tool methods is used to send `resources/updated` notification

0 commit comments

Comments
 (0)